Browse Source

Move uint8_t[] buffers into any_op_t/any_reply_t

blocking-uring-test
Vitaliy Filippov 1 year ago
parent
commit
72a89be912
  1. 16
      fio_sec_osd.cpp
  2. 12
      osd.h
  3. 4
      osd_main.cpp
  4. 2
      osd_ops.h
  5. 4
      osd_receive.cpp
  6. 4
      osd_send.cpp
  7. 20
      stub_osd.cpp
  8. 36
      test_osd.cpp

16
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);

12
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;

4
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;

2
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];
};

4
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)
{

4
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;
}

20
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;
}

36
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);

Loading…
Cancel
Save