]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/KernelDevice: implement thin utilization stats for VDO
authorSage Weil <sage@redhat.com>
Wed, 21 Feb 2018 17:13:06 +0000 (11:13 -0600)
committerSage Weil <sage@redhat.com>
Mon, 2 Apr 2018 20:19:19 +0000 (15:19 -0500)
Detect if we are a VDO device.  If so, pull the stats out of sysfs so that
we can report meaningful utilization numbers.

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

index dbc384eebb1649c21e55f3df74f3d2142ab9f50f..bbd1a0badb87e3bab8d4ab4a591a26fb5c0f30a4 100644 (file)
@@ -138,6 +138,8 @@ int KernelDevice::open(const string& p)
       dout(20) << __func__ << " devname " << devname << dendl;
       rotational = block_device_is_rotational(devname);
       this->devname = devname;
+
+      _detect_vdo();
     }
   }
 
@@ -192,6 +194,11 @@ void KernelDevice::close()
   delete fs;
   fs = NULL;
 
+  if (vdo_fd >= 0) {
+    VOID_TEMP_FAILURE_RETRY(::close(vdo_fd));
+    vdo_fd = -1;
+  }
+
   assert(fd_direct >= 0);
   VOID_TEMP_FAILURE_RETRY(::close(fd_direct));
   fd_direct = -1;
@@ -269,6 +276,26 @@ int KernelDevice::collect_metadata(const string& prefix, map<string,string> *pm)
   return 0;
 }
 
+void KernelDevice::_detect_vdo()
+{
+  vdo_fd = get_vdo_stats_handle(devname.c_str(), &vdo_name);
+  if (vdo_fd >= 0) {
+    dout(1) << __func__ << " VDO volume " << vdo_name
+           << " maps to " << devname << dendl;
+  } else {
+    dout(20) << __func__ << " no VDO volume maps to " << devname << dendl;
+  }
+  return;
+}
+
+bool KernelDevice::get_thin_utilization(uint64_t *total, uint64_t *avail) const
+{
+  if (vdo_fd < 0) {
+    return false;
+  }
+  return get_vdo_utilization(vdo_fd, total, avail);
+}
+
 int KernelDevice::flush()
 {
   // protect flush with a mutex.  note that we are not really protecting
index c0c797f0461834b12c32540551eaefc4e7f4e247..2fa40a9b781c88049ecfc260fd7a9976e1f451e0 100644 (file)
@@ -29,6 +29,9 @@ class KernelDevice : public BlockDevice {
   FS *fs;
   bool aio, dio;
 
+  int vdo_fd = -1;      ///< fd for vdo sysfs directory
+  string vdo_name;
+
   std::string devname;  ///< kernel dev name (/sys/block/$devname), if any
 
   Mutex debug_lock;
@@ -72,6 +75,8 @@ class KernelDevice : public BlockDevice {
   void debug_aio_link(aio_t& aio);
   void debug_aio_unlink(aio_t& aio);
 
+  void _detect_vdo();
+
 public:
   KernelDevice(CephContext* cct, aio_callback_t cb, void *cbpriv);
 
@@ -87,6 +92,8 @@ public:
   }
   int get_devices(std::set<std::string> *ls) override;
 
+  bool get_thin_utilization(uint64_t *total, uint64_t *avail) const override;
+
   int read(uint64_t off, uint64_t len, bufferlist *pbl,
           IOContext *ioc,
           bool buffered) override;