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;
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;
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;
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);
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";
}
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) {
}
}
}
+#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())
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());
}
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;
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)
{
return -EIO;
}
- string oid = ".dir.";
+ string oid = dir_oid_prefix;
oid.append(bucket.marker);
bufferlist in, out;
return -EIO;
}
- string oid = ".dir.";
+ string oid = dir_oid_prefix;
oid.append(bucket.marker);
bufferlist in, out;
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);