]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.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)
committerGui Hecheng <guihecheng@cmss.chinamobile.com>
Fri, 3 Mar 2017 05:56:38 +0000 (13:56 +0800)
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>
src/rgw/rgw_file.cc
src/rgw/rgw_file.h

index 296899f07d850147bf5da2d52f896cb0daf61198..a63aa45f15c7a41aae72eb9dffa3ab9e7b06a9eb 100644 (file)
@@ -205,6 +205,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;
     }
 
@@ -277,6 +278,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);
 
@@ -500,6 +507,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 */
     }
 
@@ -550,9 +560,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);
@@ -633,7 +647,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()
@@ -1180,6 +1200,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 18edb807e8179c41d9311d33f89054a3d7a93dcf..68ae24f0cce251fdef8216659e09095fe37fde8c 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) {