nvme: print namespace IDs as unsigned 32bit value
Subsystems (2)
PATCH 1/2 nvme: print namespace IDs as unsigned 32bit value
NSIDs are 32-bit unsigned values, but a number of log messages print them with %d. An NSID larger than 0x7fffffff is rendered as a negative number, which is confusing in the kernel log and makes the message hard to correlate with the namespace it talks about. Sparse NSID spaces where high NSIDs are common are the most likely to hit this.
The nsid sysfs attribute has the same problem, and there it is worse because userspace parses the value.
For example:
$ grep . /sys/class/block/nvme0*/nsid /sys/class/block/nvme0c0n1/nsid:10 /sys/class/block/nvme0c0n2/nsid:-16 /sys/class/block/nvme0c0n3/nsid:11 /sys/class/block/nvme0c0n4/nsid:-2000000016 /sys/class/block/nvme0n1/nsid:10 /sys/class/block/nvme0n2/nsid:-16 /sys/class/block/nvme0n3/nsid:11 /sys/class/block/nvme0n4/nsid:-2000000016 $
Print all of them with %u. Several messages in these files, including two in zns.c right next to the ones being changed, already use %u, so this only makes the rest consistent with them. No functional change other than how the NSID is formatted.
--- drivers/nvme/host/core.c | 18 +++++++++--------- drivers/nvme/host/sysfs.c | 2 +- drivers/nvme/host/zns.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-)
drivers/nvme/host/core.c +9 -9
@@ -1610,7 +1610,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, }if (nvme_multi_css (ctrl) && !csi_seen) { -dev_warn (ctrl->device,"Command set not reported for nsid:%d\n" , +dev_warn (ctrl->device,"Command set not reported for nsid:%u\n" , info->nsid); status = -EINVAL ; }
@@ -4126,13 +4126,13 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) ((ns->ctrl->subsys->cmic & NVME_CTRL_CMIC_MULTI_CTRL) && info->is_shared)) {dev_err (ctrl->device, -"ignoring nsid %d because of duplicate IDs\n" , +"ignoring nsid %u because of duplicate IDs\n" , info->nsid);return ret; }dev_err (ctrl->device, -"clearing duplicate IDs for nsid %d\n" , info->nsid); +"clearing duplicate IDs for nsid %u\n" , info->nsid);dev_err (ctrl->device,"use of /dev/disk/by-id/ may cause data corruption\n" );memset (&info->ids.nguid,0 ,sizeof (info->ids.nguid));
@@ -4147,7 +4147,7 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info) ret =nvme_subsys_check_duplicate_ids (ctrl->subsys, &info->ids);if (ret) {dev_err (ctrl->device, -"duplicate IDs in subsystem for nsid %d\n" , +"duplicate IDs in subsystem for nsid %u\n" , info->nsid); goto out_unlock; }
@@ -4161,20 +4161,20 @@ static int nvme_init_ns_head(struct nvme_ns *ns, struct nvme_ns_info *info)if ((!info->is_shared || !head->shared) && !list_empty (&head->list)) {dev_err (ctrl->device, -"Duplicate unshared namespace %d\n" , +"Duplicate unshared namespace %u\n" , info->nsid); goto out_put_ns_head; }if (!nvme_ns_ids_equal (&head->ids, &info->ids)) {dev_err (ctrl->device, -"IDs don't match for shared namespace %d\n" , +"IDs don't match for shared namespace %u\n" , info->nsid); goto out_put_ns_head; }if (!multipath) {dev_warn (ctrl->device, -"Found shared namespace %d, but multipathing not supported.\n" , +"Found shared namespace %u, but multipathing not supported.\n" , info->nsid);dev_warn_once (ctrl->device,"Shared namespace support requires core_nvme.multipath=Y.\n" );
@@ -4420,7 +4420,7 @@ static void nvme_validate_ns(struct nvme_ns *ns, struct nvme_ns_info *info)if (!nvme_ns_ids_equal (&ns->head->ids, &info->ids)) {dev_err (ns->ctrl->device, -"identifiers changed for nsid %d\n" , ns->head->ns_id); +"identifiers changed for nsid %u\n" , ns->head->ns_id); goto out; }
@@ -4447,7 +4447,7 @@ static void nvme_scan_ns(struct nvme_ctrl *ctrl, unsigned nsid)if (info.ids.csi !=NVME_CSI_NVM && !nvme_multi_css (ctrl)) {dev_warn (ctrl->device, -"command set not reported for nsid: %d\n" , nsid); +"command set not reported for nsid: %u\n" , nsid);return ; }
drivers/nvme/host/sysfs.c +1 -1
@@ -166,7 +166,7 @@ static DEVICE_ATTR_RO(eui);static ssize_t nsid_show (struct device *dev,struct device_attribute *attr,char *buf) { -return sysfs_emit (buf,"%d\n" ,dev_to_ns_head (dev)->ns_id); +return sysfs_emit (buf,"%u\n" ,dev_to_ns_head (dev)->ns_id); }static DEVICE_ATTR_RO (nsid);
drivers/nvme/host/zns.c +2 -2
@@ -48,12 +48,12 @@ int nvme_query_zone_info(struct nvme_ns *ns, unsigned lbaf, NVME_CMD_EFFECTS_CSUPP)) { if (test_and_clear_bit(NVME_NS_FORCE_RO, &ns->flags)) dev_warn(ns->ctrl->device, - "Zone Append supported for zoned namespace:%d. Remove read-only mode\n", + "Zone Append supported for zoned namespace:%u. Remove read-only mode\n", ns->head->ns_id); } else {set_bit (NVME_NS_FORCE_RO , &ns->flags);dev_warn (ns->ctrl->device, -"Zone Append not supported for zoned namespace:%d. Forcing to read-only mode\n" , +"Zone Append not supported for zoned namespace:%u. Forcing to read-only mode\n" , ns->head->ns_id); }
Signature · 1 line
2.54.0
PATCH 2/2 nvmet: print namespace IDs as unsigned 32bit value
struct nvmet_ns.nsid is a u32, but a few messages print it with %d. An NSID larger than 0x7fffffff is rendered as a negative number, which is misleading in general and particularly so for the configfs messages that echo back the NSID the user just asked for.
For example:
[ T200] nvmet: adding nsid -16 to subsystem mysubsystem
Print them with %u. The invalid-NSID error in nvmet_ns_make() keeps its %#x because the two values it rejects, 0 and NVME_NSID_ALL, are more readable in hex format. No functional change other than how the NSID is formatted.
--- drivers/nvme/target/configfs.c | 4 ++-- drivers/nvme/target/core.c | 2 +- drivers/nvme/target/pr.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/nvme/target/configfs.c +2 -2
@@ -814,7 +814,7 @@ static ssize_t nvmet_ns_resv_enable_store(struct config_item *item,mutex_lock (&ns->subsys->lock);if (ns->enabled) { -pr_err ("the ns:%d is already enabled.\n" , ns->nsid); +pr_err ("the ns:%u is already enabled.\n" , ns->nsid);mutex_unlock (&ns->subsys->lock);return -EINVAL ; }
@@ -880,7 +880,7 @@ static struct config_group *nvmet_ns_make(struct config_group *group, goto out;config_group_init_type_name (&ns->group, name, &nvmet_ns_type); -pr_info ("adding nsid %d to subsystem %s\n" , nsid, subsys->subsysnqn); +pr_info ("adding nsid %u to subsystem %s\n" , nsid, subsys->subsysnqn);return &ns->group; out:
drivers/nvme/target/core.c +1 -1
@@ -558,7 +558,7 @@ static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,if (ret <0 )pci_dev_put (p2p_dev); -pr_info ("using p2pmem on %s for nsid %d\n" ,pci_name (p2p_dev), +pr_info ("using p2pmem on %s for nsid %u\n" ,pci_name (p2p_dev), ns->nsid); }
drivers/nvme/target/pr.c +1 -1
@@ -145,7 +145,7 @@ static void nvmet_pr_add_resv_log(struct nvmet_ctrl *ctrl, u8 log_type, log.nsid =cpu_to_le32 (nsid);if (!kfifo_put (&log_mgr->log_queue, log)) { -pr_info ("a reservation log lost, cntlid:%d, log_type:%d, nsid:%d\n" , +pr_info ("a reservation log lost, cntlid:%d, log_type:%d, nsid:%u\n" , ctrl->cntlid, log_type, nsid); log_mgr->lost_count++; }
Signature · 1 line
2.54.0
Re: [PATCH 2/2] nvmet: print namespace IDs as unsigned 32bit value
Quoted 8 lines · Mohamed Khalfella
NSIDs are 32-bit unsigned values, but a number of log messages print them with %d. An NSID larger than
0x7fffffffis rendered as a negative number, which is confusing in the kernel log and makes the message hard to correlate with the namespace it talks about. Sparse NSID spaces where high NSIDs are common are the most likely to hit this.The nsid sysfs attribute has the same problem, and there it is worse because userspace parses the value.
Thanks, applied to nvme-7.3.