]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: class init_index
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 21 Sep 2011 21:17:58 +0000 (14:17 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 21 Sep 2011 21:17:58 +0000 (14:17 -0700)
src/cls_rgw.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h

index c83eea90b7bdba3f250349c50a6d0170788b33c3..6b9bb9f0b1c778472ea09efa874795c8af181053 100644 (file)
@@ -13,6 +13,7 @@ CLS_VER(1,0)
 CLS_NAME(rgw)
 
 cls_handle_t h_class;
+cls_method_handle_t h_rgw_bucket_init_index;
 cls_method_handle_t h_rgw_bucket_list;
 cls_method_handle_t h_rgw_bucket_modify;
 
@@ -21,7 +22,12 @@ static int read_bucket_dir(cls_method_context_t hctx, struct rgw_bucket_dir& dir
   bufferlist bl;
   bufferlist::iterator iter;
 
-  int rc = cls_cxx_read(hctx, 0, 0, &bl);
+  uint64_t size;
+  int rc = cls_cxx_stat(hctx, &size, NULL);
+  if (rc < 0)
+    return rc;
+
+  rc = cls_cxx_read(hctx, 0, size, &bl);
   if (rc < 0)
     return rc;
 
@@ -79,6 +85,26 @@ int rgw_bucket_list(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
   return 0;
 }
 
+int rgw_bucket_init_index(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+{
+  bufferlist bl;
+  bufferlist::iterator iter;
+
+  uint64_t size;
+  int rc = cls_cxx_stat(hctx, &size, NULL);
+  if (rc < 0)
+    return rc;
+  if (size != 0) {
+    CLS_LOG("ERROR: index already initialized\n");
+    return -EINVAL;
+  }
+
+  rgw_bucket_dir dir;
+  rc = write_bucket_dir(hctx, dir);
+
+  return rc;
+}
+
 int rgw_bucket_modify(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
 {
   bufferlist bl;
@@ -131,6 +157,7 @@ void __cls_init()
   CLS_LOG("Loaded rgw class!");
 
   cls_register("rgw", &h_class);
+  cls_register_cxx_method(h_class, "bucket_init_index", CLS_METHOD_RD | CLS_METHOD_WR | CLS_METHOD_PUBLIC, rgw_bucket_init_index, &h_rgw_bucket_init_index);
   cls_register_cxx_method(h_class, "bucket_list", CLS_METHOD_RD | CLS_METHOD_PUBLIC, rgw_bucket_list, &h_rgw_bucket_list);
   cls_register_cxx_method(h_class, "bucket_modify", CLS_METHOD_RD | CLS_METHOD_WR | CLS_METHOD_PUBLIC, rgw_bucket_modify, &h_rgw_bucket_modify);
 
index c18e88ec065aa94e2904871fbfcaec65698772c1..025bde2e78a0c92c4fff5ddfef9b2814842ee09e 100644 (file)
@@ -24,6 +24,7 @@ Rados *rados = NULL;
 static string notify_oid = "notify";
 static string shadow_ns = "shadow";
 static string bucket_marker_ver_oid = ".rgw.bucket-marker-ver";
+static string dir_oid_prefix = ".dir.";
 
 static string shadow_category = "rgw.shadow";
 static string main_category = "rgw.main";
@@ -231,6 +232,7 @@ int RGWRados::list_objects(string& id, rgw_bucket& bucket, int max, string& pref
   }
 
   std::map<string, string> dir_map;
+#if 0
   {
     librados::ObjectIterator i_end = io_ctx.objects_end();
     for (librados::ObjectIterator i = io_ctx.objects_begin(); i != i_end; ++i) {
@@ -257,6 +259,27 @@ int RGWRados::list_objects(string& id, rgw_bucket& bucket, int max, string& pref
        }
     }
   }
+#endif
+  std::map<string, RGWObjEnt> ent_map;
+  r = cls_bucket_list(bucket, marker, max, ent_map);
+  if (r < 0)
+    return r;
+
+  std::map<string, RGWObjEnt>::iterator eiter;
+  for (eiter = ent_map.begin(); eiter != ent_map.end(); ++eiter) {
+    string obj = eiter->first;
+    string key = obj;
+
+    if (!rgw_obj::translate_raw_obj(obj, ns))
+      continue;
+
+    if (filter && !filter->filter(obj, key))
+      continue;
+
+    if (prefix.empty() || ((obj).compare(0, prefix.size(), prefix) == 0)) {
+      dir_map[obj] = key;
+    }
+  }
 
   std::map<string, string>::iterator p;
   if (!marker.empty())
@@ -357,12 +380,12 @@ int RGWRados::create_bucket(std::string& id, rgw_bucket& bucket, map<std::string
 
   bufferlist outbl;
   int ret = root_pool_ctx.operate(bucket.name, &op);
-  if (ret < 0)
+  if (ret < 0 && ret != -EEXIST)
     return ret;
 
   if (create_pool) {
     ret = rados->pool_create(bucket.pool.c_str(), auid);
-    if (ret < 0)
+    if (ret < 0 && ret != -EEXIST)
       root_pool_ctx.remove(bucket.name.c_str());
   }
 
@@ -386,6 +409,19 @@ int RGWRados::create_bucket(std::string& id, rgw_bucket& bucket, map<std::string
     char buf[32];
     snprintf(buf, sizeof(buf), "%llu", (unsigned long long)ver);
     bucket.marker = buf;
+
+    string dir_oid =  dir_oid_prefix;
+    dir_oid.append(bucket.marker);
+
+    r = io_ctx.create(dir_oid, true);
+    if (r < 0 && r != -EEXIST)
+      return r;
+
+    if (r != -EEXIST) {
+      r = cls_rgw_init_index(bucket, dir_oid);
+      if (r < 0)
+        return r;
+    }
   }
 
   return ret;
@@ -1763,6 +1799,23 @@ int RGWRados::distribute(bufferlist& bl)
   return r;
 }
 
+int RGWRados::cls_rgw_init_index(rgw_bucket& bucket, string& oid)
+{
+  librados::IoCtx io_ctx;
+  int r = open_bucket_ctx(bucket, io_ctx);
+  if (r < 0)
+    return r;
+
+  if (bucket.marker.empty()) {
+    RGW_LOG(0) << "ERROR: empty marker for cls_rgw bucket operation" << dendl;
+    return -EIO;
+  }
+
+  bufferlist in, out;
+  r = io_ctx.exec(oid, "rgw", "bucket_init_index", in, out);
+  return r;
+}
+
 int RGWRados::cls_obj_op(rgw_bucket& bucket, uint8_t op, uint64_t epoch,
                          string& name, uint64_t size, utime_t& mtime)
 {
@@ -1776,7 +1829,7 @@ int RGWRados::cls_obj_op(rgw_bucket& bucket, uint8_t op, uint64_t epoch,
     return -EIO;
   }
 
-  string oid = ".dir.";
+  string oid = dir_oid_prefix;
   oid.append(bucket.marker);
 
   bufferlist in, out;
@@ -1814,7 +1867,7 @@ int RGWRados::cls_bucket_list(rgw_bucket& bucket, string start, uint32_t num, ma
     return -EIO;
   }
 
-  string oid = ".dir.";
+  string oid = dir_oid_prefix;
   oid.append(bucket.marker);
 
   bufferlist in, out;
index 95393097e023dd261cbd3b280488d522f0adc319..a2560d9e4ad100ebf265a6b030bc9a9046471a04 100644 (file)
@@ -277,6 +277,7 @@ public:
 
   int get_bucket_stats(rgw_bucket& bucket, map<string, RGWBucketStats>& stats);
 
+  int cls_rgw_init_index(rgw_bucket& bucket, string& oid);
   int cls_obj_op(rgw_bucket& bucket, uint8_t op, uint64_t epoch,
                  string& name, uint64_t size, utime_t& mtime);
   int cls_obj_add(rgw_bucket& bucket, uint64_t epoch, string& name, uint64_t size, utime_t& mtime);