Rename some variables and constants

Vitaliy Filippov 2022-06-26 01:40:46 +03:00
parent 8d0989bec8
commit c50cf77672
11 changed files with 54 additions and 55 deletions

View File

@ -29,9 +29,9 @@
#endif #endif
// Default block size is 128 KB, current allowed range is 4K - 128M // Default block size is 128 KB, current allowed range is 4K - 128M
#define DEFAULT_ORDER 17 #define DEFAULT_DATA_BLOCK_ORDER 17
#define MIN_BLOCK_SIZE 4*1024 #define MIN_DATA_BLOCK_SIZE 4*1024
#define MAX_BLOCK_SIZE 128*1024*1024 #define MAX_DATA_BLOCK_SIZE 128*1024*1024
#define DEFAULT_BITMAP_GRANULARITY 4096 #define DEFAULT_BITMAP_GRANULARITY 4096
#define BS_OP_MIN 1 #define BS_OP_MIN 1
@ -193,7 +193,6 @@ public:
// Print diagnostics to stdout // Print diagnostics to stdout
void dump_diagnostics(); void dump_diagnostics();
// FIXME rename to object_size
uint32_t get_block_size(); uint32_t get_block_size();
uint64_t get_block_count(); uint64_t get_block_count();
uint64_t get_free_block_count(); uint64_t get_free_block_count();

View File

@ -13,7 +13,7 @@ blockstore_impl_t::blockstore_impl_t(blockstore_config_t & config, ring_loop_t *
initialized = 0; initialized = 0;
data_fd = meta_fd = journal.fd = -1; data_fd = meta_fd = journal.fd = -1;
parse_config(config); 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 try
{ {
open_data(); 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 || 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->opcode == BS_OP_READ || op->opcode == BS_OP_WRITE || op->opcode == BS_OP_WRITE_STABLE) && (
op->offset >= block_size || op->offset >= data_block_size ||
op->len > block_size-op->offset || op->len > data_block_size-op->offset ||
(op->len % disk_alignment) (op->len % disk_alignment)
)) || )) ||
readonly && op->opcode != BS_OP_READ && op->opcode != BS_OP_LIST) 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 min_inode = op->oid.inode;
uint64_t max_inode = op->version; uint64_t max_inode = op->version;
// Check PG // 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; op->retval = -EINVAL;
FINISH_OP(op); FINISH_OP(op);

View File

@ -219,7 +219,7 @@ class blockstore_impl_t
{ {
/******* OPTIONS *******/ /******* OPTIONS *******/
std::string data_device, meta_device, journal_device; std::string data_device, meta_device, journal_device;
uint32_t block_size; uint32_t data_block_size;
uint64_t meta_offset; uint64_t meta_offset;
uint64_t data_offset; uint64_t data_offset;
uint64_t cfg_journal_size, cfg_data_size; uint64_t cfg_journal_size, cfg_data_size;
@ -274,8 +274,8 @@ class blockstore_impl_t
int meta_fd; int meta_fd;
int data_fd; int data_fd;
uint64_t meta_size, meta_area, meta_len; uint64_t meta_device_size, meta_len;
uint64_t data_size, data_len; uint64_t data_device_size, data_len;
uint64_t data_device_sect, meta_device_sect, journal_device_sect; uint64_t data_device_sect, meta_device_sect, journal_device_sect;
void *metadata_buffer = NULL; void *metadata_buffer = NULL;
@ -394,7 +394,7 @@ public:
// Print diagnostics to stdout // Print diagnostics to stdout
void dump_diagnostics(); 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_block_count() { return block_count; }
inline uint64_t get_free_block_count() { return data_alloc->get_free_count(); } inline uint64_t get_free_block_count() { return data_alloc->get_free_count(); }
inline uint32_t get_bitmap_granularity() { return disk_alignment; } inline uint32_t get_bitmap_granularity() { return disk_alignment; }

View File

@ -76,7 +76,7 @@ resume_1:
hdr->magic = BLOCKSTORE_META_MAGIC_V1; hdr->magic = BLOCKSTORE_META_MAGIC_V1;
hdr->version = BLOCKSTORE_META_VERSION_V1; hdr->version = BLOCKSTORE_META_VERSION_V1;
hdr->meta_block_size = bs->meta_block_size; 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; hdr->bitmap_granularity = bs->bitmap_granularity;
} }
if (bs->readonly) if (bs->readonly)
@ -116,7 +116,7 @@ resume_1:
exit(1); exit(1);
} }
if (hdr->meta_block_size != bs->meta_block_size || 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) hdr->bitmap_granularity != bs->bitmap_granularity)
{ {
printf( printf(
@ -124,7 +124,7 @@ resume_1:
" (meta_block_size=%u, data_block_size=%u, bitmap_granularity=%u)" " (meta_block_size=%u, data_block_size=%u, bitmap_granularity=%u)"
" differs from OSD configuration (%lu/%u/%lu).\n", " differs from OSD configuration (%lu/%u/%lu).\n",
hdr->meta_block_size, hdr->data_block_size, hdr->bitmap_granularity, 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); exit(1);
} }
@ -240,7 +240,7 @@ void blockstore_init_meta::handle_entries(void* entries, unsigned count, int blo
} }
else else
{ {
bs->inode_space_stats[entry->oid.inode] += bs->block_size; bs->inode_space_stats[entry->oid.inode] += bs->data_block_size;
} }
entries_loaded++; entries_loaded++;
#ifdef BLOCKSTORE_DEBUG #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) if (exists && clean_loc == UINT64_MAX)
{ {
auto & sp = bs->inode_space_stats[oid.inode]; auto & sp = bs->inode_space_stats[oid.inode];
if (sp > bs->block_size) if (sp > bs->data_block_size)
sp -= bs->block_size; sp -= bs->data_block_size;
else else
bs->inode_space_stats.erase(oid.inode); bs->inode_space_stats.erase(oid.inode);
} }

View File

@ -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); cfg_data_size = strtoull(config["data_size"].c_str(), NULL, 10);
meta_device = config["meta_device"]; meta_device = config["meta_device"];
meta_offset = strtoull(config["meta_offset"].c_str(), NULL, 10); 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"; inmemory_meta = config["inmemory_metadata"] != "false";
journal_device = config["journal_device"]; journal_device = config["journal_device"];
journal.offset = strtoull(config["journal_offset"].c_str(), NULL, 10); 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_target_parallelism = strtoull(config["throttle_target_parallelism"].c_str(), NULL, 10);
throttle_threshold_us = strtoull(config["throttle_threshold_us"].c_str(), NULL, 10); throttle_threshold_us = strtoull(config["throttle_threshold_us"].c_str(), NULL, 10);
// Validate // 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"); 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)); 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"); 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; throttle_threshold_us = 50;
} }
// init some fields // 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; clean_entry_size = sizeof(clean_disk_entry) + 2*clean_entry_bitmap_size;
journal.block_size = journal_block_size; journal.block_size = journal_block_size;
journal.next_free = 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() void blockstore_impl_t::calc_lengths()
{ {
// data // data
data_len = data_size - data_offset; data_len = data_device_size - data_offset;
if (data_fd == meta_fd && data_offset < meta_offset) if (data_fd == meta_fd && data_offset < meta_offset)
{ {
data_len = meta_offset - data_offset; data_len = meta_offset - data_offset;
@ -234,18 +234,18 @@ void blockstore_impl_t::calc_lengths()
data_len = cfg_data_size; data_len = cfg_data_size;
} }
// meta // 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) 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) if (meta_fd == journal.fd && meta_offset <= journal.offset)
{ {
meta_area = meta_area < journal.offset-meta_offset meta_area_size = meta_area_size < journal.offset-meta_offset
? meta_area : journal.offset-meta_offset; ? meta_area_size : journal.offset-meta_offset;
} }
// journal // 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) if (journal.fd == data_fd && journal.offset <= data_offset)
{ {
journal.len = data_offset - journal.offset; journal.len = data_offset - journal.offset;
@ -256,9 +256,9 @@ void blockstore_impl_t::calc_lengths()
? journal.len : meta_offset-journal.offset; ? journal.len : meta_offset-journal.offset;
} }
// required metadata size // 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; 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"); 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 || if (ioctl(fd, BLKGETSIZE64, size) < 0 ||
ioctl(fd, BLKSSZGET, &sect) < 0) ioctl(fd, BLKSSZGET, &sect) < 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) if (sectsize)
{ {
@ -336,7 +336,7 @@ void blockstore_impl_t::open_data()
{ {
throw std::runtime_error("Failed to open data device"); 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) if (disk_alignment % data_device_sect)
{ {
throw std::runtime_error( 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)+")" ") 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) 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"); throw std::runtime_error("Failed to open metadata device");
} }
check_size(meta_fd, &meta_size, &meta_device_sect, "metadata device"); check_size(meta_fd, &meta_device_size, &meta_device_sect, "metadata device");
if (meta_offset >= meta_size) 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) 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_fd = data_fd;
meta_device_sect = data_device_sect; meta_device_sect = data_device_sect;
meta_size = 0; meta_device_size = 0;
if (meta_offset >= data_size) 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) if (meta_block_size % meta_device_sect)
@ -413,7 +413,7 @@ void blockstore_impl_t::open_journal()
journal.fd = meta_fd; journal.fd = meta_fd;
journal_device_sect = meta_device_sect; journal_device_sect = meta_device_sect;
journal.device_size = 0; journal.device_size = 0;
if (journal.offset >= data_size) if (journal.offset >= data_device_size)
{ {
throw std::runtime_error("journal_offset exceeds device size"); throw std::runtime_error("journal_offset exceeds device size");
} }

View File

@ -186,7 +186,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *read_op)
{ {
if (!clean_entry_bitmap_size) 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 // need to wait. undo added requests, don't dequeue op
PRIV(read_op)->read_vec.clear(); PRIV(read_op)->read_vec.clear();
@ -196,7 +196,7 @@ int blockstore_impl_t::dequeue_read(blockstore_op_t *read_op)
else else
{ {
uint8_t *clean_entry_bitmap = get_clean_entry_bitmap(clean_it->second.location, 0); 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 (bmp_start < bmp_size)
{ {
while (!(clean_entry_bitmap[bmp_end >> 3] & (1 << (bmp_end & 0x7))) && bmp_end < 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) else if (fulfilled < read_op->len)
{ {
// fill remaining parts with zeroes // 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); assert(fulfilled == read_op->len);
read_op->version = result_version; read_op->version = result_version;

View File

@ -195,14 +195,14 @@ void blockstore_impl_t::mark_stable(const obj_ver_id & v, bool forget_dirty)
} }
if (!exists) 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)) else if (IS_DELETE(dirty_it->second.state))
{ {
auto & sp = inode_space_stats[dirty_it->first.oid.inode]; auto & sp = inode_space_stats[dirty_it->first.oid.inode];
if (sp > block_size) if (sp > data_block_size)
sp -= block_size; sp -= data_block_size;
else else
inode_space_stats.erase(dirty_it->first.oid.inode); inode_space_stats.erase(dirty_it->first.oid.inode);
} }

View File

@ -97,7 +97,7 @@ bool blockstore_impl_t::enqueue_write(blockstore_op_t *op)
return false; 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) immediate_commit != IMMEDIATE_ALL)
{ {
// Issue an additional sync so that the previous big write can reach the journal // 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; state = BS_ST_DELETE | BS_ST_IN_FLIGHT;
else 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) if (state == BS_ST_SMALL_WRITE && throttle_small_writes)
clock_gettime(CLOCK_REALTIME, &PRIV(op)->tv_begin); clock_gettime(CLOCK_REALTIME, &PRIV(op)->tv_begin);
if (wait_del) if (wait_del)

View File

@ -84,7 +84,7 @@ std::function<bool(cli_result_t &)> cli_tool_t::simple_offsets(json11::Json cfg)
fprintf(stderr, "Invalid device block size specified: %lu\n", device_block_size); fprintf(stderr, "Invalid device block size specified: %lu\n", device_block_size);
exit(1); 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) object_size & (object_size-1) != 0)
{ {
fprintf(stderr, "Invalid object size specified: %lu\n", object_size); fprintf(stderr, "Invalid object size specified: %lu\n", object_size);

View File

@ -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; bs_bitmap_size = bs_block_size / bs_bitmap_granularity / 8;
uint32_t block_order; 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"); throw std::runtime_error("Bad block size");
} }

View File

@ -6,8 +6,8 @@
#include "messenger.h" #include "messenger.h"
#include "etcd_state_client.h" #include "etcd_state_client.h"
#define MIN_BLOCK_SIZE 4*1024 #define MIN_DATA_BLOCK_SIZE 4*1024
#define MAX_BLOCK_SIZE 128*1024*1024 #define MAX_DATA_BLOCK_SIZE 128*1024*1024
#define DEFAULT_CLIENT_MAX_DIRTY_BYTES 32*1024*1024 #define DEFAULT_CLIENT_MAX_DIRTY_BYTES 32*1024*1024
#define DEFAULT_CLIENT_MAX_DIRTY_OPS 1024 #define DEFAULT_CLIENT_MAX_DIRTY_OPS 1024
#define INODE_LIST_DONE 1 #define INODE_LIST_DONE 1