]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: Add testing feature "corrupt-info" to ceph-objectstore-tool
authorDavid Zafman <dzafman@redhat.com>
Fri, 20 Jul 2018 19:31:56 +0000 (12:31 -0700)
committerDavid Zafman <dzafman@redhat.com>
Thu, 26 Jul 2018 18:38:38 +0000 (11:38 -0700)
Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit 8e9c08524da0cf465553f99b2e160e59abc8e84b)

Conflicts:
    src/tools/ceph_objectstore_tool.cc (adjust for Luminous transactions)

src/tools/ceph_objectstore_tool.cc

index 2e34268805b2612fb74709fdf8c40c8349bd109e..c640ec50e5f71ab74cce447f323297324f21b399 100644 (file)
@@ -2405,6 +2405,43 @@ int print_obj_info(ObjectStore *store, coll_t coll, ghobject_t &ghobj, Formatter
   return r;
 }
 
+int corrupt_info(ObjectStore *store, coll_t coll, ghobject_t &ghobj, Formatter* formatter,
+            ObjectStore::Sequencer &osr)
+{
+  bufferlist attr;
+  int r = store->getattr(coll, ghobj, OI_ATTR, attr);
+  if (r < 0) {
+    cerr << "Error getting attr on : " << make_pair(coll, ghobj) << ", "
+       << cpp_strerror(r) << std::endl;
+    return r;
+  }
+  object_info_t oi;
+  bufferlist::iterator bp = attr.begin();
+  try {
+    ::decode(oi, bp);
+  } catch (...) {
+    r = -EINVAL;
+    cerr << "Error getting attr on : " << make_pair(coll, ghobj) << ", "
+         << cpp_strerror(r) << std::endl;
+    return r;
+  }
+  cout << "Corrupting info" << std::endl;
+  if (!dry_run) {
+    attr.clear();
+    oi.alloc_hint_flags += 0xff;
+    ObjectStore::Transaction t;
+    ::encode(oi, attr, -1);  /* fixme: using full features */
+    t.setattr(coll, ghobj, OI_ATTR, attr);
+    r = store->apply_transaction(&osr, std::move(t));
+    if (r < 0) {
+      cerr << "Error writing object info: " << make_pair(coll, ghobj) << ", "
+         << cpp_strerror(r) << std::endl;
+      return r;
+    }
+  }
+  return 0;
+}
+
 int set_size(ObjectStore *store, coll_t coll, ghobject_t &ghobj, uint64_t setsize, Formatter* formatter,
             ObjectStore::Sequencer &osr, bool corrupt)
 {
@@ -3868,6 +3905,15 @@ int main(int argc, char **argv)
        }
        ret = print_obj_info(fs, coll, ghobj, formatter);
        goto out;
+      } else if (objcmd == "corrupt-info") {   // Undocumented testing feature
+       // There should not be any other arguments
+       if (vm.count("arg1") || vm.count("arg2")) {
+         usage(desc);
+          ret = 1;
+          goto out;
+        }
+        ret = corrupt_info(fs, coll, ghobj, formatter, *osr);
+        goto out;
       } else if (objcmd == "set-size" || objcmd == "corrupt-size") {
        // Undocumented testing feature
        bool corrupt = (objcmd == "corrupt-size");