From bc549553e480e111238f958cfca5f7b92a36118d Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Thu, 14 Nov 2019 01:13:07 +0300 Subject: [PATCH] Rename dirty_entry.size to len, remove some unneeded methods and fields, read metadata correctly --- blockstore.h | 17 ++++++----------- blockstore_flush.cpp | 5 ++--- blockstore_init.cpp | 28 ++++++++++++++-------------- blockstore_init.h | 2 +- blockstore_read.cpp | 2 +- blockstore_stable.cpp | 5 ----- blockstore_write.cpp | 2 +- ringloop.cpp | 12 ------------ ringloop.h | 2 -- 9 files changed, 25 insertions(+), 50 deletions(-) diff --git a/blockstore.h b/blockstore.h index dc60f6e2..02b72e95 100644 --- a/blockstore.h +++ b/blockstore.h @@ -114,26 +114,22 @@ inline bool operator < (const object_id & a, const object_id & b) return a.inode < b.inode || a.inode == b.inode && a.stripe < b.stripe; } -// 32 bytes per "clean" entry on disk with fixed metadata tables +// 24 bytes per "clean" entry on disk with fixed metadata tables // FIXME: maybe add crc32's to metadata struct __attribute__((__packed__)) clean_disk_entry { object_id oid; uint64_t version; - uint64_t flags; }; -#define DISK_ENTRY_STABLE 1 - -// 24 bytes per "clean" entry in memory +// 32 = 16 + 16 bytes per "clean" entry in memory (object_id => clean_entry) struct __attribute__((__packed__)) clean_entry { uint64_t version; uint64_t location; - uint32_t state; }; -// 48 bytes per dirty entry in memory +// 48 = 24 + 24 bytes per dirty entry in memory (obj_ver_id => dirty_entry) struct __attribute__((__packed__)) obj_ver_id { object_id oid; @@ -148,10 +144,10 @@ inline bool operator < (const obj_ver_id & a, const obj_ver_id & b) struct __attribute__((__packed__)) dirty_entry { uint32_t state; - uint32_t flags; + uint32_t flags; // unneeded, but present for alignment uint64_t location; // location in either journal or data uint32_t offset; // offset within stripe - uint32_t size; // entry size. FIXME: rename to len? + uint32_t len; // data length }; class oid_hash @@ -274,7 +270,7 @@ class blockstore inline struct io_uring_sqe* get_sqe() { - return ringloop->get_sqe(ring_consumer.number); + return ringloop->get_sqe(); } friend class blockstore_init_meta; @@ -317,7 +313,6 @@ class blockstore // Stabilize int dequeue_stable(blockstore_operation *op); - int continue_stable(blockstore_operation *op); void handle_stable_event(ring_data_t *data, blockstore_operation *op); void stabilize_object(object_id oid, uint64_t max_ver); diff --git a/blockstore_flush.cpp b/blockstore_flush.cpp index bbc9addf..865dbd8c 100644 --- a/blockstore_flush.cpp +++ b/blockstore_flush.cpp @@ -67,7 +67,7 @@ void journal_flusher_co::loop() { // First we submit all reads offset = dirty_it->second.offset; - len = dirty_it->second.size; + len = dirty_it->second.len; it = v.begin(); while (1) { @@ -161,7 +161,7 @@ void journal_flusher_co::loop() data->iov = (struct iovec){ meta_it->second.buf, 512 }; data->callback = [this](ring_data_t* data) { - + meta_it->second.state = 1; wait_count--; }; io_uring_prep_writev( @@ -208,7 +208,6 @@ void journal_flusher_co::loop() *((clean_disk_entry*)meta_it->second.buf + meta_pos) = { .oid = cur.oid, .version = cur.version, - .flags = DISK_ENTRY_STABLE, }; resume_6: sqe = bs->get_sqe(); diff --git a/blockstore_init.cpp b/blockstore_init.cpp index 11eeab37..09e621d6 100644 --- a/blockstore_init.cpp +++ b/blockstore_init.cpp @@ -50,13 +50,14 @@ int blockstore_init_meta::loop() } if (prev_done) { - assert(!(done_len % sizeof(clean_disk_entry))); - int count = done_len / sizeof(clean_disk_entry); - // FIXME this requires sizeof(clean_disk_entry) to be a divisor of 512 - struct clean_disk_entry *entries = (struct clean_disk_entry*)(metadata_buffer + (prev_done == 1 ? bs->metadata_buf_size : 0)); - // handle entries - handle_entries(entries, count); - done_cnt += count; + int count = 512 / sizeof(clean_disk_entry); + for (int sector = 0; sector < done_len; sector += 512) + { + clean_disk_entry *entries = (clean_disk_entry*)(metadata_buffer + (prev_done == 1 ? bs->metadata_buf_size : 0) + sector); + // handle entries + handle_entries(entries, count, bs->block_order); + done_cnt += count; + } prev_done = 0; done_len = 0; } @@ -70,7 +71,7 @@ int blockstore_init_meta::loop() return 1; } -void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int count) +void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int count, int block_order) { for (unsigned i = 0; i < count; i++) { @@ -78,9 +79,8 @@ void blockstore_init_meta::handle_entries(struct clean_disk_entry* entries, int { allocator_set(bs->data_alloc, done_cnt+i, true); bs->clean_db[entries[i].oid] = (struct clean_entry){ - entries[i].version, - (uint32_t)(entries[i].flags & DISK_ENTRY_STABLE ? ST_CURRENT : ST_D_META_SYNCED), - done_cnt+i + .version = entries[i].version, + .location = (done_cnt+i) << block_order, }; } } @@ -302,7 +302,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t len) .flags = 0, .location = location, .offset = je->small_write.offset, - .size = je->small_write.len, + .len = je->small_write.len, }); } else if (je->type == JE_BIG_WRITE) @@ -316,7 +316,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t len) .flags = 0, .location = je->big_write.location, .offset = 0, - .size = bs->block_size, + .len = bs->block_size, }); } else if (je->type == JE_STABLE) @@ -350,7 +350,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t len) .flags = 0, .location = 0, .offset = 0, - .size = 0, + .len = 0, }); } } diff --git a/blockstore_init.h b/blockstore_init.h index 9e71fc88..ef2423c1 100644 --- a/blockstore_init.h +++ b/blockstore_init.h @@ -6,7 +6,7 @@ class blockstore_init_meta uint8_t *metadata_buffer = NULL; uint64_t metadata_read = 0; int prev = 0, prev_done = 0, done_len = 0, submitted = 0, done_cnt = 0; - void handle_entries(struct clean_disk_entry* entries, int count); + void handle_entries(struct clean_disk_entry* entries, int count, int block_order); void handle_event(ring_data_t *data); public: blockstore_init_meta(blockstore *bs); diff --git a/blockstore_read.cpp b/blockstore_read.cpp index 21c3f464..5f3090e3 100644 --- a/blockstore_read.cpp +++ b/blockstore_read.cpp @@ -104,7 +104,7 @@ int blockstore::dequeue_read(blockstore_operation *read_op) } if (version_ok) { - if (!fulfill_read(read_op, fulfilled, dirty.offset, dirty.offset + dirty.size, + if (!fulfill_read(read_op, fulfilled, dirty.offset, dirty.offset + dirty.len, dirty.state, dirty_it->first.version, dirty.location)) { // need to wait. undo added requests, don't dequeue op diff --git a/blockstore_stable.cpp b/blockstore_stable.cpp index b8310a33..7bf54c45 100644 --- a/blockstore_stable.cpp +++ b/blockstore_stable.cpp @@ -108,11 +108,6 @@ int blockstore::dequeue_stable(blockstore_operation *op) return 1; } -int blockstore::continue_stable(blockstore_operation *op) -{ - return 0; -} - void blockstore::handle_stable_event(ring_data_t *data, blockstore_operation *op) { if (data->res < 0) diff --git a/blockstore_write.cpp b/blockstore_write.cpp index 52ca1869..f3c59d85 100644 --- a/blockstore_write.cpp +++ b/blockstore_write.cpp @@ -33,7 +33,7 @@ void blockstore::enqueue_write(blockstore_operation *op) .flags = 0, .location = 0, .offset = op->offset, - .size = op->len, + .len = op->len, }); // Remember write as unsynced here, so external consumers could get // the list of dirty objects to sync just before issuing a SYNC request diff --git a/ringloop.cpp b/ringloop.cpp index 3cc86dd8..229ac6d2 100644 --- a/ringloop.cpp +++ b/ringloop.cpp @@ -29,18 +29,6 @@ struct io_uring_sqe* ring_loop_t::get_sqe() return sqe; } -struct io_uring_sqe* ring_loop_t::get_sqe(int consumer) -{ - struct io_uring_sqe* sqe = io_uring_get_sqe(ring); - if (sqe) - { - struct ring_data_t *data = ring_data + (sqe - ring->sq.sqes); - io_uring_sqe_set_data(sqe, data); - data->source = consumer; - } - return sqe; -} - int ring_loop_t::register_consumer(ring_consumer_t & consumer) { consumer.number = consumers.size(); diff --git a/ringloop.h b/ringloop.h index b2529dde..6d5825ff 100644 --- a/ringloop.h +++ b/ringloop.h @@ -12,7 +12,6 @@ struct ring_data_t { - uint64_t source; struct iovec iov; // for single-entry read/write operations int res; std::function callback; @@ -33,7 +32,6 @@ public: ring_loop_t(int qd); ~ring_loop_t(); struct io_uring_sqe* get_sqe(); - struct io_uring_sqe* get_sqe(int consumer); int register_consumer(ring_consumer_t & consumer); void unregister_consumer(int number); void loop(bool sleep);