From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============3308239359697644094==" MIME-Version: 1.0 From: Andrey Kuzmin Subject: [SPDK] Allow attachment to an already probed controller Date: Fri, 26 Feb 2016 20:51:36 +0300 Message-ID: List-ID: To: spdk@lists.01.org --===============3308239359697644094== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable While I appreciatethe reasoning behind the current spdk_nvme_probe attach-once semantics, it still imposes an extra burden of the already probed controller tracking on the application that, for instance, seeks to attach to multiple namespaces under the same controller. The below patch provides an optional fix for the issue. Notice that it also fixes the bug of the error returned by the enumeration being ignored. Regards, Andrey diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 63a316b..2a3ac64 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -296,10 +296,32 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a nvme_mutex_lock(&g_nvme_driver.lock); + /* + * First, check if the requested controller has already been started. + */ + TAILQ_FOREACH(ctrlr, &g_nvme_driver.attached_ctrlrs, tailq) { + if (!probe_cb(cb_ctx, ctrlr->devhandle)) + continue; + + nvme_mutex_unlock(&g_nvme_driver.lock); + attach_cb(cb_ctx, ctrlr->devhandle, ctrlr); + return 0; + } + enum_ctx.probe_cb =3D probe_cb; enum_ctx.cb_ctx =3D cb_ctx; rc =3D nvme_pci_enumerate(nvme_enum_cb, &enum_ctx); + + /* + * Appreciate the error being returned + * by the nvme_pci_enumerate, if any. + */ + if (rc) { + nvme_mutex_unlock(&g_nvme_driver.lock); + return rc; + } + /* * Keep going even if one or more nvme_attach() calls failed, * but maintain the value of rc to signal errors when we return. --===============3308239359697644094==--