]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw_file: check for leaf dir objects and restore their state
authorMatt Benjamin <mbenjamin@redhat.com>
Tue, 12 Apr 2016 18:38:23 +0000 (14:38 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Tue, 12 Apr 2016 20:12:50 +0000 (16:12 -0400)
This change makes Unix/NFS attributes persistent.

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

index 180af84d3817468f5b826e2dc64efbf2c2f29af8..5c67a2ec2795562b7a957ce09e95a1318239f296 100644 (file)
@@ -85,18 +85,25 @@ namespace rgw {
       }
     }
 #endif
-    std::string object_name{path};
-    for (auto ix : { 0, 1 }) {
+
+    /* XXX the need for two round-trip operations to identify file or
+     * directory leaf objects is unecessary--the current proposed
+     * mechanism to avoid this is to store leaf object names with an
+     * object locator w/o trailing slash */
+
+    /* mutating path */
+    std::string obj_path{parent->relative_object_name()};
+    if ((obj_path.length() > 0) &&
+       (obj_path.back() != '/'))
+      obj_path += "/";
+    obj_path += path;
+
+    for (auto ix : { 0, 1, 2 }) {
       switch (ix) {
       case 0:
       {
-       std::string obj_name{parent->relative_object_name()};
-       if ((obj_name.length() > 0) &&
-           (obj_name.back() != '/'))
-         obj_name += "/";
-       obj_name += path;
        RGWStatObjRequest req(cct, get_user(),
-                             parent->bucket_name(), obj_name,
+                             parent->bucket_name(), obj_path,
                              RGWStatObjRequest::FLAG_NONE);
        int rc = rgwlib.get_fe()->execute_req(&req);
        if ((rc == 0) &&
@@ -118,6 +125,32 @@ namespace rgw {
       break;
       case 1:
       {
+       /* try dir form */
+       obj_path += "/";
+       RGWStatObjRequest req(cct, get_user(),
+                             parent->bucket_name(), obj_path,
+                             RGWStatObjRequest::FLAG_NONE);
+       int rc = rgwlib.get_fe()->execute_req(&req);
+       if ((rc == 0) &&
+           (req.get_ret() == 0)) {
+         fhr = lookup_fh(parent, path, RGWFileHandle::FLAG_DIRECTORY);
+         if (get<0>(fhr)) {
+           RGWFileHandle* rgw_fh = get<0>(fhr);
+           rgw_fh->set_size(req.get_size());
+           rgw_fh->set_mtime(real_clock::to_timespec(req.get_mtime()));
+           /* restore attributes */
+           auto ux_attrs = req.get_attr(RGW_ATTR_UNIX1);
+           if (ux_attrs) {
+             rgw_fh->decode_attrs(ux_attrs);
+           }
+         }
+         goto done;
+       }
+      }
+      break;
+      case 2:
+      {
+       std::string object_name{path};
        RGWStatLeafRequest req(cct, get_user(), parent, object_name);
        int rc = rgwlib.get_fe()->execute_req(&req);
        if ((rc == 0) &&