From: Haomai Wang Date: Thu, 21 Jan 2016 03:29:35 +0000 (+0800) Subject: BlueStore: use special symbol to distinguish backend type X-Git-Tag: v10.0.4~81^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=55c99558e783a9ad22b9df1f7c4be4c1dbff460c;p=ceph.git BlueStore: use special symbol to distinguish backend type Signed-off-by: Haomai Wang --- diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc index bb62faba4ad0..ac17b6494cbe 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 090fd1e48067..43e38ab32e42 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 a80fcc56d0ee..16fad7c2b576 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; } }