]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: convert some ceph_stat and ceph_lstat calls to ceph_statx
authorJeff Layton <jlayton@redhat.com>
Wed, 12 Oct 2016 11:04:42 +0000 (07:04 -0400)
committerJeff Layton <jlayton@redhat.com>
Wed, 12 Oct 2016 11:04:42 +0000 (07:04 -0400)
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/client/hypertable/CephBroker.cc
src/test/libcephfs/acl.cc
src/test/libcephfs/caps.cc
src/test/libcephfs/test.cc

index 9d64cfe1682317cb89837b4f5c9694b9d04e05fd..74766c063bf0848e0933bce62beec7423a6ea478 100644 (file)
@@ -310,11 +310,11 @@ void CephBroker::remove(ResponseCallback *cb, const char *fname) {
 
 void CephBroker::length(ResponseCallbackLength *cb, const char *fname, bool) {
   int r;
-  struct stat statbuf;
+  struct ceph_statx stx;
 
   HT_DEBUGF("length file='%s'", fname);
 
-  if ((r = ceph_lstat(cmount, fname, &statbuf)) < 0) {
+  if ((r = ceph_statx(cmount, fname, &stx, CEPH_STATX_SIZE, AT_SYMLINK_NOFOLLOW)) < 0) {
     String abspath;
     make_abs_path(fname, abspath);
     std::string errs(cpp_strerror(r));
@@ -322,7 +322,7 @@ void CephBroker::length(ResponseCallbackLength *cb, const char *fname, bool) {
     report_error(cb,- r);
     return;
   }
-  cb->response(statbuf.st_size);
+  cb->response(stx.stx_size);
 }
 
 void CephBroker::pread(ResponseCallbackRead *cb, uint32_t fd, uint64_t offset,
@@ -487,11 +487,11 @@ void CephBroker::readdir(ResponseCallbackReaddir *cb, const char *dname) {
 
 void CephBroker::exists(ResponseCallbackExists *cb, const char *fname) {
   String abspath;
-  struct stat statbuf;
+  struct ceph_statx stx;
   
   HT_DEBUGF("exists file='%s'", fname);
   make_abs_path(fname, abspath);
-  cb->response(ceph_lstat(cmount, abspath.c_str(), &statbuf) == 0);
+  cb->response(ceph_statx(cmount, abspath.c_str(), &stx, 0, AT_SYMLINK_NOFOLLOW) == 0);
 }
 
 void CephBroker::rename(ResponseCallback *cb, const char *src, const char *dst) {
index 54c978d1fb2387a8acf312f8ca64800e6ba78213..3ed57bf3e28ab561d83ebd835f484f1d93ed802a 100644 (file)
@@ -251,11 +251,11 @@ TEST(ACL, DefaultACL) {
   // mode and ACL are updated
   ASSERT_EQ(ceph_getxattr(cmount, test_dir2, ACL_EA_ACCESS, acl2_buf, acl_buf_size), acl_buf_size);
   {
-    struct stat stbuf;
-    ASSERT_EQ(ceph_stat(cmount, test_dir2, &stbuf), 0);
+    struct ceph_statx stx;
+    ASSERT_EQ(ceph_statx(cmount, test_dir2, &stx, CEPH_STATX_MODE, 0), 0);
     // other bits of mode &= acl other perm
-    ASSERT_EQ(stbuf.st_mode & 0777, 0750u);
-    ASSERT_EQ(check_acl_and_mode(acl2_buf, acl_buf_size, stbuf.st_mode), 0);
+    ASSERT_EQ(stx.stx_mode & 0777u, 0750u);
+    ASSERT_EQ(check_acl_and_mode(acl2_buf, acl_buf_size, stx.stx_mode), 0);
   }
 
   char test_file1[256];
@@ -269,11 +269,11 @@ TEST(ACL, DefaultACL) {
   // mode and ACL are updated
   ASSERT_EQ(ceph_fgetxattr(cmount, fd, ACL_EA_ACCESS, acl2_buf, acl_buf_size), acl_buf_size);
   {
-    struct stat stbuf;
-    ASSERT_EQ(ceph_stat(cmount, test_file1, &stbuf), 0);
+    struct ceph_statx stx;
+    ASSERT_EQ(ceph_statx(cmount, test_file1, &stx, CEPH_STATX_MODE, 0), 0);
     // other bits of mode &= acl other perm
-    ASSERT_EQ(stbuf.st_mode & 0777, 0660u);
-    ASSERT_EQ(check_acl_and_mode(acl2_buf, acl_buf_size, stbuf.st_mode), 0);
+    ASSERT_EQ(stx.stx_mode & 0777u, 0660u);
+    ASSERT_EQ(check_acl_and_mode(acl2_buf, acl_buf_size, stx.stx_mode), 0);
   }
 
   free(acl1_buf);
index 338442430273856f9f79efba3865d4dd569b405a..4af9b418d2e8345dd36aa6d6752369e1cfc9472f 100644 (file)
@@ -60,8 +60,8 @@ TEST(Caps, ReadZero) {
 
     ASSERT_EQ(0, ceph_close(cmount, wfd));
 
-    struct stat st;
-    ASSERT_EQ(0, ceph_stat(cmount, c_path, &st));
+    struct ceph_statx stx;
+    ASSERT_EQ(0, ceph_statx(cmount, c_path, &stx, CEPH_STATX_MTIME, 0));
 
     caps = ceph_debug_get_file_caps(cmount, c_path);
     ASSERT_EQ(expect, caps & expect);
index ab277b59d8cce25c56a0896265e801f98f3b6dd4..2de3336f11ca6842f9eaddd6269dedcdff5b4857 100644 (file)
@@ -272,13 +272,13 @@ TEST(LibCephFS, DirLs) {
   ASSERT_EQ(ceph_opendir(cmount, foostr, &ls_dir), -ENOENT);
 
   ASSERT_EQ(ceph_mkdir(cmount, foostr, 0777), 0);
-  struct stat stbuf;
-  ASSERT_EQ(ceph_stat(cmount, foostr, &stbuf), 0);
-  ASSERT_NE(S_ISDIR(stbuf.st_mode), 0);
+  struct ceph_statx stx;
+  ASSERT_EQ(ceph_statx(cmount, foostr, &stx, 0, 0), 0);
+  ASSERT_NE(S_ISDIR(stx.stx_mode), 0);
 
   char barstr[256];
   sprintf(barstr, "dir_ls2%d", mypid);
-  ASSERT_EQ(ceph_lstat(cmount, barstr, &stbuf), -ENOENT);
+  ASSERT_EQ(ceph_statx(cmount, barstr, &stx, 0, AT_SYMLINK_NOFOLLOW), -ENOENT);
 
   // insert files into directory and test open
   char bazstr[256];
@@ -598,9 +598,9 @@ TEST(LibCephFS, LstatSlashdot) {
   ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
   ASSERT_EQ(ceph_mount(cmount, NULL), 0);
 
-  struct stat stbuf;
-  ASSERT_EQ(ceph_lstat(cmount, "/.", &stbuf), 0);
-  ASSERT_EQ(ceph_lstat(cmount, ".", &stbuf), 0);
+  struct ceph_statx stx;
+  ASSERT_EQ(ceph_statx(cmount, "/.", &stx, 0, AT_SYMLINK_NOFOLLOW), 0);
+  ASSERT_EQ(ceph_statx(cmount, ".", &stx, 0, AT_SYMLINK_NOFOLLOW), 0);
 
   ceph_shutdown(cmount);
 }
@@ -648,9 +648,9 @@ TEST(LibCephFS, DoubleChmod) {
   ASSERT_EQ(ceph_chmod(cmount, test_file, 0600), 0);
 
   // ensure perms are correct
-  struct stat stbuf;
-  ASSERT_EQ(ceph_lstat(cmount, test_file, &stbuf), 0);
-  ASSERT_EQ(stbuf.st_mode, 0100600U);
+  struct ceph_statx stx;
+  ASSERT_EQ(ceph_statx(cmount, test_file, &stx, CEPH_STATX_MODE, AT_SYMLINK_NOFOLLOW), 0);
+  ASSERT_EQ(stx.stx_mode, 0100600U);
 
   fd = ceph_open(cmount, test_file, O_RDWR, 0);
   ASSERT_GT(fd, 0);
@@ -803,13 +803,13 @@ TEST(LibCephFS, Symlinks) {
   ASSERT_EQ(fd, -ELOOP);
 
   // stat the original file
-  struct stat stbuf_orig;
-  ASSERT_EQ(ceph_stat(cmount, test_file, &stbuf_orig), 0);
+  struct ceph_statx stx_orig;
+  ASSERT_EQ(ceph_statx(cmount, test_file, &stx_orig, CEPH_STATX_ALL_STATS, 0), 0);
   // stat the symlink
-  struct stat stbuf_symlink_orig;
-  ASSERT_EQ(ceph_stat(cmount, test_symlink, &stbuf_symlink_orig), 0);
-  // ensure the stat bufs are equal
-  ASSERT_TRUE(!memcmp(&stbuf_orig, &stbuf_symlink_orig, sizeof(stbuf_orig)));
+  struct ceph_statx stx_symlink_orig;
+  ASSERT_EQ(ceph_statx(cmount, test_symlink, &stx_symlink_orig, CEPH_STATX_ALL_STATS, 0), 0);
+  // ensure the statx bufs are equal
+  ASSERT_EQ(memcmp(&stx_orig, &stx_symlink_orig, sizeof(stx_orig)), 0);
 
   sprintf(test_file, "/test_symlinks_abs_%d", getpid());
 
@@ -823,16 +823,15 @@ TEST(LibCephFS, Symlinks) {
   ASSERT_EQ(ceph_symlink(cmount, test_file, test_symlink), 0);
 
   // stat the original file
-  ASSERT_EQ(ceph_stat(cmount, test_file, &stbuf_orig), 0);
+  ASSERT_EQ(ceph_statx(cmount, test_file, &stx_orig, CEPH_STATX_ALL_STATS, 0), 0);
   // stat the symlink
-  ASSERT_EQ(ceph_stat(cmount, test_symlink, &stbuf_symlink_orig), 0);
-  // ensure the stat bufs are equal
-  ASSERT_TRUE(!memcmp(&stbuf_orig, &stbuf_symlink_orig, sizeof(stbuf_orig)));
+  ASSERT_EQ(ceph_statx(cmount, test_symlink, &stx_symlink_orig, CEPH_STATX_ALL_STATS, 0), 0);
+  // ensure the statx bufs are equal
+  ASSERT_TRUE(!memcmp(&stx_orig, &stx_symlink_orig, sizeof(stx_orig)));
 
   // test lstat
-  struct stat stbuf_symlink;
-  ASSERT_EQ(ceph_lstat(cmount, test_symlink, &stbuf_symlink), 0);
-  ASSERT_TRUE(S_ISLNK(stbuf_symlink.st_mode));
+  ASSERT_EQ(ceph_statx(cmount, test_symlink, &stx_orig, CEPH_STATX_ALL_STATS, AT_SYMLINK_NOFOLLOW), 0);
+  ASSERT_TRUE(S_ISLNK(stx_orig.stx_mode));
 
   ceph_shutdown(cmount);
 }
@@ -860,11 +859,11 @@ TEST(LibCephFS, DirSyms) {
   ASSERT_GT(fd, 0);
   ceph_close(cmount, fd);
 
-  struct stat stbuf;
-  ASSERT_EQ(ceph_lstat(cmount, test_file, &stbuf), 0);
+  struct ceph_statx stx;
+  ASSERT_EQ(ceph_statx(cmount, test_file, &stx, 0, AT_SYMLINK_NOFOLLOW), 0);
 
   // ensure that its a file not a directory we get back
-  ASSERT_TRUE(S_ISREG(stbuf.st_mode));
+  ASSERT_TRUE(S_ISREG(stx.stx_mode));
 
   ceph_shutdown(cmount);
 }
@@ -1099,11 +1098,11 @@ TEST(LibCephFS, Rename) {
   ASSERT_EQ(0, ceph_rename(cmount, path_src, path_dst));
 
   /* test that dest path exists */
-  struct stat st;
-  ASSERT_EQ(0, ceph_lstat(cmount, path_dst, &st));
+  struct ceph_statx stx;
+  ASSERT_EQ(0, ceph_statx(cmount, path_dst, &stx, 0, 0));
 
   /* test that src path doesn't exist */
-  ASSERT_EQ(-ENOENT, ceph_lstat(cmount, path_src, &st));
+  ASSERT_EQ(-ENOENT, ceph_statx(cmount, path_src, &stx, 0, AT_SYMLINK_NOFOLLOW));
 
   /* rename with non-existent source path */
   ASSERT_EQ(-ENOENT, ceph_rename(cmount, path_src, path_dst));
@@ -1134,6 +1133,7 @@ TEST(LibCephFS, UseUnmounted) {
   EXPECT_EQ(-ENOTCONN, ceph_readdir_r(cmount, dirp, &rdent));
 
   int stmask;
+  struct ceph_statx stx;
   struct stat st;
   EXPECT_EQ(-ENOTCONN, ceph_readdirplus_r(cmount, dirp, &rdent, &st, &stmask));
   EXPECT_EQ(-ENOTCONN, ceph_getdents(cmount, dirp, NULL, 0));
@@ -1147,8 +1147,7 @@ TEST(LibCephFS, UseUnmounted) {
   EXPECT_EQ(-ENOTCONN, ceph_rmdir(cmount, "/path"));
   EXPECT_EQ(-ENOTCONN, ceph_readlink(cmount, "/path", NULL, 0));
   EXPECT_EQ(-ENOTCONN, ceph_symlink(cmount, "/path", "/path"));
-  EXPECT_EQ(-ENOTCONN, ceph_stat(cmount, "/path", &st));
-  EXPECT_EQ(-ENOTCONN, ceph_lstat(cmount, "/path", &st));
+  EXPECT_EQ(-ENOTCONN, ceph_statx(cmount, "/path", &stx, 0, 0));
   EXPECT_EQ(-ENOTCONN, ceph_setattr(cmount, "/path", &st, 0));
   EXPECT_EQ(-ENOTCONN, ceph_getxattr(cmount, "/path", "name", NULL, 0));
   EXPECT_EQ(-ENOTCONN, ceph_lgetxattr(cmount, "/path", "name", NULL, 0));
@@ -1417,14 +1416,14 @@ TEST(LibCephFS, SlashDotDot) {
   ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
   ASSERT_EQ(ceph_mount(cmount, "/"), 0);
 
-  struct stat  st;
-  ASSERT_EQ(ceph_stat(cmount, "/.", &st), 0);
+  struct ceph_statx    stx;
+  ASSERT_EQ(ceph_statx(cmount, "/.", &stx, CEPH_STATX_INO, 0), 0);
 
-  ino_t ino = st.st_ino;
-  ASSERT_EQ(ceph_stat(cmount, "/..", &st), 0);
+  ino_t ino = stx.stx_ino;
+  ASSERT_EQ(ceph_statx(cmount, "/..", &stx, CEPH_STATX_INO, 0), 0);
 
   /* At root, "." and ".." should be the same inode */
-  ASSERT_EQ(ino, st.st_ino);
+  ASSERT_EQ(ino, stx.stx_ino);
 
   /* Test accessing the parent of an unlinked directory */
   char dir1[32], dir2[32];
@@ -1453,7 +1452,7 @@ TEST(LibCephFS, SlashDotDot) {
   /* Make sure it works same way when mounting subtree */
   ASSERT_EQ(ceph_unmount(cmount), 0);
   ASSERT_EQ(ceph_mount(cmount, dir1), 0);
-  ASSERT_EQ(ceph_stat(cmount, "/..", &st), 0);
+  ASSERT_EQ(ceph_statx(cmount, "/..", &stx, CEPH_STATX_INO, 0), 0);
 
   /* Test readdir behavior */
   ASSERT_EQ(ceph_opendir(cmount, "/", &rdir), 0);