Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / qa / libceph / trivial_libceph.c
1 #define _FILE_OFFSET_BITS 64
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/statvfs.h>
9 #include "../../src/include/cephfs/libcephfs.h"
10
11 #define MB64 (1<<26)
12
13 int main(int argc, const char **argv)
14 {
15         struct ceph_mount_info *cmount;
16         int ret, fd, len;
17         char buf[1024];
18
19         if (argc < 3) {
20                 fprintf(stderr, "usage: ./%s <conf> <file>\n", argv[0]);
21                 exit(1);
22         }
23
24         ret = ceph_create(&cmount, NULL);
25         if (ret) {
26                 fprintf(stderr, "ceph_create=%d\n", ret);
27                 exit(1);
28         }
29
30         ret = ceph_conf_read_file(cmount, argv[1]);
31         if (ret) {
32                 fprintf(stderr, "ceph_conf_read_file=%d\n", ret);
33                 exit(1);
34         }
35
36         ret = ceph_conf_parse_argv(cmount, argc, argv);
37         if (ret) {
38                 fprintf(stderr, "ceph_conf_parse_argv=%d\n", ret);
39                 exit(1);
40         }
41
42         ret = ceph_mount(cmount, NULL);
43         if (ret) {
44                 fprintf(stderr, "ceph_mount=%d\n", ret);
45                 exit(1);
46         }
47
48         ret = ceph_chdir(cmount, "/");
49         if (ret) {
50                 fprintf(stderr, "ceph_chdir=%d\n", ret);
51                 exit(1);
52         }
53
54         fd = ceph_open(cmount, argv[2], O_CREAT|O_TRUNC|O_RDWR, 0777); 
55         if (fd < 0) {
56                 fprintf(stderr, "ceph_open=%d\n", fd);
57                 exit(1);
58         }
59
60         memset(buf, 'a', sizeof(buf));
61
62         len = ceph_write(cmount, fd, buf, sizeof(buf), 0);
63
64         fprintf(stdout, "wrote %d bytes\n", len);
65
66         ceph_shutdown(cmount);
67
68         return 0;
69 }