[libvirt] [PATCH tck] Avoid multicast MAC addrs in tests
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Certain MAC addrs are used for multicast and recent libvirt
will refuse to start VMs using those addrs.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
scripts/domain/215-nic-hotplug-many.t | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/domain/215-nic-hotplug-many.t b/scripts/domain/215-nic-hotplug-many.t
index 5b935cc..8b4afbd 100644
--- a/scripts/domain/215-nic-hotplug-many.t
+++ b/scripts/domain/215-nic-hotplug-many.t
@@ -47,9 +47,9 @@ diag "Creating a new transient domain";
my $dom;
ok_domain(sub { $dom = $conn->create_domain($xml) }, "created transient domain object");
-my $mac1 = "01:11:22:33:44:55";
-my $mac2 = "02:11:22:33:44:55";
-my $mac3 = "03:11:22:33:44:55";
+my $mac1 = "02:11:22:33:44:51";
+my $mac2 = "02:11:22:33:44:52";
+my $mac3 = "02:11:22:33:44:53";
my $model = "virtio";
my $netxml1 = <<EOF;
--
1.8.1.2
11 years, 8 months
[libvirt] [PATCH] Fix crash changing CDROM media
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
This change tried to fix a crash with changing CDROM media but
failed to actually do so
commit d0172d2b1b5d865aaa042070d7c2d00effb2ff8c
Author: Osier Yang <jyang(a)redhat.com>
Date: Tue Feb 19 20:27:45 2013 +0800
qemu: Remove the shared disk entry if the operation is ejecting or updating
It was still accessing disk->src, when the entire 'disk' object
has been free'd already. Even if it weren't free'd, accessing
the 'src' value of virDomainDiskDef is not allowed without
first validating disk->type is file or block. Just remove the
broken code entirely.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/qemu/qemu_driver.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1e96915..8dae8f9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5778,13 +5778,14 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
dev->data.disk = tmp;
ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, false);
+ /* 'disk' must not be accessed now - it has been free'd.
+ * 'orig_disk' now points to the new disk, while 'dev_copy'
+ * now points to the old disk */
/* Need to remove the shared disk entry for the original disk src
* if the operation is either ejecting or updating.
*/
- if (ret == 0 &&
- orig_disk->src &&
- STRNEQ_NULLABLE(orig_disk->src, disk->src))
+ if (ret == 0)
ignore_value(qemuRemoveSharedDisk(driver, dev_copy->data.disk,
vm->def->name));
break;
--
1.8.1.2
11 years, 8 months
[libvirt] [PATCH] qemu: Refactor qemuDomainSetMemoryParameters
by Peter Krempa
The new TypedParam helper APIs allow to simplify this function
significantly.
This patch integrates the fix in 75e5bec97b3045e4f926248d5c742f8a50d0f9
by correctly ordering the setting functions instead of reordering the
parameters.
---
src/qemu/qemu_driver.c | 149 ++++++++++++++++++-------------------------------
1 file changed, 54 insertions(+), 95 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 23499ef..f2f5872 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7140,15 +7140,15 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
- int i;
virDomainDefPtr persistentDef = NULL;
virCgroupPtr group = NULL;
virDomainObjPtr vm = NULL;
- virTypedParameterPtr hard_limit = NULL;
- virTypedParameterPtr swap_hard_limit = NULL;
- int hard_limit_index = 0;
- int swap_hard_limit_index = 0;
- unsigned long long val = 0;
+ unsigned long long swap_hard_limit;
+ unsigned long long memory_hard_limit;
+ unsigned long long memory_soft_limit;
+ bool set_swap_hard_limit = false;
+ bool set_memory_hard_limit = false;
+ bool set_memory_soft_limit = false;
virQEMUDriverConfigPtr cfg = NULL;
int ret = -1;
int rc;
@@ -7167,13 +7167,9 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
NULL) < 0)
return -1;
- vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
- if (vm == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("No such domain %s"), dom->uuid);
- goto cleanup;
- }
+ if (!(vm = qemuDomObjFromDomain(dom)))
+ return -1;
cfg = virQEMUDriverGetConfig(driver);
@@ -7198,110 +7194,73 @@ qemuDomainSetMemoryParameters(virDomainPtr dom,
}
}
- for (i = 0; i < nparams; i++) {
- if (STREQ(params[i].field, VIR_DOMAIN_MEMORY_HARD_LIMIT)) {
- hard_limit = ¶ms[i];
- hard_limit_index = i;
- } else if (STREQ(params[i].field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
- swap_hard_limit = ¶ms[i];
- swap_hard_limit_index = i;
- }
- }
+#define VIR_GET_LIMIT_PARAMETER(PARAM, VALUE) \
+ if ((rc = virTypedParamsGetULLong(params, nparams, PARAM, &VALUE) < 0)) \
+ goto cleanup; \
+ \
+ if (rc == 1) \
+ set_ ## VALUE = true;
+
+ VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT, swap_hard_limit)
+ VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_HARD_LIMIT, memory_hard_limit)
+ VIR_GET_LIMIT_PARAMETER(VIR_DOMAIN_MEMORY_SOFT_LIMIT, memory_soft_limit)
+
+#undef VIR_GET_LIMIT_PARAMETER
+
/* It will fail if hard limit greater than swap hard limit anyway */
- if (swap_hard_limit &&
- hard_limit &&
- (hard_limit->value.ul > swap_hard_limit->value.ul)) {
+ if (set_swap_hard_limit && set_memory_hard_limit &&
+ (memory_hard_limit > swap_hard_limit)) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("hard limit must be lower than swap hard limit"));
goto cleanup;
}
- if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- /* Get current swap hard limit */
- rc = virCgroupGetMemSwapHardLimit(group, &val);
- if (rc != 0) {
+ if (set_swap_hard_limit) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+ (rc = virCgroupSetMemSwapHardLimit(group, swap_hard_limit)) < 0) {
virReportSystemError(-rc, "%s",
- _("unable to get swap hard limit"));
+ _("unable to set memory swap_hard_limit tunable"));
goto cleanup;
}
- /* Swap hard_limit and swap_hard_limit to ensure the setting
- * could succeed if both of them are provided.
- */
- if (swap_hard_limit && hard_limit) {
- virTypedParameter param;
-
- if (swap_hard_limit->value.ul > val) {
- if (hard_limit_index < swap_hard_limit_index) {
- param = params[hard_limit_index];
- params[hard_limit_index] = params[swap_hard_limit_index];
- params[swap_hard_limit_index] = param;
- }
- } else {
- if (hard_limit_index > swap_hard_limit_index) {
- param = params[hard_limit_index];
- params[hard_limit_index] = params[swap_hard_limit_index];
- params[swap_hard_limit_index] = param;
- }
- }
- }
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG)
+ persistentDef->mem.swap_hard_limit = swap_hard_limit;
}
- ret = 0;
- for (i = 0; i < nparams; i++) {
- virTypedParameterPtr param = ¶ms[i];
-
- if (STREQ(param->field, VIR_DOMAIN_MEMORY_HARD_LIMIT)) {
- if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- rc = virCgroupSetMemoryHardLimit(group, param->value.ul);
- if (rc != 0) {
- virReportSystemError(-rc, "%s",
- _("unable to set memory hard_limit tunable"));
- ret = -1;
- }
- }
+ if (set_memory_hard_limit) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+ (rc = virCgroupSetMemoryHardLimit(group, memory_hard_limit)) < 0) {
+ virReportSystemError(-rc, "%s",
+ _("unable to set memory hard_limit tunable"));
+ goto cleanup;
+ }
- if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- persistentDef->mem.hard_limit = param->value.ul;
- }
- } else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SOFT_LIMIT)) {
- if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- rc = virCgroupSetMemorySoftLimit(group, param->value.ul);
- if (rc != 0) {
- virReportSystemError(-rc, "%s",
- _("unable to set memory soft_limit tunable"));
- ret = -1;
- }
- }
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG)
+ persistentDef->mem.hard_limit = memory_hard_limit;
+ }
- if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- persistentDef->mem.soft_limit = param->value.ul;
- }
- } else if (STREQ(param->field, VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT)) {
- if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- rc = virCgroupSetMemSwapHardLimit(group, param->value.ul);
- if (rc != 0) {
- virReportSystemError(-rc, "%s",
- _("unable to set swap_hard_limit tunable"));
- ret = -1;
- }
- }
- if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- persistentDef->mem.swap_hard_limit = param->value.ul;
- }
+ if (set_memory_soft_limit) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE &&
+ (rc = virCgroupSetMemorySoftLimit(group, memory_soft_limit)) < 0) {
+ virReportSystemError(-rc, "%s",
+ _("unable to set memory soft_limit tunable"));
+ goto cleanup;
}
- }
- if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
- if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
- ret = -1;
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG)
+ persistentDef->mem.soft_limit = memory_soft_limit;
}
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG &&
+ virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
+ goto cleanup;
+
+ ret = 0;
+
cleanup:
virCgroupFree(&group);
- if (vm)
- virObjectUnlock(vm);
+ virObjectUnlock(vm);
virObjectUnref(caps);
virObjectUnref(cfg);
return ret;
--
1.8.1.1
11 years, 8 months
[libvirt] [PATCHv2 0/5] Add API to allow TCP connection tunelling
by Peter Krempa
This series adds ability for the qemu driver to tunnel connections to TCP
ports from the host. This is useful for enabling remote VNC/SPICE sessions
without the need to configure SSH tunnels or portforwards and without the
need to open the ports for public.
There's also an advantage for tools such as virt-viewer that have to guess the remote
connection parameters and you have to hope that nothing is in your way. With
spice/VNC clients that have support for read/write callbacks, this would allow also
direct connection without an intermediate socket.
The API and tunelling works but there's no (stable and good working) client for
this API. I hacked up a dirty netcat-like terminal into virsh for testing
purposes (see patch 5/5) but that isn't what I'd like to see.
The client should be able to open a listening socket and when a client connects
to it, it opens a stream and connects it to the remote host.
For the client there are two options:
1) do all the stuff in virsh: + one tool to rule them all
- i'd like to daemonize it and I don't know if that's okay in virsh
2) add a new tool "virtunnel": + less virsh pollution
- separate tool ...
As nobody responded, I'd like to re-ask for someones opinion on this.
(note: this is my personal effort, I'm annoyed of opening ssh tunnels to remote displays on my server
and I don't want to open the ports to public. )
After this it would be great to add support for this to virt-viewer. I will have a look at that later.
----
Diff to v1:
- fixed error reporting in 2/5
- documented limitation to "localhost" in 3/5
- fixed possible segfault in 4/5
---
Peter Krempa (5):
api: Add API to allow TCP tunneling through streams to the host
fdstream: Add support for TCP connections of streams
qemu: Add configuration options to enable TCP tunelling
qemu: Implement virNodeTunnelTcp for the qemu driver
NOT_TO_BE_APPLIED_UPSTREAM: quick and dirty virsh client to test the
stuff
include/libvirt/libvirt.h.in | 11 +++++++
src/driver.h | 8 +++++
src/fdstream.c | 73 ++++++++++++++++++++++++++++++++++++++++++++
src/fdstream.h | 5 +++
src/libvirt.c | 67 ++++++++++++++++++++++++++++++++++++++++
src/libvirt_private.syms | 1 +
src/libvirt_public.syms | 1 +
src/qemu/qemu.conf | 16 ++++++++++
src/qemu/qemu_conf.c | 26 ++++++++++++++++
src/qemu/qemu_conf.h | 13 ++++++++
src/qemu/qemu_driver.c | 48 +++++++++++++++++++++++++++++
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 9 +++++-
src/remote_protocol-structs | 6 ++++
src/rpc/gendispatch.pl | 1 +
tools/console.c | 66 +++++++++++++++++++++------------------
tools/console.h | 9 ++----
tools/virsh-domain.c | 17 +++++++++--
tools/virsh-host.c | 60 ++++++++++++++++++++++++++++++++++++
19 files changed, 397 insertions(+), 41 deletions(-)
--
1.8.0
11 years, 8 months
[libvirt] [PATCH 0/2] Using client-id for DHCPv6 host identification
by Gene Czarcinski
The first patch is a trivial fix to the network schema
since the name in dhcp-host is really optional.
The second patch adds the capability to use the client id
to improve the reliability of having a system use a fixed
IPv6 address.
Gene Czarcinski (2):
Trivial fix: in dhcp-host the name is optional
use client id for IPv6 DHCP host definition
docs/formatnetwork.html.in | 18 ++++++-
docs/schemas/basictypes.rng | 59 ++++++++++++++++++++++
docs/schemas/network.rng | 7 ++-
src/conf/network_conf.c | 29 +++++++++--
src/conf/network_conf.h | 1 +
src/network/bridge_driver.c | 3 +-
src/util/virdnsmasq.c | 20 ++++++--
src/util/virdnsmasq.h | 1 +
tests/networkxml2confdata/dhcp6-nat-network.xml | 5 +-
tests/networkxml2confdata/dhcp6-network.xml | 5 +-
.../dhcp6host-routed-network.xml | 5 +-
11 files changed, 138 insertions(+), 15 deletions(-)
--
1.8.1.2
11 years, 8 months
[libvirt] Versioning/Compatibility in the XML schemas
by Pieter Hollants
Out of curiosity, seeing that we doing modifications to the XML schema
all the time, there does not seem to be some sort of version identifier
in the XML schemas.
If I take the recently merged patch for DHCP options, for instance,
suppose virt-manager would add support for it in its GUI. How would such
a network XML definition be interpreted by older libvirt versions? Is it
supposed to ignore elements it doesn't know or do we have an implicit
requirement of "always use the latest versions together"?
--
Pieter Hollants <pieter(a)hollants.com>
11 years, 8 months
[libvirt] [PATCH v2 resend 0/4]use VIR_ENUM_DECL for domain NIC model and add usb-net
by Guannan Ren
v1 to v2
*removed i8* NIC models support for QEMU/KVM
*updated docs
*rebased
This patchset uses VIR_ENUM_DECL and VIR_ENUM_IMPL macros for NIC models
and changes the related codes to use them.
All of NIC models supported by various hypervisors comprise of the enum,
so the problem is that we need to do further checking in hypervisor-specific
implementation. Fortunately, VMX and Vbox did this checking very well already.
In 4/4, a similar job is performed for QEMU/KVM.
And, adds usb-net support.
The vendorId and productID of is 0525:a4a2. The corresponding item in
usb-ids is as follows:
0525 Netchip Technology, Inc.
a4a2 Linux-USB Ethernet/RNDIS Gadget
In my opinion, using usb-net directly is good enough, so I keep it.
Any other idea is welcome.
Libvirt XML sample:
<devices>
<interface type='user'>
<mac address='52:54:00:32:6a:91'/>
<model type='usb-net'/>
<alias name='net1'/>
<address type='usb' bus='0' port='1'/>
</interface>
</devices>
qemu commandline:
qemu ${other_vm_args}
-netdev user,id=hostnet1 \
-device usb-net,netdev=hostnet1,id=net1,\
mac=52:54:00:32:6a:91,bus=usb.0,port=1
Guannan Ren(4)
[PATCH v2 resend 1/4] add domain NIC model enum macro
[PATCH v2 resend 2/4] net: use virDomainNICModelType{From|To}String functions
[PATCH v2 resend 3/4] qemu: add NIC model checking for qemu hypervisor
[PATCH v2 resend 4/4] qemu: add usb-net support
docs/formatdomain.html.in | 29 +++++++++++------------------
src/conf/domain_conf.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
src/conf/domain_conf.h | 32 +++++++++++++++++++++++++++++++-
src/libvirt_private.syms | 2 ++
src/libxl/libxl_conf.c | 5 +++--
src/parallels/parallels_driver.c | 2 +-
src/qemu/qemu_command.c | 41 +++++++++++++++++++++++++++--------------
src/qemu/qemu_driver.c | 2 +-
src/qemu/qemu_hotplug.c | 10 ++++++----
src/qemu/qemu_process.c | 14 +++++++-------
src/vbox/vbox_tmpl.c | 57 +++++++++++++++++++++++++++------------------------------
src/vmx/vmx.c | 31 ++++++++++++++++---------------
src/xenxs/xen_sxpr.c | 21 +++++++++++----------
src/xenxs/xen_xm.c | 21 +++++++++++----------
14 files changed, 208 insertions(+), 137 deletions(-)
11 years, 8 months
[libvirt] [PATCH] interface: Fix udev backend bridge device display
by Doug Goldstein
The bridge device was showing the vnet devices created for the domains
as connected to the bridge. libvirt should only show host devices when
trying to get the interface definition rather than the domain devices as
well.
---
Honestly this method sucks. But it makes the code path work and doesn't
result in brokenness. I was really thinking of sscanf() but I don't really
care to store the values. Suggestions?
---
src/interface/interface_backend_udev.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index bd83545..dca85b3 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -24,7 +24,9 @@
#include <libudev.h>
#include "virerror.h"
+#include "c-ctype.h"
#include "datatypes.h"
+#include "domain_conf.h"
#include "interface_driver.h"
#include "interface_conf.h"
#include "viralloc.h"
@@ -527,6 +529,16 @@ udevIfaceBridgeScanDirFilter(const struct dirent *entry)
if (STREQ(entry->d_name, ".") || STREQ(entry->d_name, ".."))
return 0;
+ /* Omit the domain interfaces from the list of bridge attached
+ * devices. All we can do is check for the device name matching
+ * vnet%d. Improvements to this check are welcome.
+ */
+ if (strlen(entry->d_name) >= 5) {
+ if (STRPREFIX(entry->d_name, VIR_NET_GENERATED_PREFIX) &&
+ c_isdigit(entry->d_name[4]))
+ return 0;
+ }
+
return 1;
}
--
1.7.12.4
11 years, 8 months
[libvirt] [PATCH] docs: add forward mode='hostdev' example
by Laine Stump
Also rearrange examples so that all "managed" networks (those with
bridges created by libvirt) are together.
---
docs/formatnetwork.html.in | 52 +++++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 15 deletions(-)
diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in
index 4b4c47b..46b7270 100644
--- a/docs/formatnetwork.html.in
+++ b/docs/formatnetwork.html.in
@@ -332,7 +332,7 @@
</p>
<pre>
...
- <forward mode='passthrough'>
+ <forward mode='passthrough' managed='yes'>
<pf dev='eth0'/>
</forward>
...
@@ -863,6 +863,27 @@
</ip>
</network></pre>
+ <h3><a name="examplesNoGateway">Network config with no gateway addresses</a></h3>
+
+ <p>
+ A valid network definition can contain no IPv4 or IPv6 addresses.
+ Such a definition can be used for a "very private" or "very
+ isolated" network since it will not be possible to communicate
+ with the virtualization host via this network. However, this
+ virtual network interface can be used for communication between
+ virtual guest systems. This works for IPv4
+ and <span class="since">(Since 1.0.1)</span> IPv6. However,
+ the <code>ipv6</code> attribute must be set to "yes" for
+ functional guest-to-guest IPv6 communication.
+ </p>
+
+ <pre>
+ <network ipv6='yes'>
+ <name>nogw</name>
+ <bridge name="virbr2" stp="on" delay="0"/>
+ </network>
+ </pre>
+
<h3><a name="examplesBridge">Using an existing host bridge</a></h3>
<p>
@@ -916,25 +937,26 @@
</forward>
</network></pre>
- <h3><a name="examplesNoGateway">Network config with no gateway addresses</a></h3>
+ <h3><a name="examplesPCIPassthrough">Assigning SR-IOV Virtual Functions via PCI Passthrough</a></h3>
<p>
- A valid network definition can contain no IPv4 or IPv6 addresses. Such a definition
- can be used for a "very private" or "very isolated" network since it will not be
- possible to communicate with the virtualization host via this network. However,
- this virtual network interface can be used for communication between virtual guest
- systems. This works for IPv4 and <span class="since">(Since 1.0.1)</span> IPv6.
- However, the new ipv6='yes' must be added for guest-to-guest IPv6
- communication.
+ <span class="since">Since 0.9.10, requires a host with working
+ IOMMU</span> This example shows how to use a libvirt network to
+ assign individual SR-IOV Virtual Functions (VF) to guests using
+ PCI passthrough. Only the Physical Function (PF) of the SR-IOV
+ network adapter needs to be listed in the network definition; a
+ list of all VFs will be automatically derived from that, and VFs
+ will be allocated to guest domains as requested.
</p>
<pre>
- <network ipv6='yes'>
- <name>nogw</name>
- <uuid>7a3b7497-1ec7-8aef-6d5c-38dff9109e93</uuid>
- <bridge name="virbr2" stp="on" delay="0" />
- <mac address='00:16:3E:5D:C7:9E'/>
- </network></pre>
+ <network>
+ <name>passthrough</name>
+ <forward mode='hostdev' managed='yes'>
+ <pf dev='eth3'/>
+ </forward>
+ </network>
+ </pre>
</body>
</html>
--
1.7.11.7
11 years, 8 months
[libvirt] [PATCH] virsh: add --start option to the define command
by Doug Goldstein
Adds the --start option to the define command to simplify the often used
case of virsh "define dom.xml; start dom" or virsh define dom.xml &&
virsh start dom.
This is just a rebased version of:
https://www.redhat.com/archives/libvir-list/2013-January/msg00490.html
There's a competing patchset available at:
https://www.redhat.com/archives/libvir-list/2013-February/msg01298.html
---
tools/virsh-domain.c | 23 +++++++++++++++++++++--
tools/virsh.pod | 5 +++--
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 96dd4fa..6d62197 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6602,6 +6602,10 @@ static const vshCmdOptDef opts_define[] = {
.flags = VSH_OFLAG_REQ,
.help = N_("file containing an XML domain description")
},
+ {.name = "start",
+ .type = VSH_OT_BOOL,
+ .help = N("start the domain after definition")
+ },
{.name = NULL}
};
@@ -6612,6 +6616,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
const char *from = NULL;
bool ret = true;
char *buffer;
+ bool start = false;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
@@ -6619,17 +6624,31 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
+ start = vshCommandOptBool(cmd, "start");
+
dom = virDomainDefineXML(ctl->conn, buffer);
VIR_FREE(buffer);
if (dom != NULL) {
vshPrint(ctl, _("Domain %s defined from %s\n"),
virDomainGetName(dom), from);
- virDomainFree(dom);
} else {
vshError(ctl, _("Failed to define domain from %s"), from);
- ret = false;
+ return false;
}
+
+ /* Start the domain if the user requested it and it was defined */
+ if (start) {
+ if (virDomainCreate(dom) < 0) {
+ vshError(ctl, _("Failed to start domain %s, which was "
+ "successfully defined."), virDomainGetName(dom));
+ ret = false;
+ } else {
+ vshPrint(ctl, _("Domain %s started\n"), virDomainGetName(dom));
+ }
+ }
+
+ virDomainFree(dom);
return ret;
}
diff --git a/tools/virsh.pod b/tools/virsh.pod
index a5d8fe6..660331c 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -555,11 +555,12 @@ B<Example>
vi domain.xml (or make changes with your other text editor)
virsh create domain.xml
-=item B<define> I<FILE>
+=item B<define> I<FILE> [I<--start>]
Define a domain from an XML <file>. The domain definition is registered
but not started. If domain is already running, the changes will take
-effect on the next boot.
+effect on the next boot. If I<--start> is requested, start the domain
+after defining it.
=item B<desc> I<domain> [[I<--live>] [I<--config>] |
[I<--current>]] [I<--title>] [I<--edit>] [I<--new-desc>
--
1.7.12.4
11 years, 8 months