summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorHans Rosenfeld <rosenfeld@grumpf.hope-2000.org>2021-11-01 12:36:32 +0100
committerHans Rosenfeld <rosenfeld@grumpf.hope-2000.org>2022-03-02 11:20:33 +0100
commit63cdc4a2836cf93078a5dd140d42583170a04953 (patch)
treeeee18eacf00a2c304ce2b0529824dc91b868b471 /usr
parent1767024ccd62fe7212679d959527eb445767d01a (diff)
downloadillumos-gate-63cdc4a2836cf93078a5dd140d42583170a04953.tar.gz
14529 nvmeadm should ignore requests to attach/detach ignored namespaces
Reviewed by: Andrew Giles <agiles@tintri.com> Reviewed by: Guy Morrogh <gmorrogh@tintri.com> Reviewed by: Robert Mustacchi <rm+illumos@fingolfin.org> Reviewed by: Andy Fiddaman <andy@omnios.org> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr')
-rw-r--r--usr/src/cmd/nvmeadm/nvmeadm.c30
-rw-r--r--usr/src/cmd/nvmeadm/nvmeadm.h3
-rw-r--r--usr/src/cmd/nvmeadm/nvmeadm_dev.c18
-rw-r--r--usr/src/man/man1m/nvmeadm.1m6
-rw-r--r--usr/src/uts/common/io/nvme/nvme.c23
-rw-r--r--usr/src/uts/common/sys/nvme.h3
6 files changed, 73 insertions, 10 deletions
diff --git a/usr/src/cmd/nvmeadm/nvmeadm.c b/usr/src/cmd/nvmeadm/nvmeadm.c
index b592a2bd25..d288ac1865 100644
--- a/usr/src/cmd/nvmeadm/nvmeadm.c
+++ b/usr/src/cmd/nvmeadm/nvmeadm.c
@@ -293,6 +293,7 @@ main(int argc, char **argv)
}
npa.npa_cmd = cmd;
+ npa.npa_interactive = B_TRUE;
optind++;
@@ -533,8 +534,12 @@ nvme_process(di_node_t node, di_minor_t minor, void *arg)
if (npa->npa_idns == NULL)
goto out;
- if (npa->npa_isns)
- npa->npa_dsk = nvme_dskname(npa);
+ if (npa->npa_isns) {
+ npa->npa_ignored = nvme_is_ignored_ns(fd);
+ if (!npa->npa_ignored)
+ npa->npa_dsk = nvme_dskname(npa);
+ }
+
exitcode += npa->npa_cmd->c_func(fd, npa);
@@ -1247,12 +1252,21 @@ do_attach_detach(int fd, const nvme_process_arg_t *npa)
nvme_walk(&ns_npa, npa->npa_node);
return (exitcode);
- } else {
- if ((c_name[0] == 'd' ? nvme_detach : nvme_attach)(fd)
- == B_FALSE) {
- warn("%s failed", c_name);
- return (-1);
- }
+ }
+
+ /*
+ * Unless the user interactively requested a particular namespace to be
+ * attached or detached, don't even try to attach or detach namespaces
+ * that are ignored by the driver, thereby avoiding printing pointless
+ * error messages.
+ */
+ if (!npa->npa_interactive && npa->npa_ignored)
+ return (0);
+
+ if ((c_name[0] == 'd' ? nvme_detach : nvme_attach)(fd)
+ == B_FALSE) {
+ warn("%s failed", c_name);
+ return (-1);
}
return (0);
diff --git a/usr/src/cmd/nvmeadm/nvmeadm.h b/usr/src/cmd/nvmeadm/nvmeadm.h
index 6b620f8fab..e06cd93189 100644
--- a/usr/src/cmd/nvmeadm/nvmeadm.h
+++ b/usr/src/cmd/nvmeadm/nvmeadm.h
@@ -42,6 +42,8 @@ struct nvme_process_arg {
char *npa_nsid;
int npa_found;
boolean_t npa_isns;
+ boolean_t npa_ignored;
+ boolean_t npa_interactive;
const nvmeadm_cmd_t *npa_cmd;
di_node_t npa_node;
di_minor_t npa_minor;
@@ -114,6 +116,7 @@ extern boolean_t nvme_detach(int);
extern boolean_t nvme_attach(int);
extern boolean_t nvme_firmware_load(int, void *, size_t, offset_t, uint16_t *);
extern boolean_t nvme_firmware_commit(int, int, int, uint16_t *);
+extern boolean_t nvme_is_ignored_ns(int);
/*
* ofmt related
diff --git a/usr/src/cmd/nvmeadm/nvmeadm_dev.c b/usr/src/cmd/nvmeadm/nvmeadm_dev.c
index 1617de5da9..6c837d0d8c 100644
--- a/usr/src/cmd/nvmeadm/nvmeadm_dev.c
+++ b/usr/src/cmd/nvmeadm/nvmeadm_dev.c
@@ -222,6 +222,24 @@ nvme_firmware_commit(int fd, int slot, int action, uint16_t *sc)
return (rv);
}
+boolean_t
+nvme_is_ignored_ns(int fd)
+{
+ boolean_t ret;
+ uint64_t res = 0;
+
+ /*
+ * The ioctl shouldn't fail. If it does, we treat it the same as if the
+ * namespace was ignored.
+ */
+ ret = nvme_ioctl(fd, NVME_IOC_IS_IGNORED_NS, NULL, NULL, 0, &res);
+
+ if (ret)
+ ret = (res == 0) ? B_FALSE : B_TRUE;
+
+ return (ret);
+}
+
int
nvme_open(di_minor_t minor)
{
diff --git a/usr/src/man/man1m/nvmeadm.1m b/usr/src/man/man1m/nvmeadm.1m
index 0ec278936e..422e6f0048 100644
--- a/usr/src/man/man1m/nvmeadm.1m
+++ b/usr/src/man/man1m/nvmeadm.1m
@@ -390,6 +390,9 @@ currently opened.
The detached state will not persist across reboots or reloads of the
.Xr nvme 7D
driver.
+.Pp
+It is not an error to detach a namespace that is already detached, any such
+request will be silently ignored.
.It Xo
.Nm
.Cm attach
@@ -403,6 +406,9 @@ previous
.Nm
.Cm detach
command.
+.Pp
+It is not an error to attach a namespace that is already attached, any such
+request will be silently ignored.
.It Xo
.Nm
.Cm list-firmware
diff --git a/usr/src/uts/common/io/nvme/nvme.c b/usr/src/uts/common/io/nvme/nvme.c
index c2aeda2e8a..a8a9d0b843 100644
--- a/usr/src/uts/common/io/nvme/nvme.c
+++ b/usr/src/uts/common/io/nvme/nvme.c
@@ -5272,6 +5272,26 @@ out:
}
static int
+nvme_ioctl_is_ignored_ns(nvme_t *nvme, int nsid, nvme_ioctl_t *nioc, int mode,
+ cred_t *cred_p)
+{
+ _NOTE(ARGUNUSED(cred_p));
+
+ if ((mode & FREAD) == 0)
+ return (EPERM);
+
+ if (nsid == 0)
+ return (EINVAL);
+
+ if (nvme->n_ns[nsid - 1].ns_ignore)
+ nioc->n_arg = 1;
+ else
+ nioc->n_arg = 0;
+
+ return (0);
+}
+
+static int
nvme_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred_p,
int *rval_p)
{
@@ -5298,7 +5318,8 @@ nvme_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred_p,
nvme_ioctl_attach,
nvme_ioctl_firmware_download,
nvme_ioctl_firmware_commit,
- nvme_ioctl_passthru
+ nvme_ioctl_passthru,
+ nvme_ioctl_is_ignored_ns
};
if (nvme == NULL)
diff --git a/usr/src/uts/common/sys/nvme.h b/usr/src/uts/common/sys/nvme.h
index 83d29d0b8d..bca3102270 100644
--- a/usr/src/uts/common/sys/nvme.h
+++ b/usr/src/uts/common/sys/nvme.h
@@ -54,7 +54,8 @@ extern "C" {
#define NVME_IOC_FIRMWARE_DOWNLOAD (NVME_IOC | 11)
#define NVME_IOC_FIRMWARE_COMMIT (NVME_IOC | 12)
#define NVME_IOC_PASSTHRU (NVME_IOC | 13)
-#define NVME_IOC_MAX NVME_IOC_PASSTHRU
+#define NVME_IOC_IS_IGNORED_NS (NVME_IOC | 14)
+#define NVME_IOC_MAX NVME_IOC_IS_IGNORED_NS
#define IS_NVME_IOC(x) ((x) > NVME_IOC && (x) <= NVME_IOC_MAX)
#define NVME_IOC_CMD(x) ((x) & 0xff)