nbd: use SOCK_NONBLOCK with socketpair() call

This simplifies the code a bit, removing the need
for the separate fcntl() calls.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I4fef8f01a055d1471df87bd979c21d6198e9868a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7596
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2021-02-19 19:46:25 +00:00 committed by Tomasz Zawadzki
parent 988af676da
commit c86075607b

View File

@ -957,7 +957,6 @@ nbd_start_complete(struct spdk_nbd_start_ctx *ctx)
{
int rc;
pthread_t tid;
int flag;
unsigned long nbd_flags = 0;
rc = ioctl(ctx->nbd->dev_fd, NBD_SET_BLKSIZE, spdk_bdev_get_block_size(ctx->nbd->bdev));
@ -1016,14 +1015,6 @@ nbd_start_complete(struct spdk_nbd_start_ctx *ctx)
goto err;
}
flag = fcntl(ctx->nbd->spdk_sp_fd, F_GETFL);
if (fcntl(ctx->nbd->spdk_sp_fd, F_SETFL, flag | O_NONBLOCK) < 0) {
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
ctx->nbd->spdk_sp_fd, spdk_strerror(errno));
rc = -errno;
goto err;
}
if (spdk_interrupt_mode_is_enabled()) {
ctx->nbd->intr = SPDK_INTERRUPT_REGISTER(ctx->nbd->spdk_sp_fd, nbd_poll, ctx->nbd);
}
@ -1051,20 +1042,10 @@ nbd_enable_kernel(void *arg)
{
struct spdk_nbd_start_ctx *ctx = arg;
int rc;
int flag;
/* Declare device setup by this process */
rc = ioctl(ctx->nbd->dev_fd, NBD_SET_SOCK, ctx->nbd->kernel_sp_fd);
if (!rc) {
flag = fcntl(ctx->nbd->kernel_sp_fd, F_GETFL);
rc = fcntl(ctx->nbd->kernel_sp_fd, F_SETFL, flag | O_NONBLOCK);
if (rc < 0) {
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
ctx->nbd->kernel_sp_fd, spdk_strerror(errno));
}
}
if (rc) {
if (errno == EBUSY) {
if (ctx->nbd->retry_poller == NULL) {
@ -1147,7 +1128,7 @@ spdk_nbd_start(const char *bdev_name, const char *nbd_path,
nbd->ch = spdk_bdev_get_io_channel(nbd->bdev_desc);
nbd->buf_align = spdk_max(spdk_bdev_get_buf_align(bdev), 64);
rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp);
rc = socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, sp);
if (rc != 0) {
SPDK_ERRLOG("socketpair failed\n");
rc = -errno;