254 lines
9.0 KiB
Diff
254 lines
9.0 KiB
Diff
commit 3a9b2b900c5dac18c9c48c40ec2dbeaa7c306a0e
|
|
Author: Jim Fehlig <jfehlig@novell.com>
|
|
Date: Wed Jan 13 18:54:58 2010 -0700
|
|
|
|
Modify virsh commands
|
|
|
|
Change all virsh commands that invoke virDomain{Attach,Detach}Device()
|
|
to use virDomain{Attach,Detach}DeviceFlags() instead.
|
|
|
|
Add a "--persistent" flag to these virsh commands, allowing user to
|
|
specify that the domain persisted config be modified as well.
|
|
|
|
V2: Only invoke virDomain{Attach,Detach}DeviceFlags() if
|
|
"--persistent" flag is specified. Otherwise invoke
|
|
virDomain{Attach,Detach}Device() to retain current behavior.
|
|
|
|
Index: libvirt-0.7.5/tools/virsh.c
|
|
===================================================================
|
|
--- libvirt-0.7.5.orig/tools/virsh.c
|
|
+++ libvirt-0.7.5/tools/virsh.c
|
|
@@ -6281,6 +6281,7 @@ static const vshCmdInfo info_attach_devi
|
|
static const vshCmdOptDef opts_attach_device[] = {
|
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
|
|
{"file", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("XML file")},
|
|
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist device attachment")},
|
|
{NULL, 0, 0, NULL}
|
|
};
|
|
|
|
@@ -6292,6 +6293,7 @@ cmdAttachDevice(vshControl *ctl, const v
|
|
char *buffer;
|
|
int ret = TRUE;
|
|
int found;
|
|
+ unsigned int flags;
|
|
|
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
|
return FALSE;
|
|
@@ -6311,7 +6313,14 @@ cmdAttachDevice(vshControl *ctl, const v
|
|
return FALSE;
|
|
}
|
|
|
|
- ret = virDomainAttachDevice(dom, buffer);
|
|
+ if (vshCommandOptBool(cmd, "persistent")) {
|
|
+ flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
|
|
+ if (virDomainIsActive(dom) == 1)
|
|
+ flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
|
|
+ ret = virDomainAttachDeviceFlags(dom, buffer, flags);
|
|
+ } else {
|
|
+ ret = virDomainAttachDevice(dom, buffer);
|
|
+ }
|
|
free (buffer);
|
|
|
|
if (ret < 0) {
|
|
@@ -6339,6 +6348,7 @@ static const vshCmdInfo info_detach_devi
|
|
static const vshCmdOptDef opts_detach_device[] = {
|
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
|
|
{"file", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("XML file")},
|
|
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist device detachment")},
|
|
{NULL, 0, 0, NULL}
|
|
};
|
|
|
|
@@ -6350,6 +6360,7 @@ cmdDetachDevice(vshControl *ctl, const v
|
|
char *buffer;
|
|
int ret = TRUE;
|
|
int found;
|
|
+ unsigned int flags;
|
|
|
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
|
return FALSE;
|
|
@@ -6369,7 +6380,14 @@ cmdDetachDevice(vshControl *ctl, const v
|
|
return FALSE;
|
|
}
|
|
|
|
- ret = virDomainDetachDevice(dom, buffer);
|
|
+ if (vshCommandOptBool(cmd, "persistent")) {
|
|
+ flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
|
|
+ if (virDomainIsActive(dom) == 1)
|
|
+ flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
|
|
+ ret = virDomainDetachDeviceFlags(dom, buffer, flags);
|
|
+ } else {
|
|
+ ret = virDomainDetachDevice(dom, buffer);
|
|
+ }
|
|
free (buffer);
|
|
|
|
if (ret < 0) {
|
|
@@ -6401,6 +6419,7 @@ static const vshCmdOptDef opts_attach_in
|
|
{"target", VSH_OT_DATA, 0, gettext_noop("target network name")},
|
|
{"mac", VSH_OT_DATA, 0, gettext_noop("MAC address")},
|
|
{"script", VSH_OT_DATA, 0, gettext_noop("script used to bridge network interface")},
|
|
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist interface attachment")},
|
|
{NULL, 0, 0, NULL}
|
|
};
|
|
|
|
@@ -6411,6 +6430,7 @@ cmdAttachInterface(vshControl *ctl, cons
|
|
char *mac, *target, *script, *type, *source;
|
|
int typ, ret = FALSE;
|
|
char *buf = NULL, *tmp = NULL;
|
|
+ unsigned int flags;
|
|
|
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
|
goto cleanup;
|
|
@@ -6485,13 +6505,22 @@ cmdAttachInterface(vshControl *ctl, cons
|
|
if (!buf) goto cleanup;
|
|
strcat(buf, " </interface>\n");
|
|
|
|
- if (virDomainAttachDevice(dom, buf)) {
|
|
- goto cleanup;
|
|
+ if (vshCommandOptBool(cmd, "persistent")) {
|
|
+ flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
|
|
+ if (virDomainIsActive(dom) == 1)
|
|
+ flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
|
|
+ ret = virDomainAttachDeviceFlags(dom, buf, flags);
|
|
} else {
|
|
- vshPrint(ctl, "%s", _("Interface attached successfully\n"));
|
|
+ ret = virDomainAttachDevice(dom, buf);
|
|
}
|
|
|
|
- ret = TRUE;
|
|
+ if (ret != 0) {
|
|
+ vshError(ctl, _("Failed to attach interface"));
|
|
+ ret = FALSE;
|
|
+ } else {
|
|
+ vshPrint(ctl, "%s", _("Interface attached successfully\n"));
|
|
+ ret = TRUE;
|
|
+ }
|
|
|
|
cleanup:
|
|
if (dom)
|
|
@@ -6514,6 +6543,7 @@ static const vshCmdOptDef opts_detach_in
|
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
|
|
{"type", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("network interface type")},
|
|
{"mac", VSH_OT_STRING, 0, gettext_noop("MAC address")},
|
|
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist interface detachment")},
|
|
{NULL, 0, 0, NULL}
|
|
};
|
|
|
|
@@ -6530,6 +6560,7 @@ cmdDetachInterface(vshControl *ctl, cons
|
|
char *doc, *mac =NULL, *type;
|
|
char buf[64];
|
|
int i = 0, diff_mac, ret = FALSE;
|
|
+ unsigned int flags;
|
|
|
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
|
goto cleanup;
|
|
@@ -6601,10 +6632,21 @@ cmdDetachInterface(vshControl *ctl, cons
|
|
goto cleanup;
|
|
}
|
|
|
|
- ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
|
|
- if (ret != 0)
|
|
+ if (vshCommandOptBool(cmd, "persistent")) {
|
|
+ flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
|
|
+ if (virDomainIsActive(dom) == 1)
|
|
+ flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
|
|
+ ret = virDomainDetachDeviceFlags(dom,
|
|
+ (char *)xmlBufferContent(xml_buf),
|
|
+ flags);
|
|
+ } else {
|
|
+ ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
|
|
+ }
|
|
+
|
|
+ if (ret != 0) {
|
|
+ vshError(ctl, _("Failed to detach interface"));
|
|
ret = FALSE;
|
|
- else {
|
|
+ } else {
|
|
vshPrint(ctl, "%s", _("Interface detached successfully\n"));
|
|
ret = TRUE;
|
|
}
|
|
@@ -6638,6 +6680,7 @@ static const vshCmdOptDef opts_attach_di
|
|
{"subdriver", VSH_OT_STRING, 0, gettext_noop("subdriver of disk device")},
|
|
{"type", VSH_OT_STRING, 0, gettext_noop("target device type")},
|
|
{"mode", VSH_OT_STRING, 0, gettext_noop("mode of device reading and writing")},
|
|
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist disk attachment")},
|
|
{NULL, 0, 0, NULL}
|
|
};
|
|
|
|
@@ -6648,6 +6691,7 @@ cmdAttachDisk(vshControl *ctl, const vsh
|
|
char *source, *target, *driver, *subdriver, *type, *mode;
|
|
int isFile = 0, ret = FALSE;
|
|
char *buf = NULL, *tmp = NULL;
|
|
+ unsigned int flags;
|
|
|
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
|
goto cleanup;
|
|
@@ -6763,12 +6807,22 @@ cmdAttachDisk(vshControl *ctl, const vsh
|
|
if (!buf) goto cleanup;
|
|
strcat(buf, " </disk>\n");
|
|
|
|
- if (virDomainAttachDevice(dom, buf))
|
|
- goto cleanup;
|
|
- else
|
|
- vshPrint(ctl, "%s", _("Disk attached successfully\n"));
|
|
+ if (vshCommandOptBool(cmd, "persistent")) {
|
|
+ flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
|
|
+ if (virDomainIsActive(dom) == 1)
|
|
+ flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
|
|
+ ret = virDomainAttachDeviceFlags(dom, buf, flags);
|
|
+ } else {
|
|
+ ret = virDomainAttachDevice(dom, buf);
|
|
+ }
|
|
|
|
- ret = TRUE;
|
|
+ if (ret != 0) {
|
|
+ vshError(ctl, _("Failed to attach disk"));
|
|
+ ret = FALSE;
|
|
+ } else {
|
|
+ vshPrint(ctl, "%s", _("Disk attached successfully\n"));
|
|
+ ret = TRUE;
|
|
+ }
|
|
|
|
cleanup:
|
|
if (dom)
|
|
@@ -6790,6 +6844,7 @@ static const vshCmdInfo info_detach_disk
|
|
static const vshCmdOptDef opts_detach_disk[] = {
|
|
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("domain name, id or uuid")},
|
|
{"target", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("target of disk device")},
|
|
+ {"persistent", VSH_OT_BOOL, 0, gettext_noop("persist disk detachment")},
|
|
{NULL, 0, 0, NULL}
|
|
};
|
|
|
|
@@ -6805,6 +6860,7 @@ cmdDetachDisk(vshControl *ctl, const vsh
|
|
virDomainPtr dom = NULL;
|
|
char *doc, *target;
|
|
int i = 0, diff_tgt, ret = FALSE;
|
|
+ unsigned int flags;
|
|
|
|
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
|
|
goto cleanup;
|
|
@@ -6870,10 +6926,21 @@ cmdDetachDisk(vshControl *ctl, const vsh
|
|
goto cleanup;
|
|
}
|
|
|
|
- ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
|
|
- if (ret != 0)
|
|
+ if (vshCommandOptBool(cmd, "persistent")) {
|
|
+ flags = VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
|
|
+ if (virDomainIsActive(dom) == 1)
|
|
+ flags |= VIR_DOMAIN_DEVICE_MODIFY_LIVE;
|
|
+ ret = virDomainDetachDeviceFlags(dom,
|
|
+ (char *)xmlBufferContent(xml_buf),
|
|
+ flags);
|
|
+ } else {
|
|
+ ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
|
|
+ }
|
|
+
|
|
+ if (ret != 0) {
|
|
+ vshError(ctl, _("Failed to detach disk"));
|
|
ret = FALSE;
|
|
- else {
|
|
+ } else {
|
|
vshPrint(ctl, "%s", _("Disk detached successfully\n"));
|
|
ret = TRUE;
|
|
}
|