]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: unify result cases in rgw_mkdir
authorMatt Benjamin <mbenjamin@redhat.com>
Thu, 10 Dec 2015 01:25:22 +0000 (20:25 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:06:24 +0000 (12:06 -0500)
In both paths, instantiate a file handle iff the remote op
succeeded.

If this operation lost a race to create an object with the same
name, we cannot correctly return a valid result and handle in all
cases, so don't attempt it.

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

index 06141ab8f95152d3a7e3691bdb0b37cf0f7083ea..35f41e697f2af3505a6119034710f677a63990c9 100644 (file)
@@ -221,7 +221,7 @@ int rgw_mkdir(struct rgw_fs *rgw_fs,
              const char *name, mode_t mode, struct stat *st,
              struct rgw_file_handle **fh)
 {
-  int rc;
+  int rc, rc2;
 
   /* XXXX remove uri, deal with bucket names */
   string uri;
@@ -236,16 +236,15 @@ int rgw_mkdir(struct rgw_fs *rgw_fs,
   }
 
   LookupFHResult fhr;
-  RGWFileHandle* rgw_fh;
+  RGWFileHandle* rgw_fh = nullptr;
 
   if (parent->is_root()) {
     /* bucket */
-    fhr = fs->lookup_fh(parent, name);
-    rgw_fh = get<0>(fhr);
     uri += "/"; /* XXX */
     uri += name;
     RGWCreateBucketRequest req(cct, fs->get_user(), uri);
     rc = librgw.get_fe()->execute_req(&req);
+    rc2 = req.get_ret();
   } else {
     /* create an object representing the directory (naive version) */
     buffer::list bl;
@@ -255,10 +254,19 @@ int rgw_mkdir(struct rgw_fs *rgw_fs,
     RGWPutObjRequest req(cct, fs->get_user(), rgw_fh->bucket_name(),
                         dir_name, bl);
     rc = librgw.get_fe()->execute_req(&req);
+    rc2 = req.get_ret();
   }
 
-  struct rgw_file_handle *rfh = rgw_fh->get_fh();
-  *fh = rfh;
+  if ((rc == 0) &&
+      (rc2 == 0)) {
+    fhr = fs->lookup_fh(parent, name, RGWFileHandle::FLAG_CREATE);
+    rgw_fh = get<0>(fhr);
+    if (rgw_fh) {
+      struct rgw_file_handle *rfh = rgw_fh->get_fh();
+      *fh = rfh;
+    } else
+      rc = -EIO;
+  }
 
   return rc;
 }