]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
BlueStore: use special symbol to distinguish backend type
authorHaomai Wang <haomai@xsky.com>
Thu, 21 Jan 2016 03:29:35 +0000 (11:29 +0800)
committerHaomai Wang <haomai@xsky.com>
Mon, 1 Feb 2016 14:02:19 +0000 (22:02 +0800)
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/os/bluestore/BlockDevice.cc
src/os/bluestore/BlockDevice.h
src/os/bluestore/BlueStore.cc

index bb62faba4ad0a94fea3bff3b99112c310aa521a1..ac17b6494cbe7e4660a0dbc53950a63ba88f6eba 100644 (file)
@@ -44,12 +44,12 @@ void IOContext::aio_wait()
 
 BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cbpriv)
 {
-  char buf[2];
-  int r = ::readlink(path.c_str(), buf, 2);
-
   string type = "kernel";
-  if (r < 0)
+  char buf[10];
+  int r = ::readlink(path.c_str(), buf, sizeof(buf));
+  if (r >= 0 && strncmp(buf, SPDK_PREFIX, sizeof(SPDK_PREFIX)-1) == 0) {
     type = "ust-nvme";
+  }
   dout(1) << __func__ << " path " << path << " type " << type << dendl;
 
   if (type == "kernel") {
@@ -61,7 +61,7 @@ BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cb
   }
 #endif
 
-  derr << __func__ << " unknown bacend " << type << dendl;
+  derr << __func__ << " unknown backend " << type << dendl;
   assert(0);
   return NULL;
 }
index 090fd1e48067f955a78f6860a9af2def3e18a6c8..43e38ab32e42576bfa6cf8337063fb43a242fd24 100644 (file)
@@ -20,6 +20,8 @@
 #include "acconfig.h"
 #include "os/fs/FS.h"
 
+#define SPDK_PREFIX "spdk:"
+
 /// track in-flight io
 struct IOContext {
   void *priv;
index a80fcc56d0ee71ce11cba0466e59bec21e1f86aa..16fad7c2b5768da6e28855bff6390ba6ecbc9077 100644 (file)
@@ -1565,33 +1565,40 @@ int BlueStore::_open_collections(int *errors)
 
 int BlueStore::_setup_block_symlink_or_file(
   string name,
-  string path,
+  string epath,
   uint64_t size)
 {
-  dout(20) << __func__ << " name " << name << " path " << path
+  dout(20) << __func__ << " name " << name << " path " << epath
           << " size " << size << dendl;
   int r = 0;
-  if (path.length()) {
-    string spdk_prefix = "spdk:";
-    if (!path.compare(0, spdk_prefix.size(), spdk_prefix)) {
-      int fd = ::openat(path_fd, name.c_str(), O_CREAT|O_RDWR, 0644);
+  if (epath.length()) {
+    if (!epath.compare(0, sizeof(SPDK_PREFIX-1), SPDK_PREFIX)) {
+      string symbol_spdk_file = path + "/" + epath;
+      r = ::symlinkat(symbol_spdk_file.c_str(), path_fd, name.c_str());
+      if (r < 0) {
+        r = -errno;
+        derr << __func__ << " failed to create " << name << " symlink to "
+            << symbol_spdk_file << ": " << cpp_strerror(r) << dendl;
+        return r;
+      }
+      int fd = ::openat(path_fd, epath.c_str(), O_RDWR, 0644);
       if (fd < 0) {
        r = -errno;
-       derr << __func__ << " failed to create " << name << " file: "
+       derr << __func__ << " failed to open " << epath << " file: "
             << cpp_strerror(r) << dendl;
        return r;
       }
-      string serial_number = path.substr(spdk_prefix.size());
+      string serial_number = epath.substr(sizeof(SPDK_PREFIX)-1);
       r = ::write(fd, serial_number.c_str(), serial_number.size());
       assert(r == (int)serial_number.size());
       dout(1) << __func__ << " created " << name << " file with " << dendl;
       VOID_TEMP_FAILURE_RETRY(::close(fd));
     } else {
-      r = ::symlinkat(path.c_str(), path_fd, name.c_str());
+      r = ::symlinkat(epath.c_str(), path_fd, name.c_str());
       if (r < 0) {
         r = -errno;
         derr << __func__ << " failed to create " << name << " symlink to "
-          << path << ": " << cpp_strerror(r) << dendl;
+          << epath << ": " << cpp_strerror(r) << dendl;
         return r;
       }
     }