Skip to content

Commit 66d115a

Browse files
committed
nvme: extend filter to match device name
nvme_match_device_filter is used by list-subsys where it is possible to limit the output by providing a block device. The current implementation only matches on subsystem ID level, but this is not what the expectation is from the user. It is expected to limit the output by the block device name. Change the match to use the block device name instead. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 8842f63 commit 66d115a

1 file changed

Lines changed: 11 additions & 20 deletions

File tree

nvme.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,33 +3388,24 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
33883388
static bool nvme_match_device_filter(nvme_subsystem_t s,
33893389
nvme_ctrl_t c, nvme_ns_t ns, void *f_args)
33903390
{
3391-
int ret, instance, nsid, s_num;
33923391
char *devname = f_args;
3392+
nvme_ns_t n;
33933393

3394-
if (!devname || !strlen(devname))
3394+
if (ns && !strcmp(devname, nvme_ns_get_name(ns)))
33953395
return true;
33963396

3397-
ret = sscanf(devname, "nvme%dn%d", &instance, &nsid);
3398-
if (ret != 2)
3399-
return true;
3400-
3401-
if (s) {
3402-
ret = sscanf(nvme_subsystem_get_name(s), "nvme-subsys%d",
3403-
&s_num);
3404-
if (ret == 1 && s_num == instance)
3405-
return true;
3406-
}
34073397
if (c) {
34083398
s = nvme_ctrl_get_subsystem(c);
3409-
3410-
ret = sscanf(nvme_subsystem_get_name(s), "nvme-subsys%d",
3411-
&s_num);
3412-
if (ret == 1 && s_num == instance)
3413-
return true;
3399+
nvme_ctrl_for_each_ns(c, n) {
3400+
if (!strcmp(devname, nvme_ns_get_name(n)))
3401+
return true;
3402+
}
34143403
}
3415-
if (ns) {
3416-
if (!strcmp(devname, nvme_ns_get_name(ns)))
3417-
return true;
3404+
if (s) {
3405+
nvme_subsystem_for_each_ns(s, n) {
3406+
if (!strcmp(devname, nvme_ns_get_name(n)))
3407+
return true;
3408+
}
34183409
}
34193410

34203411
return false;

0 commit comments

Comments
 (0)