From 55c99558e783a9ad22b9df1f7c4be4c1dbff460c Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Thu, 21 Jan 2016 11:29:35 +0800 Subject: [PATCH] BlueStore: use special symbol to distinguish backend type Signed-off-by: Haomai Wang --- src/os/bluestore/BlockDevice.cc | 10 +++++----- src/os/bluestore/BlockDevice.h | 2 ++ src/os/bluestore/BlueStore.cc | 27 +++++++++++++++++---------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc index bb62faba4ad..ac17b6494cb 100644 --- a/src/os/bluestore/BlockDevice.cc +++ b/src/os/bluestore/BlockDevice.cc @@ -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; } diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h index 090fd1e4806..43e38ab32e4 100644 --- a/src/os/bluestore/BlockDevice.h +++ b/src/os/bluestore/BlockDevice.h @@ -20,6 +20,8 @@ #include "acconfig.h" #include "os/fs/FS.h" +#define SPDK_PREFIX "spdk:" + /// track in-flight io struct IOContext { void *priv; diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index a80fcc56d0e..16fad7c2b57 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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; } } -- 2.47.3