]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librgw: widen rgw_mount, open-code list buckets
authorMatt Benjamin <mbenjamin@redhat.com>
Wed, 9 Sep 2015 18:11:28 +0000 (14:11 -0400)
committerMatt Benjamin <mbenjamin@redhat.com>
Fri, 12 Feb 2016 16:57:58 +0000 (11:57 -0500)
Widen rgw_mount(...) to take the library context, which from
there on follows struct rgw_fs.

Implement an open-coded version of list buckets in rgw_readdir(...),
which now...lists buckets.

The future home of this and the rest of the rgw_file impl. logic
looks to be a more fully elaborated RGWLib* class family.

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

index ca26e20e8460db056b4d02ea8fc0551ed6d5d7ef..7a830bfc8d9864f571b08d01f5607f8031982bba 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include "include/rados/librgw.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -35,6 +37,7 @@ struct rgw_file_handle
 
 struct rgw_fs
 {
+  librgw_t rgw;
   struct rgw_file_handle root_fh;
   char *user_id;
   char *access_key_id;
@@ -71,8 +74,8 @@ int rgw_check_handle(const struct rgw_file_handle *handle);
 /*
  attach rgw namespace
 */
-int rgw_mount(const char *uid, const char *key, const char *secret,
-             struct rgw_fs **rgw_fs);
+int rgw_mount(librgw_t rgw, const char *uid, const char *key,
+             const char *secret, struct rgw_fs **rgw_fs);
 
 /*
  detach rgw namespace
index ba9ff4efabeabe9f9366cf8328add2f15ec5dd67..80145d58140243b8251a3d39095586b086e10799 100644 (file)
@@ -2,13 +2,14 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "include/rados/rgw_file.h"
-#include "include/rados/librgw.h"
 
 #include "rgw_lib.h"
 #include "rgw_rados.h"
 #include "rgw_resolve.h"
 #include "rgw_op.h"
 #include "rgw_rest.h"
+#include "rgw_acl.h"
+#include "rgw_acl_s3.h"
 #include "rgw_frontend.h"
 #include "rgw_request.h"
 #include "rgw_process.h"
 #include "rgw_rest_s3.h"
 #include "rgw_rest_lib.h"
 #include "rgw_auth_s3.h"
+#include "rgw_user.h"
+#include "rgw_bucket.h"
+
 #include "rgw_lib.h"
 
 
+#define dout_subsys ceph_subsys_rgw
+
 extern RGWLib librgw;
 
 bool is_root(const string& uri)
@@ -56,8 +62,8 @@ extern "C" {
 /*
  attach rgw namespace
 */
-int rgw_mount(const char* uid, const char* key, const char* _secret,
-             struct rgw_fs **rgw_fs)
+int rgw_mount(librgw_t rgw, const char* uid, const char* key,
+             const char* _secret, struct rgw_fs **rgw_fs)
 {
   int rc;
   string uri(uid);
@@ -85,12 +91,13 @@ int rgw_mount(const char* uid, const char* key, const char* _secret,
   /* stash access data for "mount" */
   struct rgw_fs *new_fs =
     static_cast<struct rgw_fs*>(operator new (sizeof(struct rgw_fs)));
+  new_fs->rgw = rgw;
   new_fs->user_id = strdup(uid);
   new_fs->access_key_id = strdup(key);
   new_fs->secret_access_key = strdup(_secret);
 
   /* stash the root */
-  rc = rgw_get_handle(uri.c_str(), &new_fs->root_fh);
+  rc = rgw_get_handle("", &new_fs->root_fh);
 
   *rgw_fs = new_fs;
 
@@ -293,6 +300,44 @@ int rgw_readdir(struct rgw_fs *rgw_fs,
     return rc;
   }
 
+  CephContext* cct = static_cast<CephContext*>(rgw_fs->rgw);
+  RGWRados* store = librgw.get_store();
+
+  /* XXX current open-coded logic should move into librgw (need
+   * functor mechanism wrapping callback */
+
+  if (is_root(uri)) {
+    /* get the bucket list */
+    string marker; // XXX need to match offset
+    uint64_t nread, bucket_count, bucket_objcount;
+    RGWUserBuckets buckets;
+    uint64_t max_buckets = cct->_conf->rgw_list_buckets_max_chunk;
+
+    /* XXX check offsets */
+    uint64_t ix = 3;
+    rc = rgw_read_user_buckets(store, rgw_fs->user_id, buckets, marker,
+                              max_buckets, true);
+    if (rc < 0) {
+      ldout(cct, 10) << "WARNING: failed on rgw_get_user_buckets uid="
+                    << rgw_fs->user_id << dendl;
+      return rc;
+    } else {
+      bucket_count = 0;
+      bucket_objcount = 0;
+      map<string, RGWBucketEnt>& m = buckets.get_buckets();
+      for (auto& ib : m) {
+       RGWBucketEnt& bent = ib.second;
+       bucket_objcount += bent.count;
+       marker = ib.first;
+       (void) rcb(bent.bucket.name.c_str(), cb_arg, ix++);
+      }
+      bucket_count += m.size();
+    }
+  } else {
+    /* !root uri */
+    
+  }
+
 #if 0 /* TODO: implement */
   if (is_root(uri)) {
     /* get the bucket list */
@@ -305,11 +350,6 @@ int rgw_readdir(struct rgw_fs *rgw_fs,
   }
 #endif
 
-  /* XXXX */
-  (void) rcb("test1", cb_arg, 1);
-  (void) rcb("test2", cb_arg, 2);
-  (void) rcb("test3", cb_arg, 3);
-
   *eof = true;
 
   return 0;
index 084875a891ba37592f028fde73a20125db9af493..7e909bbec06cd4ddacedba59d4c41934c219dbb0 100644 (file)
@@ -32,6 +32,8 @@ public:
   RGWLib() {}
   ~RGWLib() {}
 
+  RGWRados* get_store() { return store; }
+
   int init();
   int init(vector<const char *>& args);
   int stop();
index 81fb4b7e0948ee8f6c796a9571978062fd42fb6e..7706bc14d16684111386e725c80e45c7ca2943a3 100644 (file)
@@ -42,7 +42,7 @@ TEST(LibRGW, INIT) {
 }
 
 TEST(LibRGW, MOUNT) {
-  int ret = rgw_mount(uid.c_str(), access_key.c_str(), secret_key.c_str(),
+  int ret = rgw_mount(rgw, uid.c_str(), access_key.c_str(), secret_key.c_str(),
                      &fs);
   ASSERT_EQ(ret, 0);
   ASSERT_NE(fs, nullptr);