From 5d3f3f47a75e29f3d791cea098aad7d41a8c271e Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 23 Nov 2025 14:51:22 +0300 Subject: [PATCH] Move all #defines to internal.h --- src/blockstore/blockstore_flush.cpp | 1 + src/blockstore/blockstore_flush.h | 8 --- src/blockstore/blockstore_impl.cpp | 1 + src/blockstore/blockstore_impl.h | 81 +----------------------- src/blockstore/blockstore_init.cpp | 1 + src/blockstore/blockstore_internal.h | 85 ++++++++++++++++++++++++++ src/blockstore/blockstore_journal.cpp | 1 + src/blockstore/blockstore_read.cpp | 1 + src/blockstore/blockstore_rollback.cpp | 1 + src/blockstore/blockstore_stable.cpp | 1 + src/blockstore/blockstore_sync.cpp | 1 + src/blockstore/blockstore_write.cpp | 1 + src/client/object_id.h | 12 ++++ src/osd/osd_id.h | 12 ---- 14 files changed, 107 insertions(+), 100 deletions(-) create mode 100644 src/blockstore/blockstore_internal.h diff --git a/src/blockstore/blockstore_flush.cpp b/src/blockstore/blockstore_flush.cpp index 633c4175..4ce2ff91 100644 --- a/src/blockstore/blockstore_flush.cpp +++ b/src/blockstore/blockstore_flush.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" #define META_BLOCK_UNREAD 0 #define META_BLOCK_READ 1 diff --git a/src/blockstore/blockstore_flush.h b/src/blockstore/blockstore_flush.h index 0522d0c9..3bf18f48 100644 --- a/src/blockstore/blockstore_flush.h +++ b/src/blockstore/blockstore_flush.h @@ -1,14 +1,6 @@ // Copyright (c) Vitaliy Filippov, 2019+ // License: VNPL-1.1 (see README.md for details) -#define COPY_BUF_JOURNAL 1 -#define COPY_BUF_DATA 2 -#define COPY_BUF_ZERO 4 -#define COPY_BUF_CSUM_FILL 8 -#define COPY_BUF_COALESCED 16 -#define COPY_BUF_META_BLOCK 32 -#define COPY_BUF_JOURNALED_BIG 64 - struct copy_buffer_t { int copy_flags; diff --git a/src/blockstore/blockstore_impl.cpp b/src/blockstore/blockstore_impl.cpp index 7f81c56f..2b76e595 100644 --- a/src/blockstore/blockstore_impl.cpp +++ b/src/blockstore/blockstore_impl.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" blockstore_impl_t::blockstore_impl_t(blockstore_config_t & config, ring_loop_t *ringloop, timerfd_manager_t *tfd) { diff --git a/src/blockstore/blockstore_impl.h b/src/blockstore/blockstore_impl.h index 50259237..7365ff75 100644 --- a/src/blockstore/blockstore_impl.h +++ b/src/blockstore/blockstore_impl.h @@ -29,65 +29,6 @@ //#define BLOCKSTORE_DEBUG -// States are not stored on disk. Instead, they're deduced from the journal - -#define BS_ST_SMALL_WRITE 0x01 -#define BS_ST_BIG_WRITE 0x02 -#define BS_ST_DELETE 0x03 - -#define BS_ST_WAIT_DEL 0x10 -#define BS_ST_WAIT_BIG 0x20 -#define BS_ST_IN_FLIGHT 0x30 -#define BS_ST_SUBMITTED 0x40 -#define BS_ST_WRITTEN 0x50 -#define BS_ST_SYNCED 0x60 -#define BS_ST_STABLE 0x70 - -#define BS_ST_INSTANT 0x100 - -#define BS_ST_TYPE_MASK 0x0F -#define BS_ST_WORKFLOW_MASK 0xF0 -#define IS_IN_FLIGHT(st) (((st) & 0xF0) <= BS_ST_SUBMITTED) -#define IS_STABLE(st) (((st) & 0xF0) == BS_ST_STABLE) -#define IS_SYNCED(st) (((st) & 0xF0) >= BS_ST_SYNCED) -#define IS_JOURNAL(st) (((st) & 0x0F) == BS_ST_SMALL_WRITE) -#define IS_BIG_WRITE(st) (((st) & 0x0F) == BS_ST_BIG_WRITE) -#define IS_DELETE(st) (((st) & 0x0F) == BS_ST_DELETE) -#define IS_INSTANT(st) (((st) & BS_ST_TYPE_MASK) == BS_ST_DELETE || ((st) & BS_ST_INSTANT)) - -#define BS_SUBMIT_CHECK_SQES(n) \ - if (ringloop->sqes_left() < (n))\ - {\ - /* Pause until there are more requests available */\ - PRIV(op)->wait_detail = (n);\ - PRIV(op)->wait_for = WAIT_SQE;\ - return 0;\ - } - -#define BS_SUBMIT_GET_SQE(sqe, data) \ - BS_SUBMIT_GET_ONLY_SQE(sqe); \ - struct ring_data_t *data = ((ring_data_t*)sqe->user_data) - -#define BS_SUBMIT_GET_ONLY_SQE(sqe) \ - struct io_uring_sqe *sqe = get_sqe();\ - if (!sqe)\ - {\ - /* Pause until there are more requests available */\ - PRIV(op)->wait_detail = 1;\ - PRIV(op)->wait_for = WAIT_SQE;\ - return 0;\ - } - -#define BS_SUBMIT_GET_SQE_DECL(sqe) \ - sqe = get_sqe();\ - if (!sqe)\ - {\ - /* Pause until there are more requests available */\ - PRIV(op)->wait_detail = 1;\ - PRIV(op)->wait_for = WAIT_SQE;\ - return 0;\ - } - #include "blockstore_journal.h" // 32 = 16 + 16 bytes per "clean" entry in memory (object_id => clean_entry) @@ -126,15 +67,6 @@ struct __attribute__((__packed__)) dirty_entry // Otherwise, the submit order is free, that is all operations may be submitted immediately // In fact, adding a write operation must immediately result in dirty_db being populated -// Suspend operation until there are more free SQEs -#define WAIT_SQE 1 -// Suspend operation until there are bytes of free space in the journal on disk -#define WAIT_JOURNAL 3 -// Suspend operation until the next journal sector buffer is free -#define WAIT_JOURNAL_BUFFER 4 -// Suspend operation until there is some free space on the data device -#define WAIT_FREE 5 - struct used_clean_obj_t { int refs; @@ -152,9 +84,6 @@ typedef std::map blockstore_dirty_db_t; #include "blockstore_flush.h" -#define PRIV(op) ((blockstore_op_private_t*)(op)->private_data) -#define FINISH_OP(op) PRIV(op)->~blockstore_op_private_t(); std::function(op->callback)(op) - struct blockstore_op_private_t { // Wait status @@ -180,21 +109,13 @@ struct blockstore_op_private_t std::vector sync_big_writes, sync_small_writes; }; -typedef uint32_t pool_id_t; -typedef uint64_t pool_pg_id_t; - -#define POOL_ID_BITS 16 - struct pool_shard_settings_t { uint32_t pg_count; uint32_t pg_stripe_size; }; -#define STAB_SPLIT_DONE 1 -#define STAB_SPLIT_WAIT 2 -#define STAB_SPLIT_SYNC 3 -#define STAB_SPLIT_TODO 4 +typedef uint64_t pool_pg_id_t; class blockstore_impl_t: public blockstore_i { diff --git a/src/blockstore/blockstore_init.cpp b/src/blockstore/blockstore_init.cpp index 31c0c0c3..34969858 100644 --- a/src/blockstore/blockstore_init.cpp +++ b/src/blockstore/blockstore_init.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" #define INIT_META_EMPTY 0 #define INIT_META_READING 1 diff --git a/src/blockstore/blockstore_internal.h b/src/blockstore/blockstore_internal.h new file mode 100644 index 00000000..65795be5 --- /dev/null +++ b/src/blockstore/blockstore_internal.h @@ -0,0 +1,85 @@ +#pragma once + +// States are not stored on disk. Instead, they're deduced from the journal + +#define BS_ST_SMALL_WRITE 0x01 +#define BS_ST_BIG_WRITE 0x02 +#define BS_ST_DELETE 0x03 + +#define BS_ST_WAIT_DEL 0x10 +#define BS_ST_WAIT_BIG 0x20 +#define BS_ST_IN_FLIGHT 0x30 +#define BS_ST_SUBMITTED 0x40 +#define BS_ST_WRITTEN 0x50 +#define BS_ST_SYNCED 0x60 +#define BS_ST_STABLE 0x70 + +#define BS_ST_INSTANT 0x100 + +#define BS_ST_TYPE_MASK 0x0F +#define BS_ST_WORKFLOW_MASK 0xF0 +#define IS_IN_FLIGHT(st) (((st) & 0xF0) <= BS_ST_SUBMITTED) +#define IS_STABLE(st) (((st) & 0xF0) == BS_ST_STABLE) +#define IS_SYNCED(st) (((st) & 0xF0) >= BS_ST_SYNCED) +#define IS_JOURNAL(st) (((st) & 0x0F) == BS_ST_SMALL_WRITE) +#define IS_BIG_WRITE(st) (((st) & 0x0F) == BS_ST_BIG_WRITE) +#define IS_DELETE(st) (((st) & 0x0F) == BS_ST_DELETE) +#define IS_INSTANT(st) (((st) & BS_ST_TYPE_MASK) == BS_ST_DELETE || ((st) & BS_ST_INSTANT)) + +#define BS_SUBMIT_CHECK_SQES(n) \ + if (ringloop->sqes_left() < (n))\ + {\ + /* Pause until there are more requests available */\ + PRIV(op)->wait_detail = (n);\ + PRIV(op)->wait_for = WAIT_SQE;\ + return 0;\ + } + +#define BS_SUBMIT_GET_SQE(sqe, data) \ + BS_SUBMIT_GET_ONLY_SQE(sqe); \ + struct ring_data_t *data = ((ring_data_t*)sqe->user_data) + +#define BS_SUBMIT_GET_ONLY_SQE(sqe) \ + struct io_uring_sqe *sqe = get_sqe();\ + if (!sqe)\ + {\ + /* Pause until there are more requests available */\ + PRIV(op)->wait_detail = 1;\ + PRIV(op)->wait_for = WAIT_SQE;\ + return 0;\ + } + +#define BS_SUBMIT_GET_SQE_DECL(sqe) \ + sqe = get_sqe();\ + if (!sqe)\ + {\ + /* Pause until there are more requests available */\ + PRIV(op)->wait_detail = 1;\ + PRIV(op)->wait_for = WAIT_SQE;\ + return 0;\ + } + +#define PRIV(op) ((blockstore_op_private_t*)(op)->private_data) +#define FINISH_OP(op) PRIV(op)->~blockstore_op_private_t(); std::function(op->callback)(op) + +// Suspend operation until there are more free SQEs +#define WAIT_SQE 1 +// Suspend operation until there are bytes of free space in the journal on disk +#define WAIT_JOURNAL 3 +// Suspend operation until the next journal sector buffer is free +#define WAIT_JOURNAL_BUFFER 4 +// Suspend operation until there is some free space on the data device +#define WAIT_FREE 5 + +#define COPY_BUF_JOURNAL 1 +#define COPY_BUF_DATA 2 +#define COPY_BUF_ZERO 4 +#define COPY_BUF_CSUM_FILL 8 +#define COPY_BUF_COALESCED 16 +#define COPY_BUF_META_BLOCK 32 +#define COPY_BUF_JOURNALED_BIG 64 + +#define STAB_SPLIT_DONE 1 +#define STAB_SPLIT_WAIT 2 +#define STAB_SPLIT_SYNC 3 +#define STAB_SPLIT_TODO 4 diff --git a/src/blockstore/blockstore_journal.cpp b/src/blockstore/blockstore_journal.cpp index 163ca7e0..eaccd856 100644 --- a/src/blockstore/blockstore_journal.cpp +++ b/src/blockstore/blockstore_journal.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" blockstore_journal_check_t::blockstore_journal_check_t(blockstore_impl_t *bs) { diff --git a/src/blockstore/blockstore_read.cpp b/src/blockstore/blockstore_read.cpp index fdd6ef06..4c30ac91 100644 --- a/src/blockstore/blockstore_read.cpp +++ b/src/blockstore/blockstore_read.cpp @@ -3,6 +3,7 @@ #include #include "blockstore_impl.h" +#include "blockstore_internal.h" int blockstore_impl_t::fulfill_read_push(blockstore_op_t *op, void *buf, uint64_t offset, uint64_t len, uint32_t item_state, uint64_t item_version) diff --git a/src/blockstore/blockstore_rollback.cpp b/src/blockstore/blockstore_rollback.cpp index a9621d7b..ff9c5de6 100644 --- a/src/blockstore/blockstore_rollback.cpp +++ b/src/blockstore/blockstore_rollback.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" int blockstore_impl_t::dequeue_rollback(blockstore_op_t *op) { diff --git a/src/blockstore/blockstore_stable.cpp b/src/blockstore/blockstore_stable.cpp index bfd2791e..2559bec8 100644 --- a/src/blockstore/blockstore_stable.cpp +++ b/src/blockstore/blockstore_stable.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" // Stabilize small write: // 1) Copy data from the journal to the data device diff --git a/src/blockstore/blockstore_sync.cpp b/src/blockstore/blockstore_sync.cpp index 7a653185..868c31b5 100644 --- a/src/blockstore/blockstore_sync.cpp +++ b/src/blockstore/blockstore_sync.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" #define SYNC_HAS_SMALL 1 #define SYNC_HAS_BIG 2 diff --git a/src/blockstore/blockstore_write.cpp b/src/blockstore/blockstore_write.cpp index 26322394..dcefb4a8 100644 --- a/src/blockstore/blockstore_write.cpp +++ b/src/blockstore/blockstore_write.cpp @@ -2,6 +2,7 @@ // License: VNPL-1.1 (see README.md for details) #include "blockstore_impl.h" +#include "blockstore_internal.h" bool blockstore_impl_t::enqueue_write(blockstore_op_t *op) { diff --git a/src/client/object_id.h b/src/client/object_id.h index ca768111..96156f44 100644 --- a/src/client/object_id.h +++ b/src/client/object_id.h @@ -6,8 +6,20 @@ #include #include +#define POOL_SCHEME_REPLICATED 1 +#define POOL_SCHEME_XOR 2 +#define POOL_SCHEME_EC 3 +#define POOL_ID_MAX 0x10000 +#define POOL_ID_BITS 16 +#define INODE_POOL(inode) (pool_id_t)((inode) >> (64 - POOL_ID_BITS)) +#define INODE_NO_POOL(inode) (inode_t)((inode) & (((uint64_t)1 << (64-POOL_ID_BITS)) - 1)) +#define INODE_WITH_POOL(pool_id, inode) (((inode_t)(pool_id) << (64-POOL_ID_BITS)) | INODE_NO_POOL(inode)) + typedef uint64_t inode_t; +// Pool ID is 16 bits long +typedef uint32_t pool_id_t; + // 16 bytes per object/stripe id // stripe = (start of the parity stripe + peer role) // i.e. for example (256KB + one of 0,1,2) diff --git a/src/osd/osd_id.h b/src/osd/osd_id.h index 9688bfd1..56e79286 100644 --- a/src/osd/osd_id.h +++ b/src/osd/osd_id.h @@ -5,18 +5,6 @@ #include "object_id.h" -#define POOL_SCHEME_REPLICATED 1 -#define POOL_SCHEME_XOR 2 -#define POOL_SCHEME_EC 3 -#define POOL_ID_MAX 0x10000 -#define POOL_ID_BITS 16 -#define INODE_POOL(inode) (pool_id_t)((inode) >> (64 - POOL_ID_BITS)) -#define INODE_NO_POOL(inode) (inode_t)((inode) & (((uint64_t)1 << (64-POOL_ID_BITS)) - 1)) -#define INODE_WITH_POOL(pool_id, inode) (((inode_t)(pool_id) << (64-POOL_ID_BITS)) | INODE_NO_POOL(inode)) - -// Pool ID is 16 bits long -typedef uint32_t pool_id_t; - typedef uint64_t osd_num_t; typedef uint32_t pg_num_t;