]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_filestore_dump: Add set-omap object command
authorDavid Zafman <david.zafman@inktank.com>
Tue, 20 May 2014 03:47:14 +0000 (20:47 -0700)
committerDavid Zafman <dzafman@redhat.com>
Thu, 28 Aug 2014 23:21:28 +0000 (16:21 -0700)
Signed-off-by: David Zafman <david.zafman@inktank.com>
src/tools/ceph_filestore_dump.cc

index 548ba1976cc9e1a9b520d0ef914e756b115d9cc6..23e748437723ad00547fe2a06931c1c14096790a 100644 (file)
@@ -1394,6 +1394,29 @@ int do_get_omap(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key)
   return 0;
 }
 
+int do_set_omap(ObjectStore *store, coll_t coll, ghobject_t &ghobj, string key, int fd)
+{
+  ObjectStore::Transaction tran;
+  ObjectStore::Transaction *t = &tran;
+  map<string, bufferlist> attrset;
+  bufferlist valbl;
+
+  if (debug)
+    cerr << "Set_omap " << ghobj << std::endl;
+
+  if (get_fd_data(fd, valbl))
+    return 1;
+
+  attrset.insert(pair<string, bufferlist>(key, valbl));
+
+  t->touch(coll, ghobj);
+
+  t->omap_setkeys(coll, ghobj, attrset);
+
+  store->apply_transaction(*t);
+  return 0;
+}
+
 void usage(po::options_description &desc)
 {
     cerr << std::endl;
@@ -1856,6 +1879,27 @@ int main(int argc, char **argv)
        if (r)
          ret = 1;
         goto out;
+      } else if (objcmd == "set-omap") {
+       if (vm.count("arg1") == 0)
+         usage(desc);
+
+       int fd;
+       if (vm.count("arg2") == 0 || arg2 == "-") {
+         fd = STDIN_FILENO;
+       } else {
+         fd = open(arg2.c_str(), O_RDONLY|O_LARGEFILE, 0666);
+         if (fd == -1) {
+           cerr << "open " << arg2 << " " << cpp_strerror(errno) << std::endl;
+           ret = 1;
+           goto out;
+         }
+       }
+       r = do_set_omap(fs, coll, ghobj, arg1, fd);
+       if (fd != STDIN_FILENO)
+         close(fd);
+       if (r)
+         ret = 1;
+        goto out;
       }
       cerr << "Unknown object command '" << objcmd << "'" << std::endl;
       usage(desc);