[PATCH 02/10] nvme-discover: assume device given on command line is persistent
mwilck at suse.com
mwilck at suse.com
Sat Mar 6 00:36:16 GMT 2021
From: Martin Wilck <mwilck at suse.com>
After commit "nvme-discover: lookup existing persistent controllers",
controllers without the "kato" sysfs attribute will never be used by
do_discover(). This makes sense for controllers found while traversing
sysfs in find_ctrl_with_connectargs(), but if the user passed a
device explicitly, it should be used, even on older kernels that
don't support the "kato" attribute.
Furthermore, make sure allocated memory in ctrl_matches_connectargs()
is freed.
Signed-off-by: Martin Wilck <mwilck at suse.com>
---
fabrics.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index 14899cc..dcee0c4 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -297,12 +297,14 @@ static int ctrl_instance(char *device)
* given.
* Return true/false based on whether it matches
*/
-static bool ctrl_matches_connectargs(char *name, struct connect_args *args)
+static bool ctrl_matches_connectargs(char *name, struct connect_args *args,
+ bool assume_persistent)
{
struct connect_args cargs;
bool found = false;
char *path, *addr;
int ret;
+ bool persistent = true;
ret = asprintf(&path, "%s/%s", SYS_NVME, name);
if (ret < 0)
@@ -331,17 +333,21 @@ static bool ctrl_matches_connectargs(char *name, struct connect_args *args)
* underneath us as they are owned by another program.
*
* The 'kato' attribute might not be present; assume a
- * non-persistent controller for these installations.
+ * non-persistent controller for these installations,
+ * unless assume_persistent is set.
*/
if (kato_str) {
kato = strtoul(kato_str, &p, 0);
if (p == kato_str)
kato = 0;
- }
- if (kato == 0)
- return found;
+ free(kato_str);
+ persistent = (kato != 0);
+ } else if (!assume_persistent)
+ persistent = false;
}
- if (!strcmp(cargs.subsysnqn, args->subsysnqn) &&
+
+ if (persistent &&
+ !strcmp(cargs.subsysnqn, args->subsysnqn) &&
!strcmp(cargs.transport, args->transport) &&
(!strcmp(cargs.traddr, args->traddr) ||
!strcmp(args->traddr, "none")) &&
@@ -380,7 +386,7 @@ static char *find_ctrl_with_connectargs(struct connect_args *args)
}
for (i = 0; i < n; i++) {
- if (ctrl_matches_connectargs(devices[i]->d_name, args)) {
+ if (ctrl_matches_connectargs(devices[i]->d_name, args, false)) {
devname = strdup(devices[i]->d_name);
if (devname == NULL)
fprintf(stderr, "no memory for ctrl name %s\n",
@@ -1372,7 +1378,7 @@ static int do_discover(char *argstr, bool connect, enum nvme_print_flags flags)
if (!cargs)
return -ENOMEM;
- if (!cfg.device || !ctrl_matches_connectargs(cfg.device, cargs))
+ if (!cfg.device || !ctrl_matches_connectargs(cfg.device, cargs, true))
cfg.device = find_ctrl_with_connectargs(cargs);
free_connect_args(cargs);
--
2.29.2
More information about the Linux-nvme
mailing list