From: Yehuda Sadeh Date: Wed, 21 Sep 2011 21:17:58 +0000 (-0700) Subject: rgw: class init_index X-Git-Tag: v0.37~103^2~63 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=028ba54fce34ca719f8e5445cfe94bd7619303c5;p=ceph.git rgw: class init_index --- diff --git a/src/cls_rgw.cc b/src/cls_rgw.cc index c83eea90b7b..6b9bb9f0b1c 100644 --- a/src/cls_rgw.cc +++ b/src/cls_rgw.cc @@ -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); diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index c18e88ec065..025bde2e78a 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -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 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 ent_map; + r = cls_bucket_list(bucket, marker, max, ent_map); + if (r < 0) + return r; + + std::map::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::iterator p; if (!marker.empty()) @@ -357,12 +380,12 @@ int RGWRados::create_bucket(std::string& id, rgw_bucket& bucket, mappool_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& 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);