]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: switch ceph_statx time fields to struct timespec
authorJeff Layton <jlayton@redhat.com>
Tue, 20 Sep 2016 10:26:36 +0000 (06:26 -0400)
committerJeff Layton <jlayton@redhat.com>
Tue, 20 Sep 2016 10:26:36 +0000 (06:26 -0400)
This is just much more convenient for applications that want to use
the API. We're not talking to the kernel here, so there's no real
reason we need to use fixed length fields.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/client/Client.cc
src/include/cephfs/ceph_statx.h
src/test/libcephfs/test.cc

index 989f32c4f2804dd1154de3af569201431a609f69..b65c64a9f6ddcfee661648ee83582b24dbce3074 100644 (file)
@@ -6517,7 +6517,7 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, int uid, in
       in->ctime = ceph_clock_now(cct);
       in->cap_dirtier_uid = uid;
       in->cap_dirtier_gid = gid;
-      in->btime = utime_t(stx->stx_btime, stx->stx_btime_ns);
+      in->btime = utime_t(stx->stx_btime);
       mark_caps_dirty(in, CEPH_CAP_AUTH_EXCL);
       mask &= ~CEPH_SETATTR_BTIME;
       ldout(cct,10) << "changing btime to " << in->btime << dendl;
@@ -6526,9 +6526,9 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, int uid, in
   if (in->caps_issued_mask(CEPH_CAP_FILE_EXCL)) {
     if (mask & (CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME)) {
       if (mask & CEPH_SETATTR_MTIME)
-        in->mtime = utime_t(stx->stx_mtime, stx->stx_mtime_ns);
+        in->mtime = utime_t(stx->stx_mtime);
       if (mask & CEPH_SETATTR_ATIME)
-        in->atime = utime_t(stx->stx_atime, stx->stx_atime_ns);
+        in->atime = utime_t(stx->stx_atime);
       in->ctime = ceph_clock_now(cct);
       in->cap_dirtier_uid = uid;
       in->cap_dirtier_gid = gid;
@@ -6567,17 +6567,17 @@ force_request:
     ldout(cct,10) << "changing gid to " << stx->stx_gid << dendl;
   }
   if (mask & CEPH_SETATTR_MTIME) {
-    req->head.args.setattr.mtime = utime_t(stx->stx_mtime, stx->stx_mtime_ns);
+    req->head.args.setattr.mtime = utime_t(stx->stx_mtime);
     req->inode_drop |= CEPH_CAP_AUTH_SHARED | CEPH_CAP_FILE_RD |
       CEPH_CAP_FILE_WR;
   }
   if (mask & CEPH_SETATTR_ATIME) {
-    req->head.args.setattr.atime = utime_t(stx->stx_atime, stx->stx_atime_ns);
+    req->head.args.setattr.atime = utime_t(stx->stx_atime);
     req->inode_drop |= CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_RD |
       CEPH_CAP_FILE_WR;
   }
   if (mask & CEPH_SETATTR_BTIME) {
-    req->head.args.setattr.btime = utime_t(stx->stx_btime, stx->stx_btime_ns);
+    req->head.args.setattr.btime = utime_t(stx->stx_btime);
     req->inode_drop |= CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_RD |
       CEPH_CAP_FILE_WR;
   }
@@ -6607,10 +6607,8 @@ void Client::stat_to_statx(struct stat *st, struct ceph_statx *stx)
   stx->stx_mode = st->st_mode;
   stx->stx_uid = st->st_uid;
   stx->stx_gid = st->st_gid;
-  stx->stx_mtime = stat_get_mtime_sec(st);
-  stx->stx_mtime_ns = stat_get_mtime_nsec(st);
-  stx->stx_atime = stat_get_atime_sec(st);
-  stx->stx_atime_ns = stat_get_atime_nsec(st);
+  stx->stx_mtime = st->st_mtim;
+  stx->stx_atime = st->st_atim;
 }
 
 int Client::__setattrx(Inode *in, struct ceph_statx *stx, int mask, int uid, int gid,
@@ -6868,8 +6866,7 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx)
     stx->stx_uid = in->uid;
     stx->stx_gid = in->gid;
     stx->stx_mode = in->mode;
-    stx->stx_btime = in->btime.sec();
-    stx->stx_btime_ns = in->btime.nsec();
+    in->btime.to_timespec(&stx->stx_btime);
     stx->stx_mask |= (CEPH_STATX_MODE|CEPH_STATX_UID|CEPH_STATX_GID|CEPH_STATX_BTIME);
   }
 
@@ -6879,17 +6876,14 @@ void Client::fill_statx(Inode *in, unsigned int mask, struct ceph_statx *stx)
   }
 
   if (mask & CEPH_CAP_FILE_SHARED) {
-    if (in->ctime > in->mtime) {
-      stx->stx_ctime = in->ctime.sec();
-      stx->stx_ctime_ns = in->ctime.nsec();
-    } else {
-      stx->stx_ctime = in->mtime.sec();
-      stx->stx_ctime_ns = in->mtime.nsec();
-    }
-    stx->stx_atime = in->atime.sec();
-    stx->stx_atime_ns = in->atime.nsec();
-    stx->stx_mtime = in->mtime.sec();
-    stx->stx_mtime_ns = in->mtime.nsec();
+
+    if (in->ctime > in->mtime)
+      in->ctime.to_timespec(&stx->stx_ctime);
+    else
+      in->mtime.to_timespec(&stx->stx_ctime);
+
+    in->atime.to_timespec(&stx->stx_atime);
+    in->mtime.to_timespec(&stx->stx_mtime);
     stx->stx_version = in->change_attr;
 
     if (in->is_dir()) {
index b7c295294ff7bdcef2061273c67b9075efa188ca..324dd1ec02132e0b103298ddb49e6a76353168bc 100644 (file)
@@ -40,14 +40,10 @@ struct ceph_statx {
        uint64_t        stx_size;
        uint64_t        stx_blocks;
        uint64_t        stx_version;
-       int64_t         stx_atime;
-       int64_t         stx_btime;
-       int64_t         stx_ctime;
-       int64_t         stx_mtime;
-       int32_t         stx_atime_ns;
-       int32_t         stx_btime_ns;
-       int32_t         stx_ctime_ns;
-       int32_t         stx_mtime_ns;
+       struct timespec stx_atime;
+       struct timespec stx_btime;
+       struct timespec stx_ctime;
+       struct timespec stx_mtime;
        uint32_t        stx_rdev_major;
        uint32_t        stx_rdev_minor;
        uint32_t        stx_dev_major;
index 4efb3ff7f9465d5aeec541b2b44c33d2717c104f..ab277b59d8cce25c56a0896265e801f98f3b6dd4 100644 (file)
@@ -1469,6 +1469,12 @@ TEST(LibCephFS, SlashDotDot) {
   ceph_shutdown(cmount);
 }
 
+static inline bool
+timespec_eq(timespec const& lhs, timespec const& rhs)
+{
+  return lhs.tv_sec == rhs.tv_sec && lhs.tv_nsec == rhs.tv_nsec;
+}
+
 TEST(LibCephFS, Btime) {
   struct ceph_mount_info *cmount;
   ASSERT_EQ(ceph_create(&cmount, NULL), 0);
@@ -1488,26 +1494,22 @@ TEST(LibCephFS, Btime) {
 
   ASSERT_EQ(ceph_fstatx(cmount, fd, &stx, CEPH_STATX_CTIME|CEPH_STATX_BTIME, 0), 0);
   ASSERT_TRUE(stx.stx_mask & (CEPH_STATX_CTIME|CEPH_STATX_BTIME));
-  ASSERT_EQ(stx.stx_btime, stx.stx_ctime);
-  ASSERT_EQ(stx.stx_btime_ns, stx.stx_ctime_ns);
+  ASSERT_TRUE(timespec_eq(stx.stx_ctime, stx.stx_btime));
   ceph_close(cmount, fd);
 
   ASSERT_EQ(ceph_statx(cmount, filename, &stx, CEPH_STATX_CTIME|CEPH_STATX_BTIME, 0), 0);
+  ASSERT_TRUE(timespec_eq(stx.stx_ctime, stx.stx_btime));
   ASSERT_TRUE(stx.stx_mask & (CEPH_STATX_CTIME|CEPH_STATX_BTIME));
-  ASSERT_EQ(stx.stx_btime, stx.stx_ctime);
-  ASSERT_EQ(stx.stx_btime_ns, stx.stx_ctime_ns);
 
-  int64_t old_btime = stx.stx_btime;
-  int32_t old_btime_ns = stx.stx_btime_ns;
+  struct timespec old_btime = stx.stx_btime;
 
   /* Now sleep, do a chmod and verify that the ctime changed, but btime didn't */
   sleep(1);
   ASSERT_EQ(ceph_chmod(cmount, filename, 0644), 0);
-  ASSERT_EQ(ceph_statx(cmount, filename, &stx, CEPH_STATX_BTIME, 0), 0);
+  ASSERT_EQ(ceph_statx(cmount, filename, &stx, CEPH_STATX_CTIME|CEPH_STATX_BTIME, 0), 0);
   ASSERT_TRUE(stx.stx_mask & CEPH_STATX_BTIME);
-  ASSERT_EQ(stx.stx_btime, old_btime);
-  ASSERT_EQ(stx.stx_btime_ns, old_btime_ns);
-  ASSERT_FALSE(old_btime == stx.stx_ctime && old_btime_ns == stx.stx_ctime_ns);
+  ASSERT_TRUE(timespec_eq(stx.stx_btime, old_btime));
+  ASSERT_FALSE(timespec_eq(stx.stx_ctime, stx.stx_btime));
 
   ceph_shutdown(cmount);
 }
@@ -1528,17 +1530,15 @@ TEST(LibCephFS, SetBtime) {
   ceph_close(cmount, fd);
 
   struct ceph_statx stx;
+  struct timespec old_btime = { 1, 2 };
 
-  stx.stx_btime = 1;
-  stx.stx_btime_ns = 2;
+  stx.stx_btime = old_btime;
 
   ASSERT_EQ(ceph_setattrx(cmount, filename, &stx, CEPH_SETATTR_BTIME, 0), 0);
 
   ASSERT_EQ(ceph_statx(cmount, filename, &stx, CEPH_STATX_BTIME, 0), 0);
   ASSERT_TRUE(stx.stx_mask & CEPH_STATX_BTIME);
-
-  ASSERT_EQ(stx.stx_btime, 1);
-  ASSERT_EQ(stx.stx_btime_ns, 2);
+  ASSERT_TRUE(timespec_eq(stx.stx_btime, old_btime));
 
   ceph_shutdown(cmount);
 }
@@ -1570,8 +1570,7 @@ TEST(LibCephFS, LazyStatx) {
   ASSERT_EQ(ceph_ll_lookup_root(cmount2, &root2), 0);
   ASSERT_EQ(ceph_ll_lookup(cmount2, root2, filename, &st, &file2, getuid(), getgid()), 0);
 
-  int64_t old_ctime = stat_get_ctime_sec(&st);
-  int32_t old_ctime_ns = stat_get_ctime_nsec(&st);
+  struct timespec old_ctime = st.st_ctim;
 
   /*
    * Now sleep, do a chmod on the first client and the see whether we get a
@@ -1584,8 +1583,8 @@ TEST(LibCephFS, LazyStatx) {
   struct ceph_statx    stx;
   ASSERT_EQ(ceph_ll_getattrx(cmount2, file2, &stx, CEPH_STATX_CTIME, AT_NO_ATTR_SYNC, getuid(), getgid()), 0);
   ASSERT_TRUE(stx.stx_mask & CEPH_STATX_CTIME);
-  ASSERT_EQ(stx.stx_ctime, old_ctime);
-  ASSERT_EQ(stx.stx_ctime_ns, old_ctime_ns);
+  ASSERT_TRUE(stx.stx_ctime.tv_sec == old_ctime.tv_sec &&
+             stx.stx_ctime.tv_nsec == old_ctime.tv_nsec);
 
   ceph_shutdown(cmount1);
   ceph_shutdown(cmount2);