From 9bd37c5ba99b2a5177a5c657b9d0431b81dbacd6 Mon Sep 17 00:00:00 2001 From: Changcheng Liu Date: Thu, 16 Jul 2020 18:24:49 +0800 Subject: [PATCH] blk: add configuration to be set to select block driver Besides blk's internal policy to auto select block drvier, it need supply one configuration to let user to select the driver for specific requirement. Suggested-by: Kefu Chai Signed-off-by: Changcheng Liu --- src/blk/BlockDevice.cc | 34 +++++++++++++++++++++++++++++++++- src/blk/BlockDevice.h | 1 + src/common/options.cc | 8 +++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/blk/BlockDevice.cc b/src/blk/BlockDevice.cc index 05e1dd24d89..b1a97ef7ff6 100644 --- a/src/blk/BlockDevice.cc +++ b/src/blk/BlockDevice.cc @@ -108,6 +108,32 @@ BlockDevice::detect_device_type(const std::string& path) return block_device_t::aio; } +BlockDevice::block_device_t +BlockDevice::device_type_from_name(const std::string& blk_dev_name) +{ +#if defined(HAVE_LIBAIO) || defined(HAVE_POSIXAIO) + if (blk_dev_name == "aio") { + return block_device_t::aio; + } +#endif +#if defined(HAVE_SPDK) + if (blk_dev_name == "spdk") { + return block_device_t::spdk; + } +#endif +#if defined(HAVE_BLUESTORE_PMEM) + if (blk_dev_name == "pmem") { + return block_device_t::pmem; + } +#endif +#if (defined(HAVE_LIBAIO) || defined(HAVE_POSIXAIO)) && defined(HAVE_LIZBC) + if (blk_dev_name == "hm_smr") { + return block_device_t::hm_smr; + } +#endif + return block_device_t::unknown; +} + BlockDevice* BlockDevice::create_with_type(block_device_t device_type, CephContext* cct, const std::string& path, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv) @@ -140,7 +166,13 @@ BlockDevice *BlockDevice::create( CephContext* cct, const string& path, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv) { - block_device_t device_type = detect_device_type(path); + const string blk_dev_name = cct->_conf.get_val("bdev_type"); + block_device_t device_type = block_device_t::unknown; + if (blk_dev_name.empty()) { + device_type = detect_device_type(path); + } else { + device_type = device_type_from_name(blk_dev_name); + } return create_with_type(device_type, cct, path, cb, cbpriv, d_cb, d_cbpriv); } diff --git a/src/blk/BlockDevice.h b/src/blk/BlockDevice.h index a24411d0329..3123c8aece8 100644 --- a/src/blk/BlockDevice.h +++ b/src/blk/BlockDevice.h @@ -152,6 +152,7 @@ private: #endif }; static block_device_t detect_device_type(const std::string& path); + static block_device_t device_type_from_name(const std::string& blk_dev_name); static BlockDevice *create_with_type(block_device_t device_type, CephContext* cct, const std::string& path, aio_callback_t cb, void *cbpriv, aio_callback_t d_cb, void *d_cbpriv); diff --git a/src/common/options.cc b/src/common/options.cc index 3ff9807aca2..4605c6eb6f9 100644 --- a/src/common/options.cc +++ b/src/common/options.cc @@ -5418,7 +5418,13 @@ std::vector