From 73a363bf92be38d3f9a82bf5ad1817a4cdf65f8d Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 26 Jun 2022 01:40:46 +0300 Subject: [PATCH] Rename some variables and constants --- src/blockstore.h | 7 +++--- src/blockstore_impl.cpp | 8 +++--- src/blockstore_impl.h | 8 +++--- src/blockstore_init.cpp | 12 ++++----- src/blockstore_open.cpp | 50 +++++++++++++++++++------------------- src/blockstore_read.cpp | 6 ++--- src/blockstore_stable.cpp | 6 ++--- src/blockstore_write.cpp | 4 +-- src/cli_simple_offsets.cpp | 2 +- src/cluster_client.cpp | 2 +- src/cluster_client.h | 4 +-- 11 files changed, 54 insertions(+), 55 deletions(-) diff --git a/src/blockstore.h b/src/blockstore.h index d70647ac..56fb4c86 100644 --- a/src/blockstore.h +++ b/src/blockstore.h @@ -29,9 +29,9 @@ #endif // Default block size is 128 KB, current allowed range is 4K - 128M -#define DEFAULT_ORDER 17 -#define MIN_BLOCK_SIZE 4*1024 -#define MAX_BLOCK_SIZE 128*1024*1024 +#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 BS_OP_MIN 1 @@ -193,7 +193,6 @@ public: // Print diagnostics to stdout void dump_diagnostics(); - // FIXME rename to object_size uint32_t get_block_size(); uint64_t get_block_count(); uint64_t get_free_block_count(); diff --git a/src/blockstore_impl.cpp b/src/blockstore_impl.cpp index 2ddc50c9..f10a5e86 100644 --- a/src/blockstore_impl.cpp +++ b/src/blockstore_impl.cpp @@ -13,7 +13,7 @@ blockstore_impl_t::blockstore_impl_t(blockstore_config_t & config, ring_loop_t * initialized = 0; data_fd = meta_fd = journal.fd = -1; parse_config(config); - zero_object = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, block_size); + zero_object = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, data_block_size); try { open_data(); @@ -343,8 +343,8 @@ void blockstore_impl_t::enqueue_op(blockstore_op_t *op) { if (op->opcode < BS_OP_MIN || op->opcode > BS_OP_MAX || ((op->opcode == BS_OP_READ || op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE) && ( - op->offset >= block_size || - op->len > block_size-op->offset || + op->offset >= data_block_size || + op->len > data_block_size-op->offset || (op->len % disk_alignment) )) || readonly && op->opcode != BS_OP_READ && op->opcode != BS_OP_LIST) @@ -477,7 +477,7 @@ void blockstore_impl_t::process_list(blockstore_op_t *op) uint64_t min_inode = op->oid.inode; uint64_t max_inode = op->version; // Check PG - if (pg_count != 0 && (pg_stripe_size < MIN_BLOCK_SIZE || list_pg > pg_count)) + if (pg_count != 0 && (pg_stripe_size < MIN_DATA_BLOCK_SIZE || list_pg > pg_count)) { op->retval = -EINVAL; FINISH_OP(op); diff --git a/src/blockstore_impl.h b/src/blockstore_impl.h index 4847133e..3ecd26eb 100644 --- a/src/blockstore_impl.h +++ b/src/blockstore_impl.h @@ -219,7 +219,7 @@ class blockstore_impl_t { /******* OPTIONS *******/ std::string data_device, meta_device, journal_device; - uint32_t block_size; + uint32_t data_block_size; uint64_t meta_offset; uint64_t data_offset; uint64_t cfg_journal_size, cfg_data_size; @@ -274,8 +274,8 @@ class blockstore_impl_t int meta_fd; int data_fd; - uint64_t meta_size, meta_area, meta_len; - uint64_t data_size, data_len; + uint64_t meta_device_size, meta_len; + uint64_t data_device_size, data_len; uint64_t data_device_sect, meta_device_sect, journal_device_sect; void *metadata_buffer = NULL; @@ -394,7 +394,7 @@ public: // Print diagnostics to stdout void dump_diagnostics(); - inline uint32_t get_block_size() { return block_size; } + inline uint32_t get_block_size() { return data_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_bitmap_granularity() { return disk_alignment; } diff --git a/src/blockstore_init.cpp b/src/blockstore_init.cpp index 99749c1a..f9c88681 100644 --- a/src/blockstore_init.cpp +++ b/src/blockstore_init.cpp @@ -76,7 +76,7 @@ resume_1: hdr->magic = BLOCKSTORE_META_MAGIC_V1; hdr->version = BLOCKSTORE_META_VERSION_V1; hdr->meta_block_size = bs->meta_block_size; - hdr->data_block_size = bs->block_size; + hdr->data_block_size = bs->data_block_size; hdr->bitmap_granularity = bs->bitmap_granularity; } if (bs->readonly) @@ -116,7 +116,7 @@ resume_1: exit(1); } if (hdr->meta_block_size != bs->meta_block_size || - hdr->data_block_size != bs->block_size || + hdr->data_block_size != bs->data_block_size || hdr->bitmap_granularity != bs->bitmap_granularity) { printf( @@ -124,7 +124,7 @@ resume_1: " (meta_block_size=%u, data_block_size=%u, bitmap_granularity=%u)" " differs from OSD configuration (%lu/%u/%lu).\n", hdr->meta_block_size, hdr->data_block_size, hdr->bitmap_granularity, - bs->meta_block_size, bs->block_size, bs->bitmap_granularity + bs->meta_block_size, bs->data_block_size, bs->bitmap_granularity ); exit(1); } @@ -240,7 +240,7 @@ void blockstore_init_meta::handle_entries(void* entries, unsigned count, int blo } else { - bs->inode_space_stats[entry->oid.inode] += bs->block_size; + bs->inode_space_stats[entry->oid.inode] += bs->data_block_size; } entries_loaded++; #ifdef BLOCKSTORE_DEBUG @@ -913,8 +913,8 @@ void blockstore_init_journal::erase_dirty_object(blockstore_dirty_db_t::iterator if (exists && clean_loc == UINT64_MAX) { auto & sp = bs->inode_space_stats[oid.inode]; - if (sp > bs->block_size) - sp -= bs->block_size; + if (sp > bs->data_block_size) + sp -= bs->data_block_size; else bs->inode_space_stats.erase(oid.inode); } diff --git a/src/blockstore_open.cpp b/src/blockstore_open.cpp index 5c7da48a..05f0902d 100644 --- a/src/blockstore_open.cpp +++ b/src/blockstore_open.cpp @@ -62,7 +62,7 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config) cfg_data_size = strtoull(config["data_size"].c_str(), NULL, 10); meta_device = config["meta_device"]; meta_offset = strtoull(config["meta_offset"].c_str(), NULL, 10); - block_size = strtoull(config["block_size"].c_str(), NULL, 10); + data_block_size = strtoull(config["block_size"].c_str(), NULL, 10); inmemory_meta = config["inmemory_metadata"] != "false"; journal_device = config["journal_device"]; journal.offset = strtoull(config["journal_offset"].c_str(), NULL, 10); @@ -85,11 +85,11 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config) throttle_target_parallelism = strtoull(config["throttle_target_parallelism"].c_str(), NULL, 10); throttle_threshold_us = strtoull(config["throttle_threshold_us"].c_str(), NULL, 10); // Validate - if (!block_size) + if (!data_block_size) { - block_size = (1 << DEFAULT_ORDER); + data_block_size = (1 << DEFAULT_DATA_BLOCK_ORDER); } - if ((block_order = is_power_of_two(block_size)) >= 64 || block_size < MIN_BLOCK_SIZE || block_size >= MAX_BLOCK_SIZE) + if ((block_order = is_power_of_two(data_block_size)) >= 64 || data_block_size < MIN_DATA_BLOCK_SIZE || data_block_size >= MAX_DATA_BLOCK_SIZE) { throw std::runtime_error("Bad block size"); } @@ -141,7 +141,7 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config) { throw std::runtime_error("Sparse write tracking granularity must be a multiple of disk_alignment = "+std::to_string(disk_alignment)); } - if (block_size % bitmap_granularity) + if (data_block_size % bitmap_granularity) { throw std::runtime_error("Block size must be a multiple of sparse write tracking granularity"); } @@ -202,7 +202,7 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config) throttle_threshold_us = 50; } // init some fields - clean_entry_bitmap_size = block_size / bitmap_granularity / 8; + clean_entry_bitmap_size = data_block_size / bitmap_granularity / 8; clean_entry_size = sizeof(clean_disk_entry) + 2*clean_entry_bitmap_size; journal.block_size = journal_block_size; journal.next_free = journal_block_size; @@ -214,7 +214,7 @@ void blockstore_impl_t::parse_config(blockstore_config_t & config) void blockstore_impl_t::calc_lengths() { // data - data_len = data_size - data_offset; + data_len = data_device_size - data_offset; if (data_fd == meta_fd && data_offset < meta_offset) { data_len = meta_offset - data_offset; @@ -234,18 +234,18 @@ void blockstore_impl_t::calc_lengths() data_len = cfg_data_size; } // meta - meta_area = (meta_fd == data_fd ? data_size : meta_size) - meta_offset; + uint64_t meta_area_size = (meta_fd == data_fd ? data_device_size : meta_device_size) - meta_offset; if (meta_fd == data_fd && meta_offset <= data_offset) { - meta_area = data_offset - meta_offset; + meta_area_size = data_offset - meta_offset; } if (meta_fd == journal.fd && meta_offset <= journal.offset) { - meta_area = meta_area < journal.offset-meta_offset - ? meta_area : journal.offset-meta_offset; + meta_area_size = meta_area_size < journal.offset-meta_offset + ? meta_area_size : journal.offset-meta_offset; } // journal - journal.len = (journal.fd == data_fd ? data_size : (journal.fd == meta_fd ? meta_size : journal.device_size)) - journal.offset; + journal.len = (journal.fd == data_fd ? data_device_size : (journal.fd == meta_fd ? meta_device_size : journal.device_size)) - journal.offset; if (journal.fd == data_fd && journal.offset <= data_offset) { journal.len = data_offset - journal.offset; @@ -256,9 +256,9 @@ void blockstore_impl_t::calc_lengths() ? journal.len : meta_offset-journal.offset; } // required metadata size - block_count = data_len / block_size; + block_count = data_len / data_block_size; meta_len = (1 + (block_count - 1 + meta_block_size / clean_entry_size) / (meta_block_size / clean_entry_size)) * meta_block_size; - if (meta_area < meta_len) + if (meta_area_size < meta_len) { throw std::runtime_error("Metadata area is too small, need at least "+std::to_string(meta_len)+" bytes"); } @@ -316,7 +316,7 @@ static void check_size(int fd, uint64_t *size, uint64_t *sectsize, std::string n if (ioctl(fd, BLKGETSIZE64, size) < 0 || ioctl(fd, BLKSSZGET, §) < 0) { - throw std::runtime_error("failed to get "+name+" size or block size: "+strerror(errno)); + throw std::runtime_error("Failed to get "+name+" size or block size: "+strerror(errno)); } if (sectsize) { @@ -336,7 +336,7 @@ void blockstore_impl_t::open_data() { throw std::runtime_error("Failed to open data device"); } - check_size(data_fd, &data_size, &data_device_sect, "data device"); + check_size(data_fd, &data_device_size, &data_device_sect, "data device"); if (disk_alignment % data_device_sect) { throw std::runtime_error( @@ -344,9 +344,9 @@ void blockstore_impl_t::open_data() ") is not a multiple of data device sector size ("+std::to_string(data_device_sect)+")" ); } - if (data_offset >= data_size) + if (data_offset >= data_device_size) { - throw std::runtime_error("data_offset exceeds device size = "+std::to_string(data_size)); + throw std::runtime_error("data_offset exceeds device size = "+std::to_string(data_device_size)); } if (!disable_flock && flock(data_fd, LOCK_EX|LOCK_NB) != 0) { @@ -364,10 +364,10 @@ void blockstore_impl_t::open_meta() { throw std::runtime_error("Failed to open metadata device"); } - check_size(meta_fd, &meta_size, &meta_device_sect, "metadata device"); - if (meta_offset >= meta_size) + check_size(meta_fd, &meta_device_size, &meta_device_sect, "metadata device"); + if (meta_offset >= meta_device_size) { - throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(meta_size)); + throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(meta_device_size)); } if (!disable_flock && flock(meta_fd, LOCK_EX|LOCK_NB) != 0) { @@ -378,10 +378,10 @@ void blockstore_impl_t::open_meta() { meta_fd = data_fd; meta_device_sect = data_device_sect; - meta_size = 0; - if (meta_offset >= data_size) + meta_device_size = 0; + if (meta_offset >= data_device_size) { - throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(data_size)); + throw std::runtime_error("meta_offset exceeds device size = "+std::to_string(data_device_size)); } } if (meta_block_size % meta_device_sect) @@ -413,7 +413,7 @@ void blockstore_impl_t::open_journal() journal.fd = meta_fd; journal_device_sect = meta_device_sect; journal.device_size = 0; - if (journal.offset >= data_size) + if (journal.offset >= data_device_size) { throw std::runtime_error("journal_offset exceeds device size"); } diff --git a/src/blockstore_read.cpp b/src/blockstore_read.cpp index 780c8b31..eb53cf5a 100644 --- a/src/blockstore_read.cpp +++ b/src/blockstore_read.cpp @@ -186,7 +186,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *read_op) { if (!clean_entry_bitmap_size) { - if (!fulfill_read(read_op, fulfilled, 0, block_size, (BS_ST_BIG_WRITE | BS_ST_STABLE), 0, clean_it->second.location)) + if (!fulfill_read(read_op, fulfilled, 0, data_block_size, (BS_ST_BIG_WRITE | BS_ST_STABLE), 0, clean_it->second.location)) { // need to wait. undo added requests, don't dequeue op PRIV(read_op)->read_vec.clear(); @@ -196,7 +196,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *read_op) else { uint8_t *clean_entry_bitmap = get_clean_entry_bitmap(clean_it->second.location, 0); - uint64_t bmp_start = 0, bmp_end = 0, bmp_size = block_size/bitmap_granularity; + uint64_t bmp_start = 0, bmp_end = 0, bmp_size = data_block_size/bitmap_granularity; while (bmp_start < bmp_size) { while (!(clean_entry_bitmap[bmp_end >> 3] & (1 << (bmp_end & 0x7))) && bmp_end < bmp_size) @@ -233,7 +233,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *read_op) else if (fulfilled < read_op->len) { // fill remaining parts with zeroes - assert(fulfill_read(read_op, fulfilled, 0, block_size, (BS_ST_DELETE | BS_ST_STABLE), 0, 0)); + assert(fulfill_read(read_op, fulfilled, 0, data_block_size, (BS_ST_DELETE | BS_ST_STABLE), 0, 0)); } assert(fulfilled == read_op->len); read_op->version = result_version; diff --git a/src/blockstore_stable.cpp b/src/blockstore_stable.cpp index c6f205da..3a91b8d2 100644 --- a/src/blockstore_stable.cpp +++ b/src/blockstore_stable.cpp @@ -195,14 +195,14 @@ void blockstore_impl_t::mark_stable(const obj_ver_id & v, bool forget_dirty) } if (!exists) { - inode_space_stats[dirty_it->first.oid.inode] += block_size; + inode_space_stats[dirty_it->first.oid.inode] += data_block_size; } } else if (IS_DELETE(dirty_it->second.state)) { auto & sp = inode_space_stats[dirty_it->first.oid.inode]; - if (sp > block_size) - sp -= block_size; + if (sp > data_block_size) + sp -= data_block_size; else inode_space_stats.erase(dirty_it->first.oid.inode); } diff --git a/src/blockstore_write.cpp b/src/blockstore_write.cpp index 916118dd..e1a633af 100644 --- a/src/blockstore_write.cpp +++ b/src/blockstore_write.cpp @@ -97,7 +97,7 @@ bool blockstore_impl_t::enqueue_write(blockstore_op_t *op) return false; } } - if (wait_big && !is_del && !deleted && op->len < block_size && + if (wait_big && !is_del && !deleted && op->len < data_block_size && immediate_commit != IMMEDIATE_ALL) { // Issue an additional sync so that the previous big write can reach the journal @@ -122,7 +122,7 @@ bool blockstore_impl_t::enqueue_write(blockstore_op_t *op) state = BS_ST_DELETE | BS_ST_IN_FLIGHT; else { - state = (op->len == block_size || deleted ? BS_ST_BIG_WRITE : BS_ST_SMALL_WRITE); + state = (op->len == data_block_size || deleted ? BS_ST_BIG_WRITE : BS_ST_SMALL_WRITE); if (state == BS_ST_SMALL_WRITE && throttle_small_writes) clock_gettime(CLOCK_REALTIME, &PRIV(op)->tv_begin); if (wait_del) diff --git a/src/cli_simple_offsets.cpp b/src/cli_simple_offsets.cpp index 44f6dccf..fc37e63e 100644 --- a/src/cli_simple_offsets.cpp +++ b/src/cli_simple_offsets.cpp @@ -84,7 +84,7 @@ std::function cli_tool_t::simple_offsets(json11::Json cfg) fprintf(stderr, "Invalid device block size specified: %lu\n", device_block_size); exit(1); } - if (object_size < device_block_size || object_size > MAX_BLOCK_SIZE || + if (object_size < device_block_size || object_size > MAX_DATA_BLOCK_SIZE || object_size & (object_size-1) != 0) { fprintf(stderr, "Invalid object size specified: %lu\n", object_size); diff --git a/src/cluster_client.cpp b/src/cluster_client.cpp index b934c378..70e6cdfe 100644 --- a/src/cluster_client.cpp +++ b/src/cluster_client.cpp @@ -296,7 +296,7 @@ void cluster_client_t::on_load_config_hook(json11::Json::object & config) } bs_bitmap_size = bs_block_size / bs_bitmap_granularity / 8; uint32_t block_order; - if ((block_order = is_power_of_two(bs_block_size)) >= 64 || bs_block_size < MIN_BLOCK_SIZE || bs_block_size >= MAX_BLOCK_SIZE) + if ((block_order = is_power_of_two(bs_block_size)) >= 64 || bs_block_size < MIN_DATA_BLOCK_SIZE || bs_block_size >= MAX_DATA_BLOCK_SIZE) { throw std::runtime_error("Bad block size"); } diff --git a/src/cluster_client.h b/src/cluster_client.h index a2cdbc63..37c31077 100644 --- a/src/cluster_client.h +++ b/src/cluster_client.h @@ -6,8 +6,8 @@ #include "messenger.h" #include "etcd_state_client.h" -#define MIN_BLOCK_SIZE 4*1024 -#define MAX_BLOCK_SIZE 128*1024*1024 +#define MIN_DATA_BLOCK_SIZE 4*1024 +#define MAX_DATA_BLOCK_SIZE 128*1024*1024 #define DEFAULT_CLIENT_MAX_DIRTY_BYTES 32*1024*1024 #define DEFAULT_CLIENT_MAX_DIRTY_OPS 1024 #define INODE_LIST_DONE 1