]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore/BlockDevice: collect metadata
authorSage Weil <sage@redhat.com>
Fri, 24 Mar 2017 00:41:37 +0000 (19:41 -0500)
committerSage Weil <sage@redhat.com>
Wed, 29 Mar 2017 17:24:00 +0000 (13:24 -0400)
Implement for KernelDevice and NVMEDevice

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlockDevice.h
src/os/bluestore/KernelDevice.cc
src/os/bluestore/KernelDevice.h
src/os/bluestore/NVMEDevice.cc
src/os/bluestore/NVMEDevice.h

index 603ab26d8c11e0a16550345f26652f2d0958b19c..613a73afa45fe7318c3c4145db2624e8a1bcdea7 100644 (file)
@@ -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<string,string> *pm) const = 0;
+
   virtual int read(
     uint64_t off,
     uint64_t len,
index 5f7fe838bf5f83e0d8bcaa210daec1a08b1c1703..3e03eedd5b693be9e86ef77efc0d29b0fc3948e9 100644 (file)
 #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<string,string> *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
index e1d145fef616829e813fa1cad723dca8ba006222..63c74a39d51dc37d09fd19d5b74b0ef82a72d586 100644 (file)
@@ -83,6 +83,8 @@ public:
     return block_size;
   }
 
+  int collect_metadata(string prefix, map<string,string> *pm) const override;
+
   int read(uint64_t off, uint64_t len, bufferlist *pbl,
           IOContext *ioc,
           bool buffered) override;
index beddc18f20d2d79a1d056081a17f82824f7eda45..354036ff0aa18e0971a2fecc88b1c3602e521023 100644 (file)
@@ -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<string,string> *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;
index 10e3bb2d721e399da4bcb59966fbf083de41dd25..42f4090cba54bc62d20bc4d32e806a68868fe596 100644 (file)
@@ -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<string,string> *pm) override;
 };
 
 #endif