]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
BlueStore: Add BlockDevice ability to create different backend
authorHaomai Wang <haomai@xsky.com>
Mon, 4 Jan 2016 09:45:27 +0000 (17:45 +0800)
committerHaomai Wang <haomai@xsky.com>
Mon, 1 Feb 2016 14:00:11 +0000 (22:00 +0800)
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/common/config_opts.h
src/os/bluestore/BlockDevice.cc [new file with mode: 0644]
src/os/bluestore/BlockDevice.h [new file with mode: 0644]
src/os/bluestore/BlueStore.cc
src/os/bluestore/KernelDevice.cc
src/os/bluestore/KernelDevice.h

index 25c5a3372cdfae1b2e1e7953c699aa2ee49296ea..89d697f6dd76a820369c6d55ab55119d0155d490 100644 (file)
@@ -846,6 +846,7 @@ OPTION(memstore_device_bytes, OPT_U64, 1024*1024*1024)
 OPTION(memstore_page_set, OPT_BOOL, true)
 OPTION(memstore_page_size, OPT_U64, 64 << 10)
 
+OPTION(bdev_backend_type, OPT_STR, "kernel")
 OPTION(bdev_debug_inflight_ios, OPT_BOOL, false)
 OPTION(bdev_inject_crash, OPT_INT, 0)  // if N>0, then ~ 1/N IOs will complete before we crash on flush.
 OPTION(bdev_aio, OPT_BOOL, true)
diff --git a/src/os/bluestore/BlockDevice.cc b/src/os/bluestore/BlockDevice.cc
new file mode 100644 (file)
index 0000000..741921a
--- /dev/null
@@ -0,0 +1,35 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+  *
+ * Copyright (C) 2015 XSky <haomai@xsky.com>
+ *
+ * Author: Haomai Wang <haomaiwang@gmail.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "BlockDevice.h"
+#if defined(HAVE_SPDK)
+#include "NVMEDevice.h"
+#endif
+
+BlockDevice *BlockDevice::create(const string& type, aio_callback_t cb, void *cbpriv)
+{
+  if (type == "kernel") {
+    return new KernelDevice(cb, cbpriv);
+  }
+#if defined(HAVE_SPDK)
+  if (type == "ust-nvme") {
+    return new NVMEDeivce(cb, cbpriv);
+  }
+#endif
+
+  return NULL;
+}
+
diff --git a/src/os/bluestore/BlockDevice.h b/src/os/bluestore/BlockDevice.h
new file mode 100644 (file)
index 0000000..c5ebe34
--- /dev/null
@@ -0,0 +1,77 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+  *
+ * Copyright (C) 2015 XSky <haomai@xsky.com>
+ *
+ * Author: Haomai Wang <haomaiwang@gmail.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#ifndef CEPH_OS_BLUESTORE_BLOCKDEVICE_H
+#define CEPH_OS_BLUESTORE_BLOCKDEVICE_H
+
+/// track in-flight io
+struct IOContext {
+  void *priv;
+
+  Mutex lock;
+  Cond cond;
+  //interval_set<uint64_t> blocks;  ///< blocks with aio in flight
+
+  list<FS::aio_t> pending_aios;    ///< not yet submitted
+  list<FS::aio_t> running_aios;    ///< submitting or submitted
+  atomic_t num_pending;
+  atomic_t num_running;
+  atomic_t num_reading;
+  atomic_t num_waiting;
+
+  IOContext(void *p)
+    : priv(p),
+      lock("IOContext::lock")
+    {}
+
+  // no copying
+  IOContext(const IOContext& other);
+  IOContext &operator=(const IOContext& other);
+
+  bool has_aios() {
+    Mutex::Locker l(lock);
+    return num_pending.read() + num_running.read();
+  }
+
+  void aio_wait();
+};
+
+
+class BlockDevice {
+public:
+  static BlockDevice *create(CephContext *cct, const string& type,
+                             aio_callback_t cb, void *cbpriv);
+
+  virtual aio_submit(IOContext *ioc) = 0;
+
+  virtual uint64_t get_size() const = 0;
+  virtual uint64_t get_block_size() const = 0;
+
+  virtual int read(uint64_t off, uint64_t len, bufferlist *pbl,
+          IOContext *ioc, bool buffered) = 0;
+
+  virtual int aio_write(uint64_t off, bufferlist& bl,
+               IOContext *ioc, bool buffered) = 0;
+  virtual int aio_zero(uint64_t off, uint64_t len, IOContext *ioc) = 0;
+  virtual int flush() = 0;
+
+  // for managing buffered readers/writers
+  virtual int invalidate_cache(uint64_t off, uint64_t len) = 0;
+  virtual int open(string path) = 0;
+  virtual void close() = 0;
+};
+
+#endif //CEPH_OS_BLUESTORE_BLOCKDEVICE_H
index 09536de9794270ca77039f620691aaf06be3738a..a2a355e796066fc4f1f4d708af0ba76fda81836e 100644 (file)
@@ -931,7 +931,7 @@ int BlueStore::_open_bdev(bool create)
 {
   bluestore_bdev_label_t label;
   assert(bdev == NULL);
-  bdev = new BlockDevice(aio_cb, static_cast<void*>(this));
+  bdev = BlockDevice::create(g_conf->bdev_backend_type, aio_cb, static_cast<void*>(this));
   string p = path + "/block";
   int r = bdev->open(p);
   if (r < 0)
index a25e30bfd038a46513125963979e7163139e0099..34795a985572d1b61636cb611f4b8d12161f74a6 100644 (file)
@@ -1,5 +1,16 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2014 Red Hat
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
 
 #include <unistd.h>
 #include <stdlib.h>
index 4f20d75625b40f22c933437ebd9262c6d97d1783..a04c701c0a2dac24fffd4dd7162947583ddc8b87 100644 (file)
@@ -1,5 +1,16 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2014 Red Hat
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
 
 #ifndef CEPH_OS_BLUESTORE_KERNELDEVICE_H
 #define CEPH_OS_BLUESTORE_KERNELDEVICE_H