lib: add checks for return code of pthread_spin_init
This function can fail with -EAGAIN or -ENOMEM so we should really check the return value. Change-Id: I4a443351f3c85032f47e8af9e70b6b71ba3413f5 Signed-off-by: Seth Howell <seth.howell@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3240 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Vitaliy Mysak <vitaliy.mysak@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
parent
8b155b6e3b
commit
7192849ed2
@ -667,10 +667,15 @@ file_alloc(struct spdk_filesystem *fs)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_spin_init(&file->lock, 0)) {
|
||||
free(file->tree);
|
||||
free(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file->fs = fs;
|
||||
TAILQ_INIT(&file->open_requests);
|
||||
TAILQ_INIT(&file->sync_requests);
|
||||
pthread_spin_init(&file->lock, 0);
|
||||
TAILQ_INSERT_TAIL(&fs->files, file, tailq);
|
||||
file->priority = SPDK_FILE_PRIORITY_LOW;
|
||||
return file;
|
||||
@ -1996,11 +2001,15 @@ spdk_fs_alloc_thread_ctx(struct spdk_filesystem *fs)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pthread_spin_init(&ctx->ch.lock, 0)) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fs_channel_create(fs, &ctx->ch, 512);
|
||||
|
||||
ctx->ch.send_request = fs->send_request;
|
||||
ctx->ch.sync = 1;
|
||||
pthread_spin_init(&ctx->ch.lock, 0);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
@ -133,13 +133,18 @@ static int
|
||||
ftl_band_init_md(struct ftl_band *band)
|
||||
{
|
||||
struct ftl_lba_map *lba_map = &band->lba_map;
|
||||
int rc;
|
||||
|
||||
lba_map->vld = spdk_bit_array_create(ftl_get_num_blocks_in_band(band->dev));
|
||||
if (!lba_map->vld) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
pthread_spin_init(&lba_map->lock, PTHREAD_PROCESS_PRIVATE);
|
||||
rc = pthread_spin_init(&lba_map->lock, PTHREAD_PROCESS_PRIVATE);
|
||||
if (rc) {
|
||||
spdk_bit_array_free(&lba_map->vld);
|
||||
return rc;
|
||||
}
|
||||
ftl_band_md_clear(band);
|
||||
return 0;
|
||||
}
|
||||
|
@ -216,15 +216,21 @@ jsonrpc_server_accept(struct spdk_jsonrpc_server *server)
|
||||
conn->closed = false;
|
||||
conn->recv_len = 0;
|
||||
conn->outstanding_requests = 0;
|
||||
pthread_spin_init(&conn->queue_lock, PTHREAD_PROCESS_PRIVATE);
|
||||
STAILQ_INIT(&conn->send_queue);
|
||||
conn->send_request = NULL;
|
||||
|
||||
if (pthread_spin_init(&conn->queue_lock, PTHREAD_PROCESS_PRIVATE)) {
|
||||
SPDK_ERRLOG("Unable to create queue lock for socket: %d", conn->sockfd);
|
||||
close(conn->sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
flag = fcntl(conn->sockfd, F_GETFL);
|
||||
if (fcntl(conn->sockfd, F_SETFL, flag | O_NONBLOCK) < 0) {
|
||||
SPDK_ERRLOG("fcntl can't set nonblocking mode for socket, fd: %d (%s)\n",
|
||||
conn->sockfd, spdk_strerror(errno));
|
||||
close(conn->sockfd);
|
||||
pthread_spin_destroy(&conn->queue_lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user