From d75b1cb2d2086cd7e0cbb39b5f493d57eb7b6a0a Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 22 Nov 2025 18:07:44 +0300 Subject: [PATCH] Refactor some defines --- src/blockstore/blockstore.cpp | 4 ++-- src/blockstore/blockstore.h | 29 ++++++++++++++++++++-------- src/blockstore/blockstore_impl.cpp | 7 ++++++- src/blockstore/blockstore_impl.h | 9 +++------ src/blockstore/blockstore_journal.h | 1 - src/blockstore/blockstore_stable.cpp | 6 +++--- src/blockstore/fio_engine.cpp | 6 +++--- src/client/osd_ops.h | 5 ----- src/osd/osd_rmw.h | 5 ----- src/test/osd_test.cpp | 1 + src/util/malloc_or_die.h | 5 +++++ 11 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/blockstore/blockstore.cpp b/src/blockstore/blockstore.cpp index 94cf0d6a..6e4cc931 100644 --- a/src/blockstore/blockstore.cpp +++ b/src/blockstore/blockstore.cpp @@ -48,9 +48,9 @@ int blockstore_t::read_bitmap(object_id oid, uint64_t target_version, void *bitm return impl->read_bitmap(oid, target_version, bitmap, result_version); } -std::map & blockstore_t::get_inode_space_stats() +const std::map & blockstore_t::get_inode_space_stats() { - return impl->inode_space_stats; + return impl->get_inode_space_stats(); } void blockstore_t::dump_diagnostics() diff --git a/src/blockstore/blockstore.h b/src/blockstore/blockstore.h index af1d3004..e8d46e55 100644 --- a/src/blockstore/blockstore.h +++ b/src/blockstore/blockstore.h @@ -22,17 +22,20 @@ #define DIRECT_IO_ALIGNMENT 512 #endif -// Memory allocation alignment (page size is usually optimal) -#ifndef MEM_ALIGNMENT -#define MEM_ALIGNMENT 4096 -#endif - // Default block size is 128 KB, current allowed range is 4K - 128M #define DEFAULT_DATA_BLOCK_ORDER 17 #define MIN_DATA_BLOCK_SIZE 4*1024 #define MAX_DATA_BLOCK_SIZE 128*1024*1024 #define DEFAULT_BITMAP_GRANULARITY 4096 +#define MIN_JOURNAL_SIZE 1024*1024 + +// "VITAstor" +#define BLOCKSTORE_META_MAGIC_V1 0x726F747341544956l +#define BLOCKSTORE_META_FORMAT_V1 1 +#define BLOCKSTORE_META_FORMAT_V2 2 +#define BLOCKSTORE_META_FORMAT_HEAP 3 + #define BS_OP_MIN 1 #define BS_OP_READ 1 #define BS_OP_WRITE 2 @@ -46,8 +49,18 @@ #define BS_OP_PRIVATE_DATA_SIZE 256 +#define IMMEDIATE_NONE 0 +#define IMMEDIATE_SMALL 1 +#define IMMEDIATE_ALL 2 + /* +All operations may be submitted in any order, because reads only see completed writes, +syncs only sync completed writes and writes don't depend on each other. + +The only restriction is that the external code MUST NOT submit multiple writes for one +object in parallel. This is a natural restriction because `version` numbers are used though. + Blockstore opcode documentation: ## BS_OP_READ / BS_OP_WRITE / BS_OP_WRITE_STABLE @@ -162,8 +175,8 @@ struct __attribute__ ((visibility("default"))) blockstore_op_t uint32_t list_stable_limit; }; }; - void *buf = NULL; - void *bitmap = NULL; + uint8_t *buf = NULL; + uint8_t *bitmap = NULL; int retval = 0; uint8_t private_data[BS_OP_PRIVATE_DATA_SIZE]; @@ -205,7 +218,7 @@ public: int read_bitmap(object_id oid, uint64_t target_version, void *bitmap, uint64_t *result_version = NULL); // Get per-inode space usage statistics - std::map & get_inode_space_stats(); + const std::map & get_inode_space_stats(); // Set per-pool no_inode_stats void set_no_inode_stats(const std::vector & pool_ids); diff --git a/src/blockstore/blockstore_impl.cpp b/src/blockstore/blockstore_impl.cpp index f895137a..e9bf569b 100644 --- a/src/blockstore/blockstore_impl.cpp +++ b/src/blockstore/blockstore_impl.cpp @@ -682,7 +682,7 @@ void blockstore_impl_t::process_list(blockstore_op_t *op) free(unstable); op->version = stable_count; op->retval = stable_count+unstable_count; - op->buf = stable; + op->buf = (uint8_t*)stable; FINISH_OP(op); } @@ -705,6 +705,11 @@ void blockstore_impl_t::disk_error_abort(const char *op, int retval, int expecte exit(1); } +const std::map & blockstore_impl_t::get_inode_space_stats() +{ + return inode_space_stats; +} + void blockstore_impl_t::set_no_inode_stats(const std::vector & pool_ids) { for (auto & np: no_inode_stats) diff --git a/src/blockstore/blockstore_impl.h b/src/blockstore/blockstore_impl.h index 0bea0cbc..e6dc69d9 100644 --- a/src/blockstore/blockstore_impl.h +++ b/src/blockstore/blockstore_impl.h @@ -44,10 +44,6 @@ #define BS_ST_INSTANT 0x100 -#define IMMEDIATE_NONE 0 -#define IMMEDIATE_SMALL 1 -#define IMMEDIATE_ALL 2 - #define BS_ST_TYPE_MASK 0x0F #define BS_ST_WORKFLOW_MASK 0xF0 #define IS_IN_FLIGHT(st) (((st) & 0xF0) <= BS_ST_SUBMITTED) @@ -276,6 +272,7 @@ class blockstore_impl_t std::map clean_db_settings; std::map clean_db_shards; std::map no_inode_stats; + std::map inode_space_stats; uint8_t *clean_bitmaps = NULL; blockstore_dirty_db_t dirty_db; std::vector submit_queue; @@ -430,8 +427,8 @@ public: // Unstable writes are added here (map of object_id -> version) std::unordered_map unstable_writes; - // Space usage statistics - std::map inode_space_stats; + // Get space usage statistics + const std::map & get_inode_space_stats(); // Set per-pool no_inode_stats void set_no_inode_stats(const std::vector & pool_ids); diff --git a/src/blockstore/blockstore_journal.h b/src/blockstore/blockstore_journal.h index 1260ce85..ff93d1d3 100644 --- a/src/blockstore/blockstore_journal.h +++ b/src/blockstore/blockstore_journal.h @@ -6,7 +6,6 @@ #include "crc32c.h" #include -#define MIN_JOURNAL_SIZE 4*1024*1024 #define JOURNAL_MAGIC 0x4A33 #define JOURNAL_VERSION_V1 1 #define JOURNAL_VERSION_V2 2 diff --git a/src/blockstore/blockstore_stable.cpp b/src/blockstore/blockstore_stable.cpp index bb52a776..bfd2791e 100644 --- a/src/blockstore/blockstore_stable.cpp +++ b/src/blockstore/blockstore_stable.cpp @@ -228,17 +228,17 @@ int blockstore_impl_t::split_stab_op(blockstore_op_t *op, std::functionopcode = op->opcode; - split_stab_op->buf = bad_vers.items; + split_stab_op->buf = (uint8_t*)bad_vers.items; split_stab_op->len = bad_vers.size; init_op(split_stab_op); submit_queue.push_back(split_stab_op); } if (sync_op || split_stab_op || good_vers.items) { - void *orig_buf = op->buf; + uint8_t *orig_buf = op->buf; if (good_vers.items) { - op->buf = good_vers.items; + op->buf = (uint8_t*)good_vers.items; op->len = good_vers.size; } // Make a wrapped callback diff --git a/src/blockstore/fio_engine.cpp b/src/blockstore/fio_engine.cpp index 4df68583..4ea3e600 100644 --- a/src/blockstore/fio_engine.cpp +++ b/src/blockstore/fio_engine.cpp @@ -200,7 +200,7 @@ static enum fio_q_status bs_queue(struct thread_data *td, struct io_u *io) { case DDIR_READ: op->opcode = BS_OP_READ; - op->buf = io->xfer_buf; + op->buf = (uint8_t*)io->xfer_buf; op->oid = { .inode = 1, .stripe = io->offset / bsd->bs->get_block_size(), @@ -221,7 +221,7 @@ static enum fio_q_status bs_queue(struct thread_data *td, struct io_u *io) break; case DDIR_WRITE: op->opcode = bsd->ec ? BS_OP_WRITE : BS_OP_WRITE_STABLE; - op->buf = io->xfer_buf; + op->buf = (uint8_t*)io->xfer_buf; op->oid = { .inode = 1, .stripe = io->offset / bsd->bs->get_block_size(), @@ -247,7 +247,7 @@ static enum fio_q_status bs_queue(struct thread_data *td, struct io_u *io) { auto stab_op = new blockstore_op_t; stab_op->opcode = BS_OP_STABLE; - stab_op->buf = malloc_or_die(sizeof(obj_ver_id)); + stab_op->buf = (uint8_t*)malloc_or_die(sizeof(obj_ver_id)); obj_ver_id *ver = (obj_ver_id *)stab_op->buf; ver[0].oid = op->oid; ver[0].version = op->version; diff --git a/src/client/osd_ops.h b/src/client/osd_ops.h index 28dae0a7..d93b9b27 100644 --- a/src/client/osd_ops.h +++ b/src/client/osd_ops.h @@ -44,11 +44,6 @@ #define DIRECT_IO_ALIGNMENT 512 #endif -// Memory allocation alignment (page size is usually optimal) -#ifndef MEM_ALIGNMENT -#define MEM_ALIGNMENT 4096 -#endif - // Constants for osd_reply_describe_item_t.loc_bad #define LOC_OUTDATED 1 #define LOC_CORRUPTED 2 diff --git a/src/osd/osd_rmw.h b/src/osd/osd_rmw.h index 474973c9..682a220b 100644 --- a/src/osd/osd_rmw.h +++ b/src/osd/osd_rmw.h @@ -8,11 +8,6 @@ #include "object_id.h" #include "osd_id.h" -// Memory allocation alignment (page size is usually optimal) -#ifndef MEM_ALIGNMENT -#define MEM_ALIGNMENT 4096 -#endif - struct buf_len_t { void *buf; diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index f89eb27b..e7f5f453 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -16,6 +16,7 @@ #include +#include "malloc_or_die.h" #include "addr_util.h" #include "osd_ops.h" #include "rw_blocking.h" diff --git a/src/util/malloc_or_die.h b/src/util/malloc_or_die.h index f35d2a8d..fb28274c 100644 --- a/src/util/malloc_or_die.h +++ b/src/util/malloc_or_die.h @@ -6,6 +6,11 @@ #include #include +// Memory allocation alignment (page size is usually optimal) +#ifndef MEM_ALIGNMENT +#define MEM_ALIGNMENT 4096 +#endif + #pragma GCC visibility push(default) inline void* memalign_or_die(size_t alignment, size_t size)