]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_file: posix style atime,ctime,mtime 14205/head
authorGui Hecheng <guihecheng@cmss.chinamobile.com>
Thu, 2 Mar 2017 09:21:57 +0000 (17:21 +0800)
committerMatt Benjamin <mbenjamin@redhat.com>
Tue, 28 Mar 2017 19:32:02 +0000 (15:32 -0400)
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 67db622c5d73f4191e863bf9016a03d415068d0d..0fa01eaee4dfdc2eb5eab991aae2f3f19946a20f 100644 (file)
@@ -204,6 +204,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;
     }
 
@@ -275,6 +276,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);
 
@@ -483,6 +490,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 */
     }
 
@@ -533,9 +543,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));
        }
        (void) rgw_fh->stat(st);
        get<0>(mkr) = rgw_fh;
@@ -599,7 +613,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()
@@ -1104,6 +1124,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 1c7789a423d40d9db83fc57f82efe7e1ad86037f..750f7b46e308578d7b18431fd460ccf4359e40a4 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) {