]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: namespace bugfixes
authorMatt Benjamin <mbenjamin@redhat.com>
Thu, 10 Dec 2015 21:12:37 +0000 (16:12 -0500)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 17:06:31 +0000 (12:06 -0500)
1. stat_leaf() and stat_bucket() require RGWFileHandle::FLAG_CREATE
2. refactor RGWStatLeafRequest on the model of RGWListBucketRequest
3. fix uses of is_object() which meant is_file()
4. fix parent_fh passing

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

index 35f41e697f2af3505a6119034710f677a63990c9..91135f04f46e84efae7b0d0fa91f6e8208079d11 100644 (file)
@@ -47,7 +47,8 @@ LookupFHResult RGWLibFS::stat_bucket(RGWFileHandle* parent,
       (req.get_ret() == 0) &&
       (req.matched())) {
     fhr = lookup_fh(parent, path,
-                   RGWFileHandle::FLAG_CREATE|RGWFileHandle::FLAG_BUCKET);
+                   RGWFileHandle::FLAG_CREATE|
+                   RGWFileHandle::FLAG_BUCKET);
   }
   return fhr;
 }
@@ -77,16 +78,16 @@ LookupFHResult RGWLibFS::stat_leaf(RGWFileHandle* parent,
     break;
     case 1:
     {
-      RGWStatLeafRequest req(cct, get_user(), parent->bucket_name(),
-                            object_name);
+      RGWStatLeafRequest req(cct, get_user(), parent, object_name);
       int rc = librgw.get_fe()->execute_req(&req);
       if ((rc == 0) &&
          (req.get_ret() == 0)) {
        if (req.matched) {
          fhr = lookup_fh(parent, path,
-                         (req.path.back() == '/') ?
-                         RGWFileHandle::FLAG_DIRECTORY :
-                         RGWFileHandle::FLAG_NONE);
+                         RGWFileHandle::FLAG_CREATE|
+                         ((req.path.back() == '/') ?
+                          RGWFileHandle::FLAG_DIRECTORY :
+                          RGWFileHandle::FLAG_NONE));
        }
       }
     }
@@ -183,7 +184,7 @@ int rgw_create(struct rgw_fs *rgw_fs,
   RGWFileHandle* parent = get_rgwfh(parent_fh);
   if ((! parent) ||
       (parent->is_root()) ||
-      (parent->is_object())) {
+      (parent->is_file())) {
     /* bad parent */
     return -EINVAL;
   }
@@ -366,7 +367,7 @@ int rgw_lookup(struct rgw_fs *rgw_fs,
 
   RGWFileHandle* parent = get_rgwfh(parent_fh);
   if ((! parent) ||
-      (parent->is_object())) {
+      (! parent->is_dir())) {
     /* bad parent */
     return -EINVAL;
   }
@@ -579,7 +580,7 @@ int rgw_read(struct rgw_fs *rgw_fs,
   RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
 
-  if (! rgw_fh->is_object())
+  if (! rgw_fh->is_file())
     return -EINVAL;
 
   size_t nread = 0;
@@ -619,7 +620,7 @@ int rgw_write(struct rgw_fs *rgw_fs,
   RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
 
-  if (! rgw_fh->is_object())
+  if (! rgw_fh->is_file())
     return -EINVAL;
 
   /* XXXX testing only */
@@ -678,7 +679,7 @@ int rgw_readv(struct rgw_fs *rgw_fs,
   RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
 
-  if (! rgw_fh->is_object())
+  if (! rgw_fh->is_file())
     return -EINVAL;
 
   buffer::list bl;
@@ -728,7 +729,7 @@ int rgw_readv(struct rgw_fs *rgw_fs,
   RGWLibFS *fs = static_cast<RGWLibFS*>(rgw_fs->fs_private);
   RGWFileHandle* rgw_fh = get_rgwfh(fh);
 
-  if (! rgw_fh->is_object())
+  if (! rgw_fh->is_file())
     return -EINVAL;
 
   buffer::list bl;
index aa4811afa1092071fc063e112e53d65eddd096ef..a5195dcb3645f4a3d91e48c7a928904be7ece503 100644 (file)
@@ -749,7 +749,7 @@ public:
     s->op = OP_GET;
 
     /* XXX derp derp derp */
-    string uri = "/" + rgw_fh->bucket_name() + "/";
+    std::string uri = "/" + rgw_fh->bucket_name() + "/";
     s->relative_uri = uri;
     s->info.request_uri = uri; // XXX
     s->info.effective_uri = uri;
@@ -1311,15 +1311,15 @@ class RGWStatLeafRequest : public RGWLibRequest,
                           public RGWListBucket /* RGWOp */
 {
 public:
-  const std::string& bucket;
+  RGWFileHandle* rgw_fh;
   std::string path;
   bool matched;
 
   RGWStatLeafRequest(CephContext* _cct, RGWUserInfo *_user,
-                    const std::string& _bucket, const std::string& _path)
-    : RGWLibRequest(_cct, _user), bucket(_bucket), path(_path),
+                    RGWFileHandle* _rgw_fh, const std::string& _path)
+    : RGWLibRequest(_cct, _user), rgw_fh(_rgw_fh), path(_path),
       matched(false) {
-    default_max = 2; // logical max {"foo", "foo/"}
+    default_max = 1000; // logical max {"foo", "foo/"}
     magic = 80;
     op = this;
   }
@@ -1344,7 +1344,7 @@ public:
     s->op = OP_GET;
 
     /* XXX derp derp derp */
-    std::string uri = "/" + bucket;
+    std::string uri = "/" + rgw_fh->bucket_name() + "/";
     s->relative_uri = uri;
     s->info.request_uri = uri; // XXX
     s->info.effective_uri = uri;
@@ -1354,32 +1354,28 @@ public:
     // woo
     s->user = user;
 
+    prefix = rgw_fh->full_object_name();
+    delimiter = '/';
+
     return 0;
   }
 
   virtual int get_params() {
-    // XXX S3
-    struct req_state* s = get_state();
-    list_versions = s->info.args.exists("versions");
-    if (!list_versions) {
-      marker = s->info.args.get("marker");
-    } else {
-      marker.name = s->info.args.get("key-marker");
-      marker.instance = s->info.args.get("version-id-marker");
-    }
-    max_keys = default_max; // 2
-    prefix = path;
-    delimiter = "/";
-#if 0 /* XXX? */
-    encoding_type = s->info.args.get("encoding-type");
-#endif
+    max = default_max;
     return 0;
   }
 
   virtual void send_response() {
+    // try objects
     for (const auto& iter : objs) {
       path = iter.key.name;
       matched = true;
+      return;
+    }
+    // try prefixes
+    for (auto& iter : common_prefixes) {
+      path = iter.first;
+      matched = true;
       break;
     }
   }
index 3d3d5e20f1134fd89650361623c0561782473991..9d32214e5732ccf0d5ced67528d056756145b2b8 100644 (file)
@@ -98,8 +98,10 @@ TEST(LibRGW, MOUNT) {
 
 extern "C" {
   static bool r1_cb(const char* name, void *arg, uint64_t offset) {
+    struct rgw_file_handle* parent_fh
+      = static_cast<struct rgw_file_handle*>(arg);
     obj_stack.push(
-      obj_rec{name, nullptr, nullptr, nullptr});
+      obj_rec{name, nullptr, parent_fh, nullptr});
     return true; /* XXX */
   }
 }
@@ -129,8 +131,7 @@ TEST(LibRGW, ENUMERATE1) {
          // descending
          uint64_t offset;
          bool eof; // XXX
-         rc = rgw_readdir(fs, elt.parent_fh, &offset, r1_cb,
-                          &obj_stack, &eof);
+         rc = rgw_readdir(fs, elt.fh, &offset, r1_cb, elt.fh, &eof);
          elt.state.readdir = true;
          ASSERT_EQ(rc, 0);
          ASSERT_TRUE(eof);