From: Sage Weil Date: Fri, 24 Mar 2017 00:41:37 +0000 (-0500) Subject: os/bluestore/BlockDevice: collect metadata X-Git-Tag: v12.0.2~164^2~6 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c4316637b15285c2ae7e1ba81fdebc60f21bbbfa;p=ceph.git os/bluestore/BlockDevice: collect metadata Implement for KernelDevice and NVMEDevice Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h index 603ab26d8c11..613a73afa45f 100644 --- a/src/os/bluestore/BlockDevice.h +++ b/src/os/bluestore/BlockDevice.h @@ -94,6 +94,8 @@ public: virtual uint64_t get_size() const = 0; virtual uint64_t get_block_size() const = 0; + virtual int collect_metadata(string prefix, map *pm) const = 0; + virtual int read( uint64_t off, uint64_t len, diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index 5f7fe838bf5f..3e03eedd5b69 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -21,10 +21,12 @@ #include "KernelDevice.h" #include "include/types.h" #include "include/compat.h" +#include "include/stringify.h" #include "common/errno.h" #include "common/debug.h" #include "common/blkdev.h" #include "common/align.h" +#include "common/blkdev.h" #define dout_context cct #define dout_subsys ceph_subsys_bdev @@ -187,6 +189,72 @@ void KernelDevice::close() path.clear(); } +static string get_dev_property(const char *dev, const char *property) +{ + char val[1024] = {0}; + get_block_device_string_property(dev, property, val, sizeof(val)); + return val; +} + +int KernelDevice::collect_metadata(string prefix, map *pm) const +{ + (*pm)[prefix + "rotational"] = stringify((int)(bool)rotational); + (*pm)[prefix + "size"] = stringify(get_size()); + (*pm)[prefix + "block_size"] = stringify(get_block_size()); + (*pm)[prefix + "driver"] = "KernelDevice"; + if (rotational) { + (*pm)[prefix + "type"] = "hdd"; + } else { + (*pm)[prefix + "type"] = "ssd"; + } + + struct stat st; + int r = ::fstat(fd_buffered, &st); + if (r < 0) + return -errno; + if (S_ISBLK(st.st_mode)) { + (*pm)[prefix + "access_mode"] = "blk"; + char partition_path[PATH_MAX]; + char dev_node[PATH_MAX]; + int rc = get_device_by_fd(fd_buffered, partition_path, dev_node); + switch (rc) { + case -EOPNOTSUPP: + case -EINVAL: + (*pm)[prefix + "partition_path"] = "unknown"; + (*pm)[prefix + "dev_node"] = "unknown"; + break; + case -ENODEV: + (*pm)[prefix + "partition_path"] = string(partition_path); + (*pm)[prefix + "dev_node"] = "unknown"; + break; + default: + { + (*pm)[prefix + "partition_path"] = string(partition_path); + (*pm)[prefix + "dev_node"] = string(dev_node); + (*pm)[prefix + "model"] = get_dev_property(dev_node, "device/model"); + (*pm)[prefix + "dev"] = get_dev_property(dev_node, "dev"); + + // nvme exposes a serial number + string serial = get_dev_property(dev_node, "device/serial"); + if (serial.length()) { + (*pm)[prefix + "serial"] = serial; + } + + // nvme has a device/device/* structure; infer from that. there + // is probably a better way? + string nvme_vendor = get_dev_property(dev_node, "device/device/vendor"); + if (nvme_vendor.length()) { + (*pm)[prefix + "type"] = "nvme"; + } + } + } + } else { + (*pm)[prefix + "access_mode"] = "file"; + (*pm)[prefix + "path"] = path; + } + return 0; +} + int KernelDevice::flush() { // protect flush with a mutex. not that we are not really protected diff --git a/src/os/bluestore/KernelDevice.h b/src/os/bluestore/KernelDevice.h index e1d145fef616..63c74a39d51d 100644 --- a/src/os/bluestore/KernelDevice.h +++ b/src/os/bluestore/KernelDevice.h @@ -83,6 +83,8 @@ public: return block_size; } + int collect_metadata(string prefix, map *pm) const override; + int read(uint64_t off, uint64_t len, bufferlist *pbl, IOContext *ioc, bool buffered) override; diff --git a/src/os/bluestore/NVMEDevice.cc b/src/os/bluestore/NVMEDevice.cc index beddc18f20d2..354036ff0aa1 100644 --- a/src/os/bluestore/NVMEDevice.cc +++ b/src/os/bluestore/NVMEDevice.cc @@ -865,6 +865,7 @@ int NVMEDevice::open(const string& p) driver->register_device(this); block_size = driver->get_block_size(); size = driver->get_size(); + name = serial_number; //nvme is non-rotational device. rotational = false; @@ -889,6 +890,17 @@ void NVMEDevice::close() dout(1) << __func__ << " end" << dendl; } +void NVMEDevice::collect_metadata(map *pm) +{ + (*pm)[prefix + "rotational"] = "0"; + (*pm)[prefix + "size"] = stringify(get_size()); + (*pm)[prefix + "block_size"] = stringify(get_block_size()); + (*pm)[prefix + "driver"] = "NVMEDevice"; + (*pm)[prefix + "type"] = "nvme"; + (*pm)[prefix + "access_mode"] = "spdk"; + (*pm)[prefix + "nvme_serial_number"] = name; +} + int NVMEDevice::flush() { dout(10) << __func__ << " start" << dendl; diff --git a/src/os/bluestore/NVMEDevice.h b/src/os/bluestore/NVMEDevice.h index 10e3bb2d721e..42f4090cba54 100644 --- a/src/os/bluestore/NVMEDevice.h +++ b/src/os/bluestore/NVMEDevice.h @@ -236,6 +236,7 @@ class NVMEDevice : public BlockDevice { int invalidate_cache(uint64_t off, uint64_t len) override; int open(const string& path) override; void close() override; + void collect_metadata(map *pm) override; }; #endif