pipe: Simplify the pipe code

Signed-off-by: Ziye Yang <ziye.yang@intel.com>
Change-Id: I86bfa885215c36e69f2b9c7a12dc5eb32f2a1bcd
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1566
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Ziye Yang 2020-03-29 20:30:47 +08:00 committed by Tomasz Zawadzki
parent cbe6e0f7cd
commit d848418d9b

View File

@ -79,11 +79,7 @@ spdk_pipe_writer_get_buffer(struct spdk_pipe *pipe, uint32_t requested_sz, struc
sz = spdk_min(requested_sz, pipe->sz - write);
if (sz == 0) {
iovs[0].iov_base = NULL;
} else {
iovs[0].iov_base = pipe->buf + write;
}
iovs[0].iov_base = (sz == 0) ? NULL : (pipe->buf + write);
iovs[0].iov_len = sz;
requested_sz -= sz;
@ -91,11 +87,7 @@ spdk_pipe_writer_get_buffer(struct spdk_pipe *pipe, uint32_t requested_sz, struc
if (requested_sz > 0) {
sz = spdk_min(requested_sz, read);
if (sz == 0) {
iovs[1].iov_base = NULL;
} else {
iovs[1].iov_base = pipe->buf;
}
iovs[1].iov_base = (sz == 0) ? NULL : pipe->buf;
iovs[1].iov_len = sz;
} else {
iovs[1].iov_base = NULL;
@ -104,13 +96,8 @@ spdk_pipe_writer_get_buffer(struct spdk_pipe *pipe, uint32_t requested_sz, struc
} else {
sz = spdk_min(requested_sz, read - write - 1);
if (sz == 0) {
iovs[0].iov_base = NULL;
} else {
iovs[0].iov_base = pipe->buf + write;
}
iovs[0].iov_base = (sz == 0) ? NULL : (pipe->buf + write);
iovs[0].iov_len = sz;
iovs[1].iov_base = NULL;
iovs[1].iov_len = 0;
}
@ -194,35 +181,21 @@ spdk_pipe_reader_get_buffer(struct spdk_pipe *pipe, uint32_t requested_sz, struc
if (read <= write) {
sz = spdk_min(requested_sz, write - read);
if (sz == 0) {
iovs[0].iov_base = NULL;
} else {
iovs[0].iov_base = pipe->buf + read;
}
iovs[0].iov_base = (sz == 0) ? NULL : (pipe->buf + read);
iovs[0].iov_len = sz;
iovs[1].iov_base = NULL;
iovs[1].iov_len = 0;
} else {
sz = spdk_min(requested_sz, pipe->sz - read);
if (sz == 0) {
iovs[0].iov_base = NULL;
} else {
iovs[0].iov_base = pipe->buf + read;
}
iovs[0].iov_base = (sz == 0) ? NULL : (pipe->buf + read);
iovs[0].iov_len = sz;
requested_sz -= sz;
if (requested_sz > 0) {
sz = spdk_min(requested_sz, write);
if (sz == 0) {
iovs[1].iov_base = NULL;
} else {
iovs[1].iov_base = pipe->buf;
}
iovs[1].iov_base = (sz == 0) ? NULL : pipe->buf;
iovs[1].iov_len = sz;
} else {
iovs[1].iov_base = NULL;