[PATCH 1/3] virsh-domain: Add --live, --config, --current logic to cmdAttachDevice

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

 



Use the approach established in commit
69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too.
---
 tools/virsh-domain.c | 41 ++++++++++++++++++++++++++++++++---------
 tools/virsh.pod      | 16 +++++++++++++---
 2 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0402aef..b965c11 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -173,13 +173,21 @@ static const vshCmdOptDef opts_attach_device[] = {
      .help = N_("XML file")
     },
     {.name = "persistent",
-     .type = VSH_OT_ALIAS,
-     .help = "config"
+     .type = VSH_OT_BOOL,
+     .help = N_("make live change persistent")
     },
     {.name = "config",
      .type = VSH_OT_BOOL,
      .help = N_("affect next boot")
     },
+    {.name = "live",
+     .type = VSH_OT_BOOL,
+     .help = N_("affect running domain")
+    },
+    {.name = "current",
+     .type = VSH_OT_BOOL,
+     .help = N_("affect current domain")
+    },
     {.name = NULL}
 };

@@ -191,7 +199,21 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
     char *buffer;
     int rv;
     bool ret = false;
-    unsigned int flags;
+    unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+    bool current = vshCommandOptBool(cmd, "current");
+    bool config = vshCommandOptBool(cmd, "config");
+    bool live = vshCommandOptBool(cmd, "live");
+    bool persistent = vshCommandOptBool(cmd, "persistent");
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current);
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
+    VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+
+    if (config || persistent)
+        flags |= VIR_DOMAIN_AFFECT_CONFIG;
+    if (live)
+        flags |= VIR_DOMAIN_AFFECT_LIVE;

     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -199,19 +221,20 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         goto cleanup;

+    if (persistent &&
+        virDomainIsActive(dom) == 1)
+        flags |= VIR_DOMAIN_AFFECT_LIVE;
+
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
         vshReportError(ctl);
         goto cleanup;
     }

-    if (vshCommandOptBool(cmd, "config")) {
-        flags = VIR_DOMAIN_AFFECT_CONFIG;
-        if (virDomainIsActive(dom) == 1)
-           flags |= VIR_DOMAIN_AFFECT_LIVE;
+    if (flags)
         rv = virDomainAttachDeviceFlags(dom, buffer, flags);
-    } else {
+    else
         rv = virDomainAttachDevice(dom, buffer);
-    }
+
     VIR_FREE(buffer);

     if (rv < 0) {
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 11984bc..a002623 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1809,7 +1809,8 @@ format of the device sections to get the most accurate set of accepted values.

 =over 4

-=item B<attach-device> I<domain> I<FILE> [I<--config>]
+=item B<attach-device> I<domain> I<FILE>
+[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]

 Attach a device to the domain, using a device definition in an XML
 file using a device definition element such as <disk> or <interface>
@@ -1817,13 +1818,22 @@ as the top-level element.  See the documentation at
 L<http://libvirt.org/formatdomain.html#elementsDevices> to learn about
 libvirt XML format for a device.  If I<--config> is specified the
 command alters the persistent domain configuration with the device
-attach taking effect the next time libvirt starts the domain.  For
-compatibility purposes, I<--persistent> is an alias of I<--config>.
+attach taking effect the next time libvirt starts the domain.
 For cdrom and floppy devices, this command only replaces the media
 within an existing device; consider using B<update-device> for this
 usage.  For passthrough host devices, see also B<nodedev-detach>,
 needed if the device does not use managed mode.

+If I<--live> is specified, affect a running domain.
+If I<--config> is specified, affect the next startup of a persistent domain.
+If I<--current> is specified, affect the current domain state.
+Both I<--live> and I<--config> flags may be given, but I<--current> is
+exclusive. When no flag is specified legacy API is used whose behavior depends
+on the hypervisor driver.
+
+For compatibility purposes, I<--persistent> behaves like I<--config> for
+an offline domain, and like I<--live> I<--config> for a running domain.
+
 B<Note>: using of partial device definition XML files may lead to unexpected
 results as some fields may be autogenerated and thus match devices other than
 expected.
-- 
1.8.2.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]