From: Haomai Wang Date: Mon, 4 Jan 2016 09:45:27 +0000 (+0800) Subject: BlueStore: Add BlockDevice ability to create different backend X-Git-Tag: v10.0.4~81^2~51 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b771c02dc02c8a55623e087dbf5e89d8be4cafa4;p=ceph.git BlueStore: Add BlockDevice ability to create different backend Signed-off-by: Haomai Wang --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 25c5a3372cdf..89d697f6dd76 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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 index 000000000000..741921a8d80b --- /dev/null +++ b/src/os/bluestore/BlockDevice.cc @@ -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 + * + * Author: Haomai Wang + * + * 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 index 000000000000..c5ebe3494388 --- /dev/null +++ b/src/os/bluestore/BlockDevice.h @@ -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 + * + * Author: Haomai Wang + * + * 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 blocks; ///< blocks with aio in flight + + list pending_aios; ///< not yet submitted + list 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 diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 09536de97942..a2a355e79606 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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(this)); + bdev = BlockDevice::create(g_conf->bdev_backend_type, aio_cb, static_cast(this)); string p = path + "/block"; int r = bdev->open(p); if (r < 0) diff --git a/src/os/bluestore/KernelDevice.cc b/src/os/bluestore/KernelDevice.cc index a25e30bfd038..34795a985572 100644 --- a/src/os/bluestore/KernelDevice.cc +++ b/src/os/bluestore/KernelDevice.cc @@ -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 #include diff --git a/src/os/bluestore/KernelDevice.h b/src/os/bluestore/KernelDevice.h index 4f20d75625b4..a04c701c0a2d 100644 --- a/src/os/bluestore/KernelDevice.h +++ b/src/os/bluestore/KernelDevice.h @@ -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