]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_file: posix style atime,ctime,mtime
authorGui Hecheng <guihecheng@cmss.chinamobile.com>
Thu, 2 Mar 2017 09:21:57 +0000 (17:21 +0800)
committerNathan Cutler <ncutler@suse.com>
Tue, 4 Jul 2017 07:38:17 +0000 (09:38 +0200)
As an ganesha FSAL backend, rgw_file should properly maintain
the atime,ctime,mtime properly against operations such as:
(read,write) for file
(create,unlink,mkdir,rmdir,rename) for dir
(setattr) for file and dir

Signed-off-by: Gui Hecheng <guihecheng@cmss.chinamobile.com>
(cherry picked from commit ac25da2479b9be876cbdb820560ac46a6e2b17d7)

src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index cf08a29c8dbc9728489245998d8a56856215c501..8df15a104131ddb0384f1b2dccb9035bca4096db 100644 (file)
@@ -215,6 +215,7 @@ namespace rgw {
     int rc = rgwlib.get_fe()->execute_req(&req);
     if ((rc == 0) &&
        (req.get_ret() == 0)) {
+      rgw_fh->set_atime(real_clock::to_timespec(real_clock::now()));
       *bytes_read = req.nread;
     }
 
@@ -295,6 +296,12 @@ namespace rgw {
     assert(!nfh);
 #endif
 
+    if (! rc) {
+      real_time t = real_clock::now();
+      parent->set_mtime(real_clock::to_timespec(t));
+      parent->set_ctime(real_clock::to_timespec(t));
+    }
+
     rgw_fh->mtx.unlock();
     unref(rgw_fh);
 
@@ -518,6 +525,9 @@ namespace rgw {
       if (!rc)
        rc = rc2;
     } else {
+      real_time t = real_clock::now();
+      parent->set_mtime(real_clock::to_timespec(t));
+      parent->set_ctime(real_clock::to_timespec(t));
       rgw_fh->mtx.unlock(); /* !LOCKED */
     }
 
@@ -568,9 +578,13 @@ namespace rgw {
       if (rgw_fh) {
        if (get<1>(fhr) & RGWFileHandle::FLAG_CREATE) {
          /* fill in stat data */
+         real_time t = real_clock::now();
          rgw_fh->create_stat(st, mask);
-         rgw_fh->set_times(real_clock::now());
+         rgw_fh->set_times(t);
          rgw_fh->open_for_create(); // XXX needed?
+
+         parent->set_mtime(real_clock::to_timespec(t));
+         parent->set_ctime(real_clock::to_timespec(t));
        }
         if (st)
           (void) rgw_fh->stat(st);
@@ -651,7 +665,13 @@ namespace rgw {
       rc2 = req.get_ret();
     }
 
-    return (((rc == 0) && (rc2 == 0)) ? 0 : -EIO);
+    if ((rc != 0) || (rc2 != 0)) {
+      return -EIO;
+    }
+
+    rgw_fh->set_ctime(real_clock::to_timespec(real_clock::now()));
+
+    return 0;
   } /* RGWLibFS::setattr */
 
   void RGWLibFS::close()
@@ -1221,6 +1241,7 @@ namespace rgw {
     if (! op_ret) {
       /* update stats */
       rgw_fh->set_mtime(real_clock::to_timespec(mtime));
+      rgw_fh->set_ctime(real_clock::to_timespec(mtime));
       rgw_fh->set_size(bytes_written);
     }
 
index 41ec1c4516ae0b4f63ff4c7ffc09922f3745e500..d95c3b98718cf8fc5d1be931b1f0fdad010499b1 100644 (file)
@@ -342,6 +342,13 @@ namespace rgw {
        break;
        }
       }
+
+      if (mask & RGW_SETATTR_ATIME)
+       state.atime = st->st_atim;
+      if (mask & RGW_SETATTR_MTIME)
+       state.mtime = st->st_mtim;
+      if (mask & RGW_SETATTR_CTIME)
+       state.ctime = st->st_ctim;
     }
 
     int stat(struct stat* st) {