From: Yehuda Sadeh Date: Wed, 11 Jan 2012 21:37:37 +0000 (-0800) Subject: rgw-admin: add pool rm and pools list X-Git-Tag: v0.40~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=38b9b5030747349acf657946133ef57736542310;p=ceph.git rgw-admin: add pool rm and pools list --- diff --git a/src/rgw/rgw_access.h b/src/rgw/rgw_access.h index e3c39c126a7c..c9d3077a2ff8 100644 --- a/src/rgw/rgw_access.h +++ b/src/rgw/rgw_access.h @@ -67,6 +67,8 @@ public: bool system_bucket, bool exclusive = true, uint64_t auid = 0) = 0; virtual int add_bucket_placement(std::string& new_placement) { return 0; } + virtual int remove_bucket_placement(std::string& new_placement) { return 0; } + virtual int list_placement_set(set& names) { return 0; } virtual int create_pools(vector& names, vector& retcodes, int auid = 0) { return -ENOTSUP; } /** write an object to the storage device in the appropriate pool with the given stats */ diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index ccdb3bd822a3..cbcca744932f 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -45,7 +45,9 @@ void _usage() cerr << " bucket unlink unlink bucket from specified user\n"; cerr << " bucket stats returns bucket statistics\n"; cerr << " bucket info show bucket information\n"; - cerr << " pool add add an existing pool to those which can store buckets\n"; + cerr << " pool add add an existing pool for data placement\n"; + cerr << " pool rm remove an existing pool from data placement set\n"; + cerr << " pools list list placement active set\n"; cerr << " policy read bucket/object policy\n"; cerr << " log list list log objects\n"; cerr << " log show dump a log from specific object or (bucket + date\n"; @@ -116,6 +118,8 @@ enum { OPT_BUCKET_STATS, OPT_POLICY, OPT_POOL_ADD, + OPT_POOL_RM, + OPT_POOLS_LIST, OPT_LOG_LIST, OPT_LOG_SHOW, OPT_LOG_RM, @@ -188,6 +192,7 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more) strcmp(cmd, "buckets") == 0 || strcmp(cmd, "bucket") == 0 || strcmp(cmd, "pool") == 0 || + strcmp(cmd, "pools") == 0 || strcmp(cmd, "log") == 0 || strcmp(cmd, "temp") == 0) { *need_more = true; @@ -250,6 +255,11 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more) } else if (strcmp(prev_cmd, "pool") == 0) { if (strcmp(cmd, "add") == 0) return OPT_POOL_ADD; + if (strcmp(cmd, "rm") == 0) + return OPT_POOL_RM; + } else if (strcmp(prev_cmd, "pools") == 0) { + if (strcmp(cmd, "list") == 0) + return OPT_POOLS_LIST; } return -EINVAL; @@ -1170,7 +1180,40 @@ next: return usage(); } - rgwstore->add_bucket_placement(pool_name); + int ret = rgwstore->add_bucket_placement(pool_name); + if (ret < 0) + cerr << "failed to add bucket placement: " << cpp_strerror(-ret) << std::endl; + } + + if (opt_cmd == OPT_POOL_RM) { + if (pool_name.empty()) { + cerr << "need to specify pool to remove!" << std::endl; + return usage(); + } + + int ret = rgwstore->remove_bucket_placement(pool_name); + if (ret < 0) + cerr << "failed to remove bucket placement: " << cpp_strerror(-ret) << std::endl; + } + + if (opt_cmd == OPT_POOLS_LIST) { + set pools; + int ret = rgwstore->list_placement_set(pools); + if (ret < 0) { + cerr << "could not list placement set: " << cpp_strerror(-ret) << std::endl; + return ret; + } + formatter->reset(); + formatter->open_array_section("pools"); + set::iterator siter; + for (siter = pools.begin(); siter != pools.end(); ++siter) { + formatter->open_object_section("pool"); + formatter->dump_string("name", *siter); + formatter->close_section(); + } + formatter->close_section(); + formatter->flush(cout); + cout << std::endl; } if (opt_cmd == OPT_BUCKET_STATS) { diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 5c7d770e7128..5eb4e3b6eb4f 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -567,6 +567,33 @@ int RGWRados::add_bucket_placement(std::string& new_pool) return ret; } +int RGWRados::remove_bucket_placement(std::string& old_pool) +{ + rgw_obj obj(pi_buckets_rados, avail_pools); + int ret = tmap_del(obj, old_pool); + return ret; +} + +int RGWRados::list_placement_set(set& names) +{ + bufferlist header; + map m; + string pool_name; + + rgw_obj obj(pi_buckets_rados, avail_pools); + int ret = tmap_get(obj, header, m); + if (ret < 0) + return ret; + + names.clear(); + map::iterator miter; + for (miter = m.begin(); miter != m.end(); ++miter) { + names.insert(miter->first); + } + + return names.size(); +} + int RGWRados::create_pools(vector& names, vector& retcodes, int auid) { vector::iterator iter; diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index afb7694b8969..92fe9689d0cc 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -189,6 +189,8 @@ public: bool system_bucket, bool exclusive = true, uint64_t auid = 0); virtual int add_bucket_placement(std::string& new_pool); + virtual int remove_bucket_placement(std::string& new_pool); + virtual int list_placement_set(set& names); virtual int create_pools(vector& names, vector& retcodes, int auid = 0); /** Write/overwrite an object to the bucket storage. */ diff --git a/src/test/cli/radosgw-admin/help.t b/src/test/cli/radosgw-admin/help.t index 083d56d92a43..4d36c3c240e6 100644 --- a/src/test/cli/radosgw-admin/help.t +++ b/src/test/cli/radosgw-admin/help.t @@ -16,9 +16,10 @@ bucket link link bucket to specified user bucket unlink unlink bucket from specified user bucket stats returns bucket statistics - pool add add an existing pool to those which can store buckets - pool info show pool information - pool create generate pool information (requires bucket) + bucket info show bucket information + pool add add an existing pool for data placement + pool rm remove an existing pool from data placement set + pools list list placement active set policy read bucket/object policy log list list log objects log show dump a log from specific object or (bucket + date