diff options
490 files changed, 426792 insertions, 439790 deletions
diff --git a/api/examples/glfsxmp.c b/api/examples/glfsxmp.c index 9bfb1d2..9d96eea 100644 --- a/api/examples/glfsxmp.c +++ b/api/examples/glfsxmp.c @@ -6,1593 +6,1633 @@ #include <string.h> #include <time.h> - int -test_dirops (glfs_t *fs) +test_dirops(glfs_t *fs) { - glfs_fd_t *fd = NULL; - char buf[512]; - struct dirent *entry = NULL; - - fd = glfs_opendir (fs, "/"); - if (!fd) { - fprintf (stderr, "/: %s\n", strerror (errno)); - return -1; - } - - fprintf (stderr, "Entries:\n"); - while (glfs_readdir_r (fd, (struct dirent *)buf, &entry), entry) { - fprintf (stderr, "%s: %lu\n", entry->d_name, glfs_telldir (fd)); - } - - glfs_closedir (fd); - return 0; + glfs_fd_t *fd = NULL; + char buf[512]; + struct dirent *entry = NULL; + + fd = glfs_opendir(fs, "/"); + if (!fd) { + fprintf(stderr, "/: %s\n", strerror(errno)); + return -1; + } + + fprintf(stderr, "Entries:\n"); + while (glfs_readdir_r(fd, (struct dirent *)buf, &entry), entry) { + fprintf(stderr, "%s: %lu\n", entry->d_name, glfs_telldir(fd)); + } + + glfs_closedir(fd); + return 0; } - int -test_xattr (glfs_t *fs) +test_xattr(glfs_t *fs) { - char *filename = "/filename2"; - char buf[512]; - char *ptr; - int ret; - - ret = glfs_setxattr (fs, filename, "user.testkey", "testval", 8, 0); - fprintf (stderr, "setxattr(%s): %d (%s)\n", filename, ret, - strerror (errno)); - - ret = glfs_setxattr (fs, filename, "user.testkey2", "testval", 8, 0); - fprintf (stderr, "setxattr(%s): %d (%s)\n", filename, ret, - strerror (errno)); - - ret = glfs_listxattr (fs, filename, buf, 512); - fprintf (stderr, "listxattr(%s): %d (%s)\n", filename, ret, - strerror (errno)); - if (ret < 0) - return -1; - - for (ptr = buf; ptr < buf + ret; ptr++) { - printf ("key=%s\n", ptr); - ptr += strlen (ptr); - } - - return 0; -} - - -int -test_chdir (glfs_t *fs) -{ - int ret = -1; - char *topdir = "/topdir"; - char *linkdir = "/linkdir"; - char *subdir = "./subdir"; - char *respath = NULL; - char pathbuf[4096]; - - ret = glfs_mkdir (fs, topdir, 0755); - if (ret) { - fprintf (stderr, "mkdir(%s): %s\n", topdir, strerror (errno)); - return -1; - } - - respath = glfs_getcwd (fs, pathbuf, 4096); - fprintf (stdout, "getcwd() = %s\n", respath); - - ret = glfs_symlink (fs, topdir, linkdir); - if (ret) { - fprintf (stderr, "symlink(%s, %s): %s\n", topdir, linkdir, strerror (errno)); - return -1; - } + char *filename = "/filename2"; + char buf[512]; + char *ptr; + int ret; - ret = glfs_chdir (fs, linkdir); - if (ret) { - fprintf (stderr, "chdir(%s): %s\n", linkdir, strerror (errno)); - return -1; - } + ret = glfs_setxattr(fs, filename, "user.testkey", "testval", 8, 0); + fprintf(stderr, "setxattr(%s): %d (%s)\n", filename, ret, strerror(errno)); - respath = glfs_getcwd (fs, pathbuf, 4096); - fprintf (stdout, "getcwd() = %s\n", respath); + ret = glfs_setxattr(fs, filename, "user.testkey2", "testval", 8, 0); + fprintf(stderr, "setxattr(%s): %d (%s)\n", filename, ret, strerror(errno)); - respath = glfs_realpath (fs, subdir, pathbuf); - if (respath) { - fprintf (stderr, "realpath(%s) worked unexpectedly: %s\n", subdir, respath); - return -1; - } + ret = glfs_listxattr(fs, filename, buf, 512); + fprintf(stderr, "listxattr(%s): %d (%s)\n", filename, ret, strerror(errno)); + if (ret < 0) + return -1; - ret = glfs_mkdir (fs, subdir, 0755); - if (ret) { - fprintf (stderr, "mkdir(%s): %s\n", subdir, strerror (errno)); - return -1; - } - - respath = glfs_realpath (fs, subdir, pathbuf); - if (!respath) { - fprintf (stderr, "realpath(%s): %s\n", subdir, strerror (errno)); - } else { - fprintf (stdout, "realpath(%s) = %s\n", subdir, respath); - } + for (ptr = buf; ptr < buf + ret; ptr++) { + printf("key=%s\n", ptr); + ptr += strlen(ptr); + } - ret = glfs_chdir (fs, subdir); - if (ret) { - fprintf (stderr, "chdir(%s): %s\n", subdir, strerror (errno)); - return -1; - } - - respath = glfs_getcwd (fs, pathbuf, 4096); - fprintf (stdout, "getcwd() = %s\n", respath); - - respath = glfs_realpath (fs, "/linkdir/subdir", pathbuf); - if (!respath) { - fprintf (stderr, "realpath(/linkdir/subdir): %s\n", strerror (errno)); - } else { - fprintf (stdout, "realpath(/linkdir/subdir) = %s\n", respath); - } + return 0; +} - return 0; +int +test_chdir(glfs_t *fs) +{ + int ret = -1; + char *topdir = "/topdir"; + char *linkdir = "/linkdir"; + char *subdir = "./subdir"; + char *respath = NULL; + char pathbuf[4096]; + + ret = glfs_mkdir(fs, topdir, 0755); + if (ret) { + fprintf(stderr, "mkdir(%s): %s\n", topdir, strerror(errno)); + return -1; + } + + respath = glfs_getcwd(fs, pathbuf, 4096); + fprintf(stdout, "getcwd() = %s\n", respath); + + ret = glfs_symlink(fs, topdir, linkdir); + if (ret) { + fprintf(stderr, "symlink(%s, %s): %s\n", topdir, linkdir, + strerror(errno)); + return -1; + } + + ret = glfs_chdir(fs, linkdir); + if (ret) { + fprintf(stderr, "chdir(%s): %s\n", linkdir, strerror(errno)); + return -1; + } + + respath = glfs_getcwd(fs, pathbuf, 4096); + fprintf(stdout, "getcwd() = %s\n", respath); + + respath = glfs_realpath(fs, subdir, pathbuf); + if (respath) { + fprintf(stderr, "realpath(%s) worked unexpectedly: %s\n", subdir, + respath); + return -1; + } + + ret = glfs_mkdir(fs, subdir, 0755); + if (ret) { + fprintf(stderr, "mkdir(%s): %s\n", subdir, strerror(errno)); + return -1; + } + + respath = glfs_realpath(fs, subdir, pathbuf); + if (!respath) { + fprintf(stderr, "realpath(%s): %s\n", subdir, strerror(errno)); + } else { + fprintf(stdout, "realpath(%s) = %s\n", subdir, respath); + } + + ret = glfs_chdir(fs, subdir); + if (ret) { + fprintf(stderr, "chdir(%s): %s\n", subdir, strerror(errno)); + return -1; + } + + respath = glfs_getcwd(fs, pathbuf, 4096); + fprintf(stdout, "getcwd() = %s\n", respath); + + respath = glfs_realpath(fs, "/linkdir/subdir", pathbuf); + if (!respath) { + fprintf(stderr, "realpath(/linkdir/subdir): %s\n", strerror(errno)); + } else { + fprintf(stdout, "realpath(/linkdir/subdir) = %s\n", respath); + } + + return 0; } #ifdef DEBUG static void -peek_stat (struct stat *sb) +peek_stat(struct stat *sb) { - printf ("Dumping stat information:\n"); - printf ("File type: "); - - switch (sb->st_mode & S_IFMT) { - case S_IFBLK: printf ("block device\n"); break; - case S_IFCHR: printf ("character device\n"); break; - case S_IFDIR: printf ("directory\n"); break; - case S_IFIFO: printf ("FIFO/pipe\n"); break; - case S_IFLNK: printf ("symlink\n"); break; - case S_IFREG: printf ("regular file\n"); break; - case S_IFSOCK: printf ("socket\n"); break; - default: printf ("unknown?\n"); break; - } - - printf ("I-node number: %ld\n", (long) sb->st_ino); - - printf ("Mode: %lo (octal)\n", - (unsigned long) sb->st_mode); - - printf ("Link count: %ld\n", (long) sb->st_nlink); - printf ("Ownership: UID=%ld GID=%ld\n", - (long) sb->st_uid, (long) sb->st_gid); - - printf ("Preferred I/O block size: %ld bytes\n", - (long) sb->st_blksize); - printf ("File size: %lld bytes\n", - (long long) sb->st_size); - printf ("Blocks allocated: %lld\n", - (long long) sb->st_blocks); - - printf ("Last status change: %s", ctime(&sb->st_ctime)); - printf ("Last file access: %s", ctime(&sb->st_atime)); - printf ("Last file modification: %s", ctime(&sb->st_mtime)); - - return; + printf("Dumping stat information:\n"); + printf("File type: "); + + switch (sb->st_mode & S_IFMT) { + case S_IFBLK: + printf("block device\n"); + break; + case S_IFCHR: + printf("character device\n"); + break; + case S_IFDIR: + printf("directory\n"); + break; + case S_IFIFO: + printf("FIFO/pipe\n"); + break; + case S_IFLNK: + printf("symlink\n"); + break; + case S_IFREG: + printf("regular file\n"); + break; + case S_IFSOCK: + printf("socket\n"); + break; + default: + printf("unknown?\n"); + break; + } + + printf("I-node number: %ld\n", (long)sb->st_ino); + + printf("Mode: %lo (octal)\n", + (unsigned long)sb->st_mode); + + printf("Link count: %ld\n", (long)sb->st_nlink); + printf("Ownership: UID=%ld GID=%ld\n", (long)sb->st_uid, + (long)sb->st_gid); + + printf("Preferred I/O block size: %ld bytes\n", (long)sb->st_blksize); + printf("File size: %lld bytes\n", (long long)sb->st_size); + printf("Blocks allocated: %lld\n", (long long)sb->st_blocks); + + printf("Last status change: %s", ctime(&sb->st_ctime)); + printf("Last file access: %s", ctime(&sb->st_atime)); + printf("Last file modification: %s", ctime(&sb->st_mtime)); + + return; } static void -peek_handle (unsigned char *glid) +peek_handle(unsigned char *glid) { - int i; + int i; - for (i = 0; i < GFAPI_HANDLE_LENGTH; i++) - { - printf (":%02x:", glid[i]); - } - printf ("\n"); + for (i = 0; i < GFAPI_HANDLE_LENGTH; i++) { + printf(":%02x:", glid[i]); + } + printf("\n"); } -#else /* DEBUG */ +#else /* DEBUG */ static void -peek_stat (struct stat *sb) +peek_stat(struct stat *sb) { - return; + return; } static void -peek_handle (unsigned char *id) +peek_handle(unsigned char *id) { - return; + return; } #endif /* DEBUG */ -glfs_t *fs = NULL; -char *full_parent_name = "/testdir", *parent_name = "testdir"; +glfs_t *fs = NULL; +char *full_parent_name = "/testdir", *parent_name = "testdir"; void -test_h_unlink (void) +test_h_unlink(void) { - char *my_dir = "unlinkdir"; - char *my_file = "file.txt"; - char *my_subdir = "dir1"; - struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL, - *subdir = NULL, *subleaf = NULL; - struct stat sb; - int ret; - - printf ("glfs_h_unlink tests: In Progress\n"); - - /* Prepare tests */ - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dir = glfs_h_mkdir (fs, parent, my_dir, 0644, &sb); - if (dir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - leaf = glfs_h_creat (fs, dir, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - subdir = glfs_h_mkdir (fs, dir, my_subdir, 0644, &sb); - if (subdir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_subdir, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - subleaf = glfs_h_creat (fs, subdir, my_file, O_CREAT, 0644, &sb); - if (subleaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, subdir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink non empty directory */ - ret = glfs_h_unlink (fs, dir, my_subdir); - if ((ret && errno != ENOTEMPTY) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: it is non empty: %s\n", - my_subdir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink regular file */ - ret = glfs_h_unlink (fs, subdir, my_file); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_file, subdir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink directory */ - ret = glfs_h_unlink (fs, dir, my_subdir); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_subdir, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink regular file */ - ret = glfs_h_unlink (fs, dir, my_file); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink non-existent regular file */ - ret = glfs_h_unlink (fs, dir, my_file); - if ((ret && errno != ENOENT) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking non-existent %s: invalid errno ,%d, %s\n", - my_file, ret, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink non-existent directory */ - ret = glfs_h_unlink (fs, dir, my_subdir); - if ((ret && errno != ENOENT) || (ret == 0)) { - fprintf (stderr, "glfs_h_unlink: error unlinking non-existent %s: invalid errno ,%d, %s\n", - my_subdir, ret, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - /* unlink directory */ - ret = glfs_h_unlink (fs, parent, my_dir); - if (ret) { - fprintf (stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - - printf ("glfs_h_unlink tests: PASSED\n"); + char *my_dir = "unlinkdir"; + char *my_file = "file.txt"; + char *my_subdir = "dir1"; + struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL, + *subdir = NULL, *subleaf = NULL; + struct stat sb; + int ret; + + printf("glfs_h_unlink tests: In Progress\n"); + + /* Prepare tests */ + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dir = glfs_h_mkdir(fs, parent, my_dir, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, parent, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + leaf = glfs_h_creat(fs, dir, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + subdir = glfs_h_mkdir(fs, dir, my_subdir, 0644, &sb); + if (subdir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_subdir, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + subleaf = glfs_h_creat(fs, subdir, my_file, O_CREAT, 0644, &sb); + if (subleaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, subdir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink non empty directory */ + ret = glfs_h_unlink(fs, dir, my_subdir); + if ((ret && errno != ENOTEMPTY) || (ret == 0)) { + fprintf(stderr, + "glfs_h_unlink: error unlinking %s: it is non empty: %s\n", + my_subdir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink regular file */ + ret = glfs_h_unlink(fs, subdir, my_file); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_file, subdir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink directory */ + ret = glfs_h_unlink(fs, dir, my_subdir); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_subdir, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink regular file */ + ret = glfs_h_unlink(fs, dir, my_file); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink non-existent regular file */ + ret = glfs_h_unlink(fs, dir, my_file); + if ((ret && errno != ENOENT) || (ret == 0)) { + fprintf(stderr, + "glfs_h_unlink: error unlinking non-existent %s: invalid errno " + ",%d, %s\n", + my_file, ret, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink non-existent directory */ + ret = glfs_h_unlink(fs, dir, my_subdir); + if ((ret && errno != ENOENT) || (ret == 0)) { + fprintf(stderr, + "glfs_h_unlink: error unlinking non-existent %s: invalid " + "errno ,%d, %s\n", + my_subdir, ret, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + /* unlink directory */ + ret = glfs_h_unlink(fs, parent, my_dir); + if (ret) { + fprintf(stderr, "glfs_h_unlink: error unlinking %s: from (%p),%s\n", + my_dir, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + + printf("glfs_h_unlink tests: PASSED\n"); out: - if (dir) - glfs_h_close (dir); - if (leaf) - glfs_h_close (leaf); - if (subdir) - glfs_h_close (subdir); - if (subleaf) - glfs_h_close (subleaf); - if (parent) - glfs_h_close (parent); - - return; + if (dir) + glfs_h_close(dir); + if (leaf) + glfs_h_close(leaf); + if (subdir) + glfs_h_close(subdir); + if (subleaf) + glfs_h_close(subleaf); + if (parent) + glfs_h_close(parent); + + return; } void -test_h_getsetattrs (void) +test_h_getsetattrs(void) { - char *my_dir = "attrdir"; - char *my_file = "attrfile.txt"; - struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; - struct stat sb, retsb; - int ret, valid; - struct timespec timestamp; - - printf("glfs_h_getattrs and setattrs tests: In Progress\n"); - - /* Prepare tests */ - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dir = glfs_h_mkdir (fs, parent, my_dir, 0644, &sb); - if (dir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, dir, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_unlink tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - ret = glfs_h_getattrs (fs, dir, &retsb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - peek_stat (&retsb); - /* TODO: Compare stat information */ - - retsb.st_mode = 00666; - retsb.st_uid = 1000; - retsb.st_gid = 1001; - ret = clock_gettime (CLOCK_REALTIME, ×tamp); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - retsb.st_atim = timestamp; - retsb.st_mtim = timestamp; - valid = GFAPI_SET_ATTR_MODE | GFAPI_SET_ATTR_UID | GFAPI_SET_ATTR_GID | - GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME; - peek_stat (&retsb); - - ret = glfs_h_setattrs (fs, dir, &retsb, valid); - if (ret != 0) { - fprintf (stderr, "glfs_h_setattrs: error %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - memset(&retsb, 0, sizeof (struct stat)); - ret = glfs_h_stat (fs, dir, &retsb); - if (ret != 0) { - fprintf (stderr, "glfs_h_stat: error %s: from (%p),%s\n", - my_dir, dir, strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - peek_stat (&retsb); - - printf ("glfs_h_getattrs and setattrs tests: PASSED\n"); + char *my_dir = "attrdir"; + char *my_file = "attrfile.txt"; + struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; + struct stat sb, retsb; + int ret, valid; + struct timespec timestamp; + + printf("glfs_h_getattrs and setattrs tests: In Progress\n"); + + /* Prepare tests */ + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dir = glfs_h_mkdir(fs, parent, my_dir, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, parent, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, dir, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_unlink tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + ret = glfs_h_getattrs(fs, dir, &retsb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error %s: from (%p),%s\n", my_dir, + dir, strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + peek_stat(&retsb); + /* TODO: Compare stat information */ + + retsb.st_mode = 00666; + retsb.st_uid = 1000; + retsb.st_gid = 1001; + ret = clock_gettime(CLOCK_REALTIME, ×tamp); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + retsb.st_atim = timestamp; + retsb.st_mtim = timestamp; + valid = GFAPI_SET_ATTR_MODE | GFAPI_SET_ATTR_UID | GFAPI_SET_ATTR_GID | + GFAPI_SET_ATTR_ATIME | GFAPI_SET_ATTR_MTIME; + peek_stat(&retsb); + + ret = glfs_h_setattrs(fs, dir, &retsb, valid); + if (ret != 0) { + fprintf(stderr, "glfs_h_setattrs: error %s: from (%p),%s\n", my_dir, + dir, strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + memset(&retsb, 0, sizeof(struct stat)); + ret = glfs_h_stat(fs, dir, &retsb); + if (ret != 0) { + fprintf(stderr, "glfs_h_stat: error %s: from (%p),%s\n", my_dir, dir, + strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + peek_stat(&retsb); + + printf("glfs_h_getattrs and setattrs tests: PASSED\n"); out: - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - if (dir) - glfs_h_close (dir); - - return; + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + if (dir) + glfs_h_close(dir); + + return; } void -test_h_truncate (void) +test_h_truncate(void) { - char *my_dir = "truncatedir"; - char *my_file = "file.txt"; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL; - struct stat sb; - glfs_fd_t *fd = NULL; - char buf[32]; - off_t offset = 0; - int ret = 0; - - printf("glfs_h_truncate tests: In Progress\n"); - - /* Prepare tests */ - root = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_mkdir (fs, root, my_dir, 0644, &sb); - if (parent == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, root, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - fd = glfs_h_open (fs, leaf, O_RDWR); - if (fd == NULL) { - fprintf (stderr, "glfs_h_open: error on open of %s: %s\n", - my_file, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - memcpy (buf, "abcdefghijklmnopqrstuvwxyz012345", 32); - ret = glfs_write (fd, buf, 32, 0); - - /* run tests */ - /* truncate lower */ - offset = 30; - ret = glfs_h_truncate (fs, leaf, offset); - if (ret != 0) { - fprintf (stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - ret = glfs_h_getattrs (fs, leaf, &sb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error for %s (%p),%s\n", - my_file, leaf, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - if (sb.st_size != offset) { - fprintf (stderr, "glfs_h_truncate: post size mismatch\n"); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - /* truncate higher */ - offset = 32; - ret = glfs_h_truncate (fs, leaf, offset); - if (ret != 0) { - fprintf (stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - ret = glfs_h_getattrs (fs, leaf, &sb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error for %s (%p),%s\n", - my_file, leaf, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - if (sb.st_size != offset) { - fprintf (stderr, "glfs_h_truncate: post size mismatch\n"); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - /* truncate equal */ - offset = 30; - ret = glfs_h_truncate (fs, leaf, offset); - if (ret != 0) { - fprintf (stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - ret = glfs_h_getattrs (fs, leaf, &sb); - if (ret != 0) { - fprintf (stderr, "glfs_h_getattrs: error for %s (%p),%s\n", - my_file, leaf, strerror (errno)); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - if (sb.st_size != offset) { - fprintf (stderr, "glfs_h_truncate: post size mismatch\n"); - printf ("glfs_h_truncate tests: FAILED\n"); - goto out; - } - - printf ("glfs_h_truncate tests: PASSED\n"); + char *my_dir = "truncatedir"; + char *my_file = "file.txt"; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL; + struct stat sb; + glfs_fd_t *fd = NULL; + char buf[32]; + off_t offset = 0; + int ret = 0; + + printf("glfs_h_truncate tests: In Progress\n"); + + /* Prepare tests */ + root = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_mkdir(fs, root, my_dir, 0644, &sb); + if (parent == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, root, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + fd = glfs_h_open(fs, leaf, O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_h_open: error on open of %s: %s\n", my_file, + strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + memcpy(buf, "abcdefghijklmnopqrstuvwxyz012345", 32); + ret = glfs_write(fd, buf, 32, 0); + + /* run tests */ + /* truncate lower */ + offset = 30; + ret = glfs_h_truncate(fs, leaf, offset); + if (ret != 0) { + fprintf(stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + ret = glfs_h_getattrs(fs, leaf, &sb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error for %s (%p),%s\n", my_file, + leaf, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + if (sb.st_size != offset) { + fprintf(stderr, "glfs_h_truncate: post size mismatch\n"); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + /* truncate higher */ + offset = 32; + ret = glfs_h_truncate(fs, leaf, offset); + if (ret != 0) { + fprintf(stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + ret = glfs_h_getattrs(fs, leaf, &sb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error for %s (%p),%s\n", my_file, + leaf, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + if (sb.st_size != offset) { + fprintf(stderr, "glfs_h_truncate: post size mismatch\n"); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + /* truncate equal */ + offset = 30; + ret = glfs_h_truncate(fs, leaf, offset); + if (ret != 0) { + fprintf(stderr, "glfs_h_truncate: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + ret = glfs_h_getattrs(fs, leaf, &sb); + if (ret != 0) { + fprintf(stderr, "glfs_h_getattrs: error for %s (%p),%s\n", my_file, + leaf, strerror(errno)); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + if (sb.st_size != offset) { + fprintf(stderr, "glfs_h_truncate: post size mismatch\n"); + printf("glfs_h_truncate tests: FAILED\n"); + goto out; + } + + printf("glfs_h_truncate tests: PASSED\n"); out: - if (fd) - glfs_close (fd); - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - - return; + if (fd) + glfs_close(fd); + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + + return; } void -test_h_links (void) +test_h_links(void) { - char *my_dir = "linkdir"; - char *my_file = "file.txt"; - char *my_symlnk = "slnk.txt"; - char *my_lnk = "lnk.txt"; - char *linksrc_dir = "dir1"; - char *linktgt_dir = "dir2"; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, - *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; - struct glfs_object *ln1 = NULL; - struct stat sb; - int ret; - char *buf = NULL; - - printf("glfs_h_link(s) tests: In Progress\n"); - - /* Prepare tests */ - root = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_mkdir (fs, root, my_dir, 0644, &sb); - if (parent == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, root, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirsrc = glfs_h_mkdir (fs, parent, linksrc_dir, 0644, &sb); - if (dirsrc == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - linksrc_dir, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirtgt = glfs_h_mkdir (fs, parent, linktgt_dir, 0644, &sb); - if (dirtgt == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - linktgt_dir, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dleaf = glfs_h_creat (fs, dirsrc, my_file, O_CREAT, 0644, &sb); - if (dleaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dirsrc, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* run tests */ - /* sym link: /testdir/linkdir/file.txt to ./slnk.txt */ - ln1 = glfs_h_symlink (fs, parent, my_symlnk, "./file.txt", &sb); - if (ln1 == NULL) { - fprintf (stderr, "glfs_h_symlink: error creating %s: from (%p),%s\n", - my_symlnk, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - buf = calloc (1024, sizeof(char)); - if (buf == NULL) { - fprintf (stderr, "Error allocating memory\n"); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - - ret = glfs_h_readlink (fs, ln1, buf, 1024); - if (ret <= 0) { - fprintf (stderr, "glfs_h_readlink: error reading %s: from (%p),%s\n", - my_symlnk, ln1, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - if (!(strncmp (buf, my_symlnk, strlen (my_symlnk)))) { - fprintf (stderr, "glfs_h_readlink: error mismatch in link name: actual %s: retrieved %s\n", - my_symlnk, buf); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - - /* link: /testdir/linkdir/file.txt to ./lnk.txt */ - ret = glfs_h_link (fs, leaf, parent, my_lnk); - if (ret != 0) { - fprintf (stderr, "glfs_h_link: error creating %s: from (%p),%s\n", - my_lnk, parent, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - /* TODO: Should write content to a file and read from the link */ - - /* link: /testdir/linkdir/dir1/file.txt to ../dir2/slnk.txt */ - ret = glfs_h_link (fs, dleaf, dirtgt, my_lnk); - if (ret != 0) { - fprintf (stderr, "glfs_h_link: error creating %s: from (%p),%s\n", - my_lnk, dirtgt, strerror (errno)); - printf ("glfs_h_link(s) tests: FAILED\n"); - goto out; - } - /* TODO: Should write content to a file and read from the link */ - - printf ("glfs_h_link(s) tests: PASSED\n"); + char *my_dir = "linkdir"; + char *my_file = "file.txt"; + char *my_symlnk = "slnk.txt"; + char *my_lnk = "lnk.txt"; + char *linksrc_dir = "dir1"; + char *linktgt_dir = "dir2"; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, + *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; + struct glfs_object *ln1 = NULL; + struct stat sb; + int ret; + char *buf = NULL; + + printf("glfs_h_link(s) tests: In Progress\n"); + + /* Prepare tests */ + root = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_mkdir(fs, root, my_dir, 0644, &sb); + if (parent == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, root, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirsrc = glfs_h_mkdir(fs, parent, linksrc_dir, 0644, &sb); + if (dirsrc == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + linksrc_dir, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirtgt = glfs_h_mkdir(fs, parent, linktgt_dir, 0644, &sb); + if (dirtgt == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + linktgt_dir, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dleaf = glfs_h_creat(fs, dirsrc, my_file, O_CREAT, 0644, &sb); + if (dleaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dirsrc, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* run tests */ + /* sym link: /testdir/linkdir/file.txt to ./slnk.txt */ + ln1 = glfs_h_symlink(fs, parent, my_symlnk, "./file.txt", &sb); + if (ln1 == NULL) { + fprintf(stderr, "glfs_h_symlink: error creating %s: from (%p),%s\n", + my_symlnk, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + buf = calloc(1024, sizeof(char)); + if (buf == NULL) { + fprintf(stderr, "Error allocating memory\n"); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + + ret = glfs_h_readlink(fs, ln1, buf, 1024); + if (ret <= 0) { + fprintf(stderr, "glfs_h_readlink: error reading %s: from (%p),%s\n", + my_symlnk, ln1, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + if (!(strncmp(buf, my_symlnk, strlen(my_symlnk)))) { + fprintf(stderr, + "glfs_h_readlink: error mismatch in link name: actual %s: " + "retrieved %s\n", + my_symlnk, buf); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + + /* link: /testdir/linkdir/file.txt to ./lnk.txt */ + ret = glfs_h_link(fs, leaf, parent, my_lnk); + if (ret != 0) { + fprintf(stderr, "glfs_h_link: error creating %s: from (%p),%s\n", + my_lnk, parent, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + /* TODO: Should write content to a file and read from the link */ + + /* link: /testdir/linkdir/dir1/file.txt to ../dir2/slnk.txt */ + ret = glfs_h_link(fs, dleaf, dirtgt, my_lnk); + if (ret != 0) { + fprintf(stderr, "glfs_h_link: error creating %s: from (%p),%s\n", + my_lnk, dirtgt, strerror(errno)); + printf("glfs_h_link(s) tests: FAILED\n"); + goto out; + } + /* TODO: Should write content to a file and read from the link */ + + printf("glfs_h_link(s) tests: PASSED\n"); out: - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - if (dirsrc) - glfs_h_close (dirsrc); - if (dirtgt) - glfs_h_close (dirtgt); - if (dleaf) - glfs_h_close (dleaf); - if (ln1) - glfs_h_close (ln1); - if (buf) - free (buf); - - return; + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + if (dirsrc) + glfs_h_close(dirsrc); + if (dirtgt) + glfs_h_close(dirtgt); + if (dleaf) + glfs_h_close(dleaf); + if (ln1) + glfs_h_close(ln1); + if (buf) + free(buf); + + return; } void -test_h_rename (void) +test_h_rename(void) { - char *my_dir = "renamedir"; - char *my_file = "file.txt"; - char *src_dir = "dir1"; - char *tgt_dir = "dir2"; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, - *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; - struct stat sb; - int ret; - - printf("glfs_h_rename tests: In Progress\n"); - - /* Prepare tests */ - root = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_mkdir (fs, root, my_dir, 0644, &sb); - if (parent == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, root, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, my_file, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, parent, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirsrc = glfs_h_mkdir (fs, parent, src_dir, 0644, &sb); - if (dirsrc == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - src_dir, parent, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dirtgt = glfs_h_mkdir (fs, parent, tgt_dir, 0644, &sb); - if (dirtgt == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - tgt_dir, parent, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - dleaf = glfs_h_creat (fs, dirsrc, my_file, O_CREAT, 0644, &sb); - if (dleaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dirsrc, strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* run tests */ - /* Rename file.txt -> file1.txt */ - ret = glfs_h_rename (fs, parent, "file.txt", parent, "file1.txt"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "file.txt", "file1.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir1/file.txt -> file.txt */ - ret = glfs_h_rename (fs, dirsrc, "file.txt", parent, "file.txt"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s/%s to %s (%s)\n", - src_dir, "file.txt", "file.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename file1.txt -> file.txt (exists) */ - ret = glfs_h_rename (fs, parent, "file1.txt", parent, "file.txt"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "file.txt", "file.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir1 -> dir3 */ - ret = glfs_h_rename (fs, parent, "dir1", parent, "dir3"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "dir1", "dir3", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir2 ->dir3 (exists) */ - ret = glfs_h_rename (fs, parent, "dir2", parent, "dir3"); - if (ret != 0) { - fprintf (stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", - "dir2", "dir3", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename file.txt -> dir3 (fail) */ - ret = glfs_h_rename (fs, parent, "file.txt", parent, "dir3"); - if (ret == 0) { - fprintf (stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", - "file.txt", "dir3", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - /* rename dir3 -> file.txt (fail) */ - ret = glfs_h_rename (fs, parent, "dir3", parent, "file.txt"); - if (ret == 0) { - fprintf (stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", - "dir3", "file.txt", strerror (errno)); - printf ("glfs_h_rename tests: FAILED\n"); - goto out; - } - - printf ("glfs_h_rename tests: PASSED\n"); + char *my_dir = "renamedir"; + char *my_file = "file.txt"; + char *src_dir = "dir1"; + char *tgt_dir = "dir2"; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, + *dirsrc = NULL, *dirtgt = NULL, *dleaf = NULL; + struct stat sb; + int ret; + + printf("glfs_h_rename tests: In Progress\n"); + + /* Prepare tests */ + root = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_mkdir(fs, root, my_dir, 0644, &sb); + if (parent == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, root, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, my_file, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, parent, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirsrc = glfs_h_mkdir(fs, parent, src_dir, 0644, &sb); + if (dirsrc == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + src_dir, parent, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dirtgt = glfs_h_mkdir(fs, parent, tgt_dir, 0644, &sb); + if (dirtgt == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + tgt_dir, parent, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + dleaf = glfs_h_creat(fs, dirsrc, my_file, O_CREAT, 0644, &sb); + if (dleaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dirsrc, strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* run tests */ + /* Rename file.txt -> file1.txt */ + ret = glfs_h_rename(fs, parent, "file.txt", parent, "file1.txt"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", + "file.txt", "file1.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir1/file.txt -> file.txt */ + ret = glfs_h_rename(fs, dirsrc, "file.txt", parent, "file.txt"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s/%s to %s (%s)\n", + src_dir, "file.txt", "file.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename file1.txt -> file.txt (exists) */ + ret = glfs_h_rename(fs, parent, "file1.txt", parent, "file.txt"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", + "file.txt", "file.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir1 -> dir3 */ + ret = glfs_h_rename(fs, parent, "dir1", parent, "dir3"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", "dir1", + "dir3", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir2 ->dir3 (exists) */ + ret = glfs_h_rename(fs, parent, "dir2", parent, "dir3"); + if (ret != 0) { + fprintf(stderr, "glfs_h_rename: error renaming %s to %s (%s)\n", "dir2", + "dir3", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename file.txt -> dir3 (fail) */ + ret = glfs_h_rename(fs, parent, "file.txt", parent, "dir3"); + if (ret == 0) { + fprintf(stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", + "file.txt", "dir3", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + /* rename dir3 -> file.txt (fail) */ + ret = glfs_h_rename(fs, parent, "dir3", parent, "file.txt"); + if (ret == 0) { + fprintf(stderr, "glfs_h_rename: NO error renaming %s to %s (%s)\n", + "dir3", "file.txt", strerror(errno)); + printf("glfs_h_rename tests: FAILED\n"); + goto out; + } + + printf("glfs_h_rename tests: PASSED\n"); out: - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - if (dirsrc) - glfs_h_close (dirsrc); - if (dirtgt) - glfs_h_close (dirtgt); - if (dleaf) - glfs_h_close (dleaf); - - return; + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + if (dirsrc) + glfs_h_close(dirsrc); + if (dirtgt) + glfs_h_close(dirtgt); + if (dleaf) + glfs_h_close(dleaf); + + return; } void -assimilatetime (struct timespec *ts, struct timespec ts_st, - struct timespec ts_ed) +assimilatetime(struct timespec *ts, struct timespec ts_st, + struct timespec ts_ed) { - if ((ts_ed.tv_nsec - ts_st.tv_nsec) < 0) { - ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec - 1; - ts->tv_nsec += 1000000000 + ts_ed.tv_nsec - ts_st.tv_nsec; - } else { - ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec; - ts->tv_nsec += ts_ed.tv_nsec - ts_st.tv_nsec; - } - - if (ts->tv_nsec > 1000000000) { - ts->tv_nsec = ts->tv_nsec - 1000000000; - ts->tv_sec += 1; - } - - return; + if ((ts_ed.tv_nsec - ts_st.tv_nsec) < 0) { + ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec - 1; + ts->tv_nsec += 1000000000 + ts_ed.tv_nsec - ts_st.tv_nsec; + } else { + ts->tv_sec += ts_ed.tv_sec - ts_st.tv_sec; + ts->tv_nsec += ts_ed.tv_nsec - ts_st.tv_nsec; + } + + if (ts->tv_nsec > 1000000000) { + ts->tv_nsec = ts->tv_nsec - 1000000000; + ts->tv_sec += 1; + } + + return; } #define MAX_FILES_CREATE 10 -#define MAXPATHNAME 512 +#define MAXPATHNAME 512 void -test_h_performance (void) +test_h_performance(void) { - char *my_dir = "perftest", - *full_dir_path="/testdir/perftest"; - char *my_file = "file_", my_file_name[MAXPATHNAME]; - struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; - struct stat sb; - int ret, i; - struct glfs_fd *fd; - struct timespec c_ts = {0, 0}, c_ts_st, c_ts_ed; - struct timespec o_ts = {0, 0}, o_ts_st, o_ts_ed; - - printf("glfs_h_performance tests: In Progress\n"); - - /* Prepare tests */ - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, NULL, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - dir = glfs_h_mkdir (fs, parent, my_dir, 0644, &sb); - if (dir == NULL) { - fprintf (stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* create performance */ - ret = clock_gettime (CLOCK_REALTIME, &o_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + char *my_dir = "perftest", *full_dir_path = "/testdir/perftest"; + char *my_file = "file_", my_file_name[MAXPATHNAME]; + struct glfs_object *parent = NULL, *leaf = NULL, *dir = NULL; + struct stat sb; + int ret, i; + struct glfs_fd *fd; + struct timespec c_ts = {0, 0}, c_ts_st, c_ts_ed; + struct timespec o_ts = {0, 0}, o_ts_st, o_ts_ed; + + printf("glfs_h_performance tests: In Progress\n"); + + /* Prepare tests */ + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, NULL, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; + } + + dir = glfs_h_mkdir(fs, parent, my_dir, 0644, &sb); + if (dir == NULL) { + fprintf(stderr, "glfs_h_mkdir: error creating %s: from (%p),%s\n", + my_dir, parent, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* create performance */ + ret = clock_gettime(CLOCK_REALTIME, &o_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + for (i = 0; i < MAX_FILES_CREATE; i++) { + sprintf(my_file_name, "%s%d", my_file, i); + + ret = clock_gettime(CLOCK_REALTIME, &c_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; } - for (i = 0; i < MAX_FILES_CREATE; i++) { - sprintf (my_file_name, "%s%d", my_file, i); - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - leaf = glfs_h_lookupat (fs, dir, my_file_name, &sb, 0); - if (leaf != NULL) { - fprintf (stderr, "glfs_h_lookup: exists %s\n", - my_file_name); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - leaf = glfs_h_creat (fs, dir, my_file_name, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - assimilatetime (&c_ts, c_ts_st, c_ts_ed); - glfs_h_close (leaf); leaf = NULL; + leaf = glfs_h_lookupat(fs, dir, my_file_name, &sb, 0); + if (leaf != NULL) { + fprintf(stderr, "glfs_h_lookup: exists %s\n", my_file_name); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - ret = clock_gettime (CLOCK_REALTIME, &o_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + leaf = glfs_h_creat(fs, dir, my_file_name, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - assimilatetime (&o_ts, o_ts_st, o_ts_ed); - - printf ("Creation performance (handle based):\n\t# empty files:%d\n", - MAX_FILES_CREATE); - printf ("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - o_ts.tv_sec, o_ts.tv_nsec); - printf ("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - c_ts.tv_sec, c_ts.tv_nsec); - - /* create using path */ - c_ts.tv_sec = o_ts.tv_sec = 0; - c_ts.tv_nsec = o_ts.tv_nsec = 0; - - sprintf (my_file_name, "%s1", full_dir_path); - ret = glfs_mkdir (fs, my_file_name, 0644); + ret = clock_gettime(CLOCK_REALTIME, &c_ts_ed); if (ret != 0) { - fprintf (stderr, "glfs_mkdir: error creating %s: from (%p),%s\n", - my_dir, parent, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - ret = clock_gettime (CLOCK_REALTIME, &o_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&c_ts, c_ts_st, c_ts_ed); + glfs_h_close(leaf); + leaf = NULL; + } + + ret = clock_gettime(CLOCK_REALTIME, &o_ts_ed); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&o_ts, o_ts_st, o_ts_ed); + + printf("Creation performance (handle based):\n\t# empty files:%d\n", + MAX_FILES_CREATE); + printf("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", o_ts.tv_sec, + o_ts.tv_nsec); + printf("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", + c_ts.tv_sec, c_ts.tv_nsec); + + /* create using path */ + c_ts.tv_sec = o_ts.tv_sec = 0; + c_ts.tv_nsec = o_ts.tv_nsec = 0; + + sprintf(my_file_name, "%s1", full_dir_path); + ret = glfs_mkdir(fs, my_file_name, 0644); + if (ret != 0) { + fprintf(stderr, "glfs_mkdir: error creating %s: from (%p),%s\n", my_dir, + parent, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + ret = clock_gettime(CLOCK_REALTIME, &o_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + for (i = 0; i < MAX_FILES_CREATE; i++) { + sprintf(my_file_name, "%s1/%sn%d", full_dir_path, my_file, i); + + ret = clock_gettime(CLOCK_REALTIME, &c_ts_st); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; } - for (i = 0; i < MAX_FILES_CREATE; i++) { - sprintf (my_file_name, "%s1/%sn%d", full_dir_path, my_file, i); - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_st); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - ret = glfs_stat (fs, my_file_name, &sb); - if (ret == 0) { - fprintf (stderr, "glfs_stat: exists %s\n", - my_file_name); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - fd = glfs_creat (fs, my_file_name, O_CREAT, 0644); - if (fd == NULL) { - fprintf (stderr, "glfs_creat: error creating %s: from (%p),%s\n", - my_file, dir, strerror (errno)); - printf ("glfs_h_performance tests: FAILED\n"); - goto out; - } - - ret = clock_gettime (CLOCK_REALTIME, &c_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", - strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; - } - - assimilatetime (&c_ts, c_ts_st, c_ts_ed); - glfs_close (fd); + ret = glfs_stat(fs, my_file_name, &sb); + if (ret == 0) { + fprintf(stderr, "glfs_stat: exists %s\n", my_file_name); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - ret = clock_gettime (CLOCK_REALTIME, &o_ts_ed); - if(ret != 0) { - fprintf (stderr, "clock_gettime: error %s\n", strerror (errno)); - printf ("glfs_h_getattrs and setattrs tests: FAILED\n"); - goto out; + fd = glfs_creat(fs, my_file_name, O_CREAT, 0644); + if (fd == NULL) { + fprintf(stderr, "glfs_creat: error creating %s: from (%p),%s\n", + my_file, dir, strerror(errno)); + printf("glfs_h_performance tests: FAILED\n"); + goto out; } - assimilatetime (&o_ts, o_ts_st, o_ts_ed); - - printf ("Creation performance (path based):\n\t# empty files:%d\n", - MAX_FILES_CREATE); - printf ("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - o_ts.tv_sec, o_ts.tv_nsec); - printf ("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", - c_ts.tv_sec, c_ts.tv_nsec); + ret = clock_gettime(CLOCK_REALTIME, &c_ts_ed); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&c_ts, c_ts_st, c_ts_ed); + glfs_close(fd); + } + + ret = clock_gettime(CLOCK_REALTIME, &o_ts_ed); + if (ret != 0) { + fprintf(stderr, "clock_gettime: error %s\n", strerror(errno)); + printf("glfs_h_getattrs and setattrs tests: FAILED\n"); + goto out; + } + + assimilatetime(&o_ts, o_ts_st, o_ts_ed); + + printf("Creation performance (path based):\n\t# empty files:%d\n", + MAX_FILES_CREATE); + printf("\tOverall time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", o_ts.tv_sec, + o_ts.tv_nsec); + printf("\tcreate call time time:\n\t\tSecs:%ld\n\t\tnSecs:%ld\n", + c_ts.tv_sec, c_ts.tv_nsec); out: - return; + return; } int -test_handleops (int argc, char *argv[]) +test_handleops(int argc, char *argv[]) { - int ret = 0; - glfs_fd_t *fd = NULL; - struct stat sb = {0, }; - struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, - *tmp = NULL; - char readbuf[32], writebuf[32]; - unsigned char leaf_handle[GFAPI_HANDLE_LENGTH]; - - char *full_leaf_name = "/testdir/testfile.txt", - *leaf_name = "testfile.txt", - *relative_leaf_name = "testdir/testfile.txt"; - char *leaf_name1 = "testfile1.txt"; - char *full_newparent_name = "/testdir/dir1", - *newparent_name = "dir1"; - char *full_newnod_name = "/testdir/nod1", - *newnod_name = "nod1"; - - /* Initialize test area */ - ret = glfs_mkdir (fs, full_parent_name, 0644); - if (ret != 0 && errno != EEXIST) { - fprintf (stderr, "%s: (%p) %s\n", full_parent_name, fd, - strerror (errno)); - printf ("Test initialization failed on volume %s\n", argv[1]); - goto out; - } - else if (ret != 0) { - printf ("Found test directory %s to be existing\n", - full_parent_name); - printf ("Cleanup test directory and restart tests\n"); - goto out; - } - - fd = glfs_creat (fs, full_leaf_name, O_CREAT, 0644); - if (fd == NULL) { - fprintf (stderr, "%s: (%p) %s\n", full_leaf_name, fd, - strerror (errno)); - printf ("Test initialization failed on volume %s\n", argv[1]); - goto out; - } - glfs_close (fd); - - printf ("Initialized the test area, within volume %s\n", argv[1]); - - /* Handle based APIs test area */ - - /* glfs_lookupat test */ - printf ("glfs_h_lookupat tests: In Progress\n"); - /* start at root of the volume */ - root = glfs_h_lookupat (fs, NULL, "/", &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - "/", NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* lookup a parent within root */ - parent = glfs_h_lookupat (fs, root, parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - parent_name, root, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* lookup a leaf/child within the parent */ - leaf = glfs_h_lookupat (fs, parent, leaf_name, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - leaf_name, parent, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* reset */ - glfs_h_close (root); root = NULL; - glfs_h_close (leaf); leaf = NULL; - glfs_h_close (parent); parent = NULL; - - /* check absolute paths */ - root = glfs_h_lookupat (fs, NULL, "/", &sb, 0); - if (root == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - "/", NULL, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_lookupat (fs, NULL, full_leaf_name, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_leaf_name, parent, strerror (errno)); - printf ("glfs_h_lookupat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* reset */ - glfs_h_close (leaf); leaf = NULL; - - /* check multiple component paths */ - leaf = glfs_h_lookupat (fs, root, relative_leaf_name, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - relative_leaf_name, parent, strerror (errno)); - goto out; - } - peek_stat (&sb); - - /* reset */ - glfs_h_close (root); root = NULL; - glfs_h_close (parent); parent = NULL; - - /* check symlinks in path */ - - /* TODO: -ve test cases */ - /* parent invalid - * path invalid - * path does not exist after some components - * no parent, but relative path - * parent and full path? -ve? - */ - - printf ("glfs_h_lookupat tests: PASSED\n"); - - /* glfs_openat test */ - printf ("glfs_h_open tests: In Progress\n"); - fd = glfs_h_open (fs, leaf, O_RDWR); - if (fd == NULL) { - fprintf (stderr, "glfs_h_open: error on open of %s: %s\n", - full_leaf_name, strerror (errno)); - printf ("glfs_h_open tests: FAILED\n"); - goto out; - } - - /* test read/write based on fd */ - memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); - ret = glfs_write (fd, writebuf, 32, 0); - - glfs_lseek (fd, 0, SEEK_SET); - - ret = glfs_read (fd, readbuf, 32, 0); - if (memcmp (readbuf, writebuf, 32)) { - printf ("Failed to read what I wrote: %s %s\n", readbuf, - writebuf); - glfs_close (fd); - printf ("glfs_h_open tests: FAILED\n"); - goto out; - } - - glfs_h_close (leaf); leaf = NULL; - glfs_close (fd); - - printf ("glfs_h_open tests: PASSED\n"); - - /* Create tests */ - printf ("glfs_h_creat tests: In Progress\n"); - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_creat (fs, parent, leaf_name1, O_CREAT, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n", - leaf_name1, parent, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_creat (fs, parent, leaf_name1, O_CREAT | O_EXCL, 0644, - &sb); - if (leaf != NULL || errno != EEXIST) { - fprintf (stderr, "glfs_h_creat: existing file, leaf = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - if (leaf != NULL) { - glfs_h_close (leaf); leaf = NULL; - } - } - - tmp = glfs_h_creat (fs, root, parent_name, O_CREAT, 0644, &sb); - if (tmp != NULL || !(errno == EISDIR || errno == EINVAL)) { - fprintf (stderr, "glfs_h_creat: dir create, tmp = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_creat tests: FAILED\n"); - if (tmp != NULL) { - glfs_h_close (tmp); tmp = NULL; - } - } - - /* TODO: Other combinations and -ve cases as applicable */ - printf ("glfs_h_creat tests: PASSED\n"); - - /* extract handle and create from handle test */ - printf ("glfs_h_extract_handle and glfs_h_create_from_handle tests: In Progress\n"); - /* TODO: Change the lookup to create below for a GIFD recovery failure, - * that needs to be fixed */ - leaf = glfs_h_lookupat (fs, parent, leaf_name1, &sb, 0); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - leaf_name1, parent, strerror (errno)); - printf ("glfs_h_extract_handle tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - ret = glfs_h_extract_handle (leaf, leaf_handle, - GFAPI_HANDLE_LENGTH); - if (ret < 0) { - fprintf (stderr, "glfs_h_extract_handle: error extracting handle of %s: %s\n", - full_leaf_name, strerror (errno)); - printf ("glfs_h_extract_handle tests: FAILED\n"); - goto out; - } - peek_handle (leaf_handle); - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_create_from_handle (fs, leaf_handle, GFAPI_HANDLE_LENGTH, - &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n", - leaf_name1, leaf_handle, strerror (errno)); - printf ("glfs_h_create_from_handle tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - fd = glfs_h_open (fs, leaf, O_RDWR); - if (fd == NULL) { - fprintf (stderr, "glfs_h_open: error on open of %s: %s\n", - full_leaf_name, strerror (errno)); - printf ("glfs_h_create_from_handle tests: FAILED\n"); - goto out; - } - - /* test read/write based on fd */ - memcpy (writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); - ret = glfs_write (fd, writebuf, 32, 0); - - glfs_lseek (fd, 0, SEEK_SET); - - ret = glfs_read (fd, readbuf, 32, 0); - if (memcmp (readbuf, writebuf, 32)) { - printf ("Failed to read what I wrote: %s %s\n", writebuf, - writebuf); - printf ("glfs_h_create_from_handle tests: FAILED\n"); - glfs_close (fd); - goto out; - } - - glfs_close (fd); - glfs_h_close (leaf); leaf = NULL; - glfs_h_close (parent); parent = NULL; - - printf ("glfs_h_extract_handle and glfs_h_create_from_handle tests: PASSED\n"); - - /* Mkdir tests */ - printf ("glfs_h_mkdir tests: In Progress\n"); - - ret = glfs_rmdir (fs, full_newparent_name); - if (ret && errno != ENOENT) { - fprintf (stderr, "glfs_rmdir: Failed for %s: %s\n", - full_newparent_name, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - goto out; - } - - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_mkdir (fs, parent, newparent_name, 0644, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", - newparent_name, parent, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_mkdir (fs, parent, newparent_name, 0644, &sb); - if (leaf != NULL || errno != EEXIST) { - fprintf (stderr, "glfs_h_mkdir: existing directory, leaf = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_mkdir tests: FAILED\n"); - if (leaf != NULL) { - glfs_h_close (leaf); leaf = NULL; - } - } - - glfs_h_close (parent); parent = NULL; - - printf ("glfs_h_mkdir tests: PASSED\n"); - - /* Mknod tests */ - printf ("glfs_h_mknod tests: In Progress\n"); - ret = glfs_unlink (fs, full_newnod_name); - if (ret && errno != ENOENT) { - fprintf (stderr, "glfs_unlink: Failed for %s: %s\n", - full_newnod_name, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - goto out; - } - - parent = glfs_h_lookupat (fs, NULL, full_parent_name, &sb, 0); - if (parent == NULL) { - fprintf (stderr, "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", - full_parent_name, root, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - leaf = glfs_h_mknod (fs, parent, newnod_name, S_IFIFO, 0, &sb); - if (leaf == NULL) { - fprintf (stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", - newnod_name, parent, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - goto out; - } - peek_stat (&sb); - - /* TODO: create op on a FIFO node hangs, need to check and fix - tmp = glfs_h_creat (fs, parent, newnod_name, O_CREAT, 0644, &sb); - if (tmp != NULL || errno != EINVAL) { - fprintf (stderr, "glfs_h_creat: node create, tmp = (%p), errno = %s\n", - tmp, strerror (errno)); - printf ("glfs_h_creat/mknod tests: FAILED\n"); - if (tmp != NULL) { - glfs_h_close(tmp); tmp = NULL; - } - } */ - - glfs_h_close (leaf); leaf = NULL; - - leaf = glfs_h_mknod (fs, parent, newnod_name, 0644, 0, &sb); - if (leaf != NULL || errno != EEXIST) { - fprintf (stderr, "glfs_h_mknod: existing node, leaf = (%p), errno = %s\n", - leaf, strerror (errno)); - printf ("glfs_h_mknod tests: FAILED\n"); - if (leaf != NULL) { - glfs_h_close (leaf); leaf = NULL; - } - } - - glfs_h_close (parent); parent = NULL; - - printf ("glfs_h_mknod tests: PASSED\n"); - - /* unlink tests */ - test_h_unlink (); - - /* TODO: opendir tests */ - - /* getattr tests */ - test_h_getsetattrs (); - - /* TODO: setattr tests */ - - /* truncate tests */ - test_h_truncate(); - - /* link tests */ - test_h_links (); - - /* rename tests */ - test_h_rename (); - - /* performance tests */ - test_h_performance (); - - /* END: New APIs test area */ + int ret = 0; + glfs_fd_t *fd = NULL; + struct stat sb = { + 0, + }; + struct glfs_object *root = NULL, *parent = NULL, *leaf = NULL, *tmp = NULL; + char readbuf[32], writebuf[32]; + unsigned char leaf_handle[GFAPI_HANDLE_LENGTH]; + + char *full_leaf_name = "/testdir/testfile.txt", *leaf_name = "testfile.txt", + *relative_leaf_name = "testdir/testfile.txt"; + char *leaf_name1 = "testfile1.txt"; + char *full_newparent_name = "/testdir/dir1", *newparent_name = "dir1"; + char *full_newnod_name = "/testdir/nod1", *newnod_name = "nod1"; + + /* Initialize test area */ + ret = glfs_mkdir(fs, full_parent_name, 0644); + if (ret != 0 && errno != EEXIST) { + fprintf(stderr, "%s: (%p) %s\n", full_parent_name, fd, strerror(errno)); + printf("Test initialization failed on volume %s\n", argv[1]); + goto out; + } else if (ret != 0) { + printf("Found test directory %s to be existing\n", full_parent_name); + printf("Cleanup test directory and restart tests\n"); + goto out; + } + + fd = glfs_creat(fs, full_leaf_name, O_CREAT, 0644); + if (fd == NULL) { + fprintf(stderr, "%s: (%p) %s\n", full_leaf_name, fd, strerror(errno)); + printf("Test initialization failed on volume %s\n", argv[1]); + goto out; + } + glfs_close(fd); + + printf("Initialized the test area, within volume %s\n", argv[1]); + + /* Handle based APIs test area */ + + /* glfs_lookupat test */ + printf("glfs_h_lookupat tests: In Progress\n"); + /* start at root of the volume */ + root = glfs_h_lookupat(fs, NULL, "/", &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", "/", + NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* lookup a parent within root */ + parent = glfs_h_lookupat(fs, root, parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + parent_name, root, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* lookup a leaf/child within the parent */ + leaf = glfs_h_lookupat(fs, parent, leaf_name, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + leaf_name, parent, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* reset */ + glfs_h_close(root); + root = NULL; + glfs_h_close(leaf); + leaf = NULL; + glfs_h_close(parent); + parent = NULL; + + /* check absolute paths */ + root = glfs_h_lookupat(fs, NULL, "/", &sb, 0); + if (root == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", "/", + NULL, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_lookupat(fs, NULL, full_leaf_name, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_leaf_name, parent, strerror(errno)); + printf("glfs_h_lookupat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* reset */ + glfs_h_close(leaf); + leaf = NULL; + + /* check multiple component paths */ + leaf = glfs_h_lookupat(fs, root, relative_leaf_name, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + relative_leaf_name, parent, strerror(errno)); + goto out; + } + peek_stat(&sb); + + /* reset */ + glfs_h_close(root); + root = NULL; + glfs_h_close(parent); + parent = NULL; + + /* check symlinks in path */ + + /* TODO: -ve test cases */ + /* parent invalid + * path invalid + * path does not exist after some components + * no parent, but relative path + * parent and full path? -ve? + */ + + printf("glfs_h_lookupat tests: PASSED\n"); + + /* glfs_openat test */ + printf("glfs_h_open tests: In Progress\n"); + fd = glfs_h_open(fs, leaf, O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_h_open: error on open of %s: %s\n", + full_leaf_name, strerror(errno)); + printf("glfs_h_open tests: FAILED\n"); + goto out; + } + + /* test read/write based on fd */ + memcpy(writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); + ret = glfs_write(fd, writebuf, 32, 0); + + glfs_lseek(fd, 0, SEEK_SET); + + ret = glfs_read(fd, readbuf, 32, 0); + if (memcmp(readbuf, writebuf, 32)) { + printf("Failed to read what I wrote: %s %s\n", readbuf, writebuf); + glfs_close(fd); + printf("glfs_h_open tests: FAILED\n"); + goto out; + } + + glfs_h_close(leaf); + leaf = NULL; + glfs_close(fd); + + printf("glfs_h_open tests: PASSED\n"); + + /* Create tests */ + printf("glfs_h_creat tests: In Progress\n"); + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_creat(fs, parent, leaf_name1, O_CREAT, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_creat: error on create of %s: from (%p),%s\n", + leaf_name1, parent, strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_creat(fs, parent, leaf_name1, O_CREAT | O_EXCL, 0644, &sb); + if (leaf != NULL || errno != EEXIST) { + fprintf(stderr, + "glfs_h_creat: existing file, leaf = (%p), errno = %s\n", leaf, + strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + if (leaf != NULL) { + glfs_h_close(leaf); + leaf = NULL; + } + } + + tmp = glfs_h_creat(fs, root, parent_name, O_CREAT, 0644, &sb); + if (tmp != NULL || !(errno == EISDIR || errno == EINVAL)) { + fprintf(stderr, "glfs_h_creat: dir create, tmp = (%p), errno = %s\n", + leaf, strerror(errno)); + printf("glfs_h_creat tests: FAILED\n"); + if (tmp != NULL) { + glfs_h_close(tmp); + tmp = NULL; + } + } + + /* TODO: Other combinations and -ve cases as applicable */ + printf("glfs_h_creat tests: PASSED\n"); + + /* extract handle and create from handle test */ + printf( + "glfs_h_extract_handle and glfs_h_create_from_handle tests: In " + "Progress\n"); + /* TODO: Change the lookup to create below for a GIFD recovery failure, + * that needs to be fixed */ + leaf = glfs_h_lookupat(fs, parent, leaf_name1, &sb, 0); + if (leaf == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + leaf_name1, parent, strerror(errno)); + printf("glfs_h_extract_handle tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + ret = glfs_h_extract_handle(leaf, leaf_handle, GFAPI_HANDLE_LENGTH); + if (ret < 0) { + fprintf(stderr, + "glfs_h_extract_handle: error extracting handle of %s: %s\n", + full_leaf_name, strerror(errno)); + printf("glfs_h_extract_handle tests: FAILED\n"); + goto out; + } + peek_handle(leaf_handle); + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_create_from_handle(fs, leaf_handle, GFAPI_HANDLE_LENGTH, &sb); + if (leaf == NULL) { + fprintf( + stderr, + "glfs_h_create_from_handle: error on create of %s: from (%p),%s\n", + leaf_name1, leaf_handle, strerror(errno)); + printf("glfs_h_create_from_handle tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + fd = glfs_h_open(fs, leaf, O_RDWR); + if (fd == NULL) { + fprintf(stderr, "glfs_h_open: error on open of %s: %s\n", + full_leaf_name, strerror(errno)); + printf("glfs_h_create_from_handle tests: FAILED\n"); + goto out; + } + + /* test read/write based on fd */ + memcpy(writebuf, "abcdefghijklmnopqrstuvwxyz012345", 32); + ret = glfs_write(fd, writebuf, 32, 0); + + glfs_lseek(fd, 0, SEEK_SET); + + ret = glfs_read(fd, readbuf, 32, 0); + if (memcmp(readbuf, writebuf, 32)) { + printf("Failed to read what I wrote: %s %s\n", writebuf, writebuf); + printf("glfs_h_create_from_handle tests: FAILED\n"); + glfs_close(fd); + goto out; + } + + glfs_close(fd); + glfs_h_close(leaf); + leaf = NULL; + glfs_h_close(parent); + parent = NULL; + + printf( + "glfs_h_extract_handle and glfs_h_create_from_handle tests: PASSED\n"); + + /* Mkdir tests */ + printf("glfs_h_mkdir tests: In Progress\n"); + + ret = glfs_rmdir(fs, full_newparent_name); + if (ret && errno != ENOENT) { + fprintf(stderr, "glfs_rmdir: Failed for %s: %s\n", full_newparent_name, + strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + goto out; + } + + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_mkdir(fs, parent, newparent_name, 0644, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", + newparent_name, parent, strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_mkdir(fs, parent, newparent_name, 0644, &sb); + if (leaf != NULL || errno != EEXIST) { + fprintf(stderr, + "glfs_h_mkdir: existing directory, leaf = (%p), errno = %s\n", + leaf, strerror(errno)); + printf("glfs_h_mkdir tests: FAILED\n"); + if (leaf != NULL) { + glfs_h_close(leaf); + leaf = NULL; + } + } + + glfs_h_close(parent); + parent = NULL; + + printf("glfs_h_mkdir tests: PASSED\n"); + + /* Mknod tests */ + printf("glfs_h_mknod tests: In Progress\n"); + ret = glfs_unlink(fs, full_newnod_name); + if (ret && errno != ENOENT) { + fprintf(stderr, "glfs_unlink: Failed for %s: %s\n", full_newnod_name, + strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + goto out; + } + + parent = glfs_h_lookupat(fs, NULL, full_parent_name, &sb, 0); + if (parent == NULL) { + fprintf(stderr, + "glfs_h_lookupat: error on lookup of %s: from (%p),%s\n", + full_parent_name, root, strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + leaf = glfs_h_mknod(fs, parent, newnod_name, S_IFIFO, 0, &sb); + if (leaf == NULL) { + fprintf(stderr, "glfs_h_mkdir: error on mkdir of %s: from (%p),%s\n", + newnod_name, parent, strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + goto out; + } + peek_stat(&sb); + + /* TODO: create op on a FIFO node hangs, need to check and fix + tmp = glfs_h_creat (fs, parent, newnod_name, O_CREAT, 0644, &sb); + if (tmp != NULL || errno != EINVAL) { + fprintf (stderr, "glfs_h_creat: node create, tmp = (%p), errno = + %s\n", tmp, strerror (errno)); printf ("glfs_h_creat/mknod tests: + FAILED\n"); if (tmp != NULL) { glfs_h_close(tmp); tmp = NULL; + } + } */ + + glfs_h_close(leaf); + leaf = NULL; + + leaf = glfs_h_mknod(fs, parent, newnod_name, 0644, 0, &sb); + if (leaf != NULL || errno != EEXIST) { + fprintf(stderr, + "glfs_h_mknod: existing node, leaf = (%p), errno = %s\n", leaf, + strerror(errno)); + printf("glfs_h_mknod tests: FAILED\n"); + if (leaf != NULL) { + glfs_h_close(leaf); + leaf = NULL; + } + } + + glfs_h_close(parent); + parent = NULL; + + printf("glfs_h_mknod tests: PASSED\n"); + + /* unlink tests */ + test_h_unlink(); + + /* TODO: opendir tests */ + + /* getattr tests */ + test_h_getsetattrs(); + + /* TODO: setattr tests */ + + /* truncate tests */ + test_h_truncate(); + + /* link tests */ + test_h_links(); + + /* rename tests */ + test_h_rename(); + + /* performance tests */ + test_h_performance(); + + /* END: New APIs test area */ out: - /* Cleanup glfs handles */ - if (root) - glfs_h_close (root); - if (parent) - glfs_h_close (parent); - if (leaf) - glfs_h_close (leaf); - - return ret; + /* Cleanup glfs handles */ + if (root) + glfs_h_close(root); + if (parent) + glfs_h_close(parent); + if (leaf) + glfs_h_close(leaf); + + return ret; } int -main (int argc, char *argv[]) +main(int argc, char *argv[]) { - glfs_t *fs2 = NULL; - int ret = 0; - glfs_fd_t *fd = NULL; - glfs_fd_t *fd2 = NULL; - struct stat sb = {0, }; - 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; - } + glfs_t *fs2 = NULL; + int ret = 0; + glfs_fd_t *fd = NULL; + glfs_fd_t *fd2 = NULL; + struct stat sb = { + 0, + }; + char readbuf[32]; + char writebuf[32]; - fs = glfs_new (argv[1]); - if (!fs) { - fprintf (stderr, "glfs_new: returned NULL\n"); - return 1; - } + char *filename = "/filename2"; -// ret = glfs_set_volfile (fs, "/tmp/posix.vol"); + if (argc != 3) { + printf("Expect following args\n\t%s <volname> <hostname>\n", argv[0]); + return -1; + } - ret = glfs_set_volfile_server (fs, "tcp", argv[2], 24007); + fs = glfs_new(argv[1]); + if (!fs) { + fprintf(stderr, "glfs_new: returned NULL\n"); + return 1; + } -// ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); + // ret = glfs_set_volfile (fs, "/tmp/posix.vol"); - ret = glfs_set_logging (fs, "/dev/stderr", 7); + ret = glfs_set_volfile_server(fs, "tcp", argv[2], 24007); - ret = glfs_init (fs); + // ret = glfs_set_volfile_server (fs, "unix", "/tmp/gluster.sock", 0); - fprintf (stderr, "glfs_init: returned %d\n", ret); + ret = glfs_set_logging(fs, "/dev/stderr", 7); - sleep (2); + ret = glfs_init(fs); - fs2 = glfs_new (argv[1]); - if (!fs2) { - fprintf (stderr, "glfs_new: returned NULL\n"); - return 1; - } + fprintf(stderr, "glfs_init: returned %d\n", ret); + sleep(2); -// ret = glfs_set_volfile (fs2, "/tmp/posix.vol"); + 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_volfile (fs2, "/tmp/posix.vol"); - ret = glfs_set_logging (fs2, "/dev/stderr", 7); + ret = glfs_set_volfile_server(fs2, "tcp", argv[2], 24007); - ret = glfs_init (fs2); + ret = glfs_set_logging(fs2, "/dev/stderr", 7); - fprintf (stderr, "glfs_init: returned %d\n", ret); + ret = glfs_init(fs2); - ret = glfs_lstat (fs, filename, &sb); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + fprintf(stderr, "glfs_init: returned %d\n", ret); - fd = glfs_creat (fs, filename, O_RDWR, 0644); - fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); + ret = glfs_lstat(fs, filename, &sb); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); - fd2 = glfs_open (fs2, filename, O_RDWR); - fprintf (stderr, "%s: (%p) %s\n", filename, fd, strerror (errno)); + fd = glfs_creat(fs, filename, O_RDWR, 0644); + fprintf(stderr, "%s: (%p) %s\n", filename, fd, strerror(errno)); - sprintf (writebuf, "hi there\n"); - ret = glfs_write (fd, writebuf, 32, 0); + fd2 = glfs_open(fs2, filename, O_RDWR); + fprintf(stderr, "%s: (%p) %s\n", filename, fd, strerror(errno)); - glfs_lseek (fd2, 0, SEEK_SET); + sprintf(writebuf, "hi there\n"); + ret = glfs_write(fd, writebuf, 32, 0); - ret = glfs_read (fd2, readbuf, 32, 0); + glfs_lseek(fd2, 0, SEEK_SET); - printf ("read %d, %s", ret, readbuf); + ret = glfs_read(fd2, readbuf, 32, 0); - glfs_close (fd); - glfs_close (fd2); + printf("read %d, %s", ret, readbuf); - filename = "/filename3"; - ret = glfs_mknod (fs, filename, S_IFIFO, 0); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + glfs_close(fd); + glfs_close(fd2); - ret = glfs_lstat (fs, filename, &sb); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + filename = "/filename3"; + ret = glfs_mknod(fs, filename, S_IFIFO, 0); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); + ret = glfs_lstat(fs, filename, &sb); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_rename (fs, filename, "/filename4"); - fprintf (stderr, "rename(%s): (%d) %s\n", filename, ret, - strerror (errno)); + ret = glfs_rename(fs, filename, "/filename4"); + fprintf(stderr, "rename(%s): (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_unlink (fs, "/filename4"); - fprintf (stderr, "unlink(%s): (%d) %s\n", "/filename4", ret, - strerror (errno)); + ret = glfs_unlink(fs, "/filename4"); + fprintf(stderr, "unlink(%s): (%d) %s\n", "/filename4", ret, + strerror(errno)); - filename = "/dirname2"; - ret = glfs_mkdir (fs, filename, 0); - fprintf (stderr, "%s: (%d) %s\n", filename, ret, strerror (errno)); + filename = "/dirname2"; + ret = glfs_mkdir(fs, filename, 0); + fprintf(stderr, "%s: (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_lstat (fs, filename, &sb); - fprintf (stderr, "lstat(%s): (%d) %s\n", filename, ret, strerror (errno)); + ret = glfs_lstat(fs, filename, &sb); + fprintf(stderr, "lstat(%s): (%d) %s\n", filename, ret, strerror(errno)); - ret = glfs_rmdir (fs, filename); - fprintf (stderr, "rmdir(%s): (%d) %s\n", filename, ret, strerror (errno)); + ret = glfs_rmdir(fs, filename); + fprintf(stderr, "rmdir(%s): (%d) %s\n", filename, ret, strerror(errno)); - test_dirops (fs); + test_dirops(fs); - test_xattr (fs); + test_xattr(fs); - test_chdir (fs); + test_chdir(fs); - test_handleops (argc, argv); - // done + test_handleops(argc, argv); + // done - glfs_fini (fs); - glfs_fini (fs2); + glfs_fini(fs); + glfs_fini(fs2); - return ret; + return ret; } diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 611cb14..f678684 100644 --- a/api/src/glfs-fops.c +++ b/api/src/glfs-fops.c @@ -33,23 +33,23 @@ #define READDIRBUF_SIZE (sizeof(struct dirent) + GF_NAME_MAX + 1) -typedef void (*glfs_io_cbk34) (glfs_fd_t *fd, ssize_t ret, void *data); +typedef void (*glfs_io_cbk34)(glfs_fd_t *fd, ssize_t ret, void *data); /* * This function will mark glfd for deletion and decrement its refcount. */ int -glfs_mark_glfd_for_deletion (struct glfs_fd *glfd) +glfs_mark_glfd_for_deletion(struct glfs_fd *glfd) { - LOCK (&glfd->lock); - { - glfd->state = GLFD_CLOSE; - } - UNLOCK (&glfd->lock); + LOCK(&glfd->lock); + { + glfd->state = GLFD_CLOSE; + } + UNLOCK(&glfd->lock); - GF_REF_PUT (glfd); + GF_REF_PUT(glfd); - return 0; + return 0; } /* This function is useful for all async fops. There is chance that glfd is @@ -60,33 +60,33 @@ glfs_mark_glfd_for_deletion (struct glfs_fd *glfd) * _gf_false. */ gf_boolean_t -glfs_is_glfd_still_valid (struct glfs_fd *glfd) +glfs_is_glfd_still_valid(struct glfs_fd *glfd) { - gf_boolean_t ret = _gf_false; + gf_boolean_t ret = _gf_false; - LOCK (&glfd->lock); - { - if (glfd->state != GLFD_CLOSE) - ret = _gf_true; - } - UNLOCK (&glfd->lock); + LOCK(&glfd->lock); + { + if (glfd->state != GLFD_CLOSE) + ret = _gf_true; + } + UNLOCK(&glfd->lock); - return ret; + return ret; } void -glfd_set_state_bind (struct glfs_fd *glfd) +glfd_set_state_bind(struct glfs_fd *glfd) { - LOCK (&glfd->lock); - { - glfd->state = GLFD_OPEN; - } - UNLOCK (&glfd->lock); + LOCK(&glfd->lock); + { + glfd->state = GLFD_OPEN; + } + UNLOCK(&glfd->lock); - fd_bind (glfd->fd); - glfs_fd_bind (glfd); + fd_bind(glfd->fd); + glfs_fd_bind(glfd); - return; + return; } /* @@ -97,4528 +97,4581 @@ glfd_set_state_bind (struct glfs_fd *glfd) * maintained by gfapi. */ int -glfs_get_upcall_cache_invalidation (struct gf_upcall *to_up_data, - struct gf_upcall *from_up_data) +glfs_get_upcall_cache_invalidation(struct gf_upcall *to_up_data, + struct gf_upcall *from_up_data) { + struct gf_upcall_cache_invalidation *ca_data = NULL; + struct gf_upcall_cache_invalidation *f_ca_data = NULL; + int ret = -1; - struct gf_upcall_cache_invalidation *ca_data = NULL; - struct gf_upcall_cache_invalidation *f_ca_data = NULL; - int ret = -1; + GF_VALIDATE_OR_GOTO(THIS->name, to_up_data, out); + GF_VALIDATE_OR_GOTO(THIS->name, from_up_data, out); - GF_VALIDATE_OR_GOTO (THIS->name, to_up_data, out); - GF_VALIDATE_OR_GOTO (THIS->name, from_up_data, out); + f_ca_data = from_up_data->data; + GF_VALIDATE_OR_GOTO(THIS->name, f_ca_data, out); - f_ca_data = from_up_data->data; - GF_VALIDATE_OR_GOTO (THIS->name, f_ca_data, out); + ca_data = GF_CALLOC(1, sizeof(*ca_data), glfs_mt_upcall_entry_t); - ca_data = GF_CALLOC (1, sizeof(*ca_data), - glfs_mt_upcall_entry_t); + if (!ca_data) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - if (!ca_data) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } - - to_up_data->data = ca_data; + to_up_data->data = ca_data; - ca_data->flags = f_ca_data->flags; - ca_data->expire_time_attr = f_ca_data->expire_time_attr; - ca_data->stat = f_ca_data->stat; - ca_data->p_stat = f_ca_data->p_stat; - ca_data->oldp_stat = f_ca_data->oldp_stat; + ca_data->flags = f_ca_data->flags; + ca_data->expire_time_attr = f_ca_data->expire_time_attr; + ca_data->stat = f_ca_data->stat; + ca_data->p_stat = f_ca_data->p_stat; + ca_data->oldp_stat = f_ca_data->oldp_stat; - ret = 0; + ret = 0; out: - return ret; + return ret; } int -glfs_get_upcall_lease (struct gf_upcall *to_up_data, - struct gf_upcall *from_up_data) +glfs_get_upcall_lease(struct gf_upcall *to_up_data, + struct gf_upcall *from_up_data) { + struct gf_upcall_recall_lease *ca_data = NULL; + struct gf_upcall_recall_lease *f_ca_data = NULL; + int ret = -1; - struct gf_upcall_recall_lease *ca_data = NULL; - struct gf_upcall_recall_lease *f_ca_data = NULL; - int ret = -1; + GF_VALIDATE_OR_GOTO(THIS->name, to_up_data, out); + GF_VALIDATE_OR_GOTO(THIS->name, from_up_data, out); - GF_VALIDATE_OR_GOTO (THIS->name, to_up_data, out); - GF_VALIDATE_OR_GOTO (THIS->name, from_up_data, out); + f_ca_data = from_up_data->data; + GF_VALIDATE_OR_GOTO(THIS->name, f_ca_data, out); - f_ca_data = from_up_data->data; - GF_VALIDATE_OR_GOTO (THIS->name, f_ca_data, out); + ca_data = GF_CALLOC(1, sizeof(*ca_data), glfs_mt_upcall_entry_t); - ca_data = GF_CALLOC (1, sizeof(*ca_data), - glfs_mt_upcall_entry_t); + if (!ca_data) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - if (!ca_data) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + to_up_data->data = ca_data; - to_up_data->data = ca_data; + ca_data->lease_type = f_ca_data->lease_type; + gf_uuid_copy(ca_data->tid, f_ca_data->tid); + ca_data->dict = f_ca_data->dict; - ca_data->lease_type = f_ca_data->lease_type; - gf_uuid_copy (ca_data->tid, f_ca_data->tid); - ca_data->dict = f_ca_data->dict; - - ret = 0; + ret = 0; out: - return ret; + return ret; } int -glfs_loc_link (loc_t *loc, struct iatt *iatt) +glfs_loc_link(loc_t *loc, struct iatt *iatt) { - int ret = -1; - inode_t *old_inode = NULL; - uint64_t ctx_value = LOOKUP_NOT_NEEDED; - - if (!loc->inode) { - errno = EINVAL; - return -1; - } + int ret = -1; + inode_t *old_inode = NULL; + uint64_t ctx_value = LOOKUP_NOT_NEEDED; - old_inode = loc->inode; - - /* If the inode already exists in the cache, the inode - * returned here points to the existing one. We need - * to update loc.inode accordingly. - */ - loc->inode = inode_link (loc->inode, loc->parent, loc->name, iatt); - if (loc->inode) { - inode_ctx_set (loc->inode, THIS, &ctx_value); - inode_lookup (loc->inode); - inode_unref (old_inode); - ret = 0; - } else { - ret = -1; - } + if (!loc->inode) { + errno = EINVAL; + return -1; + } + + old_inode = loc->inode; + + /* If the inode already exists in the cache, the inode + * returned here points to the existing one. We need + * to update loc.inode accordingly. + */ + loc->inode = inode_link(loc->inode, loc->parent, loc->name, iatt); + if (loc->inode) { + inode_ctx_set(loc->inode, THIS, &ctx_value); + inode_lookup(loc->inode); + inode_unref(old_inode); + ret = 0; + } else { + ret = -1; + } - return ret; + return ret; } - void -glfs_iatt_to_stat (struct glfs *fs, struct iatt *iatt, struct stat *stat) +glfs_iatt_to_stat(struct glfs *fs, struct iatt *iatt, struct stat *stat) { - iatt_to_stat (iatt, stat); - stat->st_dev = fs->dev_id; + iatt_to_stat(iatt, stat); + stat->st_dev = fs->dev_id; } - int -glfs_loc_unlink (loc_t *loc) +glfs_loc_unlink(loc_t *loc) { - inode_unlink (loc->inode, loc->parent, loc->name); + inode_unlink(loc->inode, loc->parent, loc->name); - /* since glfs_h_* objects hold a reference to inode - * it is safe to keep lookup count to '0' */ - if (!inode_has_dentry (loc->inode)) - inode_forget (loc->inode, 0); + /* since glfs_h_* objects hold a reference to inode + * it is safe to keep lookup count to '0' */ + if (!inode_has_dentry(loc->inode)) + inode_forget(loc->inode, 0); - return 0; + return 0; } - struct glfs_fd * -pub_glfs_open (struct glfs *fs, const char *path, int flags) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; +pub_glfs_open(struct glfs *fs, const char *path, int flags) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret) - goto out; - - if (IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = EISDIR; - goto out; - } - - if (!IA_ISREG (iatt.ia_type)) { - ret = -1; - errno = EINVAL; - goto out; - } - - if (glfd->fd) { - /* Retry. Safe to touch glfd->fd as we - still have not glfs_fd_bind() yet. - */ - fd_unref (glfd->fd); - glfd->fd = NULL; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - glfd->fd->flags = flags; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); - ret = syncop_open (subvol, &loc, flags, glfd->fd, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + if (ret) + goto out; - ESTALE_RETRY (ret, errno, reval, &loc, retry); + if (IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = EISDIR; + goto out; + } + + if (!IA_ISREG(iatt.ia_type)) { + ret = -1; + errno = EINVAL; + goto out; + } + + if (glfd->fd) { + /* Retry. Safe to touch glfd->fd as we + still have not glfs_fd_bind() yet. + */ + fd_unref(glfd->fd); + glfd->fd = NULL; + } + + glfd->fd = fd_create(loc.inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + glfd->fd->flags = flags; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_open(subvol, &loc, flags, glfd->fd, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (fop_attr) - dict_unref (fop_attr); + if (fop_attr) + dict_unref(fop_attr); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_open, 3.4.0); int -pub_glfs_close (struct glfs_fd *glfd) -{ - xlator_t *subvol = NULL; - int ret = -1; - fd_t *fd = NULL; - struct glfs *fs = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - if (glfd->lk_owner.len != 0) { - ret = syncopctx_setfslkowner (&glfd->lk_owner); - if (ret) - goto out; - } - ret = get_fop_attr_thrd_key (&fop_attr); +pub_glfs_close(struct glfs_fd *glfd) +{ + xlator_t *subvol = NULL; + int ret = -1; + fd_t *fd = NULL; + struct glfs *fs = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + if (glfd->lk_owner.len != 0) { + ret = syncopctx_setfslkowner(&glfd->lk_owner); if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_flush (subvol, fd, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + goto out; + } + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_flush(subvol, fd, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - fs = glfd->fs; + fs = glfd->fs; - if (fd) - fd_unref (fd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (fop_attr) + dict_unref(fop_attr); + glfs_mark_glfd_for_deletion(glfd); + glfs_subvol_done(fs, subvol); - glfs_mark_glfd_for_deletion (glfd); - glfs_subvol_done (fs, subvol); - - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_close, 3.4.0); - int -pub_glfs_lstat (struct glfs *fs, const char *path, struct stat *stat) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_lstat(struct glfs *fs, const char *path, struct stat *stat) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0 && stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (ret == 0 && stat) + glfs_iatt_to_stat(fs, &iatt, stat); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lstat, 3.4.0); - int -pub_glfs_stat (struct glfs *fs, const char *path, struct stat *stat) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_stat(struct glfs *fs, const char *path, struct stat *stat) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0 && stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (ret == 0 && stat) + glfs_iatt_to_stat(fs, &iatt, stat); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_stat, 3.4.0); - int -pub_glfs_fstat (struct glfs_fd *glfd, struct stat *stat) -{ - int ret = -1; - xlator_t *subvol = NULL; - struct iatt iatt = {0, }; - fd_t *fd = NULL; +pub_glfs_fstat(struct glfs_fd *glfd, struct stat *stat) +{ + int ret = -1; + xlator_t *subvol = NULL; + struct iatt iatt = { + 0, + }; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = syncop_fstat(subvol, fd, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == 0 && stat) + glfs_iatt_to_stat(glfd->fs, &iatt, stat); +out: + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + glfs_subvol_done(glfd->fs, subvol); - GF_REF_GET (glfd); + __GLFS_EXIT_FS; - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +invalid_fs: + return ret; +} - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } +GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fstat, 3.4.0); - ret = syncop_fstat (subvol, fd, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +struct glfs_fd * +pub_glfs_creat(struct glfs *fs, const char *path, int flags, mode_t mode) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; + + /* This must be glfs_resolve() and NOT glfs_lresolve(). + That is because open("name", O_CREAT) where "name" + is a danging symlink must create the dangling + destination. + */ +retry: + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - if (ret == 0 && stat) - glfs_iatt_to_stat (glfd->fs, &iatt, stat); -out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - glfs_subvol_done (glfd->fs, subvol); + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - __GLFS_EXIT_FS; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; -invalid_fs: - return ret; -} + if (loc.inode) { + if (flags & O_EXCL) { + ret = -1; + errno = EEXIST; + goto out; + } -GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fstat, 3.4.0); + if (IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = EISDIR; + goto out; + } + if (!IA_ISREG(iatt.ia_type)) { + ret = -1; + errno = EINVAL; + goto out; + } + } + + if (ret == -1 && errno == ENOENT) { + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } + } -struct glfs_fd * -pub_glfs_creat (struct glfs *fs, const char *path, int flags, mode_t mode) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; - - /* This must be glfs_resolve() and NOT glfs_lresolve(). - That is because open("name", O_CREAT) where "name" - is a danging symlink must create the dangling - destination. - */ -retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; - - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; - - if (loc.inode) { - if (flags & O_EXCL) { - ret = -1; - errno = EEXIST; - goto out; - } - - if (IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = EISDIR; - goto out; - } - - if (!IA_ISREG (iatt.ia_type)) { - ret = -1; - errno = EINVAL; - goto out; - } - } - - if (ret == -1 && errno == ENOENT) { - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } - } - - if (glfd->fd) { - /* Retry. Safe to touch glfd->fd as we - still have not glfs_fd_bind() yet. - */ - fd_unref (glfd->fd); - glfd->fd = NULL; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - glfd->fd->flags = flags; - - if (get_fop_attr_thrd_key (&xattr_req)) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - if (ret == 0) { - ret = syncop_open (subvol, &loc, flags, glfd->fd, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - } else { - ret = syncop_create (subvol, &loc, flags, mode, glfd->fd, - &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - } - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (glfd->fd) { + /* Retry. Safe to touch glfd->fd as we + still have not glfs_fd_bind() yet. + */ + fd_unref(glfd->fd); + glfd->fd = NULL; + } + + glfd->fd = fd_create(loc.inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + glfd->fd->flags = flags; + + if (get_fop_attr_thrd_key(&xattr_req)) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + if (ret == 0) { + ret = syncop_open(subvol, &loc, flags, glfd->fd, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + } else { + ret = syncop_create(subvol, &loc, flags, mode, glfd->fd, &iatt, + xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + } + + ESTALE_RETRY(ret, errno, reval, &loc, retry); + + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_creat, 3.4.0); #ifdef HAVE_SEEK_HOLE static int -glfs_seek (struct glfs_fd *glfd, off_t offset, int whence) +glfs_seek(struct glfs_fd *glfd, off_t offset, int whence) { - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - gf_seek_what_t what = 0; - off_t off = -1; + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + gf_seek_what_t what = 0; + off_t off = -1; - switch (whence) { + switch (whence) { case SEEK_DATA: - what = GF_SEEK_DATA; - break; + what = GF_SEEK_DATA; + break; case SEEK_HOLE: - what = GF_SEEK_HOLE; - break; + what = GF_SEEK_HOLE; + break; default: - /* other SEEK_* do not make sense, all operations get an offset - * and the position in the fd is not tracked */ - errno = EINVAL; - goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto done; - } - - ret = syncop_seek (subvol, fd, offset, what, NULL, &off); - DECODE_SYNCOP_ERR (ret); - - if (ret != -1) - glfd->offset = off; + /* other SEEK_* do not make sense, all operations get an offset + * and the position in the fd is not tracked */ + errno = EINVAL; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto done; + } + + ret = syncop_seek(subvol, fd, offset, what, NULL, &off); + DECODE_SYNCOP_ERR(ret); + + if (ret != -1) + glfd->offset = off; done: - if (fd) - fd_unref (fd); + if (fd) + fd_unref(fd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); out: - return ret; + return ret; } #endif off_t -pub_glfs_lseek (struct glfs_fd *glfd, off_t offset, int whence) -{ - struct stat sb = {0, }; - int ret = -1; - off_t off = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - switch (whence) { - case SEEK_SET: - glfd->offset = offset; - ret = 0; - break; - case SEEK_CUR: - glfd->offset += offset; - ret = 0; - break; - case SEEK_END: - ret = pub_glfs_fstat (glfd, &sb); - if (ret) { - /* seek cannot fail :O */ - break; - } - glfd->offset = sb.st_size + offset; - break; +pub_glfs_lseek(struct glfs_fd *glfd, off_t offset, int whence) +{ + struct stat sb = { + 0, + }; + int ret = -1; + off_t off = -1; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + switch (whence) { + case SEEK_SET: + glfd->offset = offset; + ret = 0; + break; + case SEEK_CUR: + glfd->offset += offset; + ret = 0; + break; + case SEEK_END: + ret = pub_glfs_fstat(glfd, &sb); + if (ret) { + /* seek cannot fail :O */ + break; + } + glfd->offset = sb.st_size + offset; + break; #ifdef HAVE_SEEK_HOLE case SEEK_DATA: case SEEK_HOLE: - ret = glfs_seek (glfd, offset, whence); - break; + ret = glfs_seek(glfd, offset, whence); + break; #endif default: - errno = EINVAL; - } + errno = EINVAL; + } - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - if (ret != -1) - off = glfd->offset; + if (ret != -1) + off = glfd->offset; - return off; + return off; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lseek, 3.4.0); - static ssize_t -glfs_preadv_common (struct glfs_fd *glfd, const struct iovec *iovec, - int iovcnt, off_t offset, int flags, struct stat *poststat) -{ - xlator_t *subvol = NULL; - ssize_t ret = -1; - ssize_t size = -1; - struct iovec *iov = NULL; - int cnt = 0; - struct iobref *iobref = NULL; - fd_t *fd = NULL; - struct iatt iatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - size = iov_length (iovec, iovcnt); - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); +glfs_preadv_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags, struct stat *poststat) +{ + xlator_t *subvol = NULL; + ssize_t ret = -1; + ssize_t size = -1; + struct iovec *iov = NULL; + int cnt = 0; + struct iobref *iobref = NULL; + fd_t *fd = NULL; + struct iatt iatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } - ret = syncop_readv (subvol, fd, size, offset, 0, &iov, &cnt, &iobref, - &iatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + size = iov_length(iovec, iovcnt); - if (ret >= 0 && poststat) - glfs_iatt_to_stat (glfd->fs, &iatt, poststat); + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); - if (ret <= 0) - goto out; + ret = syncop_readv(subvol, fd, size, offset, 0, &iov, &cnt, &iobref, &iatt, + fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); - size = iov_copy (iovec, iovcnt, iov, cnt); /* FIXME!!! */ + if (ret >= 0 && poststat) + glfs_iatt_to_stat(glfd->fs, &iatt, poststat); - glfd->offset = (offset + size); + if (ret <= 0) + goto out; - ret = size; + size = iov_copy(iovec, iovcnt, iov, cnt); /* FIXME!!! */ + + glfd->offset = (offset + size); + + ret = size; out: - if (iov) - GF_FREE (iov); - if (iobref) - iobref_unref (iobref); + if (iov) + GF_FREE(iov); + if (iobref) + iobref_unref(iobref); - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } ssize_t -pub_glfs_preadv (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags) +pub_glfs_preadv(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags) { - return glfs_preadv_common (glfd, iovec, iovcnt, offset, flags, NULL); + return glfs_preadv_common(glfd, iovec, iovcnt, offset, flags, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv, 3.4.0); - ssize_t -pub_glfs_read (struct glfs_fd *glfd, void *buf, size_t count, int flags) +pub_glfs_read(struct glfs_fd *glfd, void *buf, size_t count, int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = pub_glfs_preadv (glfd, &iov, 1, glfd->offset, flags); + ret = pub_glfs_preadv(glfd, &iov, 1, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read, 3.4.0); - ssize_t -pub_glfs_pread34 (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, - int flags) +pub_glfs_pread34(struct glfs_fd *glfd, void *buf, size_t count, off_t offset, + int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = pub_glfs_preadv (glfd, &iov, 1, offset, flags); + ret = pub_glfs_preadv(glfd, &iov, 1, offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pread34, glfs_pread, 3.4.0); - ssize_t -pub_glfs_pread (struct glfs_fd *glfd, void *buf, size_t count, off_t offset, - int flags, struct stat *poststat) +pub_glfs_pread(struct glfs_fd *glfd, void *buf, size_t count, off_t offset, + int flags, struct stat *poststat) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_common (glfd, &iov, 1, offset, flags, poststat); + ret = glfs_preadv_common(glfd, &iov, 1, offset, flags, poststat); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread, future); - ssize_t -pub_glfs_readv (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags) +pub_glfs_readv(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = pub_glfs_preadv (glfd, iov, count, glfd->offset, flags); + ret = pub_glfs_preadv(glfd, iov, count, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv, 3.4.0); - struct glfs_io { - struct glfs_fd *glfd; - int op; - off_t offset; - struct iovec *iov; - int count; - int flags; - gf_boolean_t oldcb; - union { - glfs_io_cbk34 fn34; - glfs_io_cbk fn; - }; - void *data; + struct glfs_fd *glfd; + int op; + off_t offset; + struct iovec *iov; + int count; + int flags; + gf_boolean_t oldcb; + union { + glfs_io_cbk34 fn34; + glfs_io_cbk fn; + }; + void *data; }; - static int -glfs_io_async_cbk (int op_ret, int op_errno, call_frame_t *frame, - void *cookie, struct iovec *iovec, int count, - struct iatt *prebuf, struct iatt *postbuf) -{ - struct glfs_io *gio = NULL; - xlator_t *subvol = NULL; - struct glfs *fs = NULL; - struct glfs_fd *glfd = NULL; - int ret = -1; - struct stat prestat = {}, *prestatp = NULL; - struct stat poststat = {}, *poststatp = NULL; - - GF_VALIDATE_OR_GOTO ("gfapi", frame, inval); - GF_VALIDATE_OR_GOTO ("gfapi", cookie, inval); - - gio = frame->local; - frame->local = NULL; - subvol = cookie; - glfd = gio->glfd; - fs = glfd->fs; - - if (!glfs_is_glfd_still_valid (glfd)) - goto err; - - if (op_ret <= 0) { - goto out; - } else if (gio->op == GF_FOP_READ) { - if (!iovec) { - op_ret = -1; - op_errno = EINVAL; - goto out; - } - - op_ret = iov_copy (gio->iov, gio->count, iovec, count); - glfd->offset = gio->offset + op_ret; - } else if (gio->op == GF_FOP_WRITE) { - glfd->offset = gio->offset + gio->iov->iov_len; +glfs_io_async_cbk(int op_ret, int op_errno, call_frame_t *frame, void *cookie, + struct iovec *iovec, int count, struct iatt *prebuf, + struct iatt *postbuf) +{ + struct glfs_io *gio = NULL; + xlator_t *subvol = NULL; + struct glfs *fs = NULL; + struct glfs_fd *glfd = NULL; + int ret = -1; + struct stat prestat = {}, *prestatp = NULL; + struct stat poststat = {}, *poststatp = NULL; + + GF_VALIDATE_OR_GOTO("gfapi", frame, inval); + GF_VALIDATE_OR_GOTO("gfapi", cookie, inval); + + gio = frame->local; + frame->local = NULL; + subvol = cookie; + glfd = gio->glfd; + fs = glfd->fs; + + if (!glfs_is_glfd_still_valid(glfd)) + goto err; + + if (op_ret <= 0) { + goto out; + } else if (gio->op == GF_FOP_READ) { + if (!iovec) { + op_ret = -1; + op_errno = EINVAL; + goto out; } -out: - errno = op_errno; - if (gio->oldcb) { - gio->fn34 (gio->glfd, op_ret, gio->data); - } else { - if (prebuf) { - prestatp = &prestat; - glfs_iatt_to_stat (fs, prebuf, prestatp); - } - - if (postbuf) { - poststatp = &poststat; - glfs_iatt_to_stat (fs, postbuf, poststatp); - } + op_ret = iov_copy(gio->iov, gio->count, iovec, count); + glfd->offset = gio->offset + op_ret; + } else if (gio->op == GF_FOP_WRITE) { + glfd->offset = gio->offset + gio->iov->iov_len; + } - gio->fn (gio->glfd, op_ret, prestatp, poststatp, gio->data); +out: + errno = op_errno; + if (gio->oldcb) { + gio->fn34(gio->glfd, op_ret, gio->data); + } else { + if (prebuf) { + prestatp = &prestat; + glfs_iatt_to_stat(fs, prebuf, prestatp); } -err: - fd_unref (glfd->fd); - /* Since the async operation is complete - * release the ref taken during the start - * of async operation - */ - GF_REF_PUT (glfd); - GF_FREE (gio->iov); - GF_FREE (gio); - STACK_DESTROY (frame->root); - glfs_subvol_done (fs, subvol); + if (postbuf) { + poststatp = &poststat; + glfs_iatt_to_stat(fs, postbuf, poststatp); + } - ret = 0; + gio->fn(gio->glfd, op_ret, prestatp, poststatp, gio->data); + } +err: + fd_unref(glfd->fd); + /* Since the async operation is complete + * release the ref taken during the start + * of async operation + */ + GF_REF_PUT(glfd); + + GF_FREE(gio->iov); + GF_FREE(gio); + STACK_DESTROY(frame->root); + glfs_subvol_done(fs, subvol); + + ret = 0; inval: - return ret; + return ret; } static int -glfs_preadv_async_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iovec *iovec, - int count, struct iatt *stbuf, struct iobref *iobref, - dict_t *xdata) +glfs_preadv_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iovec *iovec, int count, + struct iatt *stbuf, struct iobref *iobref, dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, iovec, count, - NULL, stbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, iovec, count, NULL, + stbuf); - return 0; + return 0; } - static int -glfs_preadv_async_common (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_preadv_async_common(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, gf_boolean_t oldcb, + glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = 0; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - struct glfs *fs = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - fs = glfd->fs; - - frame = syncop_create_frame (THIS); - if (!frame) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio->iov = iov_dup (iovec, count); - if (!gio->iov) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_READ; - gio->glfd = glfd; - gio->count = count; - gio->offset = offset; - gio->flags = flags; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_preadv_async_cbk, subvol, subvol, - subvol->fops->readv, fd, iov_length (iovec, count), - offset, flags, fop_attr); + struct glfs_io *gio = NULL; + int ret = 0; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + struct glfs *fs = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + fs = glfd->fs; + + frame = syncop_create_frame(THIS); + if (!frame) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio->iov = iov_dup(iovec, count); + if (!gio->iov) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_READ; + gio->glfd = glfd; + gio->count = count; + gio->offset = offset; + gio->flags = flags; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_preadv_async_cbk, subvol, subvol, + subvol->fops->readv, fd, iov_length(iovec, count), offset, + flags, fop_attr); out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (gio) { - GF_FREE (gio->iov); - GF_FREE (gio); - } - if (frame) { - STACK_DESTROY (frame->root); - } - glfs_subvol_done (fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (gio) { + GF_FREE(gio->iov); + GF_FREE(gio); + } + if (frame) { + STACK_DESTROY(frame->root); + } + glfs_subvol_done(fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return ret; + return ret; invalid_fs: - return -1; + return -1; } int -pub_glfs_preadv_async34 (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk34 fn, - void *data) +pub_glfs_preadv_async34(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk34 fn, + void *data) { - return glfs_preadv_async_common (glfd, iovec, count, offset, flags, - _gf_true, (void *)fn, data); + return glfs_preadv_async_common(glfd, iovec, count, offset, flags, _gf_true, + (void *)fn, data); } GFAPI_SYMVER_PUBLIC(glfs_preadv_async34, glfs_preadv_async, 3.4.0); - int -pub_glfs_preadv_async (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk fn, - void *data) +pub_glfs_preadv_async(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk fn, + void *data) { - return glfs_preadv_async_common (glfd, iovec, count, offset, flags, - _gf_false, fn, data); + return glfs_preadv_async_common(glfd, iovec, count, offset, flags, + _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_preadv_async, future); - int -pub_glfs_read_async34 (struct glfs_fd *glfd, void *buf, size_t count, int flags, - glfs_io_cbk34 fn, void *data) +pub_glfs_read_async34(struct glfs_fd *glfd, void *buf, size_t count, int flags, + glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, glfd->offset, flags, _gf_true, + (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_read_async34, glfs_read_async, 3.4.0); - int -pub_glfs_read_async (struct glfs_fd *glfd, void *buf, size_t count, int flags, - glfs_io_cbk fn, void *data) +pub_glfs_read_async(struct glfs_fd *glfd, void *buf, size_t count, int flags, + glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_false, fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, glfd->offset, flags, + _gf_false, fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_read_async, future); - int -pub_glfs_pread_async34 (struct glfs_fd *glfd, void *buf, size_t count, - off_t offset, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_pread_async34(struct glfs_fd *glfd, void *buf, size_t count, + off_t offset, int flags, glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, offset, flags, _gf_true, + (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pread_async34, glfs_pread_async, 3.4.0); - int -pub_glfs_pread_async (struct glfs_fd *glfd, void *buf, size_t count, - off_t offset, int flags, glfs_io_cbk fn, void *data) +pub_glfs_pread_async(struct glfs_fd *glfd, void *buf, size_t count, + off_t offset, int flags, glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = buf; - iov.iov_len = count; + iov.iov_base = buf; + iov.iov_len = count; - ret = glfs_preadv_async_common (glfd, &iov, 1, offset, flags, - _gf_false, fn, data); + ret = glfs_preadv_async_common(glfd, &iov, 1, offset, flags, _gf_false, fn, + data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pread_async, future); - int -pub_glfs_readv_async34 (struct glfs_fd *glfd, const struct iovec *iov, - int count, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_readv_async34(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags, glfs_io_cbk34 fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_preadv_async_common (glfd, iov, count, glfd->offset, flags, - _gf_true, (void *)fn, data); - return ret; + ret = glfs_preadv_async_common(glfd, iov, count, glfd->offset, flags, + _gf_true, (void *)fn, data); + return ret; } GFAPI_SYMVER_PUBLIC(glfs_readv_async34, glfs_readv_async, 3.4.0); - int -pub_glfs_readv_async (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags, glfs_io_cbk fn, void *data) +pub_glfs_readv_async(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags, glfs_io_cbk fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_preadv_async_common (glfd, iov, count, glfd->offset, flags, - _gf_false, fn, data); - return ret; + ret = glfs_preadv_async_common(glfd, iov, count, glfd->offset, flags, + _gf_false, fn, data); + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readv_async, future); static ssize_t -glfs_pwritev_common (struct glfs_fd *glfd, const struct iovec *iovec, - int iovcnt, off_t offset, int flags, - struct stat *prestat, struct stat *poststat) -{ - xlator_t *subvol = NULL; - int ret = -1; - struct iobref *iobref = NULL; - struct iobuf *iobuf = NULL; - struct iovec iov = {0, }; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = iobuf_copy (subvol->ctx->iobuf_pool, iovec, iovcnt, &iobref, - &iobuf, &iov); - if (ret) - goto out; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, - &preiatt, &postiatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } - - if (ret <= 0) - goto out; - - glfd->offset = (offset + iov.iov_len); +glfs_pwritev_common(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags, struct stat *prestat, + struct stat *poststat) +{ + xlator_t *subvol = NULL; + int ret = -1; + struct iobref *iobref = NULL; + struct iobuf *iobuf = NULL; + struct iovec iov = { + 0, + }; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = iobuf_copy(subvol->ctx->iobuf_pool, iovec, iovcnt, &iobref, &iobuf, + &iov); + if (ret) + goto out; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_writev(subvol, fd, &iov, 1, offset, iobref, flags, &preiatt, + &postiatt, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } + + if (ret <= 0) + goto out; + + glfd->offset = (offset + iov.iov_len); out: - if (iobuf) - iobuf_unref (iobuf); - if (iobref) - iobref_unref (iobref); - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (iobuf) + iobuf_unref(iobuf); + if (iobref) + iobref_unref(iobref); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } ssize_t -pub_glfs_pwritev (struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, - off_t offset, int flags) +pub_glfs_pwritev(struct glfs_fd *glfd, const struct iovec *iovec, int iovcnt, + off_t offset, int flags) { - return glfs_pwritev_common (glfd, iovec, iovcnt, offset, flags, - NULL, NULL); + return glfs_pwritev_common(glfd, iovec, iovcnt, offset, flags, NULL, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev, 3.4.0); - ssize_t -pub_glfs_write (struct glfs_fd *glfd, const void *buf, size_t count, int flags) +pub_glfs_write(struct glfs_fd *glfd, const void *buf, size_t count, int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = pub_glfs_pwritev (glfd, &iov, 1, glfd->offset, flags); + ret = pub_glfs_pwritev(glfd, &iov, 1, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_write, 3.4.0); - ssize_t -pub_glfs_writev (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags) +pub_glfs_writev(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = pub_glfs_pwritev (glfd, iov, count, glfd->offset, flags); + ret = pub_glfs_pwritev(glfd, iov, count, glfd->offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev, 3.4.0); - ssize_t -pub_glfs_pwrite34 (struct glfs_fd *glfd, const void *buf, size_t count, - off_t offset, int flags) +pub_glfs_pwrite34(struct glfs_fd *glfd, const void *buf, size_t count, + off_t offset, int flags) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = pub_glfs_pwritev (glfd, &iov, 1, offset, flags); + ret = pub_glfs_pwritev(glfd, &iov, 1, offset, flags); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pwrite34, glfs_pwrite, 3.4.0); ssize_t -pub_glfs_pwrite (struct glfs_fd *glfd, const void *buf, size_t count, - off_t offset, int flags, struct stat *prestat, - struct stat *poststat) +pub_glfs_pwrite(struct glfs_fd *glfd, const void *buf, size_t count, + off_t offset, int flags, struct stat *prestat, + struct stat *poststat) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_common (glfd, &iov, 1, offset, flags, - prestat, poststat); + ret = glfs_pwritev_common(glfd, &iov, 1, offset, flags, prestat, poststat); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite, future); -extern glfs_t *pub_glfs_from_glfd (glfs_fd_t *); - +extern glfs_t * +pub_glfs_from_glfd(glfs_fd_t *); static int -glfs_pwritev_async_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int op_ret, int op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +glfs_pwritev_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - prebuf, postbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf, + postbuf); - return 0; + return 0; } static int -glfs_pwritev_async_common (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_pwritev_async_common(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iobref *iobref = NULL; - struct iobuf *iobuf = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_WRITE; - gio->glfd = glfd; - gio->offset = offset; - gio->flags = flags; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - gio->count = 1; - gio->iov = GF_CALLOC (gio->count, sizeof (*(gio->iov)), - gf_common_mt_iovec); - if (!gio->iov) { - errno = ENOMEM; - goto out; - } - - ret = iobuf_copy (subvol->ctx->iobuf_pool, iovec, count, &iobref, - &iobuf, gio->iov); - if (ret) - goto out; - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - ret = -1; - goto out; - } - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_pwritev_async_cbk, subvol, subvol, - subvol->fops->writev, fd, gio->iov, - gio->count, offset, flags, iobref, fop_attr); - - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iobref *iobref = NULL; + struct iobuf *iobuf = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_WRITE; + gio->glfd = glfd; + gio->offset = offset; + gio->flags = flags; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + gio->count = 1; + gio->iov = GF_CALLOC(gio->count, sizeof(*(gio->iov)), gf_common_mt_iovec); + if (!gio->iov) { + errno = ENOMEM; + goto out; + } + + ret = iobuf_copy(subvol->ctx->iobuf_pool, iovec, count, &iobref, &iobuf, + gio->iov); + if (ret) + goto out; + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + ret = -1; + goto out; + } + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_pwritev_async_cbk, subvol, subvol, + subvol->fops->writev, fd, gio->iov, gio->count, offset, + flags, iobref, fop_attr); + + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - /* - * If there is any error condition check after the frame - * creation, we have to destroy the frame root. - */ - glfs_subvol_done (glfd->fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + /* + * If there is any error condition check after the frame + * creation, we have to destroy the frame root. + */ + glfs_subvol_done(glfd->fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - if (iobuf) - iobuf_unref (iobuf); - if (iobref) - iobref_unref (iobref); + if (iobuf) + iobuf_unref(iobuf); + if (iobref) + iobref_unref(iobref); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_pwritev_async34 (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk34 fn, - void *data) +pub_glfs_pwritev_async34(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk34 fn, + void *data) { - return glfs_pwritev_async_common (glfd, iovec, count, offset, flags, - _gf_true, (void *)fn, data); + return glfs_pwritev_async_common(glfd, iovec, count, offset, flags, + _gf_true, (void *)fn, data); } GFAPI_SYMVER_PUBLIC(glfs_pwritev_async34, glfs_pwritev_async, 3.4.0); - int -pub_glfs_pwritev_async (struct glfs_fd *glfd, const struct iovec *iovec, - int count, off_t offset, int flags, glfs_io_cbk fn, - void *data) +pub_glfs_pwritev_async(struct glfs_fd *glfd, const struct iovec *iovec, + int count, off_t offset, int flags, glfs_io_cbk fn, + void *data) { - return glfs_pwritev_async_common (glfd, iovec, count, offset, flags, - _gf_false, fn, data); + return glfs_pwritev_async_common(glfd, iovec, count, offset, flags, + _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwritev_async, future); - int -pub_glfs_write_async34 (struct glfs_fd *glfd, const void *buf, size_t count, - int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_write_async34(struct glfs_fd *glfd, const void *buf, size_t count, + int flags, glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, glfd->offset, flags, + _gf_true, (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_write_async34, glfs_write_async, 3.4.0); - int -pub_glfs_write_async (struct glfs_fd *glfd, const void *buf, size_t count, - int flags, glfs_io_cbk fn, void *data) +pub_glfs_write_async(struct glfs_fd *glfd, const void *buf, size_t count, + int flags, glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, glfd->offset, flags, - _gf_false, fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, glfd->offset, flags, + _gf_false, fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_write_async, future); - int -pub_glfs_pwrite_async34 (struct glfs_fd *glfd, const void *buf, int count, - off_t offset, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_pwrite_async34(struct glfs_fd *glfd, const void *buf, int count, + off_t offset, int flags, glfs_io_cbk34 fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, offset, flags, - _gf_true, (void *)fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, offset, flags, _gf_true, + (void *)fn, data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_pwrite_async34, glfs_pwrite_async, 3.4.0); - int -pub_glfs_pwrite_async (struct glfs_fd *glfd, const void *buf, int count, - off_t offset, int flags, glfs_io_cbk fn, void *data) +pub_glfs_pwrite_async(struct glfs_fd *glfd, const void *buf, int count, + off_t offset, int flags, glfs_io_cbk fn, void *data) { - struct iovec iov = {0, }; - ssize_t ret = 0; + struct iovec iov = { + 0, + }; + ssize_t ret = 0; - iov.iov_base = (void *) buf; - iov.iov_len = count; + iov.iov_base = (void *)buf; + iov.iov_len = count; - ret = glfs_pwritev_async_common (glfd, &iov, 1, offset, flags, - _gf_false, fn, data); + ret = glfs_pwritev_async_common(glfd, &iov, 1, offset, flags, _gf_false, fn, + data); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_pwrite_async, future); - int -pub_glfs_writev_async34 (struct glfs_fd *glfd, const struct iovec *iov, - int count, int flags, glfs_io_cbk34 fn, void *data) +pub_glfs_writev_async34(struct glfs_fd *glfd, const struct iovec *iov, + int count, int flags, glfs_io_cbk34 fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_pwritev_async_common (glfd, iov, count, glfd->offset, flags, - _gf_true, (void *)fn, data); - return ret; + ret = glfs_pwritev_async_common(glfd, iov, count, glfd->offset, flags, + _gf_true, (void *)fn, data); + return ret; } GFAPI_SYMVER_PUBLIC(glfs_writev_async34, glfs_writev_async, 3.4.0); - int -pub_glfs_writev_async (struct glfs_fd *glfd, const struct iovec *iov, int count, - int flags, glfs_io_cbk fn, void *data) +pub_glfs_writev_async(struct glfs_fd *glfd, const struct iovec *iov, int count, + int flags, glfs_io_cbk fn, void *data) { - ssize_t ret = 0; + ssize_t ret = 0; - ret = glfs_pwritev_async_common (glfd, iov, count, glfd->offset, flags, - _gf_false, fn, data); - return ret; + ret = glfs_pwritev_async_common(glfd, iov, count, glfd->offset, flags, + _gf_false, fn, data); + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_writev_async, future); - static int -glfs_fsync_common (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_fsync (subvol, fd, 0, &preiatt, &postiatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } +glfs_fsync_common(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_fsync(subvol, fd, 0, &preiatt, &postiatt, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_fsync34 (struct glfs_fd *glfd) +pub_glfs_fsync34(struct glfs_fd *glfd) { - return glfs_fsync_common (glfd, NULL, NULL); + return glfs_fsync_common(glfd, NULL, NULL); } GFAPI_SYMVER_PUBLIC(glfs_fsync34, glfs_fsync, 3.4.0); - int -pub_glfs_fsync (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +pub_glfs_fsync(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) { - return glfs_fsync_common (glfd, prestat, poststat); + return glfs_fsync_common(glfd, prestat, poststat); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync, future); - static int -glfs_fsync_async_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *prebuf, - struct iatt *postbuf, dict_t *xdata) +glfs_fsync_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - prebuf, postbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf, + postbuf); - return 0; + return 0; } static int -glfs_fsync_async_common (struct glfs_fd *glfd, gf_boolean_t oldcb, - glfs_io_cbk fn, void *data, int dataonly) -{ - struct glfs_io *gio = NULL; - int ret = 0; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - ret = -1; - goto out; - } - - gio->op = GF_FOP_FSYNC; - gio->glfd = glfd; - gio->flags = dataonly; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - STACK_WIND_COOKIE (frame, glfs_fsync_async_cbk, subvol, subvol, - subvol->fops->fsync, fd, dataonly, NULL); +glfs_fsync_async_common(struct glfs_fd *glfd, gf_boolean_t oldcb, + glfs_io_cbk fn, void *data, int dataonly) +{ + struct glfs_io *gio = NULL; + int ret = 0; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + ret = -1; + goto out; + } + + gio->op = GF_FOP_FSYNC; + gio->glfd = glfd; + gio->flags = dataonly; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + STACK_WIND_COOKIE(frame, glfs_fsync_async_cbk, subvol, subvol, + subvol->fops->fsync, fd, dataonly, NULL); out: - if (ret) { - if (fd) - fd_unref (fd); - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } + if (ret) { + if (fd) + fd_unref(fd); + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } - return ret; + return ret; } - int -pub_glfs_fsync_async34 (struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) +pub_glfs_fsync_async34(struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_true, (void *)fn, data, 0); + ret = glfs_fsync_async_common(glfd, _gf_true, (void *)fn, data, 0); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_fsync_async34, glfs_fsync_async, 3.4.0); - int -pub_glfs_fsync_async (struct glfs_fd *glfd, glfs_io_cbk fn, void *data) +pub_glfs_fsync_async(struct glfs_fd *glfd, glfs_io_cbk fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_false, fn, data, 0); + ret = glfs_fsync_async_common(glfd, _gf_false, fn, data, 0); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsync_async, future); - static int -glfs_fdatasync_common (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_fsync (subvol, fd, 1, &preiatt, &postiatt, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } +glfs_fdatasync_common(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_fsync(subvol, fd, 1, &preiatt, &postiatt, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_fdatasync34 (struct glfs_fd *glfd) +pub_glfs_fdatasync34(struct glfs_fd *glfd) { - return glfs_fdatasync_common (glfd, NULL, NULL); + return glfs_fdatasync_common(glfd, NULL, NULL); } GFAPI_SYMVER_PUBLIC(glfs_fdatasync34, glfs_fdatasync, 3.4.0); - int -pub_glfs_fdatasync (struct glfs_fd *glfd, struct stat *prestat, - struct stat *poststat) +pub_glfs_fdatasync(struct glfs_fd *glfd, struct stat *prestat, + struct stat *poststat) { - return glfs_fdatasync_common (glfd, prestat, poststat); + return glfs_fdatasync_common(glfd, prestat, poststat); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync, future); - int -pub_glfs_fdatasync_async34 (struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) +pub_glfs_fdatasync_async34(struct glfs_fd *glfd, glfs_io_cbk34 fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_true, (void *)fn, data, 1); + ret = glfs_fsync_async_common(glfd, _gf_true, (void *)fn, data, 1); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC(glfs_fdatasync_async34, glfs_fdatasync_async, 3.4.0); - int -pub_glfs_fdatasync_async (struct glfs_fd *glfd, glfs_io_cbk fn, void *data) +pub_glfs_fdatasync_async(struct glfs_fd *glfd, glfs_io_cbk fn, void *data) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - ret = glfs_fsync_async_common (glfd, _gf_false, fn, data, 1); + ret = glfs_fsync_async_common(glfd, _gf_false, fn, data, 1); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fdatasync_async, future); - static int -glfs_ftruncate_common (struct glfs_fd *glfd, off_t offset, - struct stat *prestat, struct stat *poststat) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct iatt preiatt = {0, }, postiatt = {0, }; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_ftruncate (subvol, fd, offset, &preiatt, &postiatt, - fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret >= 0) { - if (prestat) - glfs_iatt_to_stat (glfd->fs, &preiatt, prestat); - if (poststat) - glfs_iatt_to_stat (glfd->fs, &postiatt, poststat); - } +glfs_ftruncate_common(struct glfs_fd *glfd, off_t offset, struct stat *prestat, + struct stat *poststat) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct iatt preiatt = + { + 0, + }, + postiatt = { + 0, + }; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_ftruncate(subvol, fd, offset, &preiatt, &postiatt, fop_attr, + NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret >= 0) { + if (prestat) + glfs_iatt_to_stat(glfd->fs, &preiatt, prestat); + if (poststat) + glfs_iatt_to_stat(glfd->fs, &postiatt, poststat); + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_ftruncate34 (struct glfs_fd *glfd, off_t offset) +pub_glfs_ftruncate34(struct glfs_fd *glfd, off_t offset) { - return glfs_ftruncate_common (glfd, offset, NULL, NULL); + return glfs_ftruncate_common(glfd, offset, NULL, NULL); } GFAPI_SYMVER_PUBLIC(glfs_ftruncate34, glfs_ftruncate, 3.4.0); - int -pub_glfs_ftruncate (struct glfs_fd *glfd, off_t offset, struct stat *prestat, - struct stat *poststat) +pub_glfs_ftruncate(struct glfs_fd *glfd, off_t offset, struct stat *prestat, + struct stat *poststat) { - return glfs_ftruncate_common (glfd, offset, prestat, poststat); + return glfs_ftruncate_common(glfd, offset, prestat, poststat); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate, future); - int -pub_glfs_truncate (struct glfs *fs, const char *path, off_t length) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_truncate(struct glfs *fs, const char *path, off_t length) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_truncate (subvol, &loc, length, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_truncate(subvol, &loc, length, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_truncate, 3.7.15); - static int -glfs_ftruncate_async_cbk (call_frame_t *frame, void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, - dict_t *xdata) +glfs_ftruncate_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - prebuf, postbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, prebuf, + postbuf); - return 0; + return 0; } static int -glfs_ftruncate_async_common (struct glfs_fd *glfd, off_t offset, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_ftruncate_async_common(struct glfs_fd *glfd, off_t offset, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_FTRUNCATE; - gio->glfd = glfd; - gio->offset = offset; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_ftruncate_async_cbk, subvol, subvol, - subvol->fops->ftruncate, fd, offset, fop_attr); - - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_FTRUNCATE; + gio->glfd = glfd; + gio->offset = offset; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_ftruncate_async_cbk, subvol, subvol, + subvol->fops->ftruncate, fd, offset, fop_attr); + + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_ftruncate_async34 (struct glfs_fd *glfd, off_t offset, - glfs_io_cbk34 fn, void *data) +pub_glfs_ftruncate_async34(struct glfs_fd *glfd, off_t offset, glfs_io_cbk34 fn, + void *data) { - return glfs_ftruncate_async_common (glfd, offset, _gf_true, - (void *)fn, data); + return glfs_ftruncate_async_common(glfd, offset, _gf_true, (void *)fn, + data); } GFAPI_SYMVER_PUBLIC(glfs_ftruncate_async34, glfs_ftruncate_async, 3.4.0); - int -pub_glfs_ftruncate_async (struct glfs_fd *glfd, off_t offset, - glfs_io_cbk fn, void *data) +pub_glfs_ftruncate_async(struct glfs_fd *glfd, off_t offset, glfs_io_cbk fn, + void *data) { - return glfs_ftruncate_async_common (glfd, offset, _gf_false, fn, data); + return glfs_ftruncate_async_common(glfd, offset, _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_ftruncate_async, future); - int -pub_glfs_access (struct glfs *fs, const char *path, int mode) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_access(struct glfs *fs, const char *path, int mode) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_access (subvol, &loc, mode, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_access(subvol, &loc, mode, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_access, 3.4.0); - int -pub_glfs_symlink (struct glfs *fs, const char *data, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_symlink(struct glfs *fs, const char *data, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (loc.inode) { - errno = EEXIST; - ret = -1; - goto out; - } + if (loc.inode) { + errno = EEXIST; + ret = -1; + goto out; + } - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; - /* ret == -1 && errno == ENOENT */ - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } + /* ret == -1 && errno == ENOENT */ + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_symlink (subvol, &loc, data, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_symlink(subvol, &loc, data, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_symlink, 3.4.0); - int -pub_glfs_readlink (struct glfs *fs, const char *path, char *buf, size_t bufsiz) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - char *linkval = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_readlink(struct glfs *fs, const char *path, char *buf, size_t bufsiz) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + char *linkval = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (iatt.ia_type != IA_IFLNK) { - ret = -1; - errno = EINVAL; - goto out; - } + if (iatt.ia_type != IA_IFLNK) { + ret = -1; + errno = EINVAL; + goto out; + } - ret = syncop_readlink (subvol, &loc, &linkval, bufsiz, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret > 0) { - memcpy (buf, linkval, ret); - GF_FREE (linkval); - } + ret = syncop_readlink(subvol, &loc, &linkval, bufsiz, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret > 0) { + memcpy(buf, linkval, ret); + GF_FREE(linkval); + } - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readlink, 3.4.0); - int -pub_glfs_mknod (struct glfs *fs, const char *path, mode_t mode, dev_t dev) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_mknod(struct glfs *fs, const char *path, mode_t mode, dev_t dev) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (loc.inode) { - errno = EEXIST; - ret = -1; - goto out; - } + if (loc.inode) { + errno = EEXIST; + ret = -1; + goto out; + } - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; - /* ret == -1 && errno == ENOENT */ - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } + /* ret == -1 && errno == ENOENT */ + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_mknod (subvol, &loc, mode, dev, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_mknod(subvol, &loc, mode, dev, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_mknod, 3.4.0); - int -pub_glfs_mkdir (struct glfs *fs, const char *path, mode_t mode) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_mkdir(struct glfs *fs, const char *path, mode_t mode) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (loc.inode) { - errno = EEXIST; - ret = -1; - goto out; - } + if (loc.inode) { + errno = EEXIST; + ret = -1; + goto out; + } - if (ret == -1 && errno != ENOENT) - /* Any other type of error is fatal */ - goto out; + if (ret == -1 && errno != ENOENT) + /* Any other type of error is fatal */ + goto out; - if (ret == -1 && errno == ENOENT && !loc.parent) - /* The parent directory or an ancestor even - higher does not exist - */ - goto out; + if (ret == -1 && errno == ENOENT && !loc.parent) + /* The parent directory or an ancestor even + higher does not exist + */ + goto out; - /* ret == -1 && errno == ENOENT */ - loc.inode = inode_new (loc.parent->table); - if (!loc.inode) { - ret = -1; - errno = ENOMEM; - goto out; - } + /* ret == -1 && errno == ENOENT */ + loc.inode = inode_new(loc.parent->table); + if (!loc.inode) { + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_mkdir (subvol, &loc, mode, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_mkdir(subvol, &loc, mode, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_link (&loc, &iatt); + if (ret == 0) + ret = glfs_loc_link(&loc, &iatt); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_mkdir, 3.4.0); - int -pub_glfs_unlink (struct glfs *fs, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_unlink(struct glfs *fs, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (iatt.ia_type == IA_IFDIR) { - ret = -1; - errno = EISDIR; - goto out; - } + if (iatt.ia_type == IA_IFDIR) { + ret = -1; + errno = EISDIR; + goto out; + } - /* TODO: Add leaseid */ - ret = syncop_unlink (subvol, &loc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* TODO: Add leaseid */ + ret = syncop_unlink(subvol, &loc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_unlink (&loc); + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_unlink, 3.4.0); - int -pub_glfs_rmdir (struct glfs *fs, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_rmdir(struct glfs *fs, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (iatt.ia_type != IA_IFDIR) { - ret = -1; - errno = ENOTDIR; - goto out; - } + if (iatt.ia_type != IA_IFDIR) { + ret = -1; + errno = ENOTDIR; + goto out; + } - ret = syncop_rmdir (subvol, &loc, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_rmdir(subvol, &loc, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret == 0) - ret = glfs_loc_unlink (&loc); + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_rmdir, 3.4.0); - int -pub_glfs_rename (struct glfs *fs, const char *oldpath, const char *newpath) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt oldiatt = {0, }; - struct iatt newiatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_rename(struct glfs *fs, const char *oldpath, const char *newpath) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt oldiatt = { + 0, + }; + struct iatt newiatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, oldpath, &oldloc, &oldiatt, reval); + ret = glfs_lresolve(fs, subvol, oldpath, &oldloc, &oldiatt, reval); - ESTALE_RETRY (ret, errno, reval, &oldloc, retry); + ESTALE_RETRY(ret, errno, reval, &oldloc, retry); - if (ret) - goto out; + if (ret) + goto out; retrynew: - ret = glfs_lresolve (fs, subvol, newpath, &newloc, &newiatt, reval); - - ESTALE_RETRY (ret, errno, reval, &newloc, retrynew); - - if (ret && errno != ENOENT && newloc.parent) - goto out; - - if (newiatt.ia_type != IA_INVAL) { - if ((oldiatt.ia_type == IA_IFDIR) != - (newiatt.ia_type == IA_IFDIR)) { - /* Either both old and new must be dirs, - * or both must be non-dirs. Else, fail. - */ - ret = -1; - errno = EISDIR; - goto out; - } + ret = glfs_lresolve(fs, subvol, newpath, &newloc, &newiatt, reval); + + ESTALE_RETRY(ret, errno, reval, &newloc, retrynew); + + if (ret && errno != ENOENT && newloc.parent) + goto out; + + if (newiatt.ia_type != IA_INVAL) { + if ((oldiatt.ia_type == IA_IFDIR) != (newiatt.ia_type == IA_IFDIR)) { + /* Either both old and new must be dirs, + * or both must be non-dirs. Else, fail. + */ + ret = -1; + errno = EISDIR; + goto out; + } + } + + /* TODO: - check if new or old is a prefix of the other, and fail EINVAL + * - Add leaseid */ + + ret = syncop_rename(subvol, &oldloc, &newloc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == -1 && errno == ESTALE) { + if (reval < DEFAULT_REVAL_COUNT) { + reval++; + loc_wipe(&oldloc); + loc_wipe(&newloc); + goto retry; } + } - /* TODO: - check if new or old is a prefix of the other, and fail EINVAL - * - Add leaseid */ - - ret = syncop_rename (subvol, &oldloc, &newloc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == -1 && errno == ESTALE) { - if (reval < DEFAULT_REVAL_COUNT) { - reval++; - loc_wipe (&oldloc); - loc_wipe (&newloc); - goto retry; - } - } - - if (ret == 0) { - inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name, - newloc.parent, newloc.name, oldloc.inode, - &oldiatt); - - if (newloc.inode && !inode_has_dentry (newloc.inode)) - inode_forget (newloc.inode, 0); - } + if (ret == 0) { + inode_rename(oldloc.parent->table, oldloc.parent, oldloc.name, + newloc.parent, newloc.name, oldloc.inode, &oldiatt); + + if (newloc.inode && !inode_has_dentry(newloc.inode)) + inode_forget(newloc.inode, 0); + } out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_rename, 3.4.0); - int -pub_glfs_link (struct glfs *fs, const char *oldpath, const char *newpath) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt oldiatt = {0, }; - struct iatt newiatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_link(struct glfs *fs, const char *oldpath, const char *newpath) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt oldiatt = { + 0, + }; + struct iatt newiatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_lresolve (fs, subvol, oldpath, &oldloc, &oldiatt, reval); + ret = glfs_lresolve(fs, subvol, oldpath, &oldloc, &oldiatt, reval); - ESTALE_RETRY (ret, errno, reval, &oldloc, retry); + ESTALE_RETRY(ret, errno, reval, &oldloc, retry); - if (ret) - goto out; + if (ret) + goto out; retrynew: - ret = glfs_lresolve (fs, subvol, newpath, &newloc, &newiatt, reval); - - ESTALE_RETRY (ret, errno, reval, &newloc, retrynew); - - if (ret == 0) { - ret = -1; - errno = EEXIST; - goto out; - } - - if (oldiatt.ia_type == IA_IFDIR) { - ret = -1; - errno = EISDIR; - goto out; - } - - /* Filling the inode of the hard link to be same as that of the - original file - */ - if (newloc.inode) { - inode_unref (newloc.inode); - newloc.inode = NULL; - } - newloc.inode = inode_ref (oldloc.inode); - - ret = syncop_link (subvol, &oldloc, &newloc, &newiatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == -1 && errno == ESTALE) { - loc_wipe (&oldloc); - loc_wipe (&newloc); - if (reval--) - goto retry; - } - - if (ret == 0) - ret = glfs_loc_link (&newloc, &newiatt); + ret = glfs_lresolve(fs, subvol, newpath, &newloc, &newiatt, reval); + + ESTALE_RETRY(ret, errno, reval, &newloc, retrynew); + + if (ret == 0) { + ret = -1; + errno = EEXIST; + goto out; + } + + if (oldiatt.ia_type == IA_IFDIR) { + ret = -1; + errno = EISDIR; + goto out; + } + + /* Filling the inode of the hard link to be same as that of the + original file + */ + if (newloc.inode) { + inode_unref(newloc.inode); + newloc.inode = NULL; + } + newloc.inode = inode_ref(oldloc.inode); + + ret = syncop_link(subvol, &oldloc, &newloc, &newiatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == -1 && errno == ESTALE) { + loc_wipe(&oldloc); + loc_wipe(&newloc); + if (reval--) + goto retry; + } + + if (ret == 0) + ret = glfs_loc_link(&newloc, &newiatt); out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_link, 3.4.0); - struct glfs_fd * -pub_glfs_opendir (struct glfs *fs, const char *path) -{ - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; - - INIT_LIST_HEAD (&glfd->entries); +pub_glfs_opendir(struct glfs *fs, const char *path) +{ + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; + + INIT_LIST_HEAD(&glfd->entries); retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); - - if (ret) - goto out; - - if (!IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } - - if (glfd->fd) { - /* Retry. Safe to touch glfd->fd as we - still have not glfs_fd_bind() yet. - */ - fd_unref (glfd->fd); - glfd->fd = NULL; - } - - glfd->fd = fd_create (loc.inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - - ret = syncop_opendir (subvol, &loc, glfd->fd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); + + if (ret) + goto out; + + if (!IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } + + if (glfd->fd) { + /* Retry. Safe to touch glfd->fd as we + still have not glfs_fd_bind() yet. + */ + fd_unref(glfd->fd); + glfd->fd = NULL; + } + + glfd->fd = fd_create(loc.inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + + ret = syncop_opendir(subvol, &loc, glfd->fd, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_opendir, 3.4.0); - int -pub_glfs_closedir (struct glfs_fd *glfd) +pub_glfs_closedir(struct glfs_fd *glfd) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - gf_dirent_free (list_entry (&glfd->entries, gf_dirent_t, list)); + gf_dirent_free(list_entry(&glfd->entries, gf_dirent_t, list)); - glfs_mark_glfd_for_deletion (glfd); + glfs_mark_glfd_for_deletion(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - ret = 0; + ret = 0; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_closedir, 3.4.0); - long -pub_glfs_telldir (struct glfs_fd *fd) +pub_glfs_telldir(struct glfs_fd *fd) { - return fd->offset; + return fd->offset; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_telldir, 3.4.0); - void -pub_glfs_seekdir (struct glfs_fd *fd, long offset) +pub_glfs_seekdir(struct glfs_fd *fd, long offset) { - gf_dirent_t *entry = NULL; - gf_dirent_t *tmp = NULL; + gf_dirent_t *entry = NULL; + gf_dirent_t *tmp = NULL; - if (fd->offset == offset) - return; + if (fd->offset == offset) + return; - fd->offset = offset; - fd->next = NULL; + fd->offset = offset; + fd->next = NULL; - list_for_each_entry_safe (entry, tmp, &fd->entries, list) { - if (entry->d_off != offset) - continue; + list_for_each_entry_safe(entry, tmp, &fd->entries, list) + { + if (entry->d_off != offset) + continue; - if (&tmp->list != &fd->entries) { - /* found! */ - fd->next = tmp; - return; - } - } - /* could not find entry at requested offset in the cache. - next readdir_r() will result in glfd_entry_refresh() - */ + if (&tmp->list != &fd->entries) { + /* found! */ + fd->next = tmp; + return; + } + } + /* could not find entry at requested offset in the cache. + next readdir_r() will result in glfd_entry_refresh() + */ } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_seekdir, 3.4.0); static int -glfs_discard_async_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *preop_stbuf, - struct iatt *postop_stbuf, dict_t *xdata) +glfs_discard_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preop_stbuf, struct iatt *postop_stbuf, + dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - preop_stbuf, postop_stbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, preop_stbuf, + postop_stbuf); - return 0; + return 0; } static int -glfs_discard_async_common (struct glfs_fd *glfd, off_t offset, size_t len, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_discard_async_common(struct glfs_fd *glfd, off_t offset, size_t len, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_DISCARD; - gio->glfd = glfd; - gio->offset = offset; - gio->count = len; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_discard_async_cbk, subvol, subvol, - subvol->fops->discard, fd, offset, len, fop_attr); - - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_DISCARD; + gio->glfd = glfd; + gio->offset = offset; + gio->count = len; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_discard_async_cbk, subvol, subvol, + subvol->fops->discard, fd, offset, len, fop_attr); + + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_discard_async35 (struct glfs_fd *glfd, off_t offset, size_t len, - glfs_io_cbk34 fn, void *data) +pub_glfs_discard_async35(struct glfs_fd *glfd, off_t offset, size_t len, + glfs_io_cbk34 fn, void *data) { - return glfs_discard_async_common (glfd, offset, len, _gf_true, - (void *)fn, data); + return glfs_discard_async_common(glfd, offset, len, _gf_true, (void *)fn, + data); } GFAPI_SYMVER_PUBLIC(glfs_discard_async35, glfs_discard_async, 3.5.0); - int -pub_glfs_discard_async (struct glfs_fd *glfd, off_t offset, size_t len, - glfs_io_cbk fn, void *data) +pub_glfs_discard_async(struct glfs_fd *glfd, off_t offset, size_t len, + glfs_io_cbk fn, void *data) { - return glfs_discard_async_common (glfd, offset, len, _gf_false, fn, - data); + return glfs_discard_async_common(glfd, offset, len, _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_discard_async, future); - static int -glfs_zerofill_async_cbk (call_frame_t *frame, void *cookie, - xlator_t *this, int32_t op_ret, - int32_t op_errno, struct iatt *preop_stbuf, - struct iatt *postop_stbuf, dict_t *xdata) +glfs_zerofill_async_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *preop_stbuf, struct iatt *postop_stbuf, + dict_t *xdata) { - glfs_io_async_cbk (op_ret, op_errno, frame, cookie, NULL, 0, - preop_stbuf, postop_stbuf); + glfs_io_async_cbk(op_ret, op_errno, frame, cookie, NULL, 0, preop_stbuf, + postop_stbuf); - return 0; + return 0; } - static int -glfs_zerofill_async_common (struct glfs_fd *glfd, off_t offset, off_t len, - gf_boolean_t oldcb, glfs_io_cbk fn, void *data) +glfs_zerofill_async_common(struct glfs_fd *glfd, off_t offset, off_t len, + gf_boolean_t oldcb, glfs_io_cbk fn, void *data) { - struct glfs_io *gio = NULL; - int ret = -1; - call_frame_t *frame = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - /* Need to take explicit ref so that the fd - * is not destroyed before the fop is complete - */ - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - frame = syncop_create_frame (THIS); - if (!frame) { - errno = ENOMEM; - goto out; - } - - gio = GF_CALLOC (1, sizeof (*gio), glfs_mt_glfs_io_t); - if (!gio) { - errno = ENOMEM; - goto out; - } - - gio->op = GF_FOP_ZEROFILL; - gio->glfd = glfd; - gio->offset = offset; - gio->count = len; - gio->oldcb = oldcb; - gio->fn = fn; - gio->data = data; - - frame->local = gio; - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - STACK_WIND_COOKIE (frame, glfs_zerofill_async_cbk, subvol, subvol, - subvol->fops->zerofill, fd, offset, len, fop_attr); - ret = 0; + struct glfs_io *gio = NULL; + int ret = -1; + call_frame_t *frame = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + /* Need to take explicit ref so that the fd + * is not destroyed before the fop is complete + */ + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + frame = syncop_create_frame(THIS); + if (!frame) { + errno = ENOMEM; + goto out; + } + + gio = GF_CALLOC(1, sizeof(*gio), glfs_mt_glfs_io_t); + if (!gio) { + errno = ENOMEM; + goto out; + } + + gio->op = GF_FOP_ZEROFILL; + gio->glfd = glfd; + gio->offset = offset; + gio->count = len; + gio->oldcb = oldcb; + gio->fn = fn; + gio->data = data; + + frame->local = gio; + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + STACK_WIND_COOKIE(frame, glfs_zerofill_async_cbk, subvol, subvol, + subvol->fops->zerofill, fd, offset, len, fop_attr); + ret = 0; out: - if (ret) { - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - GF_FREE (gio); - if (frame) - STACK_DESTROY (frame->root); - glfs_subvol_done (glfd->fs, subvol); - } - if (fop_attr) - dict_unref (fop_attr); + if (ret) { + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + GF_FREE(gio); + if (frame) + STACK_DESTROY(frame->root); + glfs_subvol_done(glfd->fs, subvol); + } + if (fop_attr) + dict_unref(fop_attr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_zerofill_async35 (struct glfs_fd *glfd, off_t offset, off_t len, - glfs_io_cbk34 fn, void *data) +pub_glfs_zerofill_async35(struct glfs_fd *glfd, off_t offset, off_t len, + glfs_io_cbk34 fn, void *data) { - return glfs_zerofill_async_common (glfd, offset, len, _gf_true, - (void *)fn, data); + return glfs_zerofill_async_common(glfd, offset, len, _gf_true, (void *)fn, + data); } GFAPI_SYMVER_PUBLIC(glfs_zerofill_async35, glfs_zerofill_async, 3.5.0); - int -pub_glfs_zerofill_async (struct glfs_fd *glfd, off_t offset, off_t len, - glfs_io_cbk fn, void *data) +pub_glfs_zerofill_async(struct glfs_fd *glfd, off_t offset, off_t len, + glfs_io_cbk fn, void *data) { - return glfs_zerofill_async_common (glfd, offset, len, _gf_false, - fn, data); + return glfs_zerofill_async_common(glfd, offset, len, _gf_false, fn, data); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_zerofill_async, future); - void -gf_dirent_to_dirent (gf_dirent_t *gf_dirent, struct dirent *dirent) +gf_dirent_to_dirent(gf_dirent_t *gf_dirent, struct dirent *dirent) { - dirent->d_ino = gf_dirent->d_ino; + dirent->d_ino = gf_dirent->d_ino; #ifdef _DIRENT_HAVE_D_OFF - dirent->d_off = gf_dirent->d_off; + dirent->d_off = gf_dirent->d_off; #endif #ifdef _DIRENT_HAVE_D_TYPE - dirent->d_type = gf_dirent->d_type; + dirent->d_type = gf_dirent->d_type; #endif #ifdef _DIRENT_HAVE_D_NAMLEN - dirent->d_namlen = strlen (gf_dirent->d_name); + dirent->d_namlen = strlen(gf_dirent->d_name); #endif - snprintf (dirent->d_name, NAME_MAX, "%s", gf_dirent->d_name); + snprintf(dirent->d_name, NAME_MAX, "%s", gf_dirent->d_name); } - int -glfd_entry_refresh (struct glfs_fd *glfd, int plus) -{ - xlator_t *subvol = NULL; - gf_dirent_t entries; - gf_dirent_t old; - gf_dirent_t *entry = NULL; - int ret = -1; - fd_t *fd = NULL; - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - if (fd->inode->ia_type != IA_IFDIR) { - ret = -1; - errno = EBADF; - goto out; - } - - INIT_LIST_HEAD (&entries.list); - INIT_LIST_HEAD (&old.list); - - if (plus) - ret = syncop_readdirp (subvol, fd, 131072, glfd->offset, - &entries, NULL, NULL); - else - ret = syncop_readdir (subvol, fd, 131072, glfd->offset, - &entries, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret >= 0) { - if (plus) { - list_for_each_entry (entry, &entries.list, list) { - if (!entry->inode && - !IA_ISDIR (entry->d_stat.ia_type)) { - /* entry->inode for directories will be - * always set to null to force a lookup - * on the dentry. Also we will have - * proper stat if directory present on - * hashed subvolume. - */ - gf_fill_iatt_for_dirent (entry, - fd->inode, - subvol); - } - } - - gf_link_inodes_from_dirent (THIS, fd->inode, &entries); +glfd_entry_refresh(struct glfs_fd *glfd, int plus) +{ + xlator_t *subvol = NULL; + gf_dirent_t entries; + gf_dirent_t old; + gf_dirent_t *entry = NULL; + int ret = -1; + fd_t *fd = NULL; + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + if (fd->inode->ia_type != IA_IFDIR) { + ret = -1; + errno = EBADF; + goto out; + } + + INIT_LIST_HEAD(&entries.list); + INIT_LIST_HEAD(&old.list); + + if (plus) + ret = syncop_readdirp(subvol, fd, 131072, glfd->offset, &entries, NULL, + NULL); + else + ret = syncop_readdir(subvol, fd, 131072, glfd->offset, &entries, NULL, + NULL); + DECODE_SYNCOP_ERR(ret); + if (ret >= 0) { + if (plus) { + list_for_each_entry(entry, &entries.list, list) + { + if (!entry->inode && !IA_ISDIR(entry->d_stat.ia_type)) { + /* entry->inode for directories will be + * always set to null to force a lookup + * on the dentry. Also we will have + * proper stat if directory present on + * hashed subvolume. + */ + gf_fill_iatt_for_dirent(entry, fd->inode, subvol); } + } - list_splice_init (&glfd->entries, &old.list); - list_splice_init (&entries.list, &glfd->entries); + gf_link_inodes_from_dirent(THIS, fd->inode, &entries); + } - /* spurious errno is dangerous for glfd_entry_next() */ - errno = 0; - } + list_splice_init(&glfd->entries, &old.list); + list_splice_init(&entries.list, &glfd->entries); + /* spurious errno is dangerous for glfd_entry_next() */ + errno = 0; + } - if (ret > 0) - glfd->next = list_entry (glfd->entries.next, gf_dirent_t, list); + if (ret > 0) + glfd->next = list_entry(glfd->entries.next, gf_dirent_t, list); - gf_dirent_free (&old); + gf_dirent_free(&old); out: - if (fd) - fd_unref (fd); + if (fd) + fd_unref(fd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - return ret; + return ret; } - gf_dirent_t * -glfd_entry_next (struct glfs_fd *glfd, int plus) +glfd_entry_next(struct glfs_fd *glfd, int plus) { - gf_dirent_t *entry = NULL; - int ret = -1; + gf_dirent_t *entry = NULL; + int ret = -1; - if (!glfd->offset || !glfd->next) { - ret = glfd_entry_refresh (glfd, plus); - if (ret < 0) - return NULL; - } + if (!glfd->offset || !glfd->next) { + ret = glfd_entry_refresh(glfd, plus); + if (ret < 0) + return NULL; + } - entry = glfd->next; - if (!entry) - return NULL; + entry = glfd->next; + if (!entry) + return NULL; - if (&entry->next->list == &glfd->entries) - glfd->next = NULL; - else - glfd->next = entry->next; + if (&entry->next->list == &glfd->entries) + glfd->next = NULL; + else + glfd->next = entry->next; - glfd->offset = entry->d_off; + glfd->offset = entry->d_off; - return entry; + return entry; } - struct dirent * -glfs_readdirbuf_get (struct glfs_fd *glfd) +glfs_readdirbuf_get(struct glfs_fd *glfd) { - struct dirent *buf = NULL; + struct dirent *buf = NULL; - LOCK (&glfd->fd->lock); - { - buf = glfd->readdirbuf; - if (buf) { - memset (buf, 0, READDIRBUF_SIZE); - goto unlock; - } - - buf = GF_CALLOC (1, READDIRBUF_SIZE, glfs_mt_readdirbuf_t); - if (!buf) { - errno = ENOMEM; - goto unlock; - } + LOCK(&glfd->fd->lock); + { + buf = glfd->readdirbuf; + if (buf) { + memset(buf, 0, READDIRBUF_SIZE); + goto unlock; + } - glfd->readdirbuf = buf; + buf = GF_CALLOC(1, READDIRBUF_SIZE, glfs_mt_readdirbuf_t); + if (!buf) { + errno = ENOMEM; + goto unlock; } + + glfd->readdirbuf = buf; + } unlock: - UNLOCK (&glfd->fd->lock); + UNLOCK(&glfd->fd->lock); - return buf; + return buf; } - int -pub_glfs_readdirplus_r (struct glfs_fd *glfd, struct stat *stat, - struct dirent *ext, struct dirent **res) +pub_glfs_readdirplus_r(struct glfs_fd *glfd, struct stat *stat, + struct dirent *ext, struct dirent **res) { - int ret = 0; - gf_dirent_t *entry = NULL; - struct dirent *buf = NULL; + int ret = 0; + gf_dirent_t *entry = NULL; + struct dirent *buf = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - errno = 0; + errno = 0; - if (ext) - buf = ext; - else - buf = glfs_readdirbuf_get (glfd); + if (ext) + buf = ext; + else + buf = glfs_readdirbuf_get(glfd); - if (!buf) { - errno = ENOMEM; - ret = -1; - goto out; - } + if (!buf) { + errno = ENOMEM; + ret = -1; + goto out; + } - entry = glfd_entry_next (glfd, !!stat); - if (errno) - ret = -1; + entry = glfd_entry_next(glfd, !!stat); + if (errno) + ret = -1; - if (res) { - if (entry) - *res = buf; - else - *res = NULL; - } + if (res) { + if (entry) + *res = buf; + else + *res = NULL; + } - if (entry) { - gf_dirent_to_dirent (entry, buf); - if (stat) - glfs_iatt_to_stat (glfd->fs, &entry->d_stat, stat); - } + if (entry) { + gf_dirent_to_dirent(entry, buf); + if (stat) + glfs_iatt_to_stat(glfd->fs, &entry->d_stat, stat); + } out: - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return ret; + return ret; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus_r, 3.4.0); - int -pub_glfs_readdir_r (struct glfs_fd *glfd, struct dirent *buf, - struct dirent **res) +pub_glfs_readdir_r(struct glfs_fd *glfd, struct dirent *buf, + struct dirent **res) { - return pub_glfs_readdirplus_r (glfd, 0, buf, res); + return pub_glfs_readdirplus_r(glfd, 0, buf, res); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdir_r, 3.4.0); - struct dirent * -pub_glfs_readdirplus (struct glfs_fd *glfd, struct stat *stat) +pub_glfs_readdirplus(struct glfs_fd *glfd, struct stat *stat) { - struct dirent *res = NULL; - int ret = -1; + struct dirent *res = NULL; + int ret = -1; - ret = pub_glfs_readdirplus_r (glfd, stat, NULL, &res); - if (ret) - return NULL; + ret = pub_glfs_readdirplus_r(glfd, stat, NULL, &res); + if (ret) + return NULL; - return res; + return res; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdirplus, 3.5.0); - struct dirent * -pub_glfs_readdir (struct glfs_fd *glfd) +pub_glfs_readdir(struct glfs_fd *glfd) { - return pub_glfs_readdirplus (glfd, NULL); + return pub_glfs_readdirplus(glfd, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_readdir, 3.5.0); - int -pub_glfs_statvfs (struct glfs *fs, const char *path, struct statvfs *buf) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_statvfs(struct glfs *fs, const char *path, struct statvfs *buf) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_statfs (subvol, &loc, buf, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_statfs(subvol, &loc, buf, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_statvfs, 3.4.0); - int -glfs_setattr (struct glfs *fs, const char *path, struct iatt *iatt, - int valid, int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt riatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_setattr(struct glfs *fs, const char *path, struct iatt *iatt, int valid, + int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt riatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &riatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &riatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &riatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &riatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - /* TODO : Add leaseid */ - ret = syncop_setattr (subvol, &loc, iatt, valid, 0, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* TODO : Add leaseid */ + ret = syncop_setattr(subvol, &loc, iatt, valid, 0, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -glfs_fsetattr (struct glfs_fd *glfd, struct iatt *iatt, int valid) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - /* TODO : Add leaseid */ - ret = syncop_fsetattr (subvol, fd, iatt, valid, 0, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +glfs_fsetattr(struct glfs_fd *glfd, struct iatt *iatt, int valid) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + /* TODO : Add leaseid */ + ret = syncop_fsetattr(subvol, fd, iatt, valid, 0, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -pub_glfs_chmod (struct glfs *fs, const char *path, mode_t mode) +pub_glfs_chmod(struct glfs *fs, const char *path, mode_t mode) { - int ret = -1; - struct iatt iatt = {0, }; - int valid = 0; + int ret = -1; + struct iatt iatt = { + 0, + }; + int valid = 0; - iatt.ia_prot = ia_prot_from_st_mode (mode); - valid = GF_SET_ATTR_MODE; + iatt.ia_prot = ia_prot_from_st_mode(mode); + valid = GF_SET_ATTR_MODE; - ret = glfs_setattr (fs, path, &iatt, valid, 1); + ret = glfs_setattr(fs, path, &iatt, valid, 1); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chmod, 3.4.0); - int -pub_glfs_fchmod (struct glfs_fd *glfd, mode_t mode) +pub_glfs_fchmod(struct glfs_fd *glfd, mode_t mode) { - int ret = -1; - struct iatt iatt = {0, }; - int valid = 0; + int ret = -1; + struct iatt iatt = { + 0, + }; + int valid = 0; - iatt.ia_prot = ia_prot_from_st_mode (mode); - valid = GF_SET_ATTR_MODE; + iatt.ia_prot = ia_prot_from_st_mode(mode); + valid = GF_SET_ATTR_MODE; - ret = glfs_fsetattr (glfd, &iatt, valid); + ret = glfs_fsetattr(glfd, &iatt, valid); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchmod, 3.4.0); - int -pub_glfs_chown (struct glfs *fs, const char *path, uid_t uid, gid_t gid) +pub_glfs_chown(struct glfs *fs, const char *path, uid_t uid, gid_t gid) { - int ret = 0; - int valid = 0; - struct iatt iatt = {0, }; + int ret = 0; + int valid = 0; + struct iatt iatt = { + 0, + }; - if (uid != (uid_t) -1) { - iatt.ia_uid = uid; - valid = GF_SET_ATTR_UID; - } + if (uid != (uid_t)-1) { + iatt.ia_uid = uid; + valid = GF_SET_ATTR_UID; + } - if (gid != (uid_t) -1) { - iatt.ia_gid = gid; - valid = valid | GF_SET_ATTR_GID; - } + if (gid != (uid_t)-1) { + iatt.ia_gid = gid; + valid = valid | GF_SET_ATTR_GID; + } - if (valid) - ret = glfs_setattr (fs, path, &iatt, valid, 1); + if (valid) + ret = glfs_setattr(fs, path, &iatt, valid, 1); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chown, 3.4.0); - int -pub_glfs_lchown (struct glfs *fs, const char *path, uid_t uid, gid_t gid) +pub_glfs_lchown(struct glfs *fs, const char *path, uid_t uid, gid_t gid) { - int ret = 0; - int valid = 0; - struct iatt iatt = {0, }; + int ret = 0; + int valid = 0; + struct iatt iatt = { + 0, + }; - if (uid != (uid_t) -1) { - iatt.ia_uid = uid; - valid = GF_SET_ATTR_UID; - } + if (uid != (uid_t)-1) { + iatt.ia_uid = uid; + valid = GF_SET_ATTR_UID; + } - if (gid != (uid_t) -1) { - iatt.ia_gid = gid; - valid = valid | GF_SET_ATTR_GID; - } + if (gid != (uid_t)-1) { + iatt.ia_gid = gid; + valid = valid | GF_SET_ATTR_GID; + } - if (valid) - ret = glfs_setattr (fs, path, &iatt, valid, 0); + if (valid) + ret = glfs_setattr(fs, path, &iatt, valid, 0); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lchown, 3.4.0); - int -pub_glfs_fchown (struct glfs_fd *glfd, uid_t uid, gid_t gid) +pub_glfs_fchown(struct glfs_fd *glfd, uid_t uid, gid_t gid) { - int ret = 0; - int valid = 0; - struct iatt iatt = {0, }; + int ret = 0; + int valid = 0; + struct iatt iatt = { + 0, + }; - if (uid != (uid_t) -1) { - iatt.ia_uid = uid; - valid = GF_SET_ATTR_UID; - } + if (uid != (uid_t)-1) { + iatt.ia_uid = uid; + valid = GF_SET_ATTR_UID; + } - if (gid != (uid_t) -1) { - iatt.ia_gid = gid; - valid = valid | GF_SET_ATTR_GID; - } + if (gid != (uid_t)-1) { + iatt.ia_gid = gid; + valid = valid | GF_SET_ATTR_GID; + } - if (valid) - ret = glfs_fsetattr (glfd, &iatt, valid); + if (valid) + ret = glfs_fsetattr(glfd, &iatt, valid); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchown, 3.4.0); - int -pub_glfs_utimens (struct glfs *fs, const char *path, - const struct timespec times[2]) +pub_glfs_utimens(struct glfs *fs, const char *path, + const struct timespec times[2]) { - int ret = -1; - int valid = 0; - struct iatt iatt = {0, }; + int ret = -1; + int valid = 0; + struct iatt iatt = { + 0, + }; - iatt.ia_atime = times[0].tv_sec; - iatt.ia_atime_nsec = times[0].tv_nsec; - iatt.ia_mtime = times[1].tv_sec; - iatt.ia_mtime_nsec = times[1].tv_nsec; + iatt.ia_atime = times[0].tv_sec; + iatt.ia_atime_nsec = times[0].tv_nsec; + iatt.ia_mtime = times[1].tv_sec; + iatt.ia_mtime_nsec = times[1].tv_nsec; - valid = GF_SET_ATTR_ATIME|GF_SET_ATTR_MTIME; + valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - ret = glfs_setattr (fs, path, &iatt, valid, 1); + ret = glfs_setattr(fs, path, &iatt, valid, 1); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_utimens, 3.4.0); - int -pub_glfs_lutimens (struct glfs *fs, const char *path, - const struct timespec times[2]) +pub_glfs_lutimens(struct glfs *fs, const char *path, + const struct timespec times[2]) { - int ret = -1; - int valid = 0; - struct iatt iatt = {0, }; + int ret = -1; + int valid = 0; + struct iatt iatt = { + 0, + }; - iatt.ia_atime = times[0].tv_sec; - iatt.ia_atime_nsec = times[0].tv_nsec; - iatt.ia_mtime = times[1].tv_sec; - iatt.ia_mtime_nsec = times[1].tv_nsec; + iatt.ia_atime = times[0].tv_sec; + iatt.ia_atime_nsec = times[0].tv_nsec; + iatt.ia_mtime = times[1].tv_sec; + iatt.ia_mtime_nsec = times[1].tv_nsec; - valid = GF_SET_ATTR_ATIME|GF_SET_ATTR_MTIME; + valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - ret = glfs_setattr (fs, path, &iatt, valid, 0); + ret = glfs_setattr(fs, path, &iatt, valid, 0); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lutimens, 3.4.0); - int -pub_glfs_futimens (struct glfs_fd *glfd, const struct timespec times[2]) +pub_glfs_futimens(struct glfs_fd *glfd, const struct timespec times[2]) { - int ret = -1; - int valid = 0; - struct iatt iatt = {0, }; + int ret = -1; + int valid = 0; + struct iatt iatt = { + 0, + }; - iatt.ia_atime = times[0].tv_sec; - iatt.ia_atime_nsec = times[0].tv_nsec; - iatt.ia_mtime = times[1].tv_sec; - iatt.ia_mtime_nsec = times[1].tv_nsec; + iatt.ia_atime = times[0].tv_sec; + iatt.ia_atime_nsec = times[0].tv_nsec; + iatt.ia_mtime = times[1].tv_sec; + iatt.ia_mtime_nsec = times[1].tv_nsec; - valid = GF_SET_ATTR_ATIME|GF_SET_ATTR_MTIME; + valid = GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME; - ret = glfs_fsetattr (glfd, &iatt, valid); + ret = glfs_fsetattr(glfd, &iatt, valid); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_futimens, 3.4.0); - int -glfs_getxattr_process (void *value, size_t size, dict_t *xattr, - const char *name) -{ - data_t *data = NULL; - int ret = -1; - - data = dict_get (xattr, (char *)name); - if (!data) { - errno = ENODATA; - ret = -1; - goto out; - } - - ret = data->len; - if (!value || !size) - goto out; - - if (size < ret) { - ret = -1; - errno = ERANGE; - goto out; - } - - memcpy (value, data->data, ret); -out: - return ret; -} - - -ssize_t -glfs_getxattr_common (struct glfs *fs, const char *path, const char *name, - void *value, size_t size, int follow) +glfs_getxattr_process(void *value, size_t size, dict_t *xattr, const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - dict_t *xattr = NULL; - int reval = 0; + data_t *data = NULL; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + data = dict_get(xattr, (char *)name); + if (!data) { + errno = ENODATA; + ret = -1; + goto out; + } - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } + ret = data->len; + if (!value || !size) + goto out; - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } + if (size < ret) { + ret = -1; + errno = ERANGE; + goto out; + } + + memcpy(value, data->data, ret); +out: + return ret; +} - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +ssize_t +glfs_getxattr_common(struct glfs *fs, const char *path, const char *name, + void *value, size_t size, int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *xattr = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_getxattr (subvol, &loc, &xattr, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_getxattr(subvol, &loc, &xattr, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = glfs_getxattr_process (value, size, xattr, name); + ret = glfs_getxattr_process(value, size, xattr, name); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - ssize_t -pub_glfs_getxattr (struct glfs *fs, const char *path, const char *name, - void *value, size_t size) +pub_glfs_getxattr(struct glfs *fs, const char *path, const char *name, + void *value, size_t size) { - return glfs_getxattr_common (fs, path, name, value, size, 1); + return glfs_getxattr_common(fs, path, name, value, size, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_getxattr, 3.4.0); - ssize_t -pub_glfs_lgetxattr (struct glfs *fs, const char *path, const char *name, - void *value, size_t size) +pub_glfs_lgetxattr(struct glfs *fs, const char *path, const char *name, + void *value, size_t size) { - return glfs_getxattr_common (fs, path, name, value, size, 0); + return glfs_getxattr_common(fs, path, name, value, size, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lgetxattr, 3.4.0); - ssize_t -pub_glfs_fgetxattr (struct glfs_fd *glfd, const char *name, void *value, - size_t size) -{ - int ret = -1; - xlator_t *subvol = NULL; - dict_t *xattr = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = syncop_fgetxattr (subvol, fd, &xattr, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret) - goto out; - - ret = glfs_getxattr_process (value, size, xattr, name); +pub_glfs_fgetxattr(struct glfs_fd *glfd, const char *name, void *value, + size_t size) +{ + int ret = -1; + xlator_t *subvol = NULL; + dict_t *xattr = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = syncop_fgetxattr(subvol, fd, &xattr, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret) + goto out; + + ret = glfs_getxattr_process(value, size, xattr, name); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (xattr) - dict_unref (xattr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fgetxattr, 3.4.0); - int -glfs_listxattr_process (void *value, size_t size, dict_t *xattr) +glfs_listxattr_process(void *value, size_t size, dict_t *xattr) { - int ret = -1; + int ret = -1; - if (!xattr) - goto out; + if (!xattr) + goto out; - ret = dict_keys_join (NULL, 0, xattr, NULL); + ret = dict_keys_join(NULL, 0, xattr, NULL); - if (!value || !size) - goto out; + if (!value || !size) + goto out; - if (size < ret) { - ret = -1; - errno = ERANGE; - } else { - dict_keys_join (value, size, xattr, NULL); - } + if (size < ret) { + ret = -1; + errno = ERANGE; + } else { + dict_keys_join(value, size, xattr, NULL); + } out: - return ret; + return ret; } - ssize_t -glfs_listxattr_common (struct glfs *fs, const char *path, void *value, - size_t size, int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - dict_t *xattr = NULL; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_listxattr_common(struct glfs *fs, const char *path, void *value, + size_t size, int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *xattr = NULL; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_getxattr (subvol, &loc, &xattr, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_getxattr(subvol, &loc, &xattr, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = glfs_listxattr_process (value, size, xattr); + ret = glfs_listxattr_process(value, size, xattr); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - ssize_t -pub_glfs_listxattr (struct glfs *fs, const char *path, void *value, size_t size) +pub_glfs_listxattr(struct glfs *fs, const char *path, void *value, size_t size) { - return glfs_listxattr_common (fs, path, value, size, 1); + return glfs_listxattr_common(fs, path, value, size, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_listxattr, 3.4.0); - ssize_t -pub_glfs_llistxattr (struct glfs *fs, const char *path, void *value, size_t size) +pub_glfs_llistxattr(struct glfs *fs, const char *path, void *value, size_t size) { - return glfs_listxattr_common (fs, path, value, size, 0); + return glfs_listxattr_common(fs, path, value, size, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_llistxattr, 3.4.0); - ssize_t -pub_glfs_flistxattr (struct glfs_fd *glfd, void *value, size_t size) -{ - int ret = -1; - xlator_t *subvol = NULL; - dict_t *xattr = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = syncop_fgetxattr (subvol, fd, &xattr, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret) - goto out; - - ret = glfs_listxattr_process (value, size, xattr); +pub_glfs_flistxattr(struct glfs_fd *glfd, void *value, size_t size) +{ + int ret = -1; + xlator_t *subvol = NULL; + dict_t *xattr = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = syncop_fgetxattr(subvol, fd, &xattr, NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret) + goto out; + + ret = glfs_listxattr_process(value, size, xattr); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); - if (xattr) - dict_unref (xattr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_flistxattr, 3.4.0); int -glfs_setxattr_common (struct glfs *fs, const char *path, const char *name, - const void *value, size_t size, int flags, int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - dict_t *xattr = NULL; - int reval = 0; - void *value_cp = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_setxattr_common(struct glfs *fs, const char *path, const char *name, + const void *value, size_t size, int flags, int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + dict_t *xattr = NULL; + int reval = 0; + void *value_cp = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - value_cp = gf_memdup (value, size); - GF_CHECK_ALLOC_AND_LOG (subvol->name, value_cp, ret, "Failed to" - " duplicate setxattr value", out); + value_cp = gf_memdup(value, size); + GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret, + "Failed to" + " duplicate setxattr value", + out); - xattr = dict_for_key_value (name, value_cp, size, _gf_false); - if (!xattr) { - GF_FREE (value_cp); - ret = -1; - errno = ENOMEM; - goto out; - } + xattr = dict_for_key_value(name, value_cp, size, _gf_false); + if (!xattr) { + GF_FREE(value_cp); + ret = -1; + errno = ENOMEM; + goto out; + } - ret = syncop_setxattr (subvol, &loc, xattr, flags, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_setxattr(subvol, &loc, xattr, flags, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); - if (xattr) - dict_unref (xattr); + loc_wipe(&loc); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -pub_glfs_setxattr (struct glfs *fs, const char *path, const char *name, - const void *value, size_t size, int flags) +pub_glfs_setxattr(struct glfs *fs, const char *path, const char *name, + const void *value, size_t size, int flags) { - return glfs_setxattr_common (fs, path, name, value, size, flags, 1); + return glfs_setxattr_common(fs, path, name, value, size, flags, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_setxattr, 3.4.0); - int -pub_glfs_lsetxattr (struct glfs *fs, const char *path, const char *name, - const void *value, size_t size, int flags) +pub_glfs_lsetxattr(struct glfs *fs, const char *path, const char *name, + const void *value, size_t size, int flags) { - return glfs_setxattr_common (fs, path, name, value, size, flags, 0); + return glfs_setxattr_common(fs, path, name, value, size, flags, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lsetxattr, 3.4.0); - int -pub_glfs_fsetxattr (struct glfs_fd *glfd, const char *name, const void *value, - size_t size, int flags) -{ - int ret = -1; - xlator_t *subvol = NULL; - dict_t *xattr = NULL; - fd_t *fd = NULL; - void *value_cp = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - if (!name || *name == '\0') { - ret = -1; - errno = EINVAL; - goto out; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - ret = -1; - errno = ENAMETOOLONG; - goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - value_cp = gf_memdup (value, size); - GF_CHECK_ALLOC_AND_LOG (subvol->name, value_cp, ret, "Failed to" - " duplicate setxattr value", out); - - xattr = dict_for_key_value (name, value_cp, size, _gf_false); - if (!xattr) { - GF_FREE (value_cp); - ret = -1; - errno = ENOMEM; - goto out; - } - - ret = syncop_fsetxattr (subvol, fd, xattr, flags, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +pub_glfs_fsetxattr(struct glfs_fd *glfd, const char *name, const void *value, + size_t size, int flags) +{ + int ret = -1; + xlator_t *subvol = NULL; + dict_t *xattr = NULL; + fd_t *fd = NULL; + void *value_cp = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + if (!name || *name == '\0') { + ret = -1; + errno = EINVAL; + goto out; + } + + if (strlen(name) > GF_XATTR_NAME_MAX) { + ret = -1; + errno = ENAMETOOLONG; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + value_cp = gf_memdup(value, size); + GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret, + "Failed to" + " duplicate setxattr value", + out); + + xattr = dict_for_key_value(name, value_cp, size, _gf_false); + if (!xattr) { + GF_FREE(value_cp); + ret = -1; + errno = ENOMEM; + goto out; + } + + ret = syncop_fsetxattr(subvol, fd, xattr, flags, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fsetxattr, 3.4.0); - int -glfs_removexattr_common (struct glfs *fs, const char *path, const char *name, - int follow) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +glfs_removexattr_common(struct glfs *fs, const char *path, const char *name, + int follow) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - if (follow) - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); - else - ret = glfs_lresolve (fs, subvol, path, &loc, &iatt, reval); + if (follow) + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); + else + ret = glfs_lresolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - ret = syncop_removexattr (subvol, &loc, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_removexattr(subvol, &loc, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } - int -pub_glfs_removexattr (struct glfs *fs, const char *path, const char *name) +pub_glfs_removexattr(struct glfs *fs, const char *path, const char *name) { - return glfs_removexattr_common (fs, path, name, 1); + return glfs_removexattr_common(fs, path, name, 1); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_removexattr, 3.4.0); - int -pub_glfs_lremovexattr (struct glfs *fs, const char *path, const char *name) +pub_glfs_lremovexattr(struct glfs *fs, const char *path, const char *name) { - return glfs_removexattr_common (fs, path, name, 0); + return glfs_removexattr_common(fs, path, name, 0); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lremovexattr, 3.4.0); - int -pub_glfs_fremovexattr (struct glfs_fd *glfd, const char *name) +pub_glfs_fremovexattr(struct glfs_fd *glfd, const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } - ret = syncop_fremovexattr (subvol, fd, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_fremovexattr(subvol, fd, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fremovexattr, 3.4.0); - int -pub_glfs_fallocate (struct glfs_fd *glfd, int keep_size, off_t offset, size_t len) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_fallocate (subvol, fd, keep_size, offset, len, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); +pub_glfs_fallocate(struct glfs_fd *glfd, int keep_size, off_t offset, + size_t len) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_fallocate(subvol, fd, keep_size, offset, len, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref(fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fallocate, 3.5.0); - int -pub_glfs_discard (struct glfs_fd *glfd, off_t offset, size_t len) -{ - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_discard (subvol, fd, offset, len, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); +pub_glfs_discard(struct glfs_fd *glfd, off_t offset, size_t len) +{ + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_discard(subvol, fd, offset, len, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref(fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_discard, 3.5.0); - int -pub_glfs_zerofill (struct glfs_fd *glfd, off_t offset, off_t len) +pub_glfs_zerofill(struct glfs_fd *glfd, off_t offset, off_t len) { - int ret = -1; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - dict_t *fop_attr = NULL; + int ret = -1; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + dict_t *fop_attr = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - errno = EIO; - goto out; - } + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + errno = EIO; + goto out; + } - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); - ret = syncop_zerofill (subvol, fd, offset, len, fop_attr, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_zerofill(subvol, fd, offset, len, fop_attr, NULL); + DECODE_SYNCOP_ERR(ret); out: - if (fd) - fd_unref(fd); - if (glfd) - GF_REF_PUT (glfd); - if (fop_attr) - dict_unref (fop_attr); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); + if (fop_attr) + dict_unref(fop_attr); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_zerofill, 3.5.0); - int -pub_glfs_chdir (struct glfs *fs, const char *path) -{ - int ret = -1; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } +pub_glfs_chdir(struct glfs *fs, const char *path) +{ + int ret = -1; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (!IA_ISDIR (iatt.ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } + if (!IA_ISDIR(iatt.ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } - glfs_cwd_set (fs, loc.inode); + glfs_cwd_set(fs, loc.inode); out: - loc_wipe (&loc); + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_chdir, 3.4.0); - int -pub_glfs_fchdir (struct glfs_fd *glfd) -{ - int ret = -1; - inode_t *inode = NULL; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - inode = fd->inode; - - if (!IA_ISDIR (inode->ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } - - glfs_cwd_set (glfd->fs, inode); - ret = 0; +pub_glfs_fchdir(struct glfs_fd *glfd) +{ + int ret = -1; + inode_t *inode = NULL; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + inode = fd->inode; + + if (!IA_ISDIR(inode->ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } + + glfs_cwd_set(glfd->fs, inode); + ret = 0; out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchdir, 3.4.0); @@ -4626,680 +4679,673 @@ GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fchdir, 3.4.0); static gf_boolean_t warn_realpath = _gf_true; /* log once */ static char * -glfs_realpath_common (struct glfs *fs, const char *path, char *resolved_path, - gf_boolean_t warn_deprecated) -{ - int ret = -1; - char *retpath = NULL; - char *allocpath = NULL; - xlator_t *subvol = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int reval = 0; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - if (resolved_path) - retpath = resolved_path; - else if (warn_deprecated) { - retpath = allocpath = malloc (PATH_MAX + 1); - if (warn_realpath) { - warn_realpath = _gf_false; - gf_log (THIS->name, GF_LOG_WARNING, "this application " - "is compiled against an old version of " - "libgfapi, it should use glfs_free() to " - "release the path returned by " - "glfs_realpath()"); - } - } else { - retpath = allocpath = GLFS_CALLOC (1, PATH_MAX + 1, NULL, - glfs_mt_realpath_t); +glfs_realpath_common(struct glfs *fs, const char *path, char *resolved_path, + gf_boolean_t warn_deprecated) +{ + int ret = -1; + char *retpath = NULL; + char *allocpath = NULL; + xlator_t *subvol = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int reval = 0; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (resolved_path) + retpath = resolved_path; + else if (warn_deprecated) { + retpath = allocpath = malloc(PATH_MAX + 1); + if (warn_realpath) { + warn_realpath = _gf_false; + gf_log(THIS->name, GF_LOG_WARNING, + "this application " + "is compiled against an old version of " + "libgfapi, it should use glfs_free() to " + "release the path returned by " + "glfs_realpath()"); } - - if (!retpath) { - ret = -1; - errno = ENOMEM; - goto out; - } - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + } else { + retpath = allocpath = GLFS_CALLOC(1, PATH_MAX + 1, NULL, + glfs_mt_realpath_t); + } + + if (!retpath) { + ret = -1; + errno = ENOMEM; + goto out; + } + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } retry: - ret = glfs_resolve (fs, subvol, path, &loc, &iatt, reval); + ret = glfs_resolve(fs, subvol, path, &loc, &iatt, reval); - ESTALE_RETRY (ret, errno, reval, &loc, retry); + ESTALE_RETRY(ret, errno, reval, &loc, retry); - if (ret) - goto out; + if (ret) + goto out; - if (loc.path) { - snprintf (retpath, PATH_MAX, "%s", loc.path); - } + if (loc.path) { + snprintf(retpath, PATH_MAX, "%s", loc.path); + } out: - loc_wipe (&loc); + loc_wipe(&loc); - if (ret == -1) { - if (warn_deprecated && allocpath) - free (allocpath); - else if (allocpath) - GLFS_FREE (allocpath); - retpath = NULL; - } + if (ret == -1) { + if (warn_deprecated && allocpath) + free(allocpath); + else if (allocpath) + GLFS_FREE(allocpath); + retpath = NULL; + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return retpath; + return retpath; } - char * -pub_glfs_realpath34 (struct glfs *fs, const char *path, char *resolved_path) +pub_glfs_realpath34(struct glfs *fs, const char *path, char *resolved_path) { - return glfs_realpath_common (fs, path, resolved_path, _gf_true); + return glfs_realpath_common(fs, path, resolved_path, _gf_true); } GFAPI_SYMVER_PUBLIC(glfs_realpath34, glfs_realpath, 3.4.0); char * -pub_glfs_realpath (struct glfs *fs, const char *path, char *resolved_path) +pub_glfs_realpath(struct glfs *fs, const char *path, char *resolved_path) { - return glfs_realpath_common (fs, path, resolved_path, _gf_false); + return glfs_realpath_common(fs, path, resolved_path, _gf_false); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_realpath, 3.7.17); - char * -pub_glfs_getcwd (struct glfs *fs, char *buf, size_t n) -{ - int ret = -1; - inode_t *inode = NULL; - char *path = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - if (!buf || n < 2) { - ret = -1; - errno = EINVAL; - goto out; - } - - inode = glfs_cwd_get (fs); - - if (!inode) { - strncpy (buf, "/", n); - ret = 0; - goto out; - } - - ret = inode_path (inode, 0, &path); - if (n <= ret) { - ret = -1; - errno = ERANGE; - goto out; - } - - strncpy (buf, path, n); - ret = 0; +pub_glfs_getcwd(struct glfs *fs, char *buf, size_t n) +{ + int ret = -1; + inode_t *inode = NULL; + char *path = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + if (!buf || n < 2) { + ret = -1; + errno = EINVAL; + goto out; + } + + inode = glfs_cwd_get(fs); + + if (!inode) { + strncpy(buf, "/", n); + ret = 0; + goto out; + } + + ret = inode_path(inode, 0, &path); + if (n <= ret) { + ret = -1; + errno = ERANGE; + goto out; + } + + strncpy(buf, path, n); + ret = 0; out: - GF_FREE (path); + GF_FREE(path); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - if (ret < 0) - return NULL; + if (ret < 0) + return NULL; - return buf; + return buf; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_getcwd, 3.4.0); - static void -gf_flock_to_flock (struct gf_flock *gf_flock, struct flock *flock) +gf_flock_to_flock(struct gf_flock *gf_flock, struct flock *flock) { - flock->l_type = gf_flock->l_type; - flock->l_whence = gf_flock->l_whence; - flock->l_start = gf_flock->l_start; - flock->l_len = gf_flock->l_len; - flock->l_pid = gf_flock->l_pid; + flock->l_type = gf_flock->l_type; + flock->l_whence = gf_flock->l_whence; + flock->l_start = gf_flock->l_start; + flock->l_len = gf_flock->l_len; + flock->l_pid = gf_flock->l_pid; } - static void -gf_flock_from_flock (struct gf_flock *gf_flock, struct flock *flock) +gf_flock_from_flock(struct gf_flock *gf_flock, struct flock *flock) { - gf_flock->l_type = flock->l_type; - gf_flock->l_whence = flock->l_whence; - gf_flock->l_start = flock->l_start; - gf_flock->l_len = flock->l_len; - gf_flock->l_pid = flock->l_pid; + gf_flock->l_type = flock->l_type; + gf_flock->l_whence = flock->l_whence; + gf_flock->l_start = flock->l_start; + gf_flock->l_len = flock->l_len; + gf_flock->l_pid = flock->l_pid; } static int -glfs_lock_common (struct glfs_fd *glfd, int cmd, struct flock *flock, - dict_t *xdata) -{ - int ret = -1; - xlator_t *subvol = NULL; - struct gf_flock gf_flock = {0, }; - struct gf_flock saved_flock = {0, }; - fd_t *fd = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - if (!flock) { - errno = EINVAL; - goto out; - } +glfs_lock_common(struct glfs_fd *glfd, int cmd, struct flock *flock, + dict_t *xdata) +{ + int ret = -1; + xlator_t *subvol = NULL; + struct gf_flock gf_flock = { + 0, + }; + struct gf_flock saved_flock = { + 0, + }; + fd_t *fd = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + if (!flock) { + errno = EINVAL; + goto out; + } + + GF_REF_GET(glfd); + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + /* Generate glusterfs flock structure from client flock + * structure to be processed by server */ + gf_flock_from_flock(&gf_flock, flock); + + /* Keep another copy of flock for split/merge of locks + * at client side */ + gf_flock_from_flock(&saved_flock, flock); + + if (glfd->lk_owner.len != 0) { + ret = syncopctx_setfslkowner(&glfd->lk_owner); - GF_REF_GET (glfd); - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { - ret = -1; - errno = EBADFD; - goto out; - } - - /* Generate glusterfs flock structure from client flock - * structure to be processed by server */ - gf_flock_from_flock (&gf_flock, flock); + if (ret) + goto out; + } - /* Keep another copy of flock for split/merge of locks - * at client side */ - gf_flock_from_flock (&saved_flock, flock); + ret = get_fop_attr_thrd_key(&xdata); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); - if (glfd->lk_owner.len != 0) { - ret = syncopctx_setfslkowner (&glfd->lk_owner); + ret = syncop_lk(subvol, fd, cmd, &gf_flock, xdata, NULL); + DECODE_SYNCOP_ERR(ret); - if (ret) - goto out; - } + /* Convert back from gf_flock to flock as expected by application */ + gf_flock_to_flock(&gf_flock, flock); - ret = get_fop_attr_thrd_key (&xdata); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); - - ret = syncop_lk (subvol, fd, cmd, &gf_flock, xdata, NULL); - DECODE_SYNCOP_ERR (ret); - - /* Convert back from gf_flock to flock as expected by application */ - gf_flock_to_flock (&gf_flock, flock); - - if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) { - ret = fd_lk_insert_and_merge (fd, cmd, &saved_flock); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, - API_MSG_LOCK_INSERT_MERGE_FAILED, - "Lock insertion and splitting/merging failed " - "on gfid %s", uuid_utoa (fd->inode->gfid)); - ret = 0; - } + if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) { + ret = fd_lk_insert_and_merge(fd, cmd, &saved_flock); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, + API_MSG_LOCK_INSERT_MERGE_FAILED, + "Lock insertion and splitting/merging failed " + "on gfid %s", + uuid_utoa(fd->inode->gfid)); + ret = 0; } + } out: - if (fd) - fd_unref (fd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (glfd->fs, subvol); + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } int -pub_glfs_file_lock (struct glfs_fd *glfd, int cmd, struct flock *flock, - glfs_lock_mode_t lk_mode) -{ - int ret = -1; - dict_t *xdata_in = NULL; - - if (lk_mode == GLFS_LK_MANDATORY) { - /* Create a new dictionary */ - xdata_in = dict_new (); - if (xdata_in == NULL) { - ret = -1; - errno = ENOMEM; - goto out; - } +pub_glfs_file_lock(struct glfs_fd *glfd, int cmd, struct flock *flock, + glfs_lock_mode_t lk_mode) +{ + int ret = -1; + dict_t *xdata_in = NULL; + + if (lk_mode == GLFS_LK_MANDATORY) { + /* Create a new dictionary */ + xdata_in = dict_new(); + if (xdata_in == NULL) { + ret = -1; + errno = ENOMEM; + goto out; + } - /* Set GF_LK_MANDATORY internally within dictionary to map - * GLFS_LK_MANDATORY */ - ret = dict_set_uint32 (xdata_in, GF_LOCK_MODE, GF_LK_MANDATORY); - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, 0, - API_MSG_SETTING_LOCK_TYPE_FAILED, - "Setting lock type failed"); - ret = -1; - errno = ENOMEM; - goto out; - } + /* Set GF_LK_MANDATORY internally within dictionary to map + * GLFS_LK_MANDATORY */ + ret = dict_set_uint32(xdata_in, GF_LOCK_MODE, GF_LK_MANDATORY); + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, 0, + API_MSG_SETTING_LOCK_TYPE_FAILED, + "Setting lock type failed"); + ret = -1; + errno = ENOMEM; + goto out; } + } - ret = glfs_lock_common (glfd, cmd, flock, xdata_in); + ret = glfs_lock_common(glfd, cmd, flock, xdata_in); out: - if (xdata_in) - dict_unref (xdata_in); + if (xdata_in) + dict_unref(xdata_in); - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_file_lock, 4.0.0); int -pub_glfs_posix_lock (struct glfs_fd *glfd, int cmd, struct flock *flock) +pub_glfs_posix_lock(struct glfs_fd *glfd, int cmd, struct flock *flock) { - return glfs_lock_common (glfd, cmd, flock, NULL); + return glfs_lock_common(glfd, cmd, flock, NULL); } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_posix_lock, 3.4.0); int -pub_glfs_fd_set_lkowner (struct glfs_fd *glfd, void *data, int len) +pub_glfs_fd_set_lkowner(struct glfs_fd *glfd, void *data, int len) { - int ret = -1; + int ret = -1; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - if (!GF_REF_GET (glfd)) { - goto invalid_fs; - } + if (!GF_REF_GET(glfd)) { + goto invalid_fs; + } - GF_VALIDATE_OR_GOTO (THIS->name, data, out); + GF_VALIDATE_OR_GOTO(THIS->name, data, out); - if ((len <= 0) || (len > GFAPI_MAX_LOCK_OWNER_LEN)) { - errno = EINVAL; - gf_msg (THIS->name, GF_LOG_ERROR, errno, - LG_MSG_INVALID_ARG, - "Invalid lk_owner len (%d)", len); - goto out; - } + if ((len <= 0) || (len > GFAPI_MAX_LOCK_OWNER_LEN)) { + errno = EINVAL; + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "Invalid lk_owner len (%d)", len); + goto out; + } - glfd->lk_owner.len = len; + glfd->lk_owner.len = len; - memcpy (glfd->lk_owner.data, data, len); + memcpy(glfd->lk_owner.data, data, len); - ret = 0; + ret = 0; out: - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_fd_set_lkowner, 3.10.7); struct glfs_fd * -pub_glfs_dup (struct glfs_fd *glfd) -{ - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct glfs_fd *dupfd = NULL; - struct glfs *fs = NULL; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - fs = glfd->fs; - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } - - fd = glfs_resolve_fd (fs, subvol, glfd); - if (!fd) { - errno = EBADFD; - goto out; - } - - dupfd = glfs_fd_new (fs); - if (!dupfd) { - errno = ENOMEM; - goto out; - } - - dupfd->fd = fd_ref (fd); - dupfd->state = glfd->state; +pub_glfs_dup(struct glfs_fd *glfd) +{ + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct glfs_fd *dupfd = NULL; + struct glfs *fs = NULL; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + fs = glfd->fs; + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(fs, subvol, glfd); + if (!fd) { + errno = EBADFD; + goto out; + } + + dupfd = glfs_fd_new(fs); + if (!dupfd) { + errno = ENOMEM; + goto out; + } + + dupfd->fd = fd_ref(fd); + dupfd->state = glfd->state; out: - if (fd) - fd_unref (fd); - if (dupfd) - glfs_fd_bind (dupfd); - if (glfd) - GF_REF_PUT (glfd); + if (fd) + fd_unref(fd); + if (dupfd) + glfs_fd_bind(dupfd); + if (glfd) + GF_REF_PUT(glfd); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return dupfd; + return dupfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_dup, 3.4.0); static void -glfs_enqueue_upcall_data (struct glfs *fs, struct gf_upcall *upcall_data) +glfs_enqueue_upcall_data(struct glfs *fs, struct gf_upcall *upcall_data) { - int ret = -1; - upcall_entry *u_list = NULL; + int ret = -1; + upcall_entry *u_list = NULL; - if (!fs || !upcall_data) - goto out; + if (!fs || !upcall_data) + goto out; - u_list = GF_CALLOC (1, sizeof(*u_list), - glfs_mt_upcall_entry_t); + u_list = GF_CALLOC(1, sizeof(*u_list), glfs_mt_upcall_entry_t); - if (!u_list) { - gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + if (!u_list) { + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - INIT_LIST_HEAD (&u_list->upcall_list); + INIT_LIST_HEAD(&u_list->upcall_list); - gf_uuid_copy (u_list->upcall_data.gfid, upcall_data->gfid); - u_list->upcall_data.event_type = upcall_data->event_type; + gf_uuid_copy(u_list->upcall_data.gfid, upcall_data->gfid); + u_list->upcall_data.event_type = upcall_data->event_type; - switch (upcall_data->event_type) { + switch (upcall_data->event_type) { case GF_UPCALL_CACHE_INVALIDATION: - ret = glfs_get_upcall_cache_invalidation (&u_list->upcall_data, - upcall_data); - break; + ret = glfs_get_upcall_cache_invalidation(&u_list->upcall_data, + upcall_data); + break; case GF_UPCALL_RECALL_LEASE: - ret = glfs_get_upcall_lease (&u_list->upcall_data, - upcall_data); - break; + ret = glfs_get_upcall_lease(&u_list->upcall_data, upcall_data); + break; default: - break; - } + break; + } - if (ret) { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_INVALID_ENTRY, - "Upcall entry validation failed."); - goto out; - } + if (ret) { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY, + "Upcall entry validation failed."); + goto out; + } - pthread_mutex_lock (&fs->upcall_list_mutex); - { - list_add_tail (&u_list->upcall_list, - &fs->upcall_list); - } - pthread_mutex_unlock (&fs->upcall_list_mutex); + pthread_mutex_lock(&fs->upcall_list_mutex); + { + list_add_tail(&u_list->upcall_list, &fs->upcall_list); + } + pthread_mutex_unlock(&fs->upcall_list_mutex); - ret = 0; + ret = 0; out: - if (ret && u_list) { - GF_FREE (u_list->upcall_data.data); - GF_FREE(u_list); - } + if (ret && u_list) { + GF_FREE(u_list->upcall_data.data); + GF_FREE(u_list); + } } static void -glfs_free_upcall_lease (void *to_free) +glfs_free_upcall_lease(void *to_free) { - struct glfs_upcall_lease *arg = to_free; + struct glfs_upcall_lease *arg = to_free; - if (!arg) - return; + if (!arg) + return; - if (arg->object) - glfs_h_close (arg->object); + if (arg->object) + glfs_h_close(arg->object); - GF_FREE (arg); + GF_FREE(arg); } int -glfs_recall_lease_fd (struct glfs *fs, - struct gf_upcall *up_data) -{ - struct gf_upcall_recall_lease *recall_lease = NULL; - xlator_t *subvol = NULL; - int ret = 0; - inode_t *inode = NULL; - struct glfs_fd *glfd = NULL; - struct glfs_fd *tmp = NULL; - struct list_head glfd_list = { 0, }; - fd_t *fd = NULL; - uint64_t value = 0; - struct glfs_lease lease = {0, }; - - GF_VALIDATE_OR_GOTO ("gfapi", up_data, out); - GF_VALIDATE_OR_GOTO ("gfapi", fs, out); - - recall_lease = up_data->data; - GF_VALIDATE_OR_GOTO ("gfapi", recall_lease, out); - - INIT_LIST_HEAD(&glfd_list); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - gf_msg_debug (THIS->name, 0, - "Recall lease received for gfid:%s", - uuid_utoa(up_data->gfid)); - - - inode = inode_find (subvol->itable, up_data->gfid); - if (!inode) { - ret = -1; - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_INODE_FIND_FAILED, - "Unable to find inode entry for gfid:%s graph id:%d", - uuid_utoa(up_data->gfid), subvol->graph->id); - goto out; +glfs_recall_lease_fd(struct glfs *fs, struct gf_upcall *up_data) +{ + struct gf_upcall_recall_lease *recall_lease = NULL; + xlator_t *subvol = NULL; + int ret = 0; + inode_t *inode = NULL; + struct glfs_fd *glfd = NULL; + struct glfs_fd *tmp = NULL; + struct list_head glfd_list = { + 0, + }; + fd_t *fd = NULL; + uint64_t value = 0; + struct glfs_lease lease = { + 0, + }; + + GF_VALIDATE_OR_GOTO("gfapi", up_data, out); + GF_VALIDATE_OR_GOTO("gfapi", fs, out); + + recall_lease = up_data->data; + GF_VALIDATE_OR_GOTO("gfapi", recall_lease, out); + + INIT_LIST_HEAD(&glfd_list); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + gf_msg_debug(THIS->name, 0, "Recall lease received for gfid:%s", + uuid_utoa(up_data->gfid)); + + inode = inode_find(subvol->itable, up_data->gfid); + if (!inode) { + ret = -1; + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INODE_FIND_FAILED, + "Unable to find inode entry for gfid:%s graph id:%d", + uuid_utoa(up_data->gfid), subvol->graph->id); + goto out; + } + + LOCK(&inode->lock); + { + list_for_each_entry(fd, &inode->fd_list, inode_list) + { + ret = fd_ctx_get(fd, subvol, &value); + glfd = (struct glfs_fd *)value; + if (glfd) { + gf_msg_trace(THIS->name, 0, "glfd (%p) has held lease", glfd); + GF_REF_GET(glfd); + list_add_tail(&glfd->list, &glfd_list); + } } + } + UNLOCK(&inode->lock); - LOCK (&inode->lock); + list_for_each_entry_safe(glfd, tmp, &glfd_list, list) + { + LOCK(&glfd->lock); { - list_for_each_entry (fd, &inode->fd_list, inode_list) { - ret = fd_ctx_get (fd, subvol, &value); - glfd = (struct glfs_fd *) value; - if (glfd) { - gf_msg_trace (THIS->name, 0, - "glfd (%p) has held lease", glfd); - GF_REF_GET (glfd); - list_add_tail (&glfd->list, &glfd_list); - } - } + if (glfd->state != GLFD_CLOSE) { + gf_msg_trace(THIS->name, 0, + "glfd (%p) has held lease, " + "calling recall cbk", + glfd); + glfd->cbk(lease, glfd->cookie); + } } - UNLOCK (&inode->lock); - - list_for_each_entry_safe (glfd, tmp, &glfd_list, list) { - LOCK (&glfd->lock); - { - if (glfd->state != GLFD_CLOSE) { - gf_msg_trace (THIS->name, 0, - "glfd (%p) has held lease, " - "calling recall cbk", glfd); - glfd->cbk (lease, glfd->cookie); - } - } - UNLOCK (&glfd->lock); + UNLOCK(&glfd->lock); - list_del_init (&glfd->list); - GF_REF_PUT (glfd); - } + list_del_init(&glfd->list); + GF_REF_PUT(glfd); + } out: - return ret; + return ret; } int -glfs_recall_lease_upcall (struct glfs *fs, - struct glfs_upcall *up_arg, - struct gf_upcall *up_data) -{ - struct gf_upcall_recall_lease *recall_lease = NULL; - struct glfs_object *object = NULL; - xlator_t *subvol = NULL; - int ret = -1; - struct glfs_upcall_lease *up_lease_arg = NULL; - - GF_VALIDATE_OR_GOTO ("gfapi", up_data, out); - GF_VALIDATE_OR_GOTO ("gfapi", fs, out); - - recall_lease = up_data->data; - GF_VALIDATE_OR_GOTO ("gfapi", recall_lease, out); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } - - gf_msg_debug (THIS->name, 0, - "Recall lease received for gfid:%s", - uuid_utoa(up_data->gfid)); - - object = glfs_h_find_handle (fs, up_data->gfid, - GFAPI_HANDLE_LENGTH); - if (!object) { - /* The reason handle creation will fail is because we - * couldn't find the inode in the gfapi inode table. - * - * But since application would have taken inode_ref, the - * only case when this can happen is when it has closed - * the handle and hence will no more be interested in - * the upcall for this particular gfid. - */ - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_CREATE_HANDLE_FAILED, - "handle creation of %s failed", - uuid_utoa (up_data->gfid)); - errno = ESTALE; - goto out; - } - - up_lease_arg = GF_CALLOC (1, sizeof (struct glfs_upcall_lease), - glfs_mt_upcall_inode_t); - up_lease_arg->object = object; +glfs_recall_lease_upcall(struct glfs *fs, struct glfs_upcall *up_arg, + struct gf_upcall *up_data) +{ + struct gf_upcall_recall_lease *recall_lease = NULL; + struct glfs_object *object = NULL; + xlator_t *subvol = NULL; + int ret = -1; + struct glfs_upcall_lease *up_lease_arg = NULL; + + GF_VALIDATE_OR_GOTO("gfapi", up_data, out); + GF_VALIDATE_OR_GOTO("gfapi", fs, out); + + recall_lease = up_data->data; + GF_VALIDATE_OR_GOTO("gfapi", recall_lease, out); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } + + gf_msg_debug(THIS->name, 0, "Recall lease received for gfid:%s", + uuid_utoa(up_data->gfid)); + + object = glfs_h_find_handle(fs, up_data->gfid, GFAPI_HANDLE_LENGTH); + if (!object) { + /* The reason handle creation will fail is because we + * couldn't find the inode in the gfapi inode table. + * + * But since application would have taken inode_ref, the + * only case when this can happen is when it has closed + * the handle and hence will no more be interested in + * the upcall for this particular gfid. + */ + gf_msg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_CREATE_HANDLE_FAILED, + "handle creation of %s failed", uuid_utoa(up_data->gfid)); + errno = ESTALE; + goto out; + } - GF_VALIDATE_OR_GOTO ("glfs_recall_lease", - up_lease_arg, out); + up_lease_arg = GF_CALLOC(1, sizeof(struct glfs_upcall_lease), + glfs_mt_upcall_inode_t); + up_lease_arg->object = object; + GF_VALIDATE_OR_GOTO("glfs_recall_lease", up_lease_arg, out); - up_lease_arg->lease_type = recall_lease->lease_type; + up_lease_arg->lease_type = recall_lease->lease_type; - up_arg->reason = GF_UPCALL_RECALL_LEASE; - up_arg->event = up_lease_arg; - up_arg->free_event = glfs_free_upcall_lease; + up_arg->reason = GF_UPCALL_RECALL_LEASE; + up_arg->event = up_lease_arg; + up_arg->free_event = glfs_free_upcall_lease; - ret = 0; + ret = 0; out: - if (ret) { - /* Close p_object and oldp_object as well if being referenced.*/ - if (object) - glfs_h_close (object); + if (ret) { + /* Close p_object and oldp_object as well if being referenced.*/ + if (object) + glfs_h_close(object); - /* Set reason to prevent applications from using ->event */ - up_arg->reason = GF_UPCALL_EVENT_NULL; - } - return ret; + /* Set reason to prevent applications from using ->event */ + up_arg->reason = GF_UPCALL_EVENT_NULL; + } + return ret; } static void -glfs_cbk_upcall_data (struct glfs *fs, struct gf_upcall *upcall_data) +glfs_cbk_upcall_data(struct glfs *fs, struct gf_upcall *upcall_data) { - int ret = -1; - struct glfs_upcall *up_arg = NULL; + int ret = -1; + struct glfs_upcall *up_arg = NULL; - if (!fs || !upcall_data) - goto out; + if (!fs || !upcall_data) + goto out; - if (!(fs->upcall_events & upcall_data->event_type)) { - /* ignore events which application hasn't registered*/ - goto out; - } + if (!(fs->upcall_events & upcall_data->event_type)) { + /* ignore events which application hasn't registered*/ + goto out; + } - up_arg = GLFS_CALLOC (1, sizeof (struct gf_upcall), - glfs_release_upcall, - glfs_mt_upcall_entry_t); - if (!up_arg) { - gf_msg (THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, - "Upcall entry allocation failed."); - goto out; - } + up_arg = GLFS_CALLOC(1, sizeof(struct gf_upcall), glfs_release_upcall, + glfs_mt_upcall_entry_t); + if (!up_arg) { + gf_msg(THIS->name, GF_LOG_ERROR, ENOMEM, API_MSG_ALLOC_FAILED, + "Upcall entry allocation failed."); + goto out; + } - switch (upcall_data->event_type) { + switch (upcall_data->event_type) { case GF_UPCALL_CACHE_INVALIDATION: - ret = glfs_h_poll_cache_invalidation (fs, up_arg, upcall_data); - break; + ret = glfs_h_poll_cache_invalidation(fs, up_arg, upcall_data); + break; case GF_UPCALL_RECALL_LEASE: - ret = glfs_recall_lease_upcall (fs, up_arg, upcall_data); - break; + ret = glfs_recall_lease_upcall(fs, up_arg, upcall_data); + break; default: - errno = EINVAL; - } - - if (!ret && (up_arg->reason != GLFS_UPCALL_EVENT_NULL)) { - /* It could so happen that the file which got - * upcall notification may have got deleted by - * the same client. In such cases up_arg->reason - * is set to GLFS_UPCALL_EVENT_NULL. No need to - * send upcall then */ - (fs->up_cbk) (up_arg, fs->up_data); - } else if (up_arg->reason == GLFS_UPCALL_EVENT_NULL) { - gf_msg (THIS->name, GF_LOG_DEBUG, errno, - API_MSG_INVALID_ENTRY, - "Upcall_EVENT_NULL received. Skipping it."); - goto out; - } else { - gf_msg (THIS->name, GF_LOG_ERROR, errno, - API_MSG_INVALID_ENTRY, - "Upcall entry validation failed."); - goto out; - } - - /* application takes care of calling glfs_free on up_arg post - * their processing */ - ret = 0; + errno = EINVAL; + } + + if (!ret && (up_arg->reason != GLFS_UPCALL_EVENT_NULL)) { + /* It could so happen that the file which got + * upcall notification may have got deleted by + * the same client. In such cases up_arg->reason + * is set to GLFS_UPCALL_EVENT_NULL. No need to + * send upcall then */ + (fs->up_cbk)(up_arg, fs->up_data); + } else if (up_arg->reason == GLFS_UPCALL_EVENT_NULL) { + gf_msg(THIS->name, GF_LOG_DEBUG, errno, API_MSG_INVALID_ENTRY, + "Upcall_EVENT_NULL received. Skipping it."); + goto out; + } else { + gf_msg(THIS->name, GF_LOG_ERROR, errno, API_MSG_INVALID_ENTRY, + "Upcall entry validation failed."); + goto out; + } + + /* application takes care of calling glfs_free on up_arg post + * their processing */ + ret = 0; out: - if (ret && up_arg) { - GLFS_FREE (up_arg); - } + if (ret && up_arg) { + GLFS_FREE(up_arg); + } - return; + return; } /* @@ -5317,251 +5363,254 @@ out: * to be read/polled by the applications. */ void -priv_glfs_process_upcall_event (struct glfs *fs, void *data) +priv_glfs_process_upcall_event(struct glfs *fs, void *data) { - glusterfs_ctx_t *ctx = NULL; - struct gf_upcall *upcall_data = NULL; - - DECLARE_OLD_THIS; - - gf_msg_debug (THIS->name, 0, - "Upcall gfapi callback is called"); + glusterfs_ctx_t *ctx = NULL; + struct gf_upcall *upcall_data = NULL; - __GLFS_ENTRY_VALIDATE_FS (fs, err); + DECLARE_OLD_THIS; - if (!data) - goto out; - - /* Unlike in I/O path, "glfs_fini" would not have freed - * 'fs' by the time we take lock as it waits for all epoll - * threads to exit including this - */ - pthread_mutex_lock (&fs->mutex); - { - ctx = fs->ctx; - - /* if we're not interested in upcalls (anymore), skip them */ - if (ctx->cleanup_started || !fs->cache_upcalls) { - pthread_mutex_unlock (&fs->mutex); - goto out; - } + gf_msg_debug(THIS->name, 0, "Upcall gfapi callback is called"); - fs->pin_refcnt++; - } - pthread_mutex_unlock (&fs->mutex); + __GLFS_ENTRY_VALIDATE_FS(fs, err); - upcall_data = (struct gf_upcall *)data; + if (!data) + goto out; - gf_msg_trace (THIS->name, 0, "Upcall gfapi gfid = %s" , - (char *)(upcall_data->gfid)); + /* Unlike in I/O path, "glfs_fini" would not have freed + * 'fs' by the time we take lock as it waits for all epoll + * threads to exit including this + */ + pthread_mutex_lock(&fs->mutex); + { + ctx = fs->ctx; - /* * - * TODO: RECALL LEASE for each glfd - * - * In case of RECALL_LEASE, we could associate separate - * cbk function for each glfd either by - * - extending pub_glfs_lease to accept new args (recall_cbk_fn, cookie) - * - or by defining new API "glfs_register_recall_cbk_fn (glfd, recall_cbk_fn, cookie) - * . In such cases, flag it and instead of calling below upcall functions, define - * a new one to go through the glfd list and invoke each of theirs recall_cbk_fn. - * */ - - if (fs->up_cbk) { /* upcall cbk registered */ - (void) glfs_cbk_upcall_data (fs, upcall_data); - } else { - (void) glfs_enqueue_upcall_data (fs, upcall_data); + /* if we're not interested in upcalls (anymore), skip them */ + if (ctx->cleanup_started || !fs->cache_upcalls) { + pthread_mutex_unlock(&fs->mutex); + goto out; } - pthread_mutex_lock (&fs->mutex); - { - fs->pin_refcnt--; - } - pthread_mutex_unlock (&fs->mutex); + fs->pin_refcnt++; + } + pthread_mutex_unlock(&fs->mutex); + + upcall_data = (struct gf_upcall *)data; + + gf_msg_trace(THIS->name, 0, "Upcall gfapi gfid = %s", + (char *)(upcall_data->gfid)); + + /* * + * TODO: RECALL LEASE for each glfd + * + * In case of RECALL_LEASE, we could associate separate + * cbk function for each glfd either by + * - extending pub_glfs_lease to accept new args (recall_cbk_fn, cookie) + * - or by defining new API "glfs_register_recall_cbk_fn (glfd, + * recall_cbk_fn, cookie) . In such cases, flag it and instead of calling + * below upcall functions, define a new one to go through the glfd list and + * invoke each of theirs recall_cbk_fn. + * */ + + if (fs->up_cbk) { /* upcall cbk registered */ + (void)glfs_cbk_upcall_data(fs, upcall_data); + } else { + (void)glfs_enqueue_upcall_data(fs, upcall_data); + } + + pthread_mutex_lock(&fs->mutex); + { + fs->pin_refcnt--; + } + pthread_mutex_unlock(&fs->mutex); out: - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; err: - return; + return; } GFAPI_SYMVER_PRIVATE_DEFAULT(glfs_process_upcall_event, 3.7.0); ssize_t -glfs_anonymous_pwritev (struct glfs *fs, struct glfs_object *object, - const struct iovec *iovec, int iovcnt, - off_t offset, int flags) -{ - xlator_t *subvol = NULL; - struct iobref *iobref = NULL; - struct iobuf *iobuf = NULL; - struct iovec iov = {0, }; - inode_t *inode = NULL; - fd_t *fd = NULL; - int ret = -1; - size_t size = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - ret = -1; - errno = ESTALE; - goto out; - } - - fd = fd_anonymous (inode); - if (!fd) { - ret = -1; - gf_msg ("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, - "Allocating anonymous fd failed"); - errno = ENOMEM; - goto out; - } - - size = iov_length (iovec, iovcnt); - - iobuf = iobuf_get2 (subvol->ctx->iobuf_pool, size); - if (!iobuf) { - ret = -1; - errno = ENOMEM; - goto out; - } - - iobref = iobref_new (); - if (!iobref) { - iobuf_unref (iobuf); - errno = ENOMEM; - ret = -1; - goto out; - } - - ret = iobref_add (iobref, iobuf); - if (ret) { - iobuf_unref (iobuf); - iobref_unref (iobref); - errno = ENOMEM; - ret = -1; - goto out; - } - - iov_unload (iobuf_ptr (iobuf), iovec, iovcnt); - - iov.iov_base = iobuf_ptr (iobuf); - iov.iov_len = size; - - /* TODO : set leaseid */ - ret = syncop_writev (subvol, fd, &iov, 1, offset, iobref, flags, - NULL, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - iobuf_unref (iobuf); - iobref_unref (iobref); - - if (ret <= 0) - goto out; +glfs_anonymous_pwritev(struct glfs *fs, struct glfs_object *object, + const struct iovec *iovec, int iovcnt, off_t offset, + int flags) +{ + xlator_t *subvol = NULL; + struct iobref *iobref = NULL; + struct iobuf *iobuf = NULL; + struct iovec iov = { + 0, + }; + inode_t *inode = NULL; + fd_t *fd = NULL; + int ret = -1; + size_t size = -1; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + ret = -1; + errno = ESTALE; + goto out; + } + + fd = fd_anonymous(inode); + if (!fd) { + ret = -1; + gf_msg("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, + "Allocating anonymous fd failed"); + errno = ENOMEM; + goto out; + } + + size = iov_length(iovec, iovcnt); + + iobuf = iobuf_get2(subvol->ctx->iobuf_pool, size); + if (!iobuf) { + ret = -1; + errno = ENOMEM; + goto out; + } + + iobref = iobref_new(); + if (!iobref) { + iobuf_unref(iobuf); + errno = ENOMEM; + ret = -1; + goto out; + } + + ret = iobref_add(iobref, iobuf); + if (ret) { + iobuf_unref(iobuf); + iobref_unref(iobref); + errno = ENOMEM; + ret = -1; + goto out; + } + + iov_unload(iobuf_ptr(iobuf), iovec, iovcnt); + + iov.iov_base = iobuf_ptr(iobuf); + iov.iov_len = size; + + /* TODO : set leaseid */ + ret = syncop_writev(subvol, fd, &iov, 1, offset, iobref, flags, NULL, NULL, + NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + iobuf_unref(iobuf); + iobref_unref(iobref); + + if (ret <= 0) + goto out; out: - if (fd) - fd_unref(fd); + if (fd) + fd_unref(fd); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } ssize_t -glfs_anonymous_preadv (struct glfs *fs, struct glfs_object *object, - const struct iovec *iovec, int iovcnt, - off_t offset, int flags) -{ - xlator_t *subvol = NULL; - struct iovec *iov = NULL; - struct iobref *iobref = NULL; - inode_t *inode = NULL; - fd_t *fd = NULL; - int cnt = 0; - ssize_t ret = -1; - ssize_t size = -1; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - ret = -1; - errno = ESTALE; - goto out; - } - - fd = fd_anonymous (inode); - if (!fd) { - ret = -1; - gf_msg ("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, - "Allocating anonymous fd failed"); - errno = ENOMEM; - goto out; - } - - size = iov_length (iovec, iovcnt); - - /* TODO : set leaseid */ - ret = syncop_readv (subvol, fd, size, offset, flags, &iov, &cnt, - &iobref, NULL, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret <= 0) - goto out; - - size = iov_copy (iovec, iovcnt, iov, cnt); - - ret = size; +glfs_anonymous_preadv(struct glfs *fs, struct glfs_object *object, + const struct iovec *iovec, int iovcnt, off_t offset, + int flags) +{ + xlator_t *subvol = NULL; + struct iovec *iov = NULL; + struct iobref *iobref = NULL; + inode_t *inode = NULL; + fd_t *fd = NULL; + int cnt = 0; + ssize_t ret = -1; + ssize_t size = -1; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + ret = -1; + errno = ESTALE; + goto out; + } + + fd = fd_anonymous(inode); + if (!fd) { + ret = -1; + gf_msg("gfapi", GF_LOG_ERROR, ENOMEM, API_MSG_FDCREATE_FAILED, + "Allocating anonymous fd failed"); + errno = ENOMEM; + goto out; + } + + size = iov_length(iovec, iovcnt); + + /* TODO : set leaseid */ + ret = syncop_readv(subvol, fd, size, offset, flags, &iov, &cnt, &iobref, + NULL, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret <= 0) + goto out; + + size = iov_copy(iovec, iovcnt, iov, cnt); + + ret = size; out: - if (iov) - GF_FREE (iov); - if (iobref) - iobref_unref (iobref); - if (fd) - fd_unref(fd); + if (iov) + GF_FREE(iov); + if (iobref) + iobref_unref(iobref); + if (fd) + fd_unref(fd); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } -static void glfs_release_xreaddirp_stat (void *ptr) +static void +glfs_release_xreaddirp_stat(void *ptr) { - struct glfs_xreaddirp_stat *to_free = ptr; + struct glfs_xreaddirp_stat *to_free = ptr; - if (to_free->object) - glfs_h_close (to_free->object); + if (to_free->object) + glfs_h_close(to_free->object); } /* @@ -5569,253 +5618,248 @@ static void glfs_release_xreaddirp_stat (void *ptr) * xstat along with dirents. */ int -pub_glfs_xreaddirplus_r (struct glfs_fd *glfd, uint32_t flags, - struct glfs_xreaddirp_stat **xstat_p, - struct dirent *ext, - struct dirent **res) +pub_glfs_xreaddirplus_r(struct glfs_fd *glfd, uint32_t flags, + struct glfs_xreaddirp_stat **xstat_p, + struct dirent *ext, struct dirent **res) { - int ret = -1; - gf_dirent_t *entry = NULL; - struct dirent *buf = NULL; - struct glfs_xreaddirp_stat *xstat = NULL; + int ret = -1; + gf_dirent_t *entry = NULL; + struct dirent *buf = NULL; + struct glfs_xreaddirp_stat *xstat = NULL; - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); - GF_REF_GET (glfd); + GF_REF_GET(glfd); - GF_VALIDATE_OR_GOTO (THIS->name, xstat_p, out); - GF_VALIDATE_OR_GOTO (THIS->name, res, out); + GF_VALIDATE_OR_GOTO(THIS->name, xstat_p, out); + GF_VALIDATE_OR_GOTO(THIS->name, res, out); - errno = 0; + errno = 0; - if (ext) - buf = ext; - else - buf = glfs_readdirbuf_get (glfd); + if (ext) + buf = ext; + else + buf = glfs_readdirbuf_get(glfd); - if (!buf) - goto out; + if (!buf) + goto out; - xstat = GLFS_CALLOC(1, sizeof(struct glfs_xreaddirp_stat), - glfs_release_xreaddirp_stat, - glfs_mt_xreaddirp_stat_t); + xstat = GLFS_CALLOC(1, sizeof(struct glfs_xreaddirp_stat), + glfs_release_xreaddirp_stat, glfs_mt_xreaddirp_stat_t); - if (!xstat) - goto out; + if (!xstat) + goto out; - /* this is readdirplus operation */ - entry = glfd_entry_next (glfd, 1); + /* this is readdirplus operation */ + entry = glfd_entry_next(glfd, 1); - /* XXX: Ideally when we reach EOD, errno should have been - * set to ENOENT. But that doesn't seem to be the case. - * - * The only way to confirm if its EOD at this point is that - * errno == 0 and entry == NULL - */ - if (errno) - goto out; - - if (!entry) { - /* reached EOD, ret = 0 */ - ret = 0; - *res = NULL; - *xstat_p = NULL; - - /* free xstat as applications shall not be using it */ - GLFS_FREE (xstat); - - goto out; - } + /* XXX: Ideally when we reach EOD, errno should have been + * set to ENOENT. But that doesn't seem to be the case. + * + * The only way to confirm if its EOD at this point is that + * errno == 0 and entry == NULL + */ + if (errno) + goto out; - *res = buf; - gf_dirent_to_dirent (entry, buf); - - if (flags & GFAPI_XREADDIRP_STAT) { - glfs_iatt_to_stat (glfd->fs, &entry->d_stat, &xstat->st); - xstat->flags_handled |= GFAPI_XREADDIRP_STAT; - } - - if ((flags & GFAPI_XREADDIRP_HANDLE) && - /* skip . and .. */ - strcmp(buf->d_name, ".") - && strcmp(buf->d_name, "..")) { - - /* Now create object. - * We can use "glfs_h_find_handle" as well as inodes would have - * already got linked as part of 'gf_link_inodes_from_dirent' */ - xstat->object = glfs_h_create_from_handle (glfd->fs, - entry->d_stat.ia_gfid, - GFAPI_HANDLE_LENGTH, - NULL); - - if (xstat->object) { /* success */ - /* note: xstat->object->inode->ref is taken - * This shall be unref'ed when application does - * glfs_free(xstat) */ - xstat->flags_handled |= GFAPI_XREADDIRP_HANDLE; - } + if (!entry) { + /* reached EOD, ret = 0 */ + ret = 0; + *res = NULL; + *xstat_p = NULL; + + /* free xstat as applications shall not be using it */ + GLFS_FREE(xstat); + + goto out; + } + + *res = buf; + gf_dirent_to_dirent(entry, buf); + + if (flags & GFAPI_XREADDIRP_STAT) { + glfs_iatt_to_stat(glfd->fs, &entry->d_stat, &xstat->st); + xstat->flags_handled |= GFAPI_XREADDIRP_STAT; + } + + if ((flags & GFAPI_XREADDIRP_HANDLE) && + /* skip . and .. */ + strcmp(buf->d_name, ".") && strcmp(buf->d_name, "..")) { + /* Now create object. + * We can use "glfs_h_find_handle" as well as inodes would have + * already got linked as part of 'gf_link_inodes_from_dirent' */ + xstat->object = glfs_h_create_from_handle( + glfd->fs, entry->d_stat.ia_gfid, GFAPI_HANDLE_LENGTH, NULL); + + if (xstat->object) { /* success */ + /* note: xstat->object->inode->ref is taken + * This shall be unref'ed when application does + * glfs_free(xstat) */ + xstat->flags_handled |= GFAPI_XREADDIRP_HANDLE; } + } - ret = xstat->flags_handled; - *xstat_p = xstat; + ret = xstat->flags_handled; + *xstat_p = xstat; - gf_msg_debug (THIS->name, 0, - "xreaddirp- requested_flags (%x) , processed_flags (%x)", - flags, xstat->flags_handled); + gf_msg_debug(THIS->name, 0, + "xreaddirp- requested_flags (%x) , processed_flags (%x)", + flags, xstat->flags_handled); out: - GF_REF_PUT (glfd); + GF_REF_PUT(glfd); - if (ret < 0) { - gf_msg (THIS->name, GF_LOG_WARNING, errno, - API_MSG_XREADDIRP_R_FAILED, - "glfs_x_readdirp_r failed - reason (%s)", - strerror(errno)); + if (ret < 0) { + gf_msg(THIS->name, GF_LOG_WARNING, errno, API_MSG_XREADDIRP_R_FAILED, + "glfs_x_readdirp_r failed - reason (%s)", strerror(errno)); - if (xstat) - GLFS_FREE (xstat); - } + if (xstat) + GLFS_FREE(xstat); + } - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; - return ret; + return ret; invalid_fs: - return -1; + return -1; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_r, 3.11.0); -struct stat* -pub_glfs_xreaddirplus_get_stat (struct glfs_xreaddirp_stat *xstat) +struct stat * +pub_glfs_xreaddirplus_get_stat(struct glfs_xreaddirp_stat *xstat) { - GF_VALIDATE_OR_GOTO ("glfs_xreaddirplus_get_stat", xstat, out); + GF_VALIDATE_OR_GOTO("glfs_xreaddirplus_get_stat", xstat, out); - if (!xstat->flags_handled & GFAPI_XREADDIRP_STAT) - gf_msg (THIS->name, GF_LOG_ERROR, errno, - LG_MSG_INVALID_ARG, - "GFAPI_XREADDIRP_STAT is not set. Flags" - "handled for xstat(%p) are (%x)", - xstat, xstat->flags_handled); - return &xstat->st; + if (!xstat->flags_handled & GFAPI_XREADDIRP_STAT) + gf_msg(THIS->name, GF_LOG_ERROR, errno, LG_MSG_INVALID_ARG, + "GFAPI_XREADDIRP_STAT is not set. Flags" + "handled for xstat(%p) are (%x)", + xstat, xstat->flags_handled); + return &xstat->st; out: - return NULL; + return NULL; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_xreaddirplus_get_stat, 3.11.0); void -gf_lease_to_glfs_lease (struct gf_lease *gf_lease, struct glfs_lease *lease) +gf_lease_to_glfs_lease(struct gf_lease *gf_lease, struct glfs_lease *lease) { - lease->cmd = gf_lease->cmd; - lease->lease_type = gf_lease->lease_type; - memcpy (lease->lease_id, gf_lease->lease_id, LEASE_ID_SIZE); + lease->cmd = gf_lease->cmd; + lease->lease_type = gf_lease->lease_type; + memcpy(lease->lease_id, gf_lease->lease_id, LEASE_ID_SIZE); } void -glfs_lease_to_gf_lease (struct glfs_lease *lease, struct gf_lease *gf_lease) +glfs_lease_to_gf_lease(struct glfs_lease *lease, struct gf_lease *gf_lease) { - gf_lease->cmd = lease->cmd; - gf_lease->lease_type = lease->lease_type; - memcpy (gf_lease->lease_id, lease->lease_id, LEASE_ID_SIZE); + gf_lease->cmd = lease->cmd; + gf_lease->lease_type = lease->lease_type; + memcpy(gf_lease->lease_id, lease->lease_id, LEASE_ID_SIZE); } int -pub_glfs_lease (struct glfs_fd *glfd, struct glfs_lease *lease, - glfs_recall_cbk fn, void *data) -{ - int ret = -1; - loc_t loc = {0, }; - xlator_t *subvol = NULL; - fd_t *fd = NULL; - struct gf_lease gf_lease = {0, }; - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FD (glfd, invalid_fs); - - GF_REF_GET (glfd); - - if (!is_valid_lease_id (lease->lease_id)) { +pub_glfs_lease(struct glfs_fd *glfd, struct glfs_lease *lease, + glfs_recall_cbk fn, void *data) +{ + int ret = -1; + loc_t loc = { + 0, + }; + xlator_t *subvol = NULL; + fd_t *fd = NULL; + struct gf_lease gf_lease = { + 0, + }; + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FD(glfd, invalid_fs); + + GF_REF_GET(glfd); + + if (!is_valid_lease_id(lease->lease_id)) { + ret = -1; + errno = EINVAL; + goto out; + } + + subvol = glfs_active_subvol(glfd->fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + fd = glfs_resolve_fd(glfd->fs, subvol, glfd); + if (!fd) { + ret = -1; + errno = EBADFD; + goto out; + } + + switch (lease->lease_type) { + case GLFS_RD_LEASE: + if ((fd->flags != O_RDONLY) && !(fd->flags & O_RDWR)) { ret = -1; errno = EINVAL; goto out; - } - - subvol = glfs_active_subvol (glfd->fs); - if (!subvol) { + } + break; + case GLFS_RW_LEASE: + if (!((fd->flags & O_WRONLY) || (fd->flags & O_RDWR))) { ret = -1; - errno = EIO; + errno = EINVAL; goto out; - } - - fd = glfs_resolve_fd (glfd->fs, subvol, glfd); - if (!fd) { + } + break; + default: + if (lease->cmd != GLFS_GET_LEASE) { ret = -1; - errno = EBADFD; + errno = EINVAL; goto out; - } - - switch (lease->lease_type) { - case GLFS_RD_LEASE: - if ((fd->flags != O_RDONLY) && !(fd->flags & O_RDWR)) { - ret = -1; - errno = EINVAL; - goto out; - } - break; - case GLFS_RW_LEASE: - if (!((fd->flags & O_WRONLY) || (fd->flags & O_RDWR))) { - ret = -1; - errno = EINVAL; - goto out; - } - break; - default: - if (lease->cmd != GLFS_GET_LEASE) { - ret = -1; - errno = EINVAL; - goto out; - } - break; - } + } + break; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (fd->inode, loc, out); + /* populate loc */ + GLFS_LOC_FILL_INODE(fd->inode, loc, out); - glfs_lease_to_gf_lease (lease, &gf_lease); + glfs_lease_to_gf_lease(lease, &gf_lease); - ret = syncop_lease (subvol, &loc, &gf_lease, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_lease(subvol, &loc, &gf_lease, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - gf_lease_to_glfs_lease (&gf_lease, lease); + gf_lease_to_glfs_lease(&gf_lease, lease); - /* TODO: Add leases for client replay - if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) - fd_lk_insert_and_merge (fd, cmd, &saved_flock); - */ - if (ret == 0) { - ret = fd_ctx_set (glfd->fd, subvol, (uint64_t)(long)glfd); - if (ret) { - gf_msg (subvol->name, GF_LOG_ERROR, ENOMEM, API_MSG_FDCTX_SET_FAILED, - "Setting fd ctx failed for fd(%p)", glfd->fd); - goto out; - } - glfd->cbk = fn; - glfd->cookie = data; + /* TODO: Add leases for client replay + if (ret == 0 && (cmd == F_SETLK || cmd == F_SETLKW)) + fd_lk_insert_and_merge (fd, cmd, &saved_flock); + */ + if (ret == 0) { + ret = fd_ctx_set(glfd->fd, subvol, (uint64_t)(long)glfd); + if (ret) { + gf_msg(subvol->name, GF_LOG_ERROR, ENOMEM, API_MSG_FDCTX_SET_FAILED, + "Setting fd ctx failed for fd(%p)", glfd->fd); + goto out; } + glfd->cbk = fn; + glfd->cookie = data; + } out: - if (glfd) - GF_REF_PUT (glfd); + if (glfd) + GF_REF_PUT(glfd); - if (subvol) - glfs_subvol_done (glfd->fs, subvol); + if (subvol) + glfs_subvol_done(glfd->fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_lease, 4.0.0); diff --git a/api/src/glfs-handleops.c b/api/src/glfs-handleops.c index 343fc38..7e9f4c5 100644 --- a/api/src/glfs-handleops.c +++ b/api/src/glfs-handleops.c @@ -8,7 +8,6 @@ * cases as published by the Free Software Foundation. */ - #include "glfs-internal.h" #include "glfs-mem-types.h" #include "syncop.h" @@ -17,1809 +16,1844 @@ #include "gfapi-messages.h" int -glfs_listxattr_process (void *value, size_t size, dict_t *xattr); +glfs_listxattr_process(void *value, size_t size, dict_t *xattr); static void -glfs_iatt_from_stat (struct stat *stat, int valid, struct iatt *iatt, - int *glvalid) +glfs_iatt_from_stat(struct stat *stat, int valid, struct iatt *iatt, + int *glvalid) { - /* validate in args */ - if ((stat == NULL) || (iatt == NULL) || (glvalid == NULL)) { - errno = EINVAL; - return; - } - - *glvalid = 0; - - if (valid & GFAPI_SET_ATTR_MODE) { - iatt->ia_prot = ia_prot_from_st_mode (stat->st_mode); - *glvalid |= GF_SET_ATTR_MODE; - } - - if (valid & GFAPI_SET_ATTR_UID) { - iatt->ia_uid = stat->st_uid; - *glvalid |= GF_SET_ATTR_UID; - } - - if (valid & GFAPI_SET_ATTR_GID) { - iatt->ia_gid = stat->st_gid; - *glvalid |= GF_SET_ATTR_GID; - } - - if (valid & GFAPI_SET_ATTR_ATIME) { - iatt->ia_atime = stat->st_atime; - iatt->ia_atime_nsec = ST_ATIM_NSEC (stat); - *glvalid |= GF_SET_ATTR_ATIME; - } - - if (valid & GFAPI_SET_ATTR_MTIME) { - iatt->ia_mtime = stat->st_mtime; - iatt->ia_mtime_nsec = ST_MTIM_NSEC (stat); - *glvalid |= GF_SET_ATTR_MTIME; - } - + /* validate in args */ + if ((stat == NULL) || (iatt == NULL) || (glvalid == NULL)) { + errno = EINVAL; return; + } + + *glvalid = 0; + + if (valid & GFAPI_SET_ATTR_MODE) { + iatt->ia_prot = ia_prot_from_st_mode(stat->st_mode); + *glvalid |= GF_SET_ATTR_MODE; + } + + if (valid & GFAPI_SET_ATTR_UID) { + iatt->ia_uid = stat->st_uid; + *glvalid |= GF_SET_ATTR_UID; + } + + if (valid & GFAPI_SET_ATTR_GID) { + iatt->ia_gid = stat->st_gid; + *glvalid |= GF_SET_ATTR_GID; + } + + if (valid & GFAPI_SET_ATTR_ATIME) { + iatt->ia_atime = stat->st_atime; + iatt->ia_atime_nsec = ST_ATIM_NSEC(stat); + *glvalid |= GF_SET_ATTR_ATIME; + } + + if (valid & GFAPI_SET_ATTR_MTIME) { + iatt->ia_mtime = stat->st_mtime; + iatt->ia_mtime_nsec = ST_MTIM_NSEC(stat); + *glvalid |= GF_SET_ATTR_MTIME; + } + + return; } struct glfs_object * -pub_glfs_h_lookupat (struct glfs *fs, struct glfs_object *parent, - const char *path, struct stat *stat, int follow) +pub_glfs_h_lookupat(struct glfs *fs, struct glfs_object *parent, + const char *path, struct stat *stat, int follow) { - int ret = 0; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - struct iatt iatt = {0, }; - struct glfs_object *object = NULL; - loc_t loc = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if (path == NULL) { - errno = EINVAL; - return NULL; - } + int ret = 0; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + struct iatt iatt = { + 0, + }; + struct glfs_object *object = NULL; + loc_t loc = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if (path == NULL) { + errno = EINVAL; + return NULL; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - if (parent) { - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + if (parent) { + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; } + } - /* fop/op */ - ret = glfs_resolve_at (fs, subvol, inode, path, &loc, &iatt, - follow, 0); + /* fop/op */ + ret = glfs_resolve_at(fs, subvol, inode, path, &loc, &iatt, follow, 0); - /* populate out args */ - if (!ret) { - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + /* populate out args */ + if (!ret) { + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_lookupat, 3.7.4); struct glfs_object * -pub_glfs_h_lookupat34 (struct glfs *fs, struct glfs_object *parent, - const char *path, struct stat *stat) +pub_glfs_h_lookupat34(struct glfs *fs, struct glfs_object *parent, + const char *path, struct stat *stat) { - return pub_glfs_h_lookupat (fs, parent, path, stat, 0); + return pub_glfs_h_lookupat(fs, parent, path, stat, 0); } GFAPI_SYMVER_PUBLIC(glfs_h_lookupat34, glfs_h_lookupat, 3.4.2); int -pub_glfs_h_statfs (struct glfs *fs, struct glfs_object *object, - struct statvfs *statvfs) +pub_glfs_h_statfs(struct glfs *fs, struct glfs_object *object, + struct statvfs *statvfs) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((fs == NULL) || (object == NULL || statvfs == NULL)) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* validate in args */ - if ((fs == NULL) || (object == NULL || statvfs == NULL)) { - errno = EINVAL; - return -1; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + /* fop/op */ + ret = syncop_statfs(subvol, &loc, statvfs, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - /* fop/op */ - ret = syncop_statfs (subvol, &loc, statvfs, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - loc_wipe (&loc); + loc_wipe(&loc); out: - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_statfs, 3.7.0); int -pub_glfs_h_stat (struct glfs *fs, struct glfs_object *object, struct stat *stat) +pub_glfs_h_stat(struct glfs *fs, struct glfs_object *object, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = syncop_stat (subvol, &loc, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (!ret && stat) { - glfs_iatt_to_stat (fs, &iatt, stat); - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_stat(subvol, &loc, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (!ret && stat) { + glfs_iatt_to_stat(fs, &iatt, stat); + } out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_stat, 3.4.2); - int -pub_glfs_h_getattrs (struct glfs *fs, struct glfs_object *object, - struct stat *stat) +pub_glfs_h_getattrs(struct glfs *fs, struct glfs_object *object, + struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - struct iatt iatt = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + struct iatt iatt = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + ret = 0; + errno = ESTALE; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - ret = 0; - errno = ESTALE; - goto out; - } + /* fop/op */ + ret = glfs_resolve_base(fs, subvol, inode, &iatt); - /* fop/op */ - ret = glfs_resolve_base (fs, subvol, inode, &iatt); - - /* populate out args */ - if (!ret && stat) { - glfs_iatt_to_stat (fs, &iatt, stat); - } + /* populate out args */ + if (!ret && stat) { + glfs_iatt_to_stat(fs, &iatt, stat); + } out: - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_getattrs, 3.4.2); - int -glfs_h_getxattrs_common (struct glfs *fs, struct glfs_object *object, - dict_t **xattr, const char *name, - gf_boolean_t is_listxattr) +glfs_h_getxattrs_common(struct glfs *fs, struct glfs_object *object, + dict_t **xattr, const char *name, + gf_boolean_t is_listxattr) { - int ret = 0; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } - - if (!is_listxattr) { - if (!name || *name == '\0') { - errno = EINVAL; - return -1; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - errno = ENAMETOOLONG; - return -1; - } - } - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + int ret = 0; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; + if (!is_listxattr) { + if (!name || *name == '\0') { + errno = EINVAL; + return -1; } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - ret = syncop_getxattr (subvol, &loc, xattr, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + if (strlen(name) > GF_XATTR_NAME_MAX) { + errno = ENAMETOOLONG; + return -1; + } + } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + ret = syncop_getxattr(subvol, &loc, xattr, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - return ret; + return ret; } - int -pub_glfs_h_getxattrs (struct glfs *fs, struct glfs_object *object, - const char *name, void *value, size_t size) +pub_glfs_h_getxattrs(struct glfs *fs, struct glfs_object *object, + const char *name, void *value, size_t size) { - int ret = -1; - dict_t *xattr = NULL; + int ret = -1; + dict_t *xattr = NULL; - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return -1; - } + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - ret = glfs_h_getxattrs_common (fs, object, &xattr, name, - (name == NULL)); - if (ret) - goto out; + ret = glfs_h_getxattrs_common(fs, object, &xattr, name, (name == NULL)); + if (ret) + goto out; - /* If @name is NULL, means get all the xattrs (i.e listxattr). */ - if (name) - ret = glfs_getxattr_process (value, size, xattr, name); - else - ret = glfs_listxattr_process (value, size, xattr); + /* If @name is NULL, means get all the xattrs (i.e listxattr). */ + if (name) + ret = glfs_getxattr_process(value, size, xattr, name); + else + ret = glfs_listxattr_process(value, size, xattr); out: - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_getxattrs, 3.5.1); int -pub_glfs_h_setattrs (struct glfs *fs, struct glfs_object *object, - struct stat *stat, int valid) +pub_glfs_h_setattrs(struct glfs *fs, struct glfs_object *object, + struct stat *stat, int valid) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - int glvalid = 0; - - /* validate in args */ - if ((fs == NULL) || (object == NULL) || (stat == NULL)) { - errno = EINVAL; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* map valid masks from in args */ - glfs_iatt_from_stat (stat, valid, &iatt, &glvalid); - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = syncop_setattr (subvol, &loc, &iatt, glvalid, 0, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + int glvalid = 0; + + /* validate in args */ + if ((fs == NULL) || (object == NULL) || (stat == NULL)) { + errno = EINVAL; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* map valid masks from in args */ + glfs_iatt_from_stat(stat, valid, &iatt, &glvalid); + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_setattr(subvol, &loc, &iatt, glvalid, 0, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_setattrs, 3.4.2); - int -pub_glfs_h_setxattrs (struct glfs *fs, struct glfs_object *object, - const char *name, const void *value, size_t size, - int flags) +pub_glfs_h_setxattrs(struct glfs *fs, struct glfs_object *object, + const char *name, const void *value, size_t size, + int flags) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - dict_t *xattr = NULL; - void *value_cp = NULL; - - /* validate in args */ - if ((fs == NULL) || (object == NULL) || - (name == NULL) || (value == NULL)) { - errno = EINVAL; - return -1; - } - - if (!name || *name == '\0') { - errno = EINVAL; - return -1; - } - - if (strlen(name) > GF_XATTR_NAME_MAX) { - errno = ENAMETOOLONG; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - value_cp = gf_memdup (value, size); - GF_CHECK_ALLOC_AND_LOG (subvol->name, value_cp, ret, "Failed to" - " duplicate setxattr value", out); - - xattr = dict_for_key_value (name, value_cp, size, _gf_false); - if (!xattr) { - GF_FREE (value_cp); - ret = -1; - errno = ENOMEM; - goto out; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + dict_t *xattr = NULL; + void *value_cp = NULL; + + /* validate in args */ + if ((fs == NULL) || (object == NULL) || (name == NULL) || (value == NULL)) { + errno = EINVAL; + return -1; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + if (!name || *name == '\0') { + errno = EINVAL; + return -1; + } - /* fop/op */ - ret = syncop_setxattr (subvol, &loc, xattr, flags, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + if (strlen(name) > GF_XATTR_NAME_MAX) { + errno = ENAMETOOLONG; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + value_cp = gf_memdup(value, size); + GF_CHECK_ALLOC_AND_LOG(subvol->name, value_cp, ret, + "Failed to" + " duplicate setxattr value", + out); + + xattr = dict_for_key_value(name, value_cp, size, _gf_false); + if (!xattr) { + GF_FREE(value_cp); + ret = -1; + errno = ENOMEM; + goto out; + } + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_setxattr(subvol, &loc, xattr, flags, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr) - dict_unref (xattr); + if (xattr) + dict_unref(xattr); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_setxattrs, 3.5.0); - int -pub_glfs_h_removexattrs (struct glfs *fs, struct glfs_object *object, - const char *name) +pub_glfs_h_removexattrs(struct glfs *fs, struct glfs_object *object, + const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL) || (name == NULL)) { - errno = EINVAL; - return -1; - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL) || (name == NULL)) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_removexattr (subvol, &loc, name, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_removexattr(subvol, &loc, name, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_removexattrs, 3.5.1); - struct glfs_fd * -pub_glfs_h_open (struct glfs *fs, struct glfs_object *object, int flags) +pub_glfs_h_open(struct glfs *fs, struct glfs_object *object, int flags) { - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - dict_t *fop_attr = NULL; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - /* check types to open */ - if (IA_ISDIR (inode->ia_type)) { - ret = -1; - errno = EISDIR; - goto out; - } - - if (!IA_ISREG (inode->ia_type)) { - ret = -1; - errno = EINVAL; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) { - ret = -1; - errno = ENOMEM; - goto out; - } - - glfd->fd = fd_create (inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - glfd->fd->flags = flags; - - /* populate loc */ - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = get_fop_attr_thrd_key (&fop_attr); - if (ret) - gf_msg_debug ("gfapi", 0, "Getting leaseid from thread failed"); + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + dict_t *fop_attr = NULL; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + /* check types to open */ + if (IA_ISDIR(inode->ia_type)) { + ret = -1; + errno = EISDIR; + goto out; + } + + if (!IA_ISREG(inode->ia_type)) { + ret = -1; + errno = EINVAL; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) { + ret = -1; + errno = ENOMEM; + goto out; + } + + glfd->fd = fd_create(inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + glfd->fd->flags = flags; + + /* populate loc */ + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = get_fop_attr_thrd_key(&fop_attr); + if (ret) + gf_msg_debug("gfapi", 0, "Getting leaseid from thread failed"); + + ret = syncop_open(subvol, &loc, flags, glfd->fd, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + glfd->fd->flags = flags; - ret = syncop_open (subvol, &loc, flags, glfd->fd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); +out: + loc_wipe(&loc); - glfd->fd->flags = flags; + if (inode) + inode_unref(inode); + if (fop_attr) + dict_unref(fop_attr); -out: - loc_wipe (&loc); - - if (inode) - inode_unref (inode); - if (fop_attr) - dict_unref (fop_attr); - - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_open, 3.4.2); - struct glfs_object * -pub_glfs_h_creat (struct glfs *fs, struct glfs_object *parent, const char *path, - int flags, mode_t mode, struct stat *stat) +pub_glfs_h_creat(struct glfs *fs, struct glfs_object *parent, const char *path, + int flags, mode_t mode, struct stat *stat) { - int ret = -1; - fd_t *fd = NULL; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - ret = -1; - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; - } - - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - - fd = fd_create (loc.inode, getpid()); - if (!fd) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + fd_t *fd = NULL; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + ret = -1; + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, path); + + fd = fd_create(loc.inode, getpid()); + if (!fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + fd->flags = flags; + + /* fop/op */ + ret = syncop_create(subvol, &loc, flags, mode, fd, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - fd->flags = flags; - - /* fop/op */ - ret = syncop_create (subvol, &loc, flags, mode, fd, &iatt, - xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (ret == 0) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - /* Release the held reference */ - glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + /* Release the held reference */ + glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - if (fd) - fd_unref(fd); + if (fd) + fd_unref(fd); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_creat, 3.4.2); - struct glfs_object * -pub_glfs_h_mkdir (struct glfs *fs, struct glfs_object *parent, const char *path, - mode_t mode, struct stat *stat) +pub_glfs_h_mkdir(struct glfs *fs, struct glfs_object *parent, const char *path, + mode_t mode, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, path); + + /* fop/op */ + ret = syncop_mkdir(subvol, &loc, mode, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - - /* fop/op */ - ret = syncop_mkdir (subvol, &loc, mode, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if ( ret == 0 ) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_mkdir, 3.4.2); - struct glfs_object * -pub_glfs_h_mknod (struct glfs *fs, struct glfs_object *parent, const char *path, - mode_t mode, dev_t dev, struct stat *stat) +pub_glfs_h_mknod(struct glfs *fs, struct glfs_object *parent, const char *path, + mode_t mode, dev_t dev, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, path); + + /* fop/op */ + ret = syncop_mknod(subvol, &loc, mode, dev, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, path); - - /* fop/op */ - ret = syncop_mknod (subvol, &loc, mode, dev, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (ret == 0) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_mknod, 3.4.2); - int -pub_glfs_h_unlink (struct glfs *fs, struct glfs_object *parent, const char *path) +pub_glfs_h_unlink(struct glfs *fs, struct glfs_object *parent, const char *path) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (parent == NULL) || (path == NULL)) { - errno = EINVAL; - return -1; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if ( !subvol ) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - ret = glfs_resolve_at (fs, subvol, inode, path, &loc, NULL, 0 , 0); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (parent == NULL) || (path == NULL)) { + errno = EINVAL; + return -1; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + ret = glfs_resolve_at(fs, subvol, inode, path, &loc, NULL, 0, 0); + if (ret != 0) { + goto out; + } + + if (!IA_ISDIR(loc.inode->ia_type)) { + ret = syncop_unlink(subvol, &loc, NULL, NULL); + DECODE_SYNCOP_ERR(ret); if (ret != 0) { - goto out; + goto out; } - - if (!IA_ISDIR(loc.inode->ia_type)) { - ret = syncop_unlink (subvol, &loc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret != 0) { - goto out; - } - } else { - ret = syncop_rmdir (subvol, &loc, 0, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - if (ret != 0) { - goto out; - } + } else { + ret = syncop_rmdir(subvol, &loc, 0, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + if (ret != 0) { + goto out; } + } - if (ret == 0) - ret = glfs_loc_unlink (&loc); + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_unlink, 3.4.2); - struct glfs_fd * -pub_glfs_h_opendir (struct glfs *fs, struct glfs_object *object) +pub_glfs_h_opendir(struct glfs *fs, struct glfs_object *object) { - int ret = -1; - struct glfs_fd *glfd = NULL; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return NULL; - } - - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } - - if (!IA_ISDIR (inode->ia_type)) { - ret = -1; - errno = ENOTDIR; - goto out; - } - - glfd = glfs_fd_new (fs); - if (!glfd) - goto out; - - INIT_LIST_HEAD (&glfd->entries); - - glfd->fd = fd_create (inode, getpid()); - if (!glfd->fd) { - ret = -1; - errno = ENOMEM; - goto out; - } - - GLFS_LOC_FILL_INODE (inode, loc, out); - - /* fop/op */ - ret = syncop_opendir (subvol, &loc, glfd->fd, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + int ret = -1; + struct glfs_fd *glfd = NULL; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return NULL; + } + + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } + + if (!IA_ISDIR(inode->ia_type)) { + ret = -1; + errno = ENOTDIR; + goto out; + } + + glfd = glfs_fd_new(fs); + if (!glfd) + goto out; + + INIT_LIST_HEAD(&glfd->entries); + + glfd->fd = fd_create(inode, getpid()); + if (!glfd->fd) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_INODE(inode, loc, out); + + /* fop/op */ + ret = syncop_opendir(subvol, &loc, glfd->fd, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (ret && glfd) { - GF_REF_PUT (glfd); - glfd = NULL; - } else if (glfd) { - glfd_set_state_bind (glfd); - } + if (ret && glfd) { + GF_REF_PUT(glfd); + glfd = NULL; + } else if (glfd) { + glfd_set_state_bind(glfd); + } - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return glfd; + return glfd; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_opendir, 3.4.2); - int -pub_glfs_h_access (struct glfs *fs, struct glfs_object *object, int mask) +pub_glfs_h_access(struct glfs *fs, struct glfs_object *object, int mask) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((fs == NULL) || (object == NULL)) { - errno = EINVAL; - return ret; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((fs == NULL) || (object == NULL)) { + errno = EINVAL; + return ret; + } - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - GLFS_LOC_FILL_INODE (inode, loc, out); + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ + /* fop/op */ - ret = syncop_access (subvol, &loc, mask, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + ret = syncop_access(subvol, &loc, mask, NULL, NULL); + DECODE_SYNCOP_ERR(ret); out: - loc_wipe (&loc); - - if (inode) - inode_unref (inode); + loc_wipe(&loc); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_access, 3.6.0); - ssize_t -pub_glfs_h_extract_handle (struct glfs_object *object, unsigned char *handle, - int len) +pub_glfs_h_extract_handle(struct glfs_object *object, unsigned char *handle, + int len) { - ssize_t ret = -1; + ssize_t ret = -1; - /* validate in args */ - if (object == NULL) { - errno = EINVAL; - goto out; - } + /* validate in args */ + if (object == NULL) { + errno = EINVAL; + goto out; + } - if (!handle || !len) { - ret = GFAPI_HANDLE_LENGTH; - goto out; - } + if (!handle || !len) { + ret = GFAPI_HANDLE_LENGTH; + goto out; + } - if (len < GFAPI_HANDLE_LENGTH) - { - errno = ERANGE; - goto out; - } + if (len < GFAPI_HANDLE_LENGTH) { + errno = ERANGE; + goto out; + } - memcpy (handle, object->gfid, GFAPI_HANDLE_LENGTH); + memcpy(handle, object->gfid, GFAPI_HANDLE_LENGTH); - ret = GFAPI_HANDLE_LENGTH; + ret = GFAPI_HANDLE_LENGTH; out: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_extract_handle, 3.4.2); - struct glfs_object * -pub_glfs_h_create_from_handle (struct glfs *fs, unsigned char *handle, int len, - struct stat *stat) +pub_glfs_h_create_from_handle(struct glfs *fs, unsigned char *handle, int len, + struct stat *stat) { - loc_t loc = {0, }; - int ret = -1; - struct iatt iatt = {0, }; - inode_t *newinode = NULL; - xlator_t *subvol = NULL; - struct glfs_object *object = NULL; - uint64_t ctx_value = LOOKUP_NOT_NEEDED; - gf_boolean_t lookup_needed = _gf_false; - - /* validate in args */ - if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) { - errno = EINVAL; - return NULL; - } + loc_t loc = { + 0, + }; + int ret = -1; + struct iatt iatt = { + 0, + }; + inode_t *newinode = NULL; + xlator_t *subvol = NULL; + struct glfs_object *object = NULL; + uint64_t ctx_value = LOOKUP_NOT_NEEDED; + gf_boolean_t lookup_needed = _gf_false; + + /* validate in args */ + if ((fs == NULL) || (handle == NULL) || (len != GFAPI_HANDLE_LENGTH)) { + errno = EINVAL; + return NULL; + } - DECLARE_OLD_THIS; - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + errno = EIO; + goto out; + } - memcpy (loc.gfid, handle, GFAPI_HANDLE_LENGTH); - - /* make sure the gfid received is valid */ - GF_VALIDATE_OR_GOTO ("glfs_h_create_from_handle", - !(gf_uuid_is_null (loc.gfid)), out); - - newinode = inode_find (subvol->itable, loc.gfid); - if (newinode) { - if (!stat) /* No need of lookup */ - goto found; - - lookup_needed = inode_needs_lookup (newinode, THIS); - if (lookup_needed) { - loc.inode = newinode; - } else { - /* populate loc */ - GLFS_LOC_FILL_INODE (newinode, loc, fill_out); - - /* fop/op */ - ret = syncop_stat (subvol, &loc, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret) { -fill_out: - /* Drop the reference hold in inode_find */ - inode_unref (newinode); - goto out; - } - - glfs_iatt_to_stat (fs, &iatt, stat); - goto found; - } - } else { - loc.inode = inode_new (subvol->itable); - if (!loc.inode) { - errno = ENOMEM; - goto out; - } - } + memcpy(loc.gfid, handle, GFAPI_HANDLE_LENGTH); - ret = syncop_lookup (subvol, &loc, &iatt, 0, 0, 0); - DECODE_SYNCOP_ERR (ret); - if (ret) { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_REFRESH_FAILED, - "inode refresh of %s failed: %s", - uuid_utoa (loc.gfid), strerror (errno)); - goto out; - } + /* make sure the gfid received is valid */ + GF_VALIDATE_OR_GOTO("glfs_h_create_from_handle", + !(gf_uuid_is_null(loc.gfid)), out); - newinode = inode_link (loc.inode, 0, 0, &iatt); - if (newinode) { - if (newinode == loc.inode) { - inode_ctx_set (newinode, THIS, &ctx_value); - } - inode_lookup (newinode); - } else { - gf_msg (subvol->name, GF_LOG_WARNING, errno, - API_MSG_INODE_LINK_FAILED, - "inode linking of %s failed", uuid_utoa (loc.gfid)); - goto out; - } + newinode = inode_find(subvol->itable, loc.gfid); + if (newinode) { + if (!stat) /* No need of lookup */ + goto found; - /* populate stat */ - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + lookup_needed = inode_needs_lookup(newinode, THIS); + if (lookup_needed) { + loc.inode = newinode; + } else { + /* populate loc */ + GLFS_LOC_FILL_INODE(newinode, loc, fill_out); + + /* fop/op */ + ret = syncop_stat(subvol, &loc, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret) { + fill_out: + /* Drop the reference hold in inode_find */ + inode_unref(newinode); + goto out; + } + + glfs_iatt_to_stat(fs, &iatt, stat); + goto found; + } + } else { + loc.inode = inode_new(subvol->itable); + if (!loc.inode) { + errno = ENOMEM; + goto out; + } + } + + ret = syncop_lookup(subvol, &loc, &iatt, 0, 0, 0); + DECODE_SYNCOP_ERR(ret); + if (ret) { + gf_msg(subvol->name, GF_LOG_WARNING, errno, + API_MSG_INODE_REFRESH_FAILED, "inode refresh of %s failed: %s", + uuid_utoa(loc.gfid), strerror(errno)); + goto out; + } + + newinode = inode_link(loc.inode, 0, 0, &iatt); + if (newinode) { + if (newinode == loc.inode) { + inode_ctx_set(newinode, THIS, &ctx_value); + } + inode_lookup(newinode); + } else { + gf_msg(subvol->name, GF_LOG_WARNING, errno, API_MSG_INODE_LINK_FAILED, + "inode linking of %s failed", uuid_utoa(loc.gfid)); + goto out; + } + + /* populate stat */ + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); found: - object = GF_CALLOC (1, sizeof(struct glfs_object), - glfs_mt_glfs_object_t); - if (object == NULL) { - errno = ENOMEM; - ret = -1; - goto out; - } + object = GF_CALLOC(1, sizeof(struct glfs_object), glfs_mt_glfs_object_t); + if (object == NULL) { + errno = ENOMEM; + ret = -1; + goto out; + } - /* populate the return object */ - object->inode = newinode; - gf_uuid_copy (object->gfid, object->inode->gfid); + /* populate the return object */ + object->inode = newinode; + gf_uuid_copy(object->gfid, object->inode->gfid); out: - /* TODO: Check where the inode ref is being held? */ - loc_wipe (&loc); + /* TODO: Check where the inode ref is being held? */ + loc_wipe(&loc); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_create_from_handle, 3.4.2); - int -pub_glfs_h_close (struct glfs_object *object) +pub_glfs_h_close(struct glfs_object *object) { - /* since glfs_h_* objects hold a reference to inode - * it is safe to keep lookup count to '0' */ - inode_forget (object->inode, 0); - inode_unref (object->inode); - GF_FREE (object); + /* since glfs_h_* objects hold a reference to inode + * it is safe to keep lookup count to '0' */ + inode_forget(object->inode, 0); + inode_unref(object->inode); + GF_FREE(object); - return 0; + return 0; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_close, 3.4.2); - int -pub_glfs_h_truncate (struct glfs *fs, struct glfs_object *object, off_t offset) +pub_glfs_h_truncate(struct glfs *fs, struct glfs_object *object, off_t offset) { - loc_t loc = {0, }; - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; + loc_t loc = { + 0, + }; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + + DECLARE_OLD_THIS; + + /* validate in args */ + if (object == NULL) { + errno = EINVAL; + return -1; + } - DECLARE_OLD_THIS; + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* validate in args */ - if (object == NULL) { - errno = EINVAL; - return -1; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - GLFS_LOC_FILL_INODE (inode, loc, out); + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_truncate (subvol, &loc, (off_t)offset, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_truncate(subvol, &loc, (off_t)offset, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - /* populate out args */ - if (ret == 0) - ret = glfs_loc_unlink (&loc); + /* populate out args */ + if (ret == 0) + ret = glfs_loc_unlink(&loc); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_truncate, 3.4.2); - struct glfs_object * -pub_glfs_h_symlink (struct glfs *fs, struct glfs_object *parent, - const char *name, const char *data, struct stat *stat) +pub_glfs_h_symlink(struct glfs *fs, struct glfs_object *parent, + const char *name, const char *data, struct stat *stat) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - loc_t loc = {0, }; - struct iatt iatt = {0, }; - uuid_t gfid; - dict_t *xattr_req = NULL; - struct glfs_object *object = NULL; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((parent == NULL) || (name == NULL) || - (data == NULL)) { - errno = EINVAL; - return NULL; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, parent); - if (!inode) { - errno = ESTALE; - goto out; - } - - xattr_req = dict_new (); - if (!xattr_req) { - ret = -1; - errno = ENOMEM; - goto out; - } - - gf_uuid_generate (gfid); - ret = dict_set_gfuuid (xattr_req, "gfid-req", gfid, true); - if (ret) { - ret = -1; - errno = ENOMEM; - goto out; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + loc_t loc = { + 0, + }; + struct iatt iatt = { + 0, + }; + uuid_t gfid; + dict_t *xattr_req = NULL; + struct glfs_object *object = NULL; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((parent == NULL) || (name == NULL) || (data == NULL)) { + errno = EINVAL; + return NULL; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, parent); + if (!inode) { + errno = ESTALE; + goto out; + } + + xattr_req = dict_new(); + if (!xattr_req) { + ret = -1; + errno = ENOMEM; + goto out; + } + + gf_uuid_generate(gfid); + ret = dict_set_gfuuid(xattr_req, "gfid-req", gfid, true); + if (ret) { + ret = -1; + errno = ENOMEM; + goto out; + } + + GLFS_LOC_FILL_PINODE(inode, loc, ret, errno, out, name); + + /* fop/op */ + ret = syncop_symlink(subvol, &loc, data, &iatt, xattr_req, NULL); + DECODE_SYNCOP_ERR(ret); + + /* populate out args */ + if (ret == 0) { + ret = glfs_loc_link(&loc, &iatt); + if (ret != 0) { + goto out; } - GLFS_LOC_FILL_PINODE (inode, loc, ret, errno, out, name); - - /* fop/op */ - ret = syncop_symlink (subvol, &loc, data, &iatt, xattr_req, NULL); - DECODE_SYNCOP_ERR (ret); - - /* populate out args */ - if (ret == 0) { - ret = glfs_loc_link (&loc, &iatt); - if (ret != 0) { - goto out; - } - - if (stat) - glfs_iatt_to_stat (fs, &iatt, stat); + if (stat) + glfs_iatt_to_stat(fs, &iatt, stat); - ret = glfs_create_object (&loc, &object); - } + ret = glfs_create_object(&loc, &object); + } out: - if (ret && object != NULL) { - pub_glfs_h_close (object); - object = NULL; - } + if (ret && object != NULL) { + pub_glfs_h_close(object); + object = NULL; + } - loc_wipe(&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (xattr_req) - dict_unref (xattr_req); + if (xattr_req) + dict_unref(xattr_req); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return object; + return object; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_symlink, 3.4.2); - int -pub_glfs_h_readlink (struct glfs *fs, struct glfs_object *object, char *buf, - size_t bufsiz) +pub_glfs_h_readlink(struct glfs *fs, struct glfs_object *object, char *buf, + size_t bufsiz) { - loc_t loc = {0, }; - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - char *linkval = NULL; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((object == NULL) || (buf == NULL)) { - errno = EINVAL; - return -1; - } + loc_t loc = { + 0, + }; + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + char *linkval = NULL; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((object == NULL) || (buf == NULL)) { + errno = EINVAL; + return -1; + } - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, object); - if (!inode) { - errno = ESTALE; - goto out; - } + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, object); + if (!inode) { + errno = ESTALE; + goto out; + } - GLFS_LOC_FILL_INODE (inode, loc, out); + GLFS_LOC_FILL_INODE(inode, loc, out); - /* fop/op */ - ret = syncop_readlink (subvol, &loc, &linkval, bufsiz, NULL, NULL); - DECODE_SYNCOP_ERR (ret); + /* fop/op */ + ret = syncop_readlink(subvol, &loc, &linkval, bufsiz, NULL, NULL); + DECODE_SYNCOP_ERR(ret); - /* populate out args */ - if (ret > 0) - memcpy (buf, linkval, ret); + /* populate out args */ + if (ret > 0) + memcpy(buf, linkval, ret); out: - loc_wipe (&loc); + loc_wipe(&loc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (linkval) - GF_FREE (linkval); + if (linkval) + GF_FREE(linkval); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_readlink, 3.4.2); - int -pub_glfs_h_link (struct glfs *fs, struct glfs_object *linksrc, - struct glfs_object *parent, const char *name) +pub_glfs_h_link(struct glfs *fs, struct glfs_object *linksrc, + struct glfs_object *parent, const char *name) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *inode = NULL; - inode_t *pinode = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt iatt = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((linksrc == NULL) || (parent == NULL) || - (name == NULL)) { - errno = EINVAL; - return -1; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if (!subvol) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - inode = glfs_resolve_inode (fs, subvol, linksrc); - if (!inode) { - errno = ESTALE; - goto out; - } - - if (inode->ia_type == IA_IFDIR) { - ret = -1; - errno = EISDIR; - goto out; - } - - GLFS_LOC_FILL_INODE (inode, oldloc, out); - - /* get/refresh the in arg objects inode in correlation to the xlator */ - pinode = glfs_resolve_inode (fs, subvol, parent); - if (!pinode) { - errno = ESTALE; - goto out; - } - - /* setup newloc based on parent */ - newloc.parent = inode_ref (pinode); - newloc.name = name; - ret = glfs_loc_touchup (&newloc); - if (ret != 0) { - errno = EINVAL; - goto out; - } - - /* Filling the inode of the hard link to be same as that of the - * original file - */ - newloc.inode = inode_ref (inode); - - /* fop/op */ - ret = syncop_link (subvol, &oldloc, &newloc, &iatt, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == 0) - ret = glfs_loc_link (&newloc, &iatt); + int ret = -1; + xlator_t *subvol = NULL; + inode_t *inode = NULL; + inode_t *pinode = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt iatt = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((linksrc == NULL) || (parent == NULL) || (name == NULL)) { + errno = EINVAL; + return -1; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + inode = glfs_resolve_inode(fs, subvol, linksrc); + if (!inode) { + errno = ESTALE; + goto out; + } + + if (inode->ia_type == IA_IFDIR) { + ret = -1; + errno = EISDIR; + goto out; + } + + GLFS_LOC_FILL_INODE(inode, oldloc, out); + + /* get/refresh the in arg objects inode in correlation to the xlator */ + pinode = glfs_resolve_inode(fs, subvol, parent); + if (!pinode) { + errno = ESTALE; + goto out; + } + + /* setup newloc based on parent */ + newloc.parent = inode_ref(pinode); + newloc.name = name; + ret = glfs_loc_touchup(&newloc); + if (ret != 0) { + errno = EINVAL; + goto out; + } + + /* Filling the inode of the hard link to be same as that of the + * original file + */ + newloc.inode = inode_ref(inode); + + /* fop/op */ + ret = syncop_link(subvol, &oldloc, &newloc, &iatt, NULL, NULL); + DECODE_SYNCOP_ERR(ret); + + if (ret == 0) + ret = glfs_loc_link(&newloc, &iatt); out: - loc_wipe (&oldloc); - loc_wipe (&newloc); + loc_wipe(&oldloc); + loc_wipe(&newloc); - if (inode) - inode_unref (inode); + if (inode) + inode_unref(inode); - if (pinode) - inode_unref (pinode); + if (pinode) + inode_unref(pinode); - glfs_subvol_done (fs, subvol); + glfs_subvol_done(fs, subvol); - __GLFS_EXIT_FS; + __GLFS_EXIT_FS; invalid_fs: - return ret; + return ret; } GFAPI_SYMVER_PUBLIC_DEFAULT(glfs_h_link, 3.4.2); - int -pub_glfs_h_rename (struct glfs *fs, struct glfs_object *olddir, - const char *oldname, struct glfs_object *newdir, - const char *newname) +pub_glfs_h_rename(struct glfs *fs, struct glfs_object *olddir, + const char *oldname, struct glfs_object *newdir, + const char *newname) { - int ret = -1; - xlator_t *subvol = NULL; - inode_t *oldpinode = NULL; - inode_t *newpinode = NULL; - loc_t oldloc = {0, }; - loc_t newloc = {0, }; - struct iatt oldiatt = {0, }; - struct iatt newiatt = {0, }; - - DECLARE_OLD_THIS; - - /* validate in args */ - if ((olddir == NULL) || (oldname == NULL) || - (newdir == NULL) || (newname == NULL)) { - errno = EINVAL; - return -1; - } - - __GLFS_ENTRY_VALIDATE_FS (fs, invalid_fs); - - /* get the active volume */ - subvol = glfs_active_subvol (fs); - if ( !subvol ) { - ret = -1; - errno = EIO; - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - oldpinode = glfs_resolve_inode (fs, subvol, olddir); - if (!oldpinode) { - errno = ESTALE; - goto out; - } - - ret = glfs_resolve_at (fs, subvol, oldpinode, oldname, &oldloc, - &oldiatt, 0 , 0); - if (ret != 0) { - goto out; - } - - /* get/refresh the in arg objects inode in correlation to the xlator */ - newpinode = glfs_resolve_inode (fs, subvol, newdir); - if (!newpinode) { - errno = ESTALE; - goto out; - } - - ret = glfs_resolve_at (fs, subvol, newpinode, newname, &newloc, - &newiatt, 0, 0); - - if (ret && errno != ENOENT && newloc.parent) - goto out; - - if (newiatt.ia_type != IA_INVAL) { - if ((oldiatt.ia_type == IA_IFDIR) != - (newiatt.ia_type == IA_IFDIR)) { - /* Either both old and new must be dirs, - * or both must be non-dirs. Else, fail. - */ - ret = -1; - errno = EEXIST; - goto out; - } - } - - /* TODO: check if new or old is a prefix of the other, and fail EINVAL */ - - ret = syncop_rename (subvol, &oldloc, &newloc, NULL, NULL); - DECODE_SYNCOP_ERR (ret); - - if (ret == 0) { - inode_rename (oldloc.parent->table, oldloc.parent, oldloc.name, - newloc.parent, newloc.name, oldloc.inode, - &oldiatt); - - if (newloc.inode && !inode_has_dentry (newloc.inode)) - inode_forget (newloc.inode, 0); - - } + int ret = -1; + xlator_t *subvol = NULL; + inode_t *oldpinode = NULL; + inode_t *newpinode = NULL; + loc_t oldloc = { + 0, + }; + loc_t newloc = { + 0, + }; + struct iatt oldiatt = { + 0, + }; + struct iatt newiatt = { + 0, + }; + + DECLARE_OLD_THIS; + + /* validate in args */ + if ((olddir == NULL) || (oldname == NULL) || (newdir == NULL) || + (newname == NULL)) { + errno = EINVAL; + return -1; + } + + __GLFS_ENTRY_VALIDATE_FS(fs, invalid_fs); + + /* get the active volume */ + subvol = glfs_active_subvol(fs); + if (!subvol) { + ret = -1; + errno = EIO; + goto out; + } + + /* get/refresh the in arg objects inode in correlation to the xlator */ + oldpinode = glfs_resolve_inode(fs, subvol, olddir); + if (!oldpinode) { + errno = ESTALE; + goto out; + } + + ret = glfs_resolve_at(fs, subvol, oldpinode, oldname, &oldloc, &oldiatt, 0, + 0); |