]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: radosgw-admin object unlink
authorYehuda Sadeh <yehuda@inktank.com>
Tue, 5 Feb 2013 21:54:11 +0000 (13:54 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Tue, 5 Feb 2013 23:52:41 +0000 (15:52 -0800)
Add a radosgw-admin option to remove object from bucket index

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/test/cli/radosgw-admin/help.t

index 9984427de3add3b4ff95ee55838fb9a7594e070a..f0781504efc2a12eea4f1c9a0e4c2a25261f3356 100644 (file)
@@ -46,6 +46,7 @@ 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 << "  object unlink              unlink object from bucket index\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";
@@ -124,6 +125,7 @@ enum {
   OPT_BUCKET_LINK,
   OPT_BUCKET_UNLINK,
   OPT_BUCKET_STATS,
+  OPT_OBJECT_UNLINK,
   OPT_POLICY,
   OPT_POOL_ADD,
   OPT_POOL_RM,
@@ -201,6 +203,7 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
       strcmp(cmd, "key") == 0 ||
       strcmp(cmd, "buckets") == 0 ||
       strcmp(cmd, "bucket") == 0 ||
+      strcmp(cmd, "object") == 0 ||
       strcmp(cmd, "pool") == 0 ||
       strcmp(cmd, "pools") == 0 ||
       strcmp(cmd, "log") == 0 ||
@@ -253,6 +256,9 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
       return OPT_BUCKET_UNLINK;
     if (strcmp(cmd, "stats") == 0)
       return OPT_BUCKET_STATS;
+  } else if (strcmp(prev_cmd, "object") == 0) {
+    if (strcmp(cmd, "unlink") == 0)
+      return OPT_OBJECT_UNLINK;
   } else if (strcmp(prev_cmd, "log") == 0) {
     if (strcmp(cmd, "list") == 0)
       return OPT_LOG_LIST;
@@ -1496,5 +1502,13 @@ next:
     }   
   }
 
+  if (opt_cmd == OPT_OBJECT_UNLINK) {
+    int ret = rgwstore->remove_obj_from_index(bucket, object);
+    if (ret < 0) {
+      cerr << "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret) << std::endl;
+      return 1;
+    }
+  }
+
   return 0;
 }
index 9592d438b54ff5126351ccaccf63739011a62650..a5655a9038e50035f65f660eb50289943024e444 100644 (file)
@@ -2751,6 +2751,32 @@ int RGWRados::cls_obj_usage_log_trim(string& oid, string& user, uint64_t start_e
   return r;
 }
 
+int RGWRados::remove_obj_from_index(rgw_bucket& bucket, const string& oid)
+{
+  librados::IoCtx io_ctx;
+
+  int r = open_bucket_ctx(bucket, io_ctx);
+  if (r < 0)
+    return r;
+
+  string dir_oid = dir_oid_prefix;
+  dir_oid.append(bucket.marker);
+
+  rgw_bucket_dir_entry entry;
+  entry.epoch = (uint64_t)-1; // ULLONG_MAX, needed to that objclass doesn't skip out request
+  entry.name = oid;
+
+  bufferlist updates;
+  updates.append(CEPH_RGW_REMOVE);
+  ::encode(entry, updates);
+
+  bufferlist out;
+
+  r = io_ctx.exec(dir_oid, "rgw", "dir_suggest_changes", updates, out);
+
+  return r;
+}
+
 int RGWRados::check_disk_state(librados::IoCtx io_ctx,
                                rgw_bucket& bucket,
                                rgw_bucket_dir_entry& list_state,
index 4acd8e8da800edb51053f6e8f7b9c3358793d32d..7d681c9e74b73b63e21be5c9295333e76c5a62d8 100644 (file)
@@ -583,6 +583,8 @@ public:
   /// clean up/process any temporary objects older than given date[/time]
   int remove_temp_objects(string date, string time);
 
+  int remove_obj_from_index(rgw_bucket& bucket, const string& oid);
+
  private:
   int process_intent_log(rgw_bucket& bucket, string& oid,
                         time_t epoch, int flags, bool purge);
index 75a18aaa455ea4e760fb34cfc74358bc9c7fb6bd..b7aeb75548c6d4024621e37f121f51a70848a423 100644 (file)
@@ -17,6 +17,7 @@
     bucket unlink              unlink bucket from specified user
     bucket stats               returns bucket statistics
     bucket info                show bucket information
+    object unlink              unlink object from bucket index
     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