From: Gui Hecheng Date: Thu, 2 Mar 2017 09:21:57 +0000 (+0800) Subject: rgw_file: posix style atime,ctime,mtime X-Git-Tag: v10.2.7~6^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F14205%2Fhead;p=ceph.git rgw_file: posix style atime,ctime,mtime 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 (cherry picked from commit ac25da2479b9be876cbdb820560ac46a6e2b17d7) --- diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index 67db622c5d73..0fa01eaee4df 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -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); } diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 1c7789a423d4..750f7b46e308 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -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) {