glusterfs 4.0.1 api 分析笔记1

一般来说,我们写个客户端程序大概的样子是这样的:

/* glfs_example.c */ // gcc -o glfs_example glfs_example.c -L /usr/lib64/ -lgfapi -I /usr/include/glusterfs/ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include "api/glfs.h" #include "api/glfs-handles.h" #include <string.h> #include <time.h> int main (int argc, char *argv[]) { glfs_t *fs2 = NULL; int ret = 0; glfs_fd_t *fd = NULL; glfs_fd_t *fd2 = NULL; char readbuf[32]; char writebuf[32]; char *filename = "/filename2"; if (argc != 3) { printf ("Expect following args\n\t%s <volname> <hostname>\n", argv[0]); return -1; } /* 初始化gluster环境 */ fs2 = glfs_new (argv[1]); if (!fs2) { fprintf (stderr, "glfs_new: returned NULL\n"); return 1; } ret = glfs_set_volfile_server (fs2, "tcp", argv[2], 24007); ret = glfs_set_logging (fs2, "/dev/stderr", 1); ret = glfs_init (fs2); fprintf (stderr, "glfs_init: returned %d\n", ret); /* 进行libgfapi函数调用 */ fd = glfs_creat (fs2, filename, O_RDWR, 0644); fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); fd2 = glfs_open (fs2, filename, O_RDWR); fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); sprintf (writebuf, "hi there\n"); ret = glfs_write (fd, writebuf, 32, 0); glfs_lseek (fd2, 0, SEEK_SET); ret = glfs_read (fd2, readbuf, 32, 0); printf ("read %d, %s", ret, readbuf); glfs_close (fd); glfs_close (fd2); /* Gluster环境释放 */ glfs_fini (fs2); return ret; }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpdyyj.html