]> 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>
Wed, 6 Feb 2013 01:08:22 +0000 (17:08 -0800)
Add a radosgw-admin option to remove object from bucket index

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
(cherry picked from commit 16235a7acb9543d60470170bb2a09956364626cd)

Conflicts:
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.h
src/test/cli/radosgw-admin/help.t

src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_rados.h
src/test/cli/radosgw-admin/help.t

index fb419d93b4cfd459408b653fa4034f5970dfc229..6f368188511ace7b21839c5f1a42b9cc384fb63c 100644 (file)
@@ -55,6 +55,7 @@ void _usage()
   cerr << "  bucket rm                  remove bucket\n";
   cerr << "  bucket check               check bucket index\n";
   cerr << "  object rm                  remove object\n";
+  cerr << "  object unlink              unlink object from bucket index\n";
   cerr << "  cluster info               show cluster params info\n";
   cerr << "  pool add                   add an existing pool for data placement\n";
   cerr << "  pool rm                    remove an existing pool from data placement set\n";
@@ -155,6 +156,7 @@ enum {
   OPT_USAGE_TRIM,
   OPT_TEMP_REMOVE,
   OPT_OBJECT_RM,
+  OPT_OBJECT_UNLINK,
   OPT_GC_LIST,
   OPT_GC_PROCESS,
   OPT_CLUSTER_INFO,
@@ -227,6 +229,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 ||
@@ -318,6 +321,8 @@ static int get_cmd(const char *cmd, const char *prev_cmd, bool *need_more)
   } else if (strcmp(prev_cmd, "object") == 0) {
     if (strcmp(cmd, "rm") == 0)
       return OPT_OBJECT_RM;
+    if (strcmp(cmd, "unlink") == 0)
+      return OPT_OBJECT_UNLINK;
   } else if (strcmp(prev_cmd, "cluster") == 0) {
     if (strcmp(cmd, "info") == 0)
       return OPT_CLUSTER_INFO;
@@ -1627,6 +1632,14 @@ next:
     }
   }
 
+  if (opt_cmd == OPT_OBJECT_UNLINK) {
+    int ret = store->remove_obj_from_index(bucket, object);
+    if (ret < 0) {
+      cerr << "ERROR: remove_obj_from_index() returned error: " << cpp_strerror(-ret) << std::endl;
+      return 1;
+    }
+  }
+
   if (opt_cmd == OPT_BUCKET_CHECK) {
     map<RGWObjCategory, RGWBucketStats> existing_stats;
     map<RGWObjCategory, RGWBucketStats> calculated_stats;
@@ -1757,5 +1770,6 @@ next:
     store->params.dump(formatter);
     formatter->flush(cout);
   }
+
   return 0;
 }
index d75b0d8a8e558fe09441c24b501aee0c50fb2ee0..895dd7001e14ed5ec034e30c7bcabc9a8270bc24 100644 (file)
@@ -3228,6 +3228,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 e2ab4e244994fce53311c84418cca4bf8e6edfef..e50ef5d4490aea984761f6e0722e75b180630d14 100644 (file)
@@ -720,6 +720,8 @@ public:
                          map<RGWObjCategory, RGWBucketStats> *existing_stats,
                          map<RGWObjCategory, RGWBucketStats> *calculated_stats);
   int bucket_rebuild_index(rgw_bucket& bucket);
+  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 a9269ecb69142dc6126a89445e2c5c31f81ceb5c..714f5dea773bc38f93e7c594674066dfd4712bbc 100644 (file)
@@ -21,6 +21,7 @@
     bucket rm                  remove bucket
     bucket check               check bucket index
     object rm                  remove object
+    object unlink              unlink object from bucket index
     cluster info               show cluster params info
     pool add                   add an existing pool for data placement
     pool rm                    remove an existing pool from data placement set