From 72a89be912778cd3afc788d646ce39ea72e51ff7 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 23 Feb 2020 18:57:20 +0300 Subject: [PATCH] Move uint8_t[] buffers into any_op_t/any_reply_t --- fio_sec_osd.cpp | 16 ++++------------ osd.h | 12 ++---------- osd_main.cpp | 4 ++-- osd_ops.h | 2 ++ osd_receive.cpp | 4 ++-- osd_send.cpp | 4 ++-- stub_osd.cpp | 20 ++++++-------------- test_osd.cpp | 36 ++++++++++-------------------------- 8 files changed, 30 insertions(+), 68 deletions(-) diff --git a/fio_sec_osd.cpp b/fio_sec_osd.cpp index 9db76a6f..b9730007 100644 --- a/fio_sec_osd.cpp +++ b/fio_sec_osd.cpp @@ -160,11 +160,7 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) } io->engine_data = bsd; - union - { - osd_any_op_t op; - uint8_t op_buf[OSD_PACKET_SIZE] = { 0 }; - }; + osd_any_op_t op = { 0 }; op.hdr.magic = SECONDARY_OSD_OP_MAGIC; op.hdr.id = n; @@ -208,7 +204,7 @@ static enum fio_q_status sec_queue(struct thread_data *td, struct io_u *io) bsd->op_n++; bsd->queue[n] = io; - if (write(bsd->connect_fd, op_buf, OSD_PACKET_SIZE) != OSD_PACKET_SIZE) + if (write(bsd->connect_fd, op.buf, OSD_PACKET_SIZE) != OSD_PACKET_SIZE) { perror("write"); exit(1); @@ -228,14 +224,10 @@ static int sec_getevents(struct thread_data *td, unsigned int min, unsigned int { sec_data *bsd = (sec_data*)td->io_ops_data; // FIXME timeout, at least poll. Now it's the stupidest implementation possible - union - { - osd_any_reply_t reply; - uint8_t reply_buf[OSD_PACKET_SIZE] = { 0 }; - }; + osd_any_reply_t reply; while (bsd->completed.size() < min) { - read_blocking(bsd->connect_fd, reply_buf, OSD_PACKET_SIZE); + read_blocking(bsd->connect_fd, reply.buf, OSD_PACKET_SIZE); if (reply.hdr.magic != SECONDARY_OSD_REPLY_MAGIC) { fprintf(stderr, "bad reply: magic = %lx instead of %lx\n", reply.hdr.magic, SECONDARY_OSD_REPLY_MAGIC); diff --git a/osd.h b/osd.h index 3d9666f9..5c2f6c44 100644 --- a/osd.h +++ b/osd.h @@ -98,16 +98,8 @@ struct osd_op_t { int op_type; int peer_fd; - union - { - osd_any_op_t op; - uint8_t op_buf[OSD_PACKET_SIZE] = { 0 }; - }; - union - { - osd_any_reply_t reply; - uint8_t reply_buf[OSD_PACKET_SIZE] = { 0 }; - }; + osd_any_op_t op; + osd_any_reply_t reply; blockstore_op_t bs_op; void *buf = NULL; osd_primary_op_data_t* op_data = NULL; diff --git a/osd_main.cpp b/osd_main.cpp index c6c357ba..77684939 100644 --- a/osd_main.cpp +++ b/osd_main.cpp @@ -9,8 +9,8 @@ void handle_sigint(int sig) int main(int narg, char *args[]) { - if (sizeof(osd_any_op_t) >= OSD_PACKET_SIZE || - sizeof(osd_any_reply_t) >= OSD_PACKET_SIZE) + if (sizeof(osd_any_op_t) > OSD_PACKET_SIZE || + sizeof(osd_any_reply_t) > OSD_PACKET_SIZE) { perror("BUG: too small packet size"); return 1; diff --git a/osd_ops.h b/osd_ops.h index 47b17bc3..cb7282ff 100644 --- a/osd_ops.h +++ b/osd_ops.h @@ -180,6 +180,7 @@ union osd_any_op_t osd_op_show_config_t show_conf; osd_op_rw_t rw; osd_op_sync_t sync; + uint8_t buf[OSD_PACKET_SIZE]; }; union osd_any_reply_t @@ -193,4 +194,5 @@ union osd_any_reply_t osd_reply_show_config_t show_conf; osd_reply_rw_t rw; osd_reply_sync_t sync; + uint8_t buf[OSD_PACKET_SIZE]; }; diff --git a/osd_receive.cpp b/osd_receive.cpp index dcac3bd8..875aa443 100644 --- a/osd_receive.cpp +++ b/osd_receive.cpp @@ -23,7 +23,7 @@ void osd_t::read_requests() cl.read_op->peer_fd = peer_fd; } cl.read_op->op_type = OSD_OP_IN; - cl.read_buf = &cl.read_op->op_buf; + cl.read_buf = &cl.read_op->op.buf; cl.read_remaining = OSD_PACKET_SIZE; cl.read_state = CL_READ_OP; } @@ -145,7 +145,7 @@ void osd_t::handle_read_reply(osd_client_t *cl) return; } osd_op_t *request = req_it->second; - memcpy(request->reply_buf, cur_op->op_buf, OSD_PACKET_SIZE); + memcpy(request->reply.buf, cur_op->op.buf, OSD_PACKET_SIZE); if (request->reply.hdr.opcode == OSD_OP_SECONDARY_READ && request->reply.hdr.retval > 0) { diff --git a/osd_send.cpp b/osd_send.cpp index 04b1657f..8c78a3bf 100644 --- a/osd_send.cpp +++ b/osd_send.cpp @@ -32,13 +32,13 @@ void osd_t::send_replies() cl.outbox.pop_front(); if (cl.write_op->op_type == OSD_OP_OUT) { - cl.write_buf = &cl.write_op->op_buf; + cl.write_buf = &cl.write_op->op.buf; cl.write_remaining = OSD_PACKET_SIZE; cl.write_state = CL_WRITE_REPLY; } else { - cl.write_buf = &cl.write_op->reply_buf; + cl.write_buf = &cl.write_op->reply.buf; cl.write_remaining = OSD_PACKET_SIZE; cl.write_state = CL_WRITE_REPLY; } diff --git a/stub_osd.cpp b/stub_osd.cpp index 623530c2..4878c9be 100644 --- a/stub_osd.cpp +++ b/stub_osd.cpp @@ -112,20 +112,12 @@ int bind_stub(const char *bind_address, int bind_port) void run_stub(int peer_fd) { - union - { - osd_any_op_t op; - uint8_t op_buf[OSD_PACKET_SIZE] = { 0 }; - }; - union - { - osd_any_reply_t reply; - uint8_t reply_buf[OSD_PACKET_SIZE] = { 0 }; - }; + osd_any_op_t op; + osd_any_reply_t reply; void *buf = NULL; while (1) { - int r = read_blocking(peer_fd, op_buf, OSD_PACKET_SIZE); + int r = read_blocking(peer_fd, op.buf, OSD_PACKET_SIZE); if (r < OSD_PACKET_SIZE) { break; @@ -142,7 +134,7 @@ void run_stub(int peer_fd) { reply.hdr.retval = op.sec_rw.len; buf = malloc(op.sec_rw.len); - r = write_blocking(peer_fd, reply_buf, OSD_PACKET_SIZE); + r = write_blocking(peer_fd, reply.buf, OSD_PACKET_SIZE); if (r == OSD_PACKET_SIZE) r = write_blocking(peer_fd, &buf, op.sec_rw.len); free(buf); @@ -156,7 +148,7 @@ void run_stub(int peer_fd) free(buf); reply.hdr.retval = op.sec_rw.len; if (r == op.sec_rw.len) - r = write_blocking(peer_fd, reply_buf, OSD_PACKET_SIZE); + r = write_blocking(peer_fd, reply.buf, OSD_PACKET_SIZE); else r = 0; if (r < OSD_PACKET_SIZE) @@ -165,7 +157,7 @@ void run_stub(int peer_fd) else if (op.hdr.opcode == OSD_OP_TEST_SYNC_STAB_ALL) { reply.hdr.retval = 0; - r = write_blocking(peer_fd, reply_buf, OSD_PACKET_SIZE); + r = write_blocking(peer_fd, reply.buf, OSD_PACKET_SIZE); if (r < OSD_PACKET_SIZE) break; } diff --git a/test_osd.cpp b/test_osd.cpp index 336a63a8..624f7f0c 100644 --- a/test_osd.cpp +++ b/test_osd.cpp @@ -117,16 +117,8 @@ bool check_reply(int r, osd_any_op_t & op, osd_any_reply_t & reply, int expected uint64_t test_write(int connect_fd, uint64_t inode, uint64_t stripe, uint64_t version, uint64_t pattern) { - union - { - osd_any_op_t op; - uint8_t op_buf[OSD_PACKET_SIZE] = { 0 }; - }; - union - { - osd_any_reply_t reply; - uint8_t reply_buf[OSD_PACKET_SIZE] = { 0 }; - }; + osd_any_op_t op; + osd_any_reply_t reply; op.hdr.magic = SECONDARY_OSD_OP_MAGIC; op.hdr.id = 1; op.hdr.opcode = OSD_OP_SECONDARY_WRITE; @@ -140,9 +132,9 @@ uint64_t test_write(int connect_fd, uint64_t inode, uint64_t stripe, uint64_t ve void *data = memalign(512, op.sec_rw.len); for (int i = 0; i < (op.sec_rw.len)/sizeof(uint64_t); i++) ((uint64_t*)data)[i] = pattern; - write_blocking(connect_fd, op_buf, OSD_PACKET_SIZE); + write_blocking(connect_fd, op.buf, OSD_PACKET_SIZE); write_blocking(connect_fd, data, op.sec_rw.len); - int r = read_blocking(connect_fd, reply_buf, OSD_PACKET_SIZE); + int r = read_blocking(connect_fd, reply.buf, OSD_PACKET_SIZE); if (!check_reply(r, op, reply, op.sec_rw.len)) { free(data); @@ -151,8 +143,8 @@ uint64_t test_write(int connect_fd, uint64_t inode, uint64_t stripe, uint64_t ve version = reply.sec_rw.version; op.hdr.opcode = OSD_OP_TEST_SYNC_STAB_ALL; op.hdr.id = 2; - write_blocking(connect_fd, op_buf, OSD_PACKET_SIZE); - r = read_blocking(connect_fd, reply_buf, OSD_PACKET_SIZE); + write_blocking(connect_fd, op.buf, OSD_PACKET_SIZE); + r = read_blocking(connect_fd, reply.buf, OSD_PACKET_SIZE); if (!check_reply(r, op, reply, 0)) { free(data); @@ -164,16 +156,8 @@ uint64_t test_write(int connect_fd, uint64_t inode, uint64_t stripe, uint64_t ve void* test_primary_read(int connect_fd, uint64_t inode, uint64_t offset, uint64_t len) { - union - { - osd_any_op_t op; - uint8_t op_buf[OSD_PACKET_SIZE] = { 0 }; - }; - union - { - osd_any_reply_t reply; - uint8_t reply_buf[OSD_PACKET_SIZE] = { 0 }; - }; + osd_any_op_t op; + osd_any_reply_t reply; op.hdr.magic = SECONDARY_OSD_OP_MAGIC; op.hdr.id = 1; op.hdr.opcode = OSD_OP_READ; @@ -181,8 +165,8 @@ void* test_primary_read(int connect_fd, uint64_t inode, uint64_t offset, uint64_ op.rw.offset = offset; op.rw.len = len; void *data = memalign(512, len); - write_blocking(connect_fd, op_buf, OSD_PACKET_SIZE); - int r = read_blocking(connect_fd, reply_buf, OSD_PACKET_SIZE); + write_blocking(connect_fd, op.buf, OSD_PACKET_SIZE); + int r = read_blocking(connect_fd, reply.buf, OSD_PACKET_SIZE); if (!check_reply(r, op, reply, len)) { free(data);