Yet again, we don't need listing by device capabilities, so flags
are unused.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
tools/virsh-completer.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
tools/virsh-completer.h | 4 ++++
tools/virsh-nodedev.c | 16 +++++++++++-----
3 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 2c0d4f640..c50143142 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -348,3 +348,48 @@ virshNetworkNameCompleter(vshControl *ctl,
VIR_FREE(ret);
return NULL;
}
+
+
+char **
+virshNodeDeviceNameCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+ virshControlPtr priv = ctl->privData;
+ virNodeDevicePtr *devs = NULL;
+ int ndevs = 0;
+ size_t i = 0;
+ char **ret = NULL;
+
+ virCheckFlags(0, NULL);
+
+ if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+ return NULL;
+
+ if ((ndevs = virConnectListAllNodeDevices(priv->conn, &devs, flags)) < 0)
+ return NULL;
+
+ if (VIR_ALLOC_N(ret, ndevs + 1) < 0)
+ goto error;
+
+ for (i = 0; i < ndevs; i++) {
+ const char *name = virNodeDeviceGetName(devs[i]);
+
+ if (VIR_STRDUP(ret[i], name) < 0)
+ goto error;
+
+ virNodeDeviceFree(devs[i]);
+ }
+ VIR_FREE(devs);
+
+ return ret;
+
+ error:
+ for (; i < ndevs; i++)
+ virNodeDeviceFree(devs[i]);
+ VIR_FREE(devs);
+ for (i = 0; i < ndevs; i++)
+ VIR_FREE(ret[i]);
+ VIR_FREE(ret);
+ return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index 20ba4cb55..19fa2113d 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -54,4 +54,8 @@ char ** virshNetworkNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+char ** virshNodeDeviceNameCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags);
+
#endif
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index c7ef6bfde..d25fe0e09 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -109,7 +109,8 @@ static const vshCmdOptDef opts_node_device_destroy[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
- .help = N_("device name or wwn pair in 'wwnn,wwpn' format")
+ .help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
+ .completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@@ -534,6 +535,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = {
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
.help = N_("device name or wwn pair in 'wwnn,wwpn' format"),
+ .completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@@ -604,7 +606,8 @@ static const vshCmdOptDef opts_node_device_detach[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
- .help = N_("device key")
+ .help = N_("device key"),
+ .completer = virshNodeDeviceNameCompleter,
},
{.name = "driver",
.type = VSH_OT_STRING,
@@ -670,7 +673,8 @@ static const vshCmdOptDef opts_node_device_reattach[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
- .help = N_("device key")
+ .help = N_("device key"),
+ .completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@@ -720,7 +724,8 @@ static const vshCmdOptDef opts_node_device_reset[] = {
{.name = "device",
.type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ,
- .help = N_("device key")
+ .help = N_("device key"),
+ .completer = virshNodeDeviceNameCompleter,
},
{.name = NULL}
};
@@ -866,7 +871,8 @@ static const vshCmdInfo info_node_device_event[] = {
static const vshCmdOptDef opts_node_device_event[] = {
{.name = "device",
.type = VSH_OT_STRING,
- .help = N_("filter by node device name")
+ .help = N_("filter by node device name"),
+ .completer = virshNodeDeviceNameCompleter,
},
{.name = "event",
.type = VSH_OT_STRING,
--
2.13.6