]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-bluestore-tool: implement prime-osd-dir
authorSage Weil <sage@redhat.com>
Wed, 11 Oct 2017 22:36:40 +0000 (17:36 -0500)
committerSage Weil <sage@redhat.com>
Mon, 16 Oct 2017 19:29:10 +0000 (14:29 -0500)
This populates an osd dir based on the metadata in a bluestore
device label.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/bluestore_tool.cc

index 23d595442080bd14e12efbca10ab9eeafda67db9..c1b44ced8e0593d0695d2f8c7dfb141060216e24 100644 (file)
@@ -14,6 +14,7 @@
 #include "common/ceph_argparse.h"
 #include "include/stringify.h"
 #include "common/errno.h"
+#include "common/safe_io.h"
 
 #include "os/bluestore/BlueFS.h"
 #include "os/bluestore/BlueStore.h"
@@ -143,7 +144,7 @@ int main(int argc, char **argv)
     ;
   po::options_description po_positional("Positional options");
   po_positional.add_options()
-    ("command", po::value<string>(&action), "fsck, repair, bluefs-export, bluefs-bdev-sizes, bluefs-bdev-expand, show-label")
+    ("command", po::value<string>(&action), "fsck, repair, bluefs-export, bluefs-bdev-sizes, bluefs-bdev-expand, show-label, prime-osd-dir")
     ;
   po::options_description po_all("All options");
   po_all.add(po_options).add(po_positional);
@@ -179,6 +180,16 @@ int main(int argc, char **argv)
       exit(EXIT_FAILURE);
     }
   }
+  if (action == "prime-osd-dev") {
+    if (devs.size() != 1) {
+      cerr << "must specify the main bluestore device" << std::endl;
+      exit(EXIT_FAILURE);
+    }
+    if (path.empty()) {
+      cerr << "must specify osd dir to prime" << std::endl;
+      exit(EXIT_FAILURE);
+    }
+  }
   if (action == "show-label") {
     if (devs.empty() && path.empty()) {
       cerr << "must specify bluestore path *or* raw device(s)" << std::endl;
@@ -267,6 +278,68 @@ int main(int argc, char **argv)
     }
     cout << action << " success" << std::endl;
   }
+  else if (action == "prime-osd-dir") {
+    bluestore_bdev_label_t label;
+    int r = BlueStore::_read_bdev_label(cct.get(), devs.front(), &label);
+    if (r < 0) {
+      cerr << "failed to read label for " << devs.front() << ": "
+          << cpp_strerror(r) << std::endl;
+      exit(EXIT_FAILURE);
+    }
+
+    // kludge some things into the map that we want to populate into
+    // target dir
+    label.meta["path_block"] = devs.front();
+    label.meta["type"] = "bluestore";
+    label.meta["fsid"] = stringify(label.osd_uuid);
+    
+    for (auto kk : {
+       "whoami",
+         "osd_key",
+         "path_block", "path_block.db", "path_block.wal",
+         "ceph_fsid",
+         "fsid",
+         "type",
+         "ready" }) {
+      string k = kk;
+      auto i = label.meta.find(k);
+      if (i == label.meta.end()) {
+       continue;
+      }
+      string p = path + "/" + k;
+      string v = i->second;
+      if (k == "osd_key") {
+       p = path + "/keyring";
+       v = "[osd.";
+       v += label.meta["whoami"];
+       v += "]\nkey = " + i->second;
+      }
+      v += "\n";
+      if (k.find("path_") == 0) {
+       p = path + "/" + k.substr(5);
+       int r = ::symlink(v.c_str(), p.c_str());
+       if (r < 0) {
+         cerr << "error symlinking " << p << ": " << cpp_strerror(errno)
+              << std::endl;
+         exit(EXIT_FAILURE);
+       }
+      } else {
+       int fd = ::open(p.c_str(), O_CREAT|O_TRUNC|O_WRONLY, 0600);
+       if (fd < 0) {
+         cerr << "error writing " << p << ": " << cpp_strerror(errno)
+              << std::endl;
+         exit(EXIT_FAILURE);
+       }
+       int r = safe_write(fd, v.c_str(), v.size());
+       if (r < 0) {
+         cerr << "error writing to " << p << ": " << cpp_strerror(errno)
+              << std::endl;
+         exit(EXIT_FAILURE);
+       }
+       ::close(fd);
+      }
+    }
+  }
   else if (action == "show-label") {
     JSONFormatter jf(true);
     jf.open_array_section("devices");