]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_rgw: don't write list entry when converting when deleting
authorYehuda Sadeh <yehuda@redhat.com>
Thu, 13 Nov 2014 22:51:11 +0000 (14:51 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Mon, 19 Jan 2015 23:57:52 +0000 (15:57 -0800)
when converting the plain entry into a versioned entry, don't write the
list entry if this is a delete op with a null instance.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/cls/rgw/cls_rgw.cc

index ace835c0070710bec6bdf1924963e2c641b976c3..a974dff1c4d2bf5f4e079543dd672db153e68118 100644 (file)
@@ -983,10 +983,7 @@ static string escape_str(const string& s)
    return string(escaped);
 }
 
-/*
- * write object instance entry, and if needed also the list entry
- */
-static int write_obj_entries(cls_method_context_t hctx, struct rgw_bucket_dir_entry& instance_entry, const string& instance_idx)
+static int write_obj_instance_entry(cls_method_context_t hctx, struct rgw_bucket_dir_entry& instance_entry, const string& instance_idx)
 {
   CLS_LOG(20, "write_entry() instance=%s idx=%s flags=%d", escape_str(instance_entry.key.instance).c_str(), instance_idx.c_str(), instance_entry.flags);
   /* write the instance entry */
@@ -995,6 +992,18 @@ static int write_obj_entries(cls_method_context_t hctx, struct rgw_bucket_dir_en
     CLS_LOG(0, "ERROR: write_entry() instance_key=%s ret=%d", escape_str(instance_idx).c_str(), ret);
     return ret;
   }
+  return 0;
+}
+
+/*
+ * write object instance entry, and if needed also the list entry
+ */
+static int write_obj_entries(cls_method_context_t hctx, struct rgw_bucket_dir_entry& instance_entry, const string& instance_idx)
+{
+  int ret = write_obj_instance_entry(hctx, instance_entry, instance_idx);
+  if (ret < 0) {
+    return ret;
+  }
   string instance_list_idx;
   get_list_index_key(instance_entry, &instance_list_idx);
 
@@ -1225,12 +1234,25 @@ public:
   }
 };
 
+static int write_version_marker(cls_method_context_t hctx, cls_rgw_obj_key& key)
+{
+  struct rgw_bucket_dir_entry entry;
+  entry.key = key;
+  entry.flags = RGW_BUCKET_DIRENT_FLAG_VER_MARKER;
+  int ret = write_entry(hctx, entry, key.name);
+  if (ret < 0) {
+    CLS_LOG(0, "ERROR: write_entry returned ret=%d", ret);
+    return ret;
+  }
+  return 0;
+}
+
 /*
  * plain entries are the ones who were created when bucket was not versioned,
  * if we override these objects, we need to convert these to versioned entries -- ones that have
  * both data entry, and listing key. Their version is going to be empty though
  */
-static int convert_plain_entry_to_versioned(cls_method_context_t hctx, cls_rgw_obj_key& key, uint64_t epoch, bool demote_current)
+static int convert_plain_entry_to_versioned(cls_method_context_t hctx, cls_rgw_obj_key& key, uint64_t epoch, bool demote_current, bool instance_only)
 {
   if (!key.instance.empty()) {
     return -EINVAL;
@@ -1256,20 +1278,22 @@ static int convert_plain_entry_to_versioned(cls_method_context_t hctx, cls_rgw_o
     string new_idx;
     encode_obj_versioned_data_key(key, &new_idx);
 
-    ret = write_obj_entries(hctx, entry, new_idx);
+    if (instance_only) {
+      ret = write_obj_instance_entry(hctx, entry, new_idx);
+    } else {
+      ret = write_obj_entries(hctx, entry, new_idx);
+    }
     if (ret < 0) {
       CLS_LOG(0, "ERROR: write_obj_entries new_idx=%s returned %d", new_idx.c_str(), ret);
       return ret;
     }
   }
 
-  entry.key = key;
-  entry.flags = RGW_BUCKET_DIRENT_FLAG_VER_MARKER;
-  ret = write_entry(hctx, entry, key.name);
+  ret = write_version_marker(hctx, key);
   if (ret < 0) {
-    CLS_LOG(0, "ERROR: write_entry returned ret=%d", ret);
     return ret;
   }
+
   return 0;
 }
 
@@ -1373,8 +1397,9 @@ static int rgw_bucket_link_olh(cls_method_context_t hctx, bufferlist *in, buffer
       }
     }
   } else {
+    bool instance_only = (op.key.instance.empty() && op.delete_marker);
     cls_rgw_obj_key key(op.key.name);
-    ret = convert_plain_entry_to_versioned(hctx, key, olh.get_epoch(), true);
+    ret = convert_plain_entry_to_versioned(hctx, key, olh.get_epoch(), true, instance_only);
     if (ret < 0) {
       CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret);
       return ret;