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

[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 | 53 ++++++++++++++++++++++++++++++++++++----------------
 tools/virsh.pod      | 13 +++++++++++--
 2 files changed, 48 insertions(+), 18 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index b965c11..4de5dd5 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -299,14 +299,6 @@ static const vshCmdOptDef opts_attach_disk[] = {
      .type = VSH_OT_STRING,
      .help = N_("mode of device reading and writing")
     },
-    {.name = "persistent",
-     .type = VSH_OT_ALIAS,
-     .help = "config"
-    },
-    {.name = "config",
-     .type = VSH_OT_BOOL,
-     .help = N_("affect next boot")
-    },
     {.name = "sourcetype",
      .type = VSH_OT_STRING,
      .help = N_("type of source (block|file)")
@@ -335,7 +327,22 @@ static const vshCmdOptDef opts_attach_disk[] = {
      .type = VSH_OT_BOOL,
      .help = N_("print XML document rather than attach the disk")
     },
-
+    {.name = "persistent",
+     .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}
 };

@@ -496,15 +503,33 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
     struct DiskAddress diskAddr;
     bool isFile = false, functionReturn = false;
     int ret;
-    unsigned int flags;
+    unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
     const char *stype = NULL;
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *xml = NULL;
     struct stat st;
+    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;

+    if (persistent &&
+        virDomainIsActive(dom) == 1)
+        flags |= VIR_DOMAIN_AFFECT_LIVE;
+
     if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 ||
         vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 ||
@@ -635,14 +660,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }

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

     if (ret != 0) {
         vshError(ctl, "%s", _("Failed to attach disk"));
diff --git a/tools/virsh.pod b/tools/virsh.pod
index a002623..9ae96d1 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1839,6 +1839,7 @@ results as some fields may be autogenerated and thus match devices other than
 expected.

 =item B<attach-disk> I<domain> I<source> I<target>
+[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
 [I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>]
 [I<--type type>] [I<--mode mode>] [I<--config>] [I<--sourcetype soucetype>]
 [I<--serial serial>] [I<--shareable>] [I<--rawio>] [I<--address address>]
@@ -1859,8 +1860,6 @@ alternative to the disk default, although this use only replaces the media
 within the existing virtual cdrom or floppy device; consider using
 B<update-device> for this usage instead.
 I<mode> can specify the two specific mode I<readonly> or I<shareable>.
-I<--config> indicates the changes will affect the next boot of the domain,
-for compatibility purposes, I<--persistent> is alias of I<--config>.
 I<sourcetype> can indicate the type of source (block|file)
 I<cache> can be one of "default", "none", "writethrough", "writeback",
 "directsync" or "unsafe".
@@ -1875,6 +1874,16 @@ address.
 If I<--print-xml> is specified, then the XML of the disk that would be attached
 is printed instead.

+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.
+
 =item B<attach-interface> I<domain> I<type> I<source>
 [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>]
 [I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>]
-- 
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]