|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <fcntl.h>
|
|
#include <cephfs/libcephfs.h>
|
|
|
|
int main(void) {
|
|
int failed = 0;
|
|
int fd;
|
|
int ret;
|
|
char *path = "/test_file";
|
|
struct ceph_mount_info *mount;
|
|
|
|
fprintf(stdout, "Testing %s ...\n", path);
|
|
|
|
fprintf(stdout, "Setting up ...\n");
|
|
ret = ceph_create(&mount, NULL);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_create failed\n");
|
|
failed = 1;
|
|
goto done_not_created;
|
|
}
|
|
ret = ceph_conf_read_file(mount, NULL);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_conf_read_file failed\n");
|
|
failed = 1;
|
|
goto done_not_mounted;
|
|
}
|
|
ret = ceph_mount(mount, NULL);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_mount failed\n");
|
|
failed = 1;
|
|
goto done_not_mounted;
|
|
}
|
|
|
|
fprintf(stdout, "Create file ...\n");
|
|
fd = ceph_open(mount, path, O_CREAT|O_WRONLY|O_TRUNC, 0644);
|
|
if (fd < 0) {
|
|
fprintf(stderr, "ceph_open failed\n");
|
|
failed = 1;
|
|
goto done;
|
|
}
|
|
ret = ceph_close(mount, fd);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_close failed\n");
|
|
failed = 1;
|
|
goto done;
|
|
}
|
|
|
|
fprintf(stdout, "Testing truncate and write ...\n");
|
|
fd = ceph_open(mount, path, O_RDONLY, 0644);
|
|
if (fd < 0) {
|
|
fprintf(stderr, "ceph_open failed\n");
|
|
failed = 1;
|
|
goto done;
|
|
}
|
|
ret = ceph_ftruncate(mount, fd, 4096);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_ftruncate failed\n");
|
|
failed = 1;
|
|
goto close;
|
|
}
|
|
ret = ceph_write(mount, fd, "this is just a test.", 20, 0);
|
|
if (ret < 0) {
|
|
fprintf(stderr, "ceph_write failed\n");
|
|
failed = 1;
|
|
goto close;
|
|
}
|
|
close:
|
|
ret = ceph_close(mount, fd);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_close failed\n");
|
|
failed = 1;
|
|
goto done;
|
|
}
|
|
|
|
done:
|
|
ret = ceph_unmount(mount);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_unmount failed\n");
|
|
failed = 1;
|
|
}
|
|
done_not_mounted:
|
|
ret = ceph_release(mount);
|
|
if (ret != 0) {
|
|
fprintf(stderr, "ceph_release failed\n");
|
|
failed = 1;
|
|
}
|
|
done_not_created:
|
|
return failed;
|
|
}
|