diff --git a/osd.cpp b/osd.cpp index 799772de5..30a80b06e 100644 --- a/osd.cpp +++ b/osd.cpp @@ -94,6 +94,10 @@ osd_t::~osd_t() osd_op_t::~osd_op_t() { + if (bs_op) + { + delete bs_op; + } if (buf) { // Note: reusing osd_op_t WILL currently lead to memory leaks @@ -311,7 +315,7 @@ void osd_t::exec_op(osd_op_t *cur_op) (cur_op->req.sec_rw.len > OSD_RW_MAX || cur_op->req.sec_rw.len % OSD_RW_ALIGN || cur_op->req.sec_rw.offset % OSD_RW_ALIGN)) { // Bad command - cur_op->bs_op.retval = -EINVAL; + cur_op->bs_op->retval = -EINVAL; secondary_op_callback(cur_op); return; } diff --git a/osd.h b/osd.h index 2dc622625..005297c2f 100644 --- a/osd.h +++ b/osd.h @@ -100,7 +100,7 @@ struct osd_op_t int peer_fd; osd_any_op_t req; osd_any_reply_t reply; - blockstore_op_t bs_op; + blockstore_op_t *bs_op = NULL; void *buf = NULL; osd_primary_op_data_t* op_data = NULL; std::function callback; diff --git a/osd_peering.cpp b/osd_peering.cpp index 579dfaf82..5ad12a503 100644 --- a/osd_peering.cpp +++ b/osd_peering.cpp @@ -249,10 +249,10 @@ void osd_t::start_pg_peering(int pg_idx) if (list_op->peer_fd == 0) { // Self - list_op->bs_op.callback = [list_op](blockstore_op_t *bs_op) + list_op->bs_op->callback = [list_op](blockstore_op_t *bs_op) { - if (list_op->bs_op.buf) - free(list_op->bs_op.buf); + if (list_op->bs_op->buf) + free(list_op->bs_op->buf); delete list_op; }; } @@ -315,13 +315,14 @@ void osd_t::start_pg_peering(int pg_idx) osd_op_t *op = new osd_op_t(); op->op_type = 0; op->peer_fd = 0; - op->bs_op.opcode = BS_OP_LIST; - op->bs_op.oid.stripe = parity_block_size; - op->bs_op.len = pg_count, - op->bs_op.offset = pg.pg_num-1, - op->bs_op.callback = [ps, op, role_osd](blockstore_op_t *bs_op) + op->bs_op = new blockstore_op_t(); + op->bs_op->opcode = BS_OP_LIST; + op->bs_op->oid.stripe = parity_block_size; + op->bs_op->len = pg_count, + op->bs_op->offset = pg.pg_num-1, + op->bs_op->callback = [ps, op, role_osd](blockstore_op_t *bs_op) { - if (op->bs_op.retval < 0) + if (op->bs_op->retval < 0) { throw std::runtime_error("local OP_LIST failed"); } @@ -330,15 +331,15 @@ void osd_t::start_pg_peering(int pg_idx) role_osd, bs_op->retval, bs_op->version ); ps->list_results[role_osd] = { - .buf = (obj_ver_id*)op->bs_op.buf, - .total_count = (uint64_t)op->bs_op.retval, - .stable_count = op->bs_op.version, + .buf = (obj_ver_id*)op->bs_op->buf, + .total_count = (uint64_t)op->bs_op->retval, + .stable_count = op->bs_op->version, }; ps->list_done++; ps->list_ops.erase(role_osd); delete op; }; - bs->enqueue_op(&op->bs_op); + bs->enqueue_op(op->bs_op); ps->list_ops[role_osd] = op; } else diff --git a/osd_primary.cpp b/osd_primary.cpp index 0078e71c8..e0de2bd5e 100644 --- a/osd_primary.cpp +++ b/osd_primary.cpp @@ -202,7 +202,7 @@ void osd_t::submit_read_subops(int read_pg_size, const uint64_t* osd_set, osd_op { if (role_osd_num == this->osd_num) { - subops[subop].bs_op = { + subops[subop].bs_op = new blockstore_op_t({ .opcode = BS_OP_READ, .callback = [cur_op, this](blockstore_op_t *subop) { @@ -216,8 +216,8 @@ void osd_t::submit_read_subops(int read_pg_size, const uint64_t* osd_set, osd_op .offset = stripes[role].read_start, .len = stripes[role].read_end - stripes[role].read_start, .buf = stripes[role].read_buf, - }; - bs->enqueue_op(&subops[subop].bs_op); + }); + bs->enqueue_op(subops[subop].bs_op); } else { diff --git a/osd_secondary.cpp b/osd_secondary.cpp index 0702f8203..d95558111 100644 --- a/osd_secondary.cpp +++ b/osd_secondary.cpp @@ -20,8 +20,9 @@ void osd_t::secondary_op_callback(osd_op_t *cur_op) void osd_t::exec_secondary(osd_op_t *cur_op) { - cur_op->bs_op.callback = [this, cur_op](blockstore_op_t* bs_op) { secondary_op_callback(cur_op); }; - cur_op->bs_op.opcode = (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_READ ? BS_OP_READ + cur_op->bs_op = new blockstore_op_t(); + cur_op->bs_op->callback = [this, cur_op](blockstore_op_t* bs_op) { secondary_op_callback(cur_op); }; + cur_op->bs_op->opcode = (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_READ ? BS_OP_READ : (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE ? BS_OP_WRITE : (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_SYNC ? BS_OP_SYNC : (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_STABILIZE ? BS_OP_STABLE @@ -32,41 +33,41 @@ void osd_t::exec_secondary(osd_op_t *cur_op) if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_READ || cur_op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE) { - cur_op->bs_op.oid = cur_op->req.sec_rw.oid; - cur_op->bs_op.version = cur_op->req.sec_rw.version; - cur_op->bs_op.offset = cur_op->req.sec_rw.offset; - cur_op->bs_op.len = cur_op->req.sec_rw.len; - cur_op->bs_op.buf = cur_op->buf; + cur_op->bs_op->oid = cur_op->req.sec_rw.oid; + cur_op->bs_op->version = cur_op->req.sec_rw.version; + cur_op->bs_op->offset = cur_op->req.sec_rw.offset; + cur_op->bs_op->len = cur_op->req.sec_rw.len; + cur_op->bs_op->buf = cur_op->buf; } else if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_DELETE) { - cur_op->bs_op.oid = cur_op->req.sec_del.oid; - cur_op->bs_op.version = cur_op->req.sec_del.version; + cur_op->bs_op->oid = cur_op->req.sec_del.oid; + cur_op->bs_op->version = cur_op->req.sec_del.version; } else if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_STABILIZE || cur_op->req.hdr.opcode == OSD_OP_SECONDARY_ROLLBACK) { - cur_op->bs_op.len = cur_op->req.sec_stab.len/sizeof(obj_ver_id); - cur_op->bs_op.buf = cur_op->buf; + cur_op->bs_op->len = cur_op->req.sec_stab.len/sizeof(obj_ver_id); + cur_op->bs_op->buf = cur_op->buf; } else if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_LIST) { if (cur_op->req.sec_list.pg_count < cur_op->req.sec_list.list_pg) { // requested pg number is greater than total pg count - cur_op->bs_op.retval = -EINVAL; + cur_op->bs_op->retval = -EINVAL; secondary_op_callback(cur_op); return; } - cur_op->bs_op.oid.stripe = cur_op->req.sec_list.parity_block_size; - cur_op->bs_op.len = cur_op->req.sec_list.pg_count; - cur_op->bs_op.offset = cur_op->req.sec_list.list_pg - 1; + cur_op->bs_op->oid.stripe = cur_op->req.sec_list.parity_block_size; + cur_op->bs_op->len = cur_op->req.sec_list.pg_count; + cur_op->bs_op->offset = cur_op->req.sec_list.list_pg - 1; } #ifdef OSD_STUB - cur_op->bs_op.retval = cur_op->bs_op.len; + cur_op->bs_op->retval = cur_op->bs_op->len; secondary_op_callback(cur_op); #else - bs->enqueue_op(&cur_op->bs_op); + bs->enqueue_op(cur_op->bs_op); #endif } @@ -84,22 +85,23 @@ void osd_t::exec_sync_stab_all(osd_op_t *cur_op) { // Sync and stabilize all objects // This command is only valid for tests + cur_op->bs_op = new blockstore_op_t(); if (!allow_test_ops) { - cur_op->bs_op.retval = -EINVAL; + cur_op->bs_op->retval = -EINVAL; secondary_op_callback(cur_op); return; } - cur_op->bs_op.opcode = BS_OP_SYNC_STAB_ALL; - cur_op->bs_op.callback = [this, cur_op](blockstore_op_t *bs_op) + cur_op->bs_op->opcode = BS_OP_SYNC_STAB_ALL; + cur_op->bs_op->callback = [this, cur_op](blockstore_op_t *bs_op) { secondary_op_callback(cur_op); }; #ifdef OSD_STUB - cur_op->bs_op.retval = 0; + cur_op->bs_op->retval = 0; secondary_op_callback(cur_op); #else - bs->enqueue_op(&cur_op->bs_op); + bs->enqueue_op(cur_op->bs_op); #endif } @@ -116,14 +118,14 @@ void osd_t::make_reply(osd_op_t *op) } else { - op->reply.hdr.retval = op->bs_op.retval; + op->reply.hdr.retval = op->bs_op->retval; if (op->req.hdr.opcode == OSD_OP_SECONDARY_LIST) - op->reply.sec_list.stable_count = op->bs_op.version; + op->reply.sec_list.stable_count = op->bs_op->version; else if (op->req.hdr.opcode == OSD_OP_SECONDARY_READ || op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE) - op->reply.sec_rw.version = op->bs_op.version; + op->reply.sec_rw.version = op->bs_op->version; else if (op->req.hdr.opcode == OSD_OP_SECONDARY_DELETE) - op->reply.sec_del.version = op->bs_op.version; + op->reply.sec_del.version = op->bs_op->version; } if (op->req.hdr.opcode == OSD_OP_SECONDARY_READ && op->reply.hdr.retval > 0) @@ -133,7 +135,7 @@ void osd_t::make_reply(osd_op_t *op) else if (op->req.hdr.opcode == OSD_OP_SECONDARY_LIST && op->reply.hdr.retval > 0) { - op->buf = op->bs_op.buf; // allocated by blockstore + op->buf = op->bs_op->buf; // allocated by blockstore op->send_list.push_back(op->buf, op->reply.hdr.retval * sizeof(obj_ver_id)); } }