]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: forge Unix attrs in rgw_create
authorMatt Benjamin <mbenjamin@redhat.com>
Thu, 12 Nov 2015 15:32:12 +0000 (10:32 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:05:56 +0000 (12:05 -0500)
Possibly RGW vnodes should cache Unix attrs, it would reduce the
latency of (frequent) getattr calls, and eventually lines up with
more materialized Unix attributes.

Signed-off-by: Matt Benjamin <mbenjamin@redhat.com>
src/rgw/rgw_file.cc

index e4f20fbed18fa391632bcc7f00f6b38a18ba58b8..c2baf04af889e1727a0f0de15baf4755cf181d6a 100644 (file)
@@ -35,6 +35,13 @@ const string RGWFileHandle::root_name = "/";
 
 atomic<uint32_t> RGWLibFS::fs_inst;
 
+
+#define RGW_RWXMODE  (S_IRWXU | S_IRWXG | S_IRWXO)
+
+#define RGW_RWMODE (RGW_RWXMODE &                      \
+                     ~(S_IXUSR | S_IXGRP | S_IXOTH))
+
+
 /* librgw */
 extern "C" {
 
@@ -134,8 +141,24 @@ int rgw_create(struct rgw_fs *rgw_fs,
 
 
   /* mark if we created it */
-  if (get<1>(fhr) & RGWFileHandle::FLAG_CREATE)
+  if (get<1>(fhr) & RGWFileHandle::FLAG_CREATE) {
+        /* fill in stat data */
+    time_t now = time(0);
+    memset(st, 0, sizeof(struct stat));
+    st->st_dev = fs->get_inst();
+    st->st_ino = rgw_fh->get_fh()->fh_hk.object; // XXX
+    st->st_mode = RGW_RWMODE|S_IFREG;
+    st->st_nlink = 1;
+    st->st_uid = 0; // XXX
+    st->st_gid = 0; // XXX
+    st->st_size = 0;
+    st->st_blksize = 4096;
+    st->st_blocks = 0;
+    st->st_atim.tv_sec = now;
+    st->st_mtim.tv_sec = now;
+    st->st_ctim.tv_sec = now;
     rgw_fh->open_for_create();
+  }
 
   struct rgw_file_handle *rfh = rgw_fh->get_fh();
   *fh = rfh;
@@ -343,11 +366,6 @@ int rgw_fh_rele(struct rgw_fs *rgw_fs, struct rgw_file_handle *fh,
   return 0;
 }
 
-#define RGW_RWXMODE  (S_IRWXU | S_IRWXG | S_IRWXO)
-
-#define RGW_RWMODE (RGW_RWXMODE &                      \
-                     ~(S_IXUSR | S_IXGRP | S_IXOTH))
-
 /*
    get unix attributes for object
 */