forked from vitalif/vitastor
Use writev in libfio_sec_osd
parent
79839ec31d
commit
7eac7b6d55
|
@ -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)
|
||||
{
|
||||
perror("write");
|
||||
exit(1);
|
||||
}
|
||||
iovec iov[2] = { { .iov_base = op.buf, .iov_len = OSD_PACKET_SIZE } };
|
||||
int iovcnt = 1, wtotal = OSD_PACKET_SIZE;
|
||||
if (io->ddir == DDIR_WRITE)
|
||||
{
|
||||
// Send data
|
||||
write_blocking(bsd->connect_fd, io->xfer_buf, io->xfer_buflen);
|
||||
iov[1] = { .iov_base = io->xfer_buf, .iov_len = io->xfer_buflen };
|
||||
wtotal += io->xfer_buflen;
|
||||
iovcnt++;
|
||||
}
|
||||
if (writev_blocking(bsd->connect_fd, iov, iovcnt) != wtotal)
|
||||
{
|
||||
perror("writev");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (io->error != 0)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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…
Reference in New Issue