[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv2 13/15] virsh: add command aliases, and rename nodedev-detach

Just because our public API has a typo doesn't mean that virsh
has to keep the typo.

* tools/virsh.c (VSH_CMD_FLAG_ALIAS): New flag.
(nodedevCmds): Use it.
(cmdHelp): Omit alias commands.
(cmdNodeDeviceDettach): Rename...
(cmdNodeDeviceDetach): ...to this.
* tools/virsh.pod (nodedev-detach): Document it.

v2: no real change

 tools/virsh.c   |   30 +++++++++++++++++++-----------
 tools/virsh.pod |   10 ++++++----
 2 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 75a1a3b..4361a6b 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -212,6 +212,7 @@ typedef struct vshCmdOpt {
 enum {
     VSH_CMD_FLAG_NOCONNECT = (1 << 0),  /* no prior connection needed */
+    VSH_CMD_FLAG_ALIAS     = (1 << 1),  /* command is an alias */

@@ -685,9 +686,12 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
             vshPrint(ctl, _(" %s (help keyword '%s'):\n"), grp->name,

-            for (def = grp->commands; def->name; def++)
+            for (def = grp->commands; def->name; def++) {
+                if (def->flags & VSH_CMD_FLAG_ALIAS)
+                    continue;
                 vshPrint(ctl, "    %-30s %s\n", def->name,
                          _(vshCmddefGetInfo(def, "help")));
+            }

             vshPrint(ctl, "\n");
@@ -12939,22 +12943,22 @@ cmdNodeDeviceDumpXML (vshControl *ctl, const vshCmd *cmd)

- * "nodedev-dettach" command
+ * "nodedev-detach" command
-static const vshCmdInfo info_node_device_dettach[] = {
-    {"help", N_("dettach node device from its device driver")},
-    {"desc", N_("Dettach node device from its device driver before assigning to a domain.")},
+static const vshCmdInfo info_node_device_detach[] = {
+    {"help", N_("detach node device from its device driver")},
+    {"desc", N_("Detach node device from its device driver before assigning to a domain.")},
     {NULL, NULL}

-static const vshCmdOptDef opts_node_device_dettach[] = {
+static const vshCmdOptDef opts_node_device_detach[] = {
     {"device", VSH_OT_DATA, VSH_OFLAG_REQ, N_("device key")},
     {NULL, 0, 0, NULL}

 static bool
-cmdNodeDeviceDettach (vshControl *ctl, const vshCmd *cmd)
+cmdNodeDeviceDetach (vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL;
     virNodeDevicePtr device;
@@ -12969,10 +12973,12 @@ cmdNodeDeviceDettach (vshControl *ctl, const vshCmd *cmd)
         return false;

+    /* Yes, our public API is misspelled.  At least virsh can accept
+     * either spelling.  */
     if (virNodeDeviceDettach(device) == 0) {
-        vshPrint(ctl, _("Device %s dettached\n"), name);
+        vshPrint(ctl, _("Device %s detached\n"), name);
     } else {
-        vshError(ctl, _("Failed to dettach device %s"), name);
+        vshError(ctl, _("Failed to detach device %s"), name);
         ret = false;
@@ -17090,8 +17096,10 @@ static const vshCmdDef nodedevCmds[] = {
      info_node_device_create, 0},
     {"nodedev-destroy", cmdNodeDeviceDestroy, opts_node_device_destroy,
      info_node_device_destroy, 0},
-    {"nodedev-dettach", cmdNodeDeviceDettach, opts_node_device_dettach,
-     info_node_device_dettach, 0},
+    {"nodedev-detach", cmdNodeDeviceDetach, opts_node_device_detach,
+     info_node_device_detach, 0},
+    {"nodedev-dettach", cmdNodeDeviceDetach, opts_node_device_detach,
+     info_node_device_detach, VSH_CMD_FLAG_ALIAS},
     {"nodedev-dumpxml", cmdNodeDeviceDumpXML, opts_node_device_dumpxml,
      info_node_device_dumpxml, 0},
     {"nodedev-list", cmdNodeListDevices, opts_node_list_devices,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 1bc55c4..b365624 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1442,7 +1442,7 @@ Attach a device to the domain, using a device definition in an XML file.
 See the documentation to learn about libvirt XML format for a device.
 For cdrom and floppy devices, this command only replaces the media within
 the single existing device; consider using B<update-device> for this usage.
-For passthrough host devices, see also B<nodedev-dettach>, needed if
+For passthrough host devices, see also B<nodedev-detach>, needed if
 the device does not use managed mode.

 =item B<attach-disk> I<domain-id> I<source> I<target>
@@ -1571,7 +1571,7 @@ guest domains, nor by multiple active guests at once.  If the
 <hostdev> description includes the attribute B<managed='yes'>, and the
 hypervisor driver supports it, then the device is in managed mode, and
 attempts to use that passthrough device in an active guest will
-automatically behave as if B<nodedev-dettach> (guest start, device
+automatically behave as if B<nodedev-detach> (guest start, device
 hot-plug) and B<nodedev-reattach> (guest stop, device hot-unplug) were
 called at the right points (currently, qemu does this for PCI devices,
 but not USB).  If a device is not marked as managed, then it must
@@ -1596,11 +1596,13 @@ Destroy (stop) a device on the host.  Note that this makes libvirt
 quit managing a host device, and may even make that device unusable
 by the rest of the physical host until a reboot.

-=item B<nodedev-dettach> I<nodedev>
+=item B<nodedev-detach> I<nodedev>

 Detach I<nodedev> from the host, so that it can safely be used by
 guests via <hostdev> passthrough.  This is reversed with
 B<nodedev-reattach>, and is done automatically for managed devices.
+For compatibility purposes, this command can also be spelled

 =item B<nodedev-dumpxml> I<nodedev>

@@ -1621,7 +1623,7 @@ formatted in a tree representing parents of each node.
 Declare that I<nodedev> is no longer in use by any guests, and that
 the host can resume normal use of the device.  This is done
 automatically for devices in managed mode, but must be done explicitly
-to match any explicit B<nodedev-dettach>.
+to match any explicit B<nodedev-detach>.

 =item B<nodedev-reset> I<nodedev>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]