If the given device is the controller device, set nsid to 0xFFFFFFFF.
This allows something like
nvme set-feature /dev/nvme0 -f 0x5 -v $((1 << 16))
to work as expected.
Since we cannot use S_ISCHR/S_ISBLK to differentiate between controller
and namespace devices since commit
e77046661509 ("remove block device
checking for namespace"), just try the NVME_IOCTL_ID ioctl and if it
fails with ENOTTY, assume that it is the controller device.
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
};
struct config cfg = {
- .namespace_id = 1,
+ .namespace_id = 0,
.feature_id = 0,
.sel = 0,
.cdw11 = 0,
if (fd < 0)
goto ret;
+ if (!cfg.namespace_id) {
+ err = cfg.namespace_id = nvme_get_nsid(fd);
+ if (err < 0) {
+ if (errno != ENOTTY) {
+ perror("get-namespace-id");
+ goto close_fd;
+ }
+
+ cfg.namespace_id = NVME_NSID_ALL;
+ }
+ }
+
if (cfg.sel > 7) {
fprintf(stderr, "invalid 'select' param:%d\n", cfg.sel);
err = -EINVAL;
if (fd < 0)
goto ret;
+ if (!cfg.namespace_id) {
+ err = cfg.namespace_id = nvme_get_nsid(fd);
+ if (err < 0) {
+ if (errno != ENOTTY) {
+ perror("get-namespace-id");
+ goto close_fd;
+ }
+
+ cfg.namespace_id = NVME_NSID_ALL;
+ }
+ }
+
if (!cfg.feature_id) {
fprintf(stderr, "feature-id required param\n");
err = -EINVAL;