Skip to content

Commit 97c8bb0

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 ac005e7 commit 97c8bb0

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
@@ -3386,33 +3386,24 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
33863386
static bool nvme_match_device_filter(nvme_subsystem_t s,
33873387
nvme_ctrl_t c, nvme_ns_t ns, void *f_args)
33883388
{
3389-
int ret, instance, nsid, s_num;
33903389
char *devname = f_args;
3390+
nvme_ns_t n;
33913391

3392-
if (!devname || !strlen(devname))
3392+
if (ns && !strcmp(devname, nvme_ns_get_name(ns)))
33933393
return true;
33943394

3395-
ret = sscanf(devname, "nvme%dn%d", &instance, &nsid);
3396-
if (ret != 2)
3397-
return true;
3398-
3399-
if (s) {
3400-
ret = sscanf(nvme_subsystem_get_name(s), "nvme-subsys%d",
3401-
&s_num);
3402-
if (ret == 1 && s_num == instance)
3403-
return true;
3404-
}
34053395
if (c) {
34063396
s = nvme_ctrl_get_subsystem(c);
3407-
3408-
ret = sscanf(nvme_subsystem_get_name(s), "nvme-subsys%d",
3409-
&s_num);
3410-
if (ret == 1 && s_num == instance)
3411-
return true;
3397+
nvme_ctrl_for_each_ns(c, n) {
3398+
if (!strcmp(devname, nvme_ns_get_name(n)))
3399+
return true;
3400+
}
34123401
}
3413-
if (ns) {
3414-
if (!strcmp(devname, nvme_ns_get_name(ns)))
3415-
return true;
3402+
if (s) {
3403+
nvme_subsystem_for_each_ns(s, n) {
3404+
if (!strcmp(devname, nvme_ns_get_name(n)))
3405+
return true;
3406+
}
34163407
}
34173408

34183409
return false;

0 commit comments

Comments
 (0)