diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index c4a296a2d8..12caed6d70 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -68,6 +68,7 @@ struct spdk_fio_ctrlr { static struct spdk_fio_ctrlr *ctrlr_g; static int td_count; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +static bool g_error; struct spdk_fio_qpair { struct fio_file *f; @@ -130,6 +131,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, ns_id = atoi(p + 3); if (!ns_id) { SPDK_ERRLOG("namespace id should be >=1, but current value=0\n"); + g_error = true; return; } @@ -140,6 +142,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, fio_ctrlr = calloc(1, sizeof(*fio_ctrlr)); if (!fio_ctrlr) { SPDK_ERRLOG("Cannot allocate space for fio_ctrlr\n"); + g_error = true; return; } fio_ctrlr->opts = *opts; @@ -152,6 +155,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, ns = spdk_nvme_ctrlr_get_ns(fio_ctrlr->ctrlr, ns_id); if (ns == NULL) { SPDK_ERRLOG("Cannot get namespace by ns_id=%d\n", ns_id); + g_error = true; return; } @@ -160,6 +164,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, if ((fio_qpair->f == f) || ((spdk_nvme_transport_id_compare(trid, &fio_qpair->fio_ctrlr->tr_id) == 0) && (spdk_nvme_ns_get_id(fio_qpair->ns) == ns_id))) { + /* Not the error case. Avoid duplicated connection */ return; } fio_qpair = fio_qpair->next; @@ -168,10 +173,19 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, /* create a new qpair */ fio_qpair = calloc(1, sizeof(*fio_qpair)); if (!fio_qpair) { + g_error = true; SPDK_ERRLOG("Cannot allocate space for fio_qpair\n"); return; } + fio_qpair->qpair = spdk_nvme_ctrlr_alloc_io_qpair(fio_ctrlr->ctrlr, NULL, 0); + if (!fio_qpair->qpair) { + SPDK_ERRLOG("Cannot allocate nvme io_qpair any more\n"); + g_error = true; + free(fio_qpair); + return; + } + fio_qpair->ns = ns; fio_qpair->f = f; fio_qpair->fio_ctrlr = fio_ctrlr; @@ -180,6 +194,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, f->real_file_size = spdk_nvme_ns_get_size(fio_qpair->ns); if (f->real_file_size <= 0) { + g_error = true; SPDK_ERRLOG("Cannot get namespace size by ns=%p\n", ns); return; } @@ -200,7 +215,7 @@ static int spdk_fio_setup(struct thread_data *td) struct spdk_env_opts opts; struct fio_file *f; char *p; - int rc; + int rc = 0; struct spdk_nvme_transport_id trid; struct spdk_fio_ctrlr *fio_ctrlr; char *trid_info; @@ -284,13 +299,19 @@ static int spdk_fio_setup(struct thread_data *td) continue; } } + + if (g_error) { + log_err("Failed to initialize spdk fio plugin\n"); + rc = 1; + break; + } } td_count++; pthread_mutex_unlock(&mutex); - return 0; + return rc; } static int spdk_fio_open(struct thread_data *td, struct fio_file *f)