From 522faef3e21661b28ff93845a266a3af1eedc59b Mon Sep 17 00:00:00 2001 From: Curt Bruns Date: Tue, 1 Jun 2021 18:40:00 -0400 Subject: [PATCH] nvme: add cuse support for RESCAN IOCTL Nvme-cli submits a RESCAN IOCTL after a format command to update any information that may have changed during the format, such as LBA Format. This patch adds support for RESCAN by executing nvme_ctrlr_update_namespaces to update the controller information. Fixes: #1964 Change-Id: I9f03e00a7f39339947ff02390f69ce806e1cfa0e Signed-off-by: Curt Bruns Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8146 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Ziye Yang Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker --- lib/nvme/nvme_ctrlr.c | 2 +- lib/nvme/nvme_cuse.c | 35 +++++++++++++++++++ lib/nvme/nvme_internal.h | 1 + test/nvme/cuse/cuse.c | 2 ++ test/unit/lib/nvme/nvme_cuse.c/nvme_cuse_ut.c | 2 ++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/lib/nvme/nvme_ctrlr.c b/lib/nvme/nvme_ctrlr.c index dea7daa0a2..705d02c592 100644 --- a/lib/nvme/nvme_ctrlr.c +++ b/lib/nvme/nvme_ctrlr.c @@ -2533,7 +2533,7 @@ nvme_ctrlr_destruct_namespaces(struct spdk_nvme_ctrlr *ctrlr) } } -static void +void nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr) { uint32_t i, nn = ctrlr->cdata.nn; diff --git a/lib/nvme/nvme_cuse.c b/lib/nvme/nvme_cuse.c index b28315f22e..2a38ba4d23 100644 --- a/lib/nvme/nvme_cuse.c +++ b/lib/nvme/nvme_cuse.c @@ -313,6 +313,36 @@ cuse_nvme_reset(fuse_req_t req, int cmd, void *arg, } } +static void +cuse_nvme_rescan_execute(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid, void *arg) +{ + fuse_req_t req = arg; + + nvme_ctrlr_update_namespaces(ctrlr); + fuse_reply_ioctl_iov(req, 0, NULL, 0); +} + +static void +cuse_nvme_rescan(fuse_req_t req, int cmd, void *arg, + struct fuse_file_info *fi, unsigned flags, + const void *in_buf, size_t in_bufsz, size_t out_bufsz) +{ + int rv; + struct cuse_device *cuse_device = fuse_req_userdata(req); + + if (cuse_device->nsid) { + SPDK_ERRLOG("Namespace rescan not supported\n"); + fuse_reply_err(req, EINVAL); + return; + } + + rv = nvme_io_msg_send(cuse_device->ctrlr, cuse_device->nsid, cuse_nvme_rescan_execute, (void *)req); + if (rv) { + SPDK_ERRLOG("Cannot send rescan\n"); + fuse_reply_err(req, EINVAL); + } +} + /***************************************************************************** * Namespace IO requests */ @@ -615,6 +645,11 @@ cuse_ctrlr_ioctl(fuse_req_t req, int cmd, void *arg, cuse_nvme_reset(req, cmd, arg, fi, flags, in_buf, in_bufsz, out_bufsz); break; + case NVME_IOCTL_RESCAN: + SPDK_DEBUGLOG(nvme_cuse, "NVME_IOCTL_RESCAN\n"); + cuse_nvme_rescan(req, cmd, arg, fi, flags, in_buf, in_bufsz, out_bufsz); + break; + default: SPDK_ERRLOG("Unsupported IOCTL 0x%X.\n", cmd); fuse_reply_err(req, EINVAL); diff --git a/lib/nvme/nvme_internal.h b/lib/nvme/nvme_internal.h index 98607a06a7..b23a9fc915 100644 --- a/lib/nvme/nvme_internal.h +++ b/lib/nvme/nvme_internal.h @@ -1318,6 +1318,7 @@ const struct spdk_nvme_transport *nvme_get_transport(const char *transport_name) const struct spdk_nvme_transport *nvme_get_first_transport(void); const struct spdk_nvme_transport *nvme_get_next_transport(const struct spdk_nvme_transport *transport); +void nvme_ctrlr_update_namespaces(struct spdk_nvme_ctrlr *ctrlr); /* Transport specific functions */ struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(const struct spdk_nvme_transport_id *trid, diff --git a/test/nvme/cuse/cuse.c b/test/nvme/cuse/cuse.c index f217b99077..9999c51c22 100644 --- a/test/nvme/cuse/cuse.c +++ b/test/nvme/cuse/cuse.c @@ -91,6 +91,8 @@ DEFINE_STUB(nvme_io_msg_ctrlr_register, int, DEFINE_STUB_V(nvme_io_msg_ctrlr_unregister, (struct spdk_nvme_ctrlr *ctrlr, struct nvme_io_msg_producer *io_msg_producer)); +DEFINE_STUB_V(nvme_ctrlr_update_namespaces, (struct spdk_nvme_ctrlr *ctrlr)); + static bool wait_for_file(char *filename, bool exists) { diff --git a/test/unit/lib/nvme/nvme_cuse.c/nvme_cuse_ut.c b/test/unit/lib/nvme/nvme_cuse.c/nvme_cuse_ut.c index 086b7f157e..20fb266ed3 100644 --- a/test/unit/lib/nvme/nvme_cuse.c/nvme_cuse_ut.c +++ b/test/unit/lib/nvme/nvme_cuse.c/nvme_cuse_ut.c @@ -81,6 +81,8 @@ DEFINE_STUB(spdk_nvme_ctrlr_is_active_ns, bool, DEFINE_STUB(fuse_reply_err, int, (fuse_req_t req, int err), 0); +DEFINE_STUB_V(nvme_ctrlr_update_namespaces, (struct spdk_nvme_ctrlr *ctrlr)); + struct cuse_io_ctx *g_ut_ctx; struct spdk_nvme_ctrlr *g_ut_ctrlr; uint32_t g_ut_nsid;