]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw-admin: add pool rm and pools list
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 11 Jan 2012 21:37:37 +0000 (13:37 -0800)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 11 Jan 2012 21:37:37 +0000 (13:37 -0800)
src/rgw/rgw_access.h
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/test/cli/radosgw-admin/help.t

index e3c39c126a7caedc44ae33397edfa6f926b6b981..c9d3077a2ff85c0888a1bb0fdb5c0ae25a2ed99c 100644 (file)
@@ -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<string>& names) { return 0; }
   virtual int create_pools(vector<string>& names, vector<int>& retcodes, int auid = 0) { return -ENOTSUP; }
   /** write an object to the storage device in the appropriate pool
     with the given stats */
index ccdb3bd822a3e55a44212dc4ac37bd2246c5d6be..cbcca744932f37b4249c2b7cee3721b978bc73ea 100644 (file)
@@ -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<string> 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<string>::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) {
index 5c7d770e7128f29b83b950442a48ab6517344092..5eb4e3b6eb4f950dc4a29489d7a4c30462f5a0bd 100644 (file)
@@ -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<string>& names)
+{
+  bufferlist header;
+  map<string, bufferlist> 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<string, bufferlist>::iterator miter;
+  for (miter = m.begin(); miter != m.end(); ++miter) {
+    names.insert(miter->first);
+  }
+
+  return names.size();
+}
+
 int RGWRados::create_pools(vector<string>& names, vector<int>& retcodes, int auid)
 {
   vector<string>::iterator iter;
index afb7694b89698cac9048b04eea9f1814930f888c..92fe9689d0cce230c8097679a0607583e80703b8 100644 (file)
@@ -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<string>& names);
   virtual int create_pools(vector<string>& names, vector<int>& retcodes, int auid = 0);
 
   /** Write/overwrite an object to the bucket storage. */
index 083d56d92a43b84faa97d7223ca36413d364e541..4d36c3c240e693cd2d87320424d55d068ab4dac6 100644 (file)
     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