From 54f2353f24dc70a880a929116e1989dcd0eaaa68 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 10 Jan 2021 11:57:41 +0300 Subject: [PATCH] Use bitmap granularity for alignment checks --- src/blockstore.cpp | 4 ++-- src/blockstore.h | 2 +- src/blockstore_impl.cpp | 2 +- src/blockstore_impl.h | 2 +- src/cluster_client.cpp | 7 +------ src/cluster_client.h | 1 - src/osd.cpp | 22 +++++++++++++--------- src/osd.h | 4 ++-- src/osd_main.cpp | 5 +---- src/osd_primary.cpp | 4 ++-- 10 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/blockstore.cpp b/src/blockstore.cpp index 56de3eb17..c1bc574d7 100644 --- a/src/blockstore.cpp +++ b/src/blockstore.cpp @@ -58,7 +58,7 @@ uint64_t blockstore_t::get_free_block_count() return impl->get_free_block_count(); } -uint32_t blockstore_t::get_disk_alignment() +uint32_t blockstore_t::get_bitmap_granularity() { - return impl->get_disk_alignment(); + return impl->get_bitmap_granularity(); } diff --git a/src/blockstore.h b/src/blockstore.h index 6141a8453..05dd9dbd9 100644 --- a/src/blockstore.h +++ b/src/blockstore.h @@ -183,5 +183,5 @@ public: uint64_t get_block_count(); uint64_t get_free_block_count(); - uint32_t get_disk_alignment(); + uint32_t get_bitmap_granularity(); }; diff --git a/src/blockstore_impl.cpp b/src/blockstore_impl.cpp index c77b427b2..48fa8ea6b 100644 --- a/src/blockstore_impl.cpp +++ b/src/blockstore_impl.cpp @@ -10,9 +10,9 @@ blockstore_impl_t::blockstore_impl_t(blockstore_config_t & config, ring_loop_t * ring_consumer.loop = [this]() { loop(); }; ringloop->register_consumer(&ring_consumer); initialized = 0; - zero_object = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, block_size); data_fd = meta_fd = journal.fd = -1; parse_config(config); + zero_object = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, block_size); try { open_data(); diff --git a/src/blockstore_impl.h b/src/blockstore_impl.h index eea9c5940..d4d411233 100644 --- a/src/blockstore_impl.h +++ b/src/blockstore_impl.h @@ -327,5 +327,5 @@ public: inline uint32_t get_block_size() { return block_size; } inline uint64_t get_block_count() { return block_count; } inline uint64_t get_free_block_count() { return data_alloc->get_free_count(); } - inline uint32_t get_disk_alignment() { return disk_alignment; } + inline uint32_t get_bitmap_granularity() { return disk_alignment; } }; diff --git a/src/cluster_client.cpp b/src/cluster_client.cpp index ea2fbeda3..dee811cf4 100644 --- a/src/cluster_client.cpp +++ b/src/cluster_client.cpp @@ -133,16 +133,11 @@ static uint32_t is_power_of_two(uint64_t value) void cluster_client_t::on_load_config_hook(json11::Json::object & config) { bs_block_size = config["block_size"].uint64_value(); - bs_disk_alignment = config["disk_alignment"].uint64_value(); bs_bitmap_granularity = config["bitmap_granularity"].uint64_value(); if (!bs_block_size) { bs_block_size = DEFAULT_BLOCK_SIZE; } - if (!bs_disk_alignment) - { - bs_disk_alignment = DEFAULT_DISK_ALIGNMENT; - } if (!bs_bitmap_granularity) { bs_bitmap_granularity = DEFAULT_BITMAP_GRANULARITY; @@ -298,7 +293,7 @@ void cluster_client_t::execute(cluster_op_t *op) op->retval = 0; if (op->opcode != OSD_OP_SYNC && op->opcode != OSD_OP_READ && op->opcode != OSD_OP_WRITE || (op->opcode == OSD_OP_READ || op->opcode == OSD_OP_WRITE) && (!op->inode || !op->len || - op->offset % bs_disk_alignment || op->len % bs_disk_alignment)) + op->offset % bs_bitmap_granularity || op->len % bs_bitmap_granularity)) { op->retval = -EINVAL; std::function(op->callback)(op); diff --git a/src/cluster_client.h b/src/cluster_client.h index 1199a0a67..9bf61748e 100644 --- a/src/cluster_client.h +++ b/src/cluster_client.h @@ -53,7 +53,6 @@ class cluster_client_t ring_loop_t *ringloop; uint64_t bs_block_size = 0; - uint64_t bs_disk_alignment = 0; uint64_t bs_bitmap_granularity = 0; std::map pg_counts; bool immediate_commit = false; diff --git a/src/osd.cpp b/src/osd.cpp index cdadfb72d..17192888f 100644 --- a/src/osd.cpp +++ b/src/osd.cpp @@ -9,15 +9,18 @@ #include "osd.h" -osd_t::osd_t(blockstore_config_t & config, blockstore_t *bs, ring_loop_t *ringloop) +osd_t::osd_t(blockstore_config_t & config, ring_loop_t *ringloop) { + config["entry_attr_size"] = "0"; + this->config = config; - this->bs = bs; this->ringloop = ringloop; + // FIXME: Create Blockstore from on-disk superblock config and check it against the OSD cluster config + this->bs = new blockstore_t(config, ringloop); + this->bs_block_size = bs->get_block_size(); - // FIXME: use bitmap granularity instead - this->bs_disk_alignment = bs->get_disk_alignment(); + this->bs_bitmap_granularity = bs->get_bitmap_granularity(); parse_config(config); @@ -49,6 +52,7 @@ osd_t::~osd_t() { ringloop->unregister_consumer(&consumer); delete epmgr; + delete bs; close(listen_fd); } @@ -171,7 +175,7 @@ bool osd_t::shutdown() { return false; } - return bs->is_safe_to_stop(); + return !bs || bs->is_safe_to_stop(); } void osd_t::loop() @@ -200,14 +204,14 @@ void osd_t::exec_op(osd_op_t *cur_op) cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE || cur_op->req.hdr.opcode == OSD_OP_SEC_WRITE_STABLE) && (cur_op->req.sec_rw.len > OSD_RW_MAX || - cur_op->req.sec_rw.len % bs_disk_alignment || - cur_op->req.sec_rw.offset % bs_disk_alignment)) || + cur_op->req.sec_rw.len % bs_bitmap_granularity || + cur_op->req.sec_rw.offset % bs_bitmap_granularity)) || ((cur_op->req.hdr.opcode == OSD_OP_READ || cur_op->req.hdr.opcode == OSD_OP_WRITE || cur_op->req.hdr.opcode == OSD_OP_DELETE) && (cur_op->req.rw.len > OSD_RW_MAX || - cur_op->req.rw.len % bs_disk_alignment || - cur_op->req.rw.offset % bs_disk_alignment))) + cur_op->req.rw.len % bs_bitmap_granularity || + cur_op->req.rw.offset % bs_bitmap_granularity))) { // Bad command finish_op(cur_op, -EINVAL); diff --git a/src/osd.h b/src/osd.h index b0c656789..720b9cdc3 100644 --- a/src/osd.h +++ b/src/osd.h @@ -115,7 +115,7 @@ class osd_t bool stopping = false; int inflight_ops = 0; blockstore_t *bs; - uint32_t bs_block_size, bs_disk_alignment; + uint32_t bs_block_size, bs_bitmap_granularity; ring_loop_t *ringloop; timerfd_manager_t *tfd = NULL; epoll_manager_t *epmgr = NULL; @@ -221,7 +221,7 @@ class osd_t } public: - osd_t(blockstore_config_t & config, blockstore_t *bs, ring_loop_t *ringloop); + osd_t(blockstore_config_t & config, ring_loop_t *ringloop); ~osd_t(); void force_stop(int exitcode); bool shutdown(); diff --git a/src/osd_main.cpp b/src/osd_main.cpp index 6fe0f6df9..a39326c9d 100644 --- a/src/osd_main.cpp +++ b/src/osd_main.cpp @@ -41,16 +41,13 @@ int main(int narg, char *args[]) signal(SIGINT, handle_sigint); signal(SIGTERM, handle_sigint); ring_loop_t *ringloop = new ring_loop_t(512); - // FIXME: Create Blockstore from on-disk superblock config and check it against the OSD cluster config - blockstore_t *bs = new blockstore_t(config, ringloop); - osd = new osd_t(config, bs, ringloop); + osd = new osd_t(config, ringloop); while (1) { ringloop->loop(); ringloop->wait(); } delete osd; - delete bs; delete ringloop; return 0; } diff --git a/src/osd_primary.cpp b/src/osd_primary.cpp index bc5c5bf4a..26129a143 100644 --- a/src/osd_primary.cpp +++ b/src/osd_primary.cpp @@ -44,8 +44,8 @@ bool osd_t::prepare_primary_rw(osd_op_t *cur_op) return false; } if ((cur_op->req.rw.offset + cur_op->req.rw.len) > (oid.stripe + pg_block_size) || - (cur_op->req.rw.offset % bs_disk_alignment) != 0 || - (cur_op->req.rw.len % bs_disk_alignment) != 0) + (cur_op->req.rw.offset % bs_bitmap_granularity) != 0 || + (cur_op->req.rw.len % bs_bitmap_granularity) != 0) { finish_op(cur_op, -EINVAL); return false;