Browse Source

Use writev in libfio_sec_osd

test-sq-poll
Vitaliy Filippov 1 year ago
parent
commit
7eac7b6d55
  1. 15
      fio_sec_osd.cpp
  2. 34
      rw_blocking.cpp
  3. 2
      rw_blocking.h

15
fio_sec_osd.cpp

@ -261,15 +261,18 @@ 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)
iovec iov[2] = { { .iov_base = op.buf, .iov_len = OSD_PACKET_SIZE } };
int iovcnt = 1, wtotal = OSD_PACKET_SIZE;
if (io->ddir == DDIR_WRITE)
{
perror("write");
exit(1);
iov[1] = { .iov_base = io->xfer_buf, .iov_len = io->xfer_buflen };
wtotal += io->xfer_buflen;
iovcnt++;
}
if (io->ddir == DDIR_WRITE)
if (writev_blocking(bsd->connect_fd, iov, iovcnt) != wtotal)
{
// Send data
write_blocking(bsd->connect_fd, io->xfer_buf, io->xfer_buflen);
perror("writev");
exit(1);
}
if (io->error != 0)

34
rw_blocking.cpp

@ -50,3 +50,37 @@ int write_blocking(int fd, void *write_buf, size_t remaining)
}
return done;
}
int writev_blocking(int fd, iovec *iov, int iovcnt)
{
int v = 0;
int done = 0;
while (v < iovcnt)
{
ssize_t r = writev(fd, iov, iovcnt);
if (r < 0)
{
if (errno != EAGAIN && errno != EPIPE)
{
perror("writev");
exit(1);
}
continue;
}
while (v < iovcnt)
{
if (iov[v].iov_len > r)
{
iov[v].iov_len -= r;
iov[v].iov_base += r;
break;
}
else
{
v++;
}
}
done += r;
}
return done;
}

2
rw_blocking.h

@ -1,6 +1,8 @@
#pragma once
#include <unistd.h>
#include <sys/uio.h>
int read_blocking(int fd, void *read_buf, size_t remaining);
int write_blocking(int fd, void *write_buf, size_t remaining);
int writev_blocking(int fd, iovec *iov, int iovcnt);
Loading…
Cancel
Save