*
*/
+#include <libgen.h>
#include <unistd.h>
#include "KernelDevice.h"
BlockDevice *BlockDevice::create(const string& path, aio_callback_t cb, void *cbpriv)
{
string type = "kernel";
- char buf[10];
+ char buf[PATH_MAX];
int r = ::readlink(path.c_str(), buf, sizeof(buf));
- if (r >= 0 && strncmp(buf, SPDK_PREFIX, sizeof(SPDK_PREFIX)-1) == 0) {
- type = "ust-nvme";
+ if (r >= 0) {
+ char *bname = ::basename(buf);
+ if (strncmp(bname, SPDK_PREFIX, sizeof(SPDK_PREFIX)-1) == 0)
+ type = "ust-nvme";
}
dout(1) << __func__ << " path " << path << " type " << type << dendl;
flags |= O_CREAT;
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());
+ r = ::symlinkat(epath.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;
+ << epath << ": " << cpp_strerror(r) << dendl;
return r;
}
int fd = ::openat(path_fd, epath.c_str(), flags, 0644);