[libvirt] [PATCH] qemu: save config after pivot only if domain is persistent
by Michael Chapman
When pivoting after a completed block job, only save the domain's
persistent configuration if the domain is actually marked persistent.
This commit also refactors the logic surrounding the copying of the new
disk definition into vm->newDef to avoid a NULL pointer dereference if
virStorageSourceCopy were to fail to allocate memory.
Signed-off-by: Michael Chapman <mike(a)very.puzzling.org>
---
src/qemu/qemu_blockjob.c | 34 ++++++++++++++--------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index 1d5b7ce..ae936a2 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -116,26 +116,20 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
switch ((virConnectDomainEventBlockJobStatus) status) {
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
if (disk->mirrorState == VIR_DOMAIN_DISK_MIRROR_STATE_PIVOT) {
- if (vm->newDef) {
- virStorageSourcePtr copy = NULL;
-
- if ((persistDisk = virDomainDiskByName(vm->newDef,
- disk->dst, false))) {
- copy = virStorageSourceCopy(disk->mirror, false);
- if (virStorageSourceInitChainElement(copy,
- persistDisk->src,
- true) < 0) {
- VIR_WARN("Unable to update persistent definition "
- "on vm %s after block job",
- vm->def->name);
- virStorageSourceFree(copy);
- copy = NULL;
- persistDisk = NULL;
- }
- }
- if (copy) {
+ if (vm->newDef &&
+ (persistDisk = virDomainDiskByName(vm->newDef, disk->dst, false))) {
+ virStorageSourcePtr copy = virStorageSourceCopy(disk->mirror, false);
+ if (copy && virStorageSourceInitChainElement(copy,
+ persistDisk->src,
+ true) == 0) {
virStorageSourceFree(persistDisk->src);
persistDisk->src = copy;
+ } else {
+ VIR_WARN("Unable to update persistent definition "
+ "on vm %s after block job",
+ vm->def->name);
+ virStorageSourceFree(copy);
+ persistDisk = NULL;
}
}
@@ -188,8 +182,8 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
VIR_WARN("Unable to save status on vm %s after block job",
vm->def->name);
- if (persistDisk && virDomainSaveConfig(cfg->configDir,
- vm->newDef) < 0)
+ if (vm->persistent && persistDisk &&
+ virDomainSaveConfig(cfg->configDir, vm->newDef) < 0)
VIR_WARN("Unable to update persistent definition on vm %s "
"after block job", vm->def->name);
}
--
2.4.3
9 years, 2 months
[libvirt] [BUG?] qemu was accidently killed by libvirtd after we restart libvirtd by service command
by Hailiang Zhang
Hi all,
We came across a problem, qemu was accidently killed by libvirtd after we restart libvirtd by service command.
Steps to reproduce:
1) Attach net device to VM by 'virsh attach-device' command
2) Detach the net device that added before by 'virsh detach-device' command
3) Do the above two steps repeatedly, and at the same time, we restart libvirtd daemon.
And then we have chance to find that, after libvirtd is restarted at one time, qemu is killed accidently.
The libvirt log message is:
[2015-12-17 11:34:36]: libvirtd : 216046: info : libvirt version: 1.2.17
[2015-12-17 11:34:36]: libvirtd : 216046: warning : virDriverLoadModule:65 : Module /usr/lib64/libvirt/connection-driver/libvirt_driver_nwfilter.so not accessible
[2015-12-17 11:34:36]: libvirtd : 216046: info : virNetlinkEventServiceStart:662 : starting netlink event service with protocol 0
[2015-12-17 11:34:36]: libvirtd : 216046: info : virNetlinkEventServiceStart:712 : set netlink socket big buffer size
[2015-12-17 11:34:36]: libvirtd : 216046: info : virNetlinkEventServiceStart:662 : starting netlink event service with protocol 15
[2015-12-17 11:34:36]: libvirtd : 216046: info : virNetlinkEventServiceStart:712 : set netlink socket big buffer size
[2015-12-17 11:34:36]: libvirtd : 216079: error : dnsmasqCapsRefreshInternal:741 : Cannot check dnsmasq binary /usr/sbin/dnsmasq: No such file or directory
[2015-12-17 11:34:36]: libvirtd : 216079: info : networkReloadFirewallRules:1861 : Reloading iptables rules
[2015-12-17 11:34:36]: libvirtd : 216079: info : networkRefreshDaemons:1830 : Refreshing network daemons
[2015-12-17 11:34:36]: libvirtd : 216079: error : virNodeSuspendSupportsTarget:332 : internal error: Cannot probe for supported suspend types
[2015-12-17 11:34:36]: libvirtd : 216079: warning : virQEMUCapsInit:1037 : Failed to get host power management capabilities
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23039 : Scanning for configs in /var/run/libvirt/qemu
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23063 : Loading config file 'VMName.xml'
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23063 : Loading config file 'VMName2.xml'
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23063 : Loading config file 'VMName3.xml'
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23039 : Scanning for configs in /etc/libvirt/qemu
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23063 : Loading config file 'VMName.xml'
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23063 : Loading config file 'VMName2.xml'
[2015-12-17 11:34:36]: libvirtd : 216079: info : virDomainObjListLoadAllConfigs:23063 : Loading config file 'VMName3.xml'
[2015-12-17 11:34:36]: libvirtd : 216079: info : qemuDomainSnapshotLoad:490 : Scanning for snapshots for domain VMName in /var/lib/libvirt/qemu/snapshot/VMName
[2015-12-17 11:34:36]: libvirtd : 216079: info : qemuDomainSnapshotLoad:490 : Scanning for snapshots for domain VMName2 in /var/lib/libvirt/qemu/snapshot/VMName2
[2015-12-17 11:34:36]: libvirtd : 216079: info : qemuDomainSnapshotLoad:490 : Scanning for snapshots for domain VMName3 in /var/lib/libvirt/qemu/snapshot/VMName3
[2015-12-17 11:34:36]: libvirtd : 216047: info : remoteDispatchDomainDetachDevice:4105 : Domain is detached a device by client: 127.0.0.1;0
[2015-12-17 11:34:36]: libvirtd : 216050: info : remoteDispatchDomainDetachDevice:4105 : Domain is detached a device by client: 127.0.0.1;0
[2015-12-17 11:34:36]: libvirtd : 216047: info : virDomainDetachDevice:8508 : enter virDomainDetachDevice domainname=VMName2, xml= <interface type='bridge'>^M
<source bridge='br-1'/>^M
<mac address='00:16:3e:76:85:17'/>^M
<virtualport type='openvswitch' />^M
<model type='virtio'/>^M
</interface>^M
^M
[2015-12-17 11:34:36]: libvirtd : 216050: info : virDomainDetachDevice:8508 : enter virDomainDetachDevice domainname=VMName, xml= <interface type='bridge'>^M
<source bridge='br-1'/>^M
<mac address='00:16:3e:76:85:15'/>^M
2015-12-17 11:34:36]: libvirtd : 216095: error : qemuMonitorJSONCheckError:380 : internal error: unable to execute QEMU command 'netdev_del': Device 'hostnet5' not found
[2015-12-17 11:34:36]: libvirtd : 216096: error : qemuMonitorJSONCheckError:380 : internal error: unable to execute QEMU command 'netdev_del': Device 'hostnet2' not found
[2015-12-17 11:34:36]: libvirtd : 216097: error : qemuMonitorJSONCheckError:380 : internal error: unable to execute QEMU command 'netdev_del': Device 'hostnet1' not found
[2015-12-17 11:34:37]: libvirtd : 216095: info : virSecurityDACRestoreSecurityFileLabelInternal:325 : Restoring DAC user and group on '/data/suse11_sp3_64_1'
[2015-12-17 11:34:37]: libvirtd : 216095: info : virSecurityDACSetOwnershipInternal:248 : Setting DAC user and group on '/data/suse11_sp3_64_1' to '0:0'
[2015-12-17 11:34:37]: libvirtd : 216096: info : virSecurityDACRestoreSecurityFileLabelInternal:325 : Restoring DAC user and group on '/data/suse11_sp3_64_2'
[2015-12-17 11:34:37]: libvirtd : 216096: info : virSecurityDACSetOwnershipInternal:248 : Setting DAC user and group on '/data/suse11_sp3_64_2' to '0:0'
[2015-12-17 11:34:37]: libvirtd : 216095: info : qemuProcessStop:5720 : VM 'VMName' is dying,remove vBMC
[2015-12-17 11:34:37]: libvirtd : 216095: error : rtev_vBMC_send:209 : Failed to remove domain vBMC bind path for 33ae1cb0-c451-4620-8cee-1bbddd124b82, errno is 2
[2015-12-17 11:34:37]: libvirtd : 216050: info : remoteDispatchDomainAttachDevice:2855 : Domain is attached a device by client: 127.0.0.1;0
[2015-12-17 11:34:37]: libvirtd : 216050: info : virDomainAttachDevice:8390 : enter virDomainAttachDevice domainname=VMName, xml=<interface type='bridge'>^M
The VM's qemu log is:
[2015-12-17 11:34:30] handle_qmp_command:5115 qmp_cmd_name: device_del, qmp_cmd_arguments: {"id": "net4"}
[2015-12-17 11:34:30] virtio_set_status:524 virtio-net device status is 1 that means ACKNOWLEDGE
[2015-12-17 11:34:30] virtio_set_status:524 virtio-net device status is 1 that means ACKNOWLEDGE
[2015-12-17 11:34:30] virtio_pci_device_unplugged:966 virtio-net
[2015-12-17 11:34:30] monitor_qapi_event_emit:483 {"timestamp": {"seconds": 1450352070, "microseconds": 402473}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/net4/virtio-backend"}}
[2015-12-17 11:34:30] monitor_qapi_event_emit:483 {"timestamp": {"seconds": 1450352070, "microseconds": 402586}, "event": "DEVICE_DELETED", "data": {"device": "net4", "path": "/machine/peripheral/net4"}}
[2015-12-17 11:34:30] handle_qmp_command:5115 qmp_cmd_name: netdev_del, qmp_cmd_arguments: {"id": "hostnet4"}
[2015-12-17 11:34:30] handle_qmp_command:5115 qmp_cmd_name: qom-list, qmp_cmd_arguments: {"path": "/machine/peripheral"}
---------------------------------------------- At this time, We restart libvirtd just right ------------------------------------------------------------
[2015-12-17 11:34:30] handle_qmp_command:5115 qmp_cmd_name: device_del, qmp_cmd_arguments: {"id": "net5"}
[2015-12-17 11:34:30] virtio_set_status:524 virtio-net device status is 1 that means ACKNOWLEDGE
[2015-12-17 11:34:30] virtio_set_status:524 virtio-net device status is 1 that means ACKNOWLEDGE
[2015-12-17 11:34:30] virtio_pci_device_unplugged:966 virtio-net
[2015-12-17 11:34:30] monitor_qapi_event_emit:483 {"timestamp": {"seconds": 1450352070, "microseconds": 810030}, "event": "DEVICE_DELETED", "data": {"path": "/machine/peripheral/net5/virtio-backend"}}
[2015-12-17 11:34:30] monitor_qapi_event_emit:483 {"timestamp": {"seconds": 1450352070, "microseconds": 810150}, "event": "DEVICE_DELETED", "data": {"device": "net5", "path": "/machine/peripheral/net5"}}
[2015-12-17 11:34:30] handle_qmp_command:5115 qmp_cmd_name: netdev_del, qmp_cmd_arguments: {"id": "hostnet5"}
[2015-12-17 11:34:35] send_control_event:225 virtio serial port 2 send control message event = 6, value = 0
[2015-12-17 11:34:36] handle_qmp_command:5105 qmp_cmd_name: qmp_capabilities
[2015-12-17 11:34:36] handle_qmp_command:5105 qmp_cmd_name: query-commands
[2015-12-17 11:34:36] handle_qmp_command:5115 qmp_cmd_name: add-fd, qmp_cmd_arguments: {"fdset-id": 0, "opaque": "/dev/null"}
[2015-12-17 11:34:36] handle_qmp_command:5115 qmp_cmd_name: block-commit, qmp_cmd_arguments: {"device": "bogus"}
[2015-12-17 11:34:36] handle_qmp_command:5105 qmp_cmd_name: query-events
[2015-12-17 11:34:36] send_control_event:225 virtio serial port 2 send control message event = 6, value = 1
[2015-12-17 11:34:36] handle_qmp_command:5105 qmp_cmd_name: query-status
[2015-12-17 11:34:36] handle_qmp_command:5105 qmp_cmd_name: query-block
[2015-12-17 11:34:36] handle_qmp_command:5105 qmp_cmd_name: query-chardev
[2015-12-17 11:34:36] handle_qmp_command:5115 qmp_cmd_name: qom-list, qmp_cmd_arguments: {"path": "/machine/peripheral"}
[2015-12-17 11:34:36] handle_qmp_command:5115 qmp_cmd_name: netdev_del, qmp_cmd_arguments: {"id": "hostnet5"}
[2015-12-17 11:34:36]: shutting down
[2015-12-17 11:34:36] send_control_event:225 virtio serial port 2 send control message event = 6, value = 0
qemu: terminating on signal 15 from pid 216046(libvirtd)
[2015-12-17 11:34:36] monitor_qapi_event_emit:483 {"timestamp": {"seconds": 1450352076, "microseconds": 267427}, "event": "SHUTDOWN"}
[2015-12-17 11:34:36] monitor_qapi_event_emit:483 {"timestamp": {"seconds": 1450352076, "microseconds": 267773}, "event": "DEVICE_TRAY_MOVED", "data": {"device": "drive-ide0-0-1", "tray-open": true}}
We have analyzed this problem, and thought it was triggered by the inconsistent state for the net device
between qemu and the new libvirtd.
After libvirtd is started, it will connect to qemu, and updates the devices state by command 'qom-list',
and also it will read the configure information from XML stored.
The codes call process is:
qemuProcessReconnect
->qemuProcessUpdateDevices
->if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
->if ((tmp = old)) {
while (*tmp) {
if (!virStringArrayHasString(priv->qemuDevices, *tmp) &&
virDomainDefFindDevice(vm->def, *tmp, &dev, false) == 0 &&
qemuDomainRemoveDevice(driver, vm, &dev) < 0) {
goto cleanup; --->If we fail here, it will return -1; and it will call
qemuProcessStop() in qemuProcessReconnect to kill VM.
}
tmp++;
}
}
It is a little hard to reproduce this problem, we can reproduce it in a special way:
1) Attach a net device by virsh command
2) Stop libvirtd
3) Detach the net device by directly send qmp command to QEMU though the monitor, just like:
# ./qmp-shell /var/lib/libvirt/qemu/redhat.monitor
Welcome to the QMP low-level shell!
Connected to QEMU 2.3.0
(QEMU) qom-list path=/machine/peripheral
{u'return': [{u'type': u'child<virtio-net-pci>', u'name': u'net1'}, {u'type': u'child<cirrus-vga>', u'name': u'video0'}, {u'type': u'child<usb-tablet>', u'name': u'input0'}, {u'type': u'child<isa-serial>', u'name': u'serial0'}, {u'type': u'child<virtio-net-pci>', u'name': u'net0'}, {u'type': u'child<scsi-hd>', u'name': u'scsi0-0-0-0'}, {u'type': u'child<virtio-scsi-pci>', u'name': u'scsi0'}, {u'type': u'child<piix3-usb-uhci>', u'name': u'usb'}, {u'type': u'string', u'name': u'type'}]}
(QEMU) device_del id=net1
{u'return': {}}
(QEMU) netdev_del id=hostnet1
{u'return': {}}
4) Restart libvirtd daemon and then you will found that qemu is killed by libvirtd.
The main reason for the inconsistent state is, we accidently restarted libvirtd before it finished treating
'detach device' work.
It seems a little violent to kill such VM directly.
Can we just do the unfinished cleanup work for the VM after libvirtd is starting ?
(IMHO, we can't ensure not to restart libvirtd while it is treating the detach device work.)
Thanks.
zhanghailiang
9 years, 2 months
[libvirt] ANNOUNCE: libguestfs 1.32 released
by Richard W.M. Jones
I'm pleased to announce libguestfs 1.32, a library and set of tools
for accessing and modifying virtual machine disk images.
This release took 6 months of work by many people - see release notes
below.
You can get libguestfs 1.32 here:
Main website: http://libguestfs.org/
Source: http://libguestfs.org/download/1.32-stable/
Fedora 23+: http://koji.fedoraproject.org/koji/packageinfo?packageID=8391
It will appear as an update for F23 in about a week.
Debian/experimental coming soon, see:
https://packages.debian.org/libguestfs0
Release notes (from http://libguestfs.org/guestfs-release-notes.1.html):
New features
New tools
The new virt-v2v-copy-to-local(1) tool is an ancillary tool for
virt-v2v(1) allowing you to convert source guests that virt-v2v is
unable to access directly.
New features in existing tools
Virt-customize knows how to write a random seed to CirrOS (Pino
Toscano).
On Fedora, virt-customize runs dnf(8) with the --best flag, ensuring it
always updates to the latest available packages.
Virt-builder now provides 32 bit Fedora templates.
Virt-builder and virt-customize --install option now works on 32 bit
Fedora guests. Previously it would try to install 64 bit packages (Jan
Sedlák).
Virt-builder can now fetch cloud images using Simple Streams v1.0
metadata (Pino Toscano).
Virt-builder can now fetch openSUSE cloud images out of the box (Cédric
Bosdonnat).
Virt-customize will now use stronger (SHA-512) encrypted passwords by
default on openSUSE ≥ 11 (Pino Toscano).
Virt-builder will now correctly handle output filenames containing
colon characters (":"), and will create temporary files in the
libguestfs cache directory instead of defaulting to /tmp (Pino
Toscano).
Virt-resize has a new --unknown-filesystems option to control what to
do when asked to resize a filesystem that libguestfs doesn't know how
to resize.
Virt-v2v now has an --in-place flag/mode, allowing in-place conversion
of guests (Roman Kagan).
Virt-v2v has a --compressed option for creating compressed qcow2 output
files.
Virt-v2v can now correctly get the VMware datacenter path (dcPath) from
libvirt, instead of having to calculate it using an algorithm that
occasionally got the wrong answer (Matthias Bolte, Tingting Zheng).
Virt-v2v now processes RAM sizes correctly for 64 bit guests when
running on a 32 bit host.
Language bindings
In Perl and Python programs, the "get_program_name" API now returns the
true program name, instead of the incorrect string "perl" or "python".
The Python bindings can now be compiled against a different version of
libguestfs, allowing the pip module to be built against any version of
libguestfs (instead of requiring the pip module and libguestfs to have
exactly the same version).
The quality of the Ruby rdoc (documentation) has been improved (Pino
Toscano).
Perl scripts no longer hard-code the location of perl in the shebang
line, but use env(1) to locate it instead (Pino Toscano).
In OCaml programs, the guestfs handle was incorrectly made into a
global root, meaning it could never be garbage collected. If you
didn't call the "close" function explicitly, the handle would not be
closed until the whole program exited. This has now been fixed so
handles will be garbage collected in the usual way. This changes the
API of the OCaml function "Guestfs.event_callback". Note that non-C
language bindings are not covered by the libguestfs API/ABI guarantee,
although we try hard not to change them, but in this case it was
essential in order to fix this very serious bug.
Inspection
Alpine Linux and the APK package manager, ALT Linux, Frugalware, and
PLD Linux are now recognized (Pino Toscano).
If it exists, /etc/os-release will be preferred for inspecting Linux
guests (Pino Toscano).
The correct kernel version is returned for Windows guests ≥ 10.
Documentation
The large guestfs(3) man page has been split into several separate man
pages: guestfs-hacking(1) guestfs-internals(1) guestfs-security(1). In
the source tree, a new docs directory contains this documentation.
Architectures and platforms
Libguestfs now supports ARM 64 bit platforms with vGICv3.
Security
See also guestfs-security(1).
"CVE-2015-5745"
https://bugzilla.redhat.com/1251157
This is not a vulnerability in libguestfs, but because we always
give a virtio-serial port to each guest (since that is how guest-
host communication happens), an escalation from the appliance to
the host qemu process is possible. This could affect you if:
· your libguestfs program runs untrusted programs out of the
guest (using "guestfs_sh" etc), or
· another exploit was found in (for example) kernel filesystem
code that allowed a malformed filesystem to take over the
appliance.
If you use sVirt to confine qemu, that would thwart some attacks.
Virt-customize permissions on .ssh, .ssh/authorized_keys
https://bugzilla.redhat.com/1260778.
Previously when asked to inject an SSH key into a guest, virt-
customize (hence virt-builder too) would create the .ssh directory
and .ssh/authorized_keys file with too broad permissions, allowing
other users to read. They are now created as 0700 and 0600
respectively, which is the same as the ssh-copy-id(1) utility.
API
New APIs
"guestfs_get_identifier"
"guestfs_set_identifier"
Get/set a per-handle identifier. The main effect of this is to
change trace output from:
libguestfs: trace: foo
to:
libguestfs: trace: ID: foo
making it easier to follow traces in multi-threaded programs, or
where a program uses multiple handles (especially virt-v2v).
"guestfs_vfs_minimum_size"
Return the minimum size of a filesystem (when shrunk). This
supports ext2/3/4, XFS and btrfs, and can support other filesystem
types in future (Maxim Perevedentsev).
Other API changes
"guestfs_disk_create": add "preallocation" = "off"/"metadata"/"full".
For raw, this allows "off" as a synonym for "sparse" (making it
consistent with qcow2). For qcow2, this allows "sparse" as a
synonym for "off".
It also adds "full", which corresponds to fully allocated, but uses
posix_fallocate(3) for efficiency.
"guestfs_tar_in": new "xattrs", "selinux", "acl" parameters.
"guestfs_tar_out": new "xattrs", "selinux", "acl" parameters.
These extra parameters control whether extended attributes, SELinux
contexts and/or POSIX ACLs are restored from / saved to tarballs.
"guestfs_add_drive"
The existing "username" and "secret" parameters can be used to
supply authentication for iSCSI (Pino Toscano).
Build changes
The "./configure --enable-valgrind-daemon" option has been removed.
You can no longer build libguestfs on RHEL 5-era (c.2007) machines.
See the "oldlinux" branch if you need (limited) RHEL 5 support.
Virt-p2v can now be built on RHEL 6-era (c.2010) Linux distros.
OCaml ≥ 3.11 (released in 2008) is now required to build from git.
Building the Perl bindings now requires "Module::Build" (instead of
"ExtUtils::MakeMaker").
Builds should be faster (especially when incrementally rebuilding),
because work was done to reduce build times.
Both OCaml and the OCaml findlib module are required if you need to run
the generator at build time. Previously the build would have failed if
findlib was not installed.
"make check" tests now run in parallel (within each test directory).
"make install" no longer installs OCaml bindtests.* files incorrectly.
"make install" can now be run twice. Previously it would fail on the
second run.
"make clean" should now remove nearly every file that "make" creates.
A new "make installcheck" rule has been added, allowing the installed
copy of libguestfs to be tested.
Internals
Some effort was put into minimizing the size of the appliance, which
reduces temporary disk space and time needed by libguestfs handles.
The appliance now passes the NIC name to dhcpd, fixing hangs when
running the appliance on some distros (Cédric Bosdonnat).
OCaml "Guestfs.Errno" is now generated (Pino Toscano).
In OCaml tools, common code now handles --debug-gc, --verbose and other
common options (Roman Kagan, Pino Toscano).
The virt-v2v test harness allows us to boot the test guests at fixed
dates in the past, ensuring that Windows reactivation doesn't kick in.
There is a new internal API for reading/writing a subprocess via a pipe
from library code.
Used "deheader" program to remove unused "#include" directives.
In OCaml tools, the "Char" and "String" modules now implicitly
reference the "Common_utils.Char" and "Common_utils.String" modules
(instead of the ones from stdlib). The "Common_utils" modules contain
a number of extra char/string utility functions, and also hide some
unsafe functions in stdlib.
Many more virt-v2v tests will now be run even if you don't have
rhsrvany and virtio-win installed (Roman Kagan).
The huge configure.ac file has been split into several smaller files
called m4/guestfs_*.m4.
The old tests/data and tests/guests directories have been moved to
test-data/. This new top level directory carries all test data which
is common, large and/or shared between multiple tests.
There is a new top level website/ directory containing the public
http://libguestfs.org website (or most of it).
The fuzz testing of inspection (tests/fuzz) has been removed.
Virt-p2v now saves the source physical machine dmesg output into the
conversion server debug directory, making it simpler to debug cases of
missing drivers, firmware etc.
Bugs fixed
https://bugzilla.redhat.com/1294956
set-label returns wrong error message when set the ext3/ext4
filesystem label
https://bugzilla.redhat.com/1288733
Add a Fedora 23 32-bit base image for virt-builder
https://bugzilla.redhat.com/1288201
virt-builder writes temporary files to /tmp
https://bugzilla.redhat.com/1285847
virt-resize does not copy logical partitions
https://bugzilla.redhat.com/1281578
virt-inspector returns version 6.3 for win10 images (should return
10.0)
https://bugzilla.redhat.com/1281577
virt-inspector --xpath segfault on attribute get
https://bugzilla.redhat.com/1280029
libguestfs can run commands with stdin not open (or worse still,
connected to arbitrary guest-chosen random devices)
https://bugzilla.redhat.com/1279273
About compression option for qcow2
https://bugzilla.redhat.com/1278878
guestfish should be able to handle LVM thin layouts
https://bugzilla.redhat.com/1278382
DNF python programming error when run from virt-builder
https://bugzilla.redhat.com/1278371
inspection returns arch="unknown" for Windows guest if file command
is not installed
https://bugzilla.redhat.com/1277274
Document permissions needed for non-admin users to use virt-v2v
https://bugzilla.redhat.com/1277122
RFE: virt-sparsify: make '--in-place' sparsification safe to abort
(gracefully or ungracefully)
https://bugzilla.redhat.com/1277074
Virt-p2v client shouldn't present the vdsm option because it's not
usable
https://bugzilla.redhat.com/1276540
virt-v2v fails to convert Windows raw image: error "device name is
not a partition"
https://bugzilla.redhat.com/1275806
virt-builder: error: [file] is not a regular file in the guest
https://bugzilla.redhat.com/1270011
Simplestreams test fails: virt-builder: error: the value for the
key 'size' is not an integer
https://bugzilla.redhat.com/1267032
guestfish copy-in command behaves oddly/unexpectedly with wildcards
https://bugzilla.redhat.com/1262983
python: Cannot compile pip module if installed libguestfs != pip
guestfs version
https://bugzilla.redhat.com/1262127
Better diagnostic message when virbr0 doesn't exist
https://bugzilla.redhat.com/1261436
No warning shows when convert a win7 guest with AVG AntiVirus
installed
https://bugzilla.redhat.com/1260778
virt-builder --ssh-inject doesn't set proper permissions on created
files
https://bugzilla.redhat.com/1260689
RFE: V2V to check and warn user to disable group policy and anti
virus on Windows guests
https://bugzilla.redhat.com/1260590
Wrong graphics protocal and video type set for guest after convert
to rhev 3.6 by virt-v2v
https://bugzilla.redhat.com/1258342
extra slashes in vcenter URL confuses virt-v2v
https://bugzilla.redhat.com/1257895
[RHEV][V2V] virt-v2v ignores NIC if interface source/@network or
source/@bridge is an empty string
https://bugzilla.redhat.com/1256405
virt-builder created Fedora 22 32bit disk image cannot be updated
https://bugzilla.redhat.com/1256222
virt-p2v no GUI mode:error opening control connection to
$ip:22:unexpected …rompt
https://bugzilla.redhat.com/1251909
Option -oa preallocated -of qcow2 of virt-v2v didn't work
efficiently
https://bugzilla.redhat.com/1250715
v2v: spaces need to be escaped as %20 in paths
https://bugzilla.redhat.com/1248678
Close all incoming ports on virt-p2v ISO
https://bugzilla.redhat.com/1246882
man virt-customize shows synopsis twice
https://bugzilla.redhat.com/1242853
mount-loop failed to setup loop device: No such file or directory
https://bugzilla.redhat.com/1237136
BUG: unable to handle kernel NULL pointer dereference at <addr> in
function __blkg_lookup
https://bugzilla.redhat.com/1230412
virt-v2v should ignore bogus kernel entries in grub config
https://bugzilla.redhat.com/1229119
Unrelated info in fstab makes virt-v2v fail with unclear error info
https://bugzilla.redhat.com/1227609
virt-p2v: Using "Back" button causes output list to be repopulated
multiple times
https://bugzilla.redhat.com/1225789
Wrong video driver is installed for rhel5.11 guest after conversion
to libvirt
https://bugzilla.redhat.com/1204131
RFE: virt-builder creates qcow v3 images, add build option for qcow
v2
https://bugzilla.redhat.com/1176801
File /etc/sysconfig/kernel isn't updated when convert XenPV guest
with regular kernel installed
https://bugzilla.redhat.com/1174551
"lstatnslist" and "lstatlist" don't give an error if the API is
used wrongly
https://bugzilla.redhat.com/1168223
koji spin-livecd cannot build a working live CD
https://bugzilla.redhat.com/1165785
mount-loop command fails: mount failed: Unknown error -1
https://bugzilla.redhat.com/1164708
set-label can only set <=127 bytes for btrfs and <=126 bytes for
ntfs filesystem which not meet the help message. Also for ntfs it
should give a warning message when the length >128 bytes
https://bugzilla.redhat.com/1020216
libvirt fails to shut down domain: could not destroy libvirt
domain: Requested operation is not valid: domain is not running
https://bugzilla.redhat.com/1011907
mount-loop failed to setup loop device: No such file or directory
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
9 years, 2 months
[libvirt] [PATCH] rbd: Do not append Ceph monitor port number 6789 if not provided
by Wido den Hollander
If no port number was provided for a storage pool libvirt would default
to port 6789.
librbd/librados will however already default to 6789 when no port number
is provided.
In the future Ceph will however switch to a new port for the Ceph monitors
since port 6789 is already assigned to a different application by IANA.
Port 6789 is assigned to SMC-HTTPS and Ceph now has port 3300 assigned as
the 'Ceph monitor' port.
In this case it is the best solution to not hardcode any port number into
libvirt and let librados handle the connection.
Only if a user specifies a different port number we pass it down to librados,
otherwise we leave it blank.
Signed-off-by: Wido den Hollander <wido(a)widodh.nl>
---
src/storage/storage_backend_rbd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index cdbfdee..df4a3d3 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -173,7 +173,7 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
for (i = 0; i < source->nhost; i++) {
if (source->hosts[i].name != NULL &&
!source->hosts[i].port) {
- virBufferAsprintf(&mon_host, "%s:6789,",
+ virBufferAsprintf(&mon_host, "%s,",
source->hosts[i].name);
} else if (source->hosts[i].name != NULL &&
source->hosts[i].port) {
--
1.9.1
9 years, 2 months
[libvirt] [PATCH] rbd: Do not error out on a single image during pool refresh
by Wido den Hollander
It could happen that rbd_list() returns X names, but that while
refreshing the pool one of those RBD images is removed from Ceph
through a different route then libvirt.
We do not need to error out in such case, we can simply ignore the
volume and continue.
error : volStorageBackendRBDRefreshVolInfo:289 :
failed to open the RBD image 'vol-998': No such file or directory
It could also be that one or more Placement Groups (PGs) inside Ceph
are inactive due to a system failure.
If that happens it could be that some RBD images can not be refreshed
and a timeout will be raised by librados.
error : volStorageBackendRBDRefreshVolInfo:289 :
failed to open the RBD image 'vol-893': Connection timed out
Ignore the error and continue to refresh the rest of the pool's
contents.
Signed-off-by: Wido den Hollander <wido(a)widodh.nl>
---
src/storage/storage_backend_rbd.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 80684eb..888e3be 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -279,18 +279,17 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
virStoragePoolObjPtr pool,
virStorageBackendRBDStatePtr ptr)
{
- int ret = -1;
- int r = 0;
- rbd_image_t image;
+ int r = -1;
+ rbd_image_t image = NULL;
+ rbd_image_info_t info;
r = rbd_open(ptr->ioctx, vol->name, &image, NULL);
if (r < 0) {
virReportSystemError(-r, _("failed to open the RBD image '%s'"),
vol->name);
- return ret;
+ goto cleanup;
}
- rbd_image_info_t info;
r = rbd_stat(image, &info, sizeof(info));
if (r < 0) {
virReportSystemError(-r, _("failed to stat the RBD image '%s'"),
@@ -308,6 +307,8 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
vol->type = VIR_STORAGE_VOL_NETWORK;
vol->target.format = VIR_STORAGE_FILE_RAW;
+ r = -1;
+
VIR_FREE(vol->target.path);
if (virAsprintf(&vol->target.path, "%s/%s",
pool->def->source.name,
@@ -320,11 +321,13 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
vol->name) == -1)
goto cleanup;
- ret = 0;
+ r = 0;
cleanup:
- rbd_close(image);
- return ret;
+ if (image)
+ rbd_close(image);
+
+ return r;
}
static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
@@ -399,7 +402,23 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
name += strlen(name) + 1;
- if (volStorageBackendRBDRefreshVolInfo(vol, pool, &ptr) < 0) {
+ r = volStorageBackendRBDRefreshVolInfo(vol, pool, &ptr);
+
+ /* It could be that a volume has been deleted through a different route
+ * then libvirt and that will cause a -ENOENT to be returned.
+ *
+ * Another possibility is that there is something wrong with the placement
+ * group (PG) that RBD image's header is in and that causes -ETIMEDOUT
+ * to be returned.
+ *
+ * Do not error out and simply ignore the volume
+ */
+ if (r == -ENOENT || r == -ETIMEDOUT) {
+ virStorageVolDefFree(vol);
+ continue;
+ }
+
+ if (r < 0) {
virStorageVolDefFree(vol);
goto cleanup;
}
--
1.9.1
9 years, 2 months
[libvirt] [PATCHv2] "Don't include .c file for editing support" bug was fixed. Callbacks in special struct were added instead of EDIT-* macros
by rodinasophie@gmail.com
From: Sofia Rodina <rodinasophie(a)gmail.com>
---
tools/Makefile.am | 1 +
tools/virsh-domain.c | 187 ++++++++++++++++++++++++++++++++++++------------
tools/virsh-edit.c | 79 ++++++--------------
tools/virsh-edit.h | 42 +++++++++++
tools/virsh-interface.c | 64 +++++++++++++----
tools/virsh-network.c | 62 ++++++++++++----
tools/virsh-nwfilter.c | 64 +++++++++++++----
tools/virsh-pool.c | 64 +++++++++++++----
tools/virsh-snapshot.c | 76 ++++++++++++++------
9 files changed, 464 insertions(+), 175 deletions(-)
create mode 100644 tools/virsh-edit.h
diff --git a/tools/Makefile.am b/tools/Makefile.am
index d5638d9..88bb1b2 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -205,6 +205,7 @@ virsh_SOURCES = \
virsh-domain.c virsh-domain.h \
virsh-domain-monitor.c virsh-domain-monitor.h \
virsh-host.c virsh-host.h \
+ virsh-edit.c virsh-edit.h \
virsh-interface.c virsh-interface.h \
virsh-network.c virsh-network.h \
virsh-nodedev.c virsh-nodedev.h \
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 12e85e3..0beaa62 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -56,6 +56,7 @@
#include "virtime.h"
#include "virtypedparam.h"
#include "virxml.h"
+#include "virsh-edit.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
@@ -4622,6 +4623,44 @@ static const vshCmdOptDef opts_save_image_edit[] = {
{.name = NULL}
};
+typedef struct virshEditDomainUniversalStruct
+{
+ vshControl *ctl;
+ virshControlPtr priv;
+ const char *file;
+ virDomainPtr dom;
+ unsigned int getxml_flags;
+ bool *ret;
+ unsigned int *define_flags;
+ const char *key;
+ virDomainPtr *dom_edited;
+} virshEditDomainUniversalStruct;
+
+static char *
+virshEditDomainSaveImageGetXML(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct *)args;
+ return virDomainSaveImageGetXMLDesc(str->priv->conn, str->file, str->getxml_flags);
+}
+
+static void
+virshEditDomainSaveImageNotChanged(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ vshPrint(str->ctl, _("Saved image %s XML configuration not changed.\n"), str->file);
+ *(str->ret) = true;
+}
+
+static bool
+virshEditDomainSaveIageDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ return (virDomainSaveImageDefineXML(str->priv->conn, str->file,
+ doc_edited, *(str->define_flags)) == 0);
+}
+
static bool
cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -4647,20 +4686,22 @@ cmdSaveImageEdit(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &file) < 0)
return false;
-
-#define EDIT_GET_XML \
- virDomainSaveImageGetXMLDesc(priv->conn, file, getxml_flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Saved image %s XML configuration " \
- "not changed.\n"), file); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (virDomainSaveImageDefineXML(priv->conn, file, doc_edited, define_flags) == 0)
-#include "virsh-edit.c"
-
+ {
+ virshEditDomainUniversalStruct editDomainArgs = {
+ NULL, priv, file, NULL, getxml_flags,
+ &ret, &define_flags, NULL, NULL
+ };
+ virshEditControl editCtl = {
+ &virshEditDomainSaveImageGetXML,
+ &virshEditDomainSaveImageNotChanged,
+ &virshEditDomainSaveIageDefine,
+ NULL,
+ &editDomainArgs,
+ };
+
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("State file %s edited.\n"), file);
ret = true;
@@ -8145,6 +8186,30 @@ virshDomainGetEditMetadata(vshControl *ctl,
return ret;
}
+static char *
+virshEditDomainMetadataGetXML(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)(args);
+ return virshDomainGetEditMetadata(str->ctl, str->dom, str->file, str->getxml_flags);
+}
+
+static void
+virshEditMetadataNotChanged(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ vshPrint(str->ctl, "%s", _("Metadata not changed"));
+ *(str->ret) = true;
+}
+
+static bool
+virshEditMetadataDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ return (virDomainSetMetadata(str->dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited,
+ str->key, str->file, *(str->define_flags)) == 0);
+}
static bool
cmdMetadata(vshControl *ctl, const vshCmd *cmd)
@@ -8196,20 +8261,19 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
else
vshPrint("%s\n", _("Metadata modified"));
} else if (edit) {
-#define EDIT_GET_XML \
- virshDomainGetEditMetadata(ctl, dom, uri, flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, "%s", _("Metadata not changed")); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-
-#define EDIT_DEFINE \
- (virDomainSetMetadata(dom, VIR_DOMAIN_METADATA_ELEMENT, doc_edited, \
- key, uri, flags) == 0)
-#include "virsh-edit.c"
-
+ virshEditDomainUniversalStruct editMetadataArgs = {
+ ctl, NULL, uri, dom,
+ flags, &ret, &flags, key, NULL
+ };
+ virshEditControl editCtl = {
+ &virshEditDomainMetadataGetXML,
+ &virshEditMetadataNotChanged,
+ &virshEditMetadataDefine,
+ NULL,
+ &editMetadataArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
vshPrint("%s\n", _("Metadata modified"));
} else {
char *data;
@@ -11764,6 +11828,40 @@ static const vshCmdOptDef opts_edit[] = {
{.name = NULL}
};
+static char *
+virshEditDomainGetXML(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ return virDomainGetXMLDesc(str->dom, str->getxml_flags);
+}
+
+static void
+virshEditDomainNotChanged(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ vshPrint(str->ctl, _("Domain %s XML configuration not changed.\n"),
+ virDomainGetName(str->dom));
+ *(str->ret) = true;
+}
+
+static bool
+virshEditDomainDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ return
+ (*(str->dom_edited) = virshDomainDefine(str->priv->conn, doc_edited,
+ *(str->define_flags)));
+}
+
+static void
+virshEditDomainRelax(void *args)
+{
+ virshEditDomainUniversalStruct *str = (virshEditDomainUniversalStruct*)args;
+ *(str->define_flags) &= ~VIR_DOMAIN_DEFINE_VALIDATE;
+}
+
static bool
cmdEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -11780,24 +11878,21 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "skip-validate"))
define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE;
-
-#define EDIT_GET_XML virDomainGetXMLDesc(dom, query_flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Domain %s XML configuration not changed.\n"), \
- virDomainGetName(dom)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (dom_edited = virshDomainDefine(priv->conn, doc_edited, define_flags))
-#define EDIT_RELAX \
- do { \
- define_flags &= ~VIR_DOMAIN_DEFINE_VALIDATE; \
- } while (0);
-
-#include "virsh-edit.c"
-#undef EDIT_RELAX
+ {
+ virshEditDomainUniversalStruct editDomainArgs = {
+ ctl, priv, NULL, dom,
+ query_flags, &ret, &define_flags, NULL, &dom_edited
+ };
+ virshEditControl editCtl = {
+ &virshEditDomainGetXML,
+ &virshEditDomainNotChanged,
+ &virshEditDomainDefine,
+ &virshEditDomainRelax,
+ &editDomainArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Domain %s XML configuration edited.\n"),
virDomainGetName(dom_edited));
diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c
index 1b39cb7..fdc2842 100644
--- a/tools/virsh-edit.c
+++ b/tools/virsh-edit.c
@@ -1,7 +1,7 @@
/*
- * virsh-edit.c: Implementation of generic virsh *-edit intelligence
+ * virsh-edit.c: Main function to edit in virsh
*
- * Copyright (C) 2012, 2015 Red Hat, Inc.
+ * Copyright (C) 2005, 2007-2015 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -17,45 +17,17 @@
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
- * Usage:
- * Define macros:
- * EDIT_GET_XML - expression which produces a pointer to XML string, e.g:
- * #define EDIT_GET_XML virDomainGetXMLDesc(dom, flags)
- *
- * EDIT_NOT_CHANGED - this action is taken if the XML wasn't changed.
- * Note, that you don't want to jump to cleanup but edit_cleanup label
- * where temporary variables are free()-d and temporary file is deleted:
- * #define EDIT_NOT_CHANGED vshPrint(ctl, _("Domain %s XML not changed"), \
- * virDomainGetName(dom)); \
- * ret = true; goto edit_cleanup;
- * Note that this is a statement.
- *
- * EDIT_DEFINE - expression which redefines the object. The edited XML from
- * user is in 'doc_edited' variable. Don't overwrite the pointer to the
- * object, as we may iterate once more over and therefore the pointer
- * would be invalid. Hence assign object to a different variable.
- * Moreover, this needs to be an expression where:
- * - 0 is taken as error (our virDefine* APIs often return NULL on error)
- * - everything else is taken as success
- * For example:
- * #define EDIT_DEFINE (dom_edited = virDomainDefineXML(ctl->conn, doc_edited))
- *
- * Michal Privoznik <mprivozn(a)redhat.com>
*/
-#ifndef EDIT_GET_XML
-# error Missing EDIT_GET_XML definition
-#endif
+#include <config.h>
+#include "internal.h"
-#ifndef EDIT_NOT_CHANGED
-# error Missing EDIT_NOT_CHANGED definition
-#endif
+#include "virsh-edit.h"
+#include "viralloc.h"
-#ifndef EDIT_DEFINE
-# error Missing EDIT_DEFINE definition
-#endif
-
-do {
+bool
+virshEdit(vshControl *ctl, virshEditControl *editCtl)
+{
char *tmp = NULL;
char *doc = NULL;
char *doc_edited = NULL;
@@ -65,7 +37,7 @@ do {
bool relax_avail = false;
/* Get the XML configuration of the object. */
- doc = (EDIT_GET_XML);
+ doc = (*editCtl->virshEditGetXML)(editCtl->virshEditArgs);
if (!doc)
goto edit_cleanup;
@@ -75,10 +47,8 @@ do {
goto edit_cleanup;
reedit:
-
-#ifdef EDIT_RELAX
- relax_avail = true;
-#endif
+ if (editCtl->virshEditRelax)
+ relax_avail = true;
/* Start the editor. */
if (vshEditFile(ctl, tmp) == -1)
@@ -91,8 +61,10 @@ do {
goto edit_cleanup;
/* Compare original XML with edited. Has it changed at all? */
- if (STREQ(doc, doc_edited))
- EDIT_NOT_CHANGED;
+ if (STREQ(doc, doc_edited)) {
+ (*editCtl->virshEditNotChanged)(editCtl->virshEditArgs);
+ goto edit_cleanup;
+ }
redefine:
msg = NULL;
@@ -102,7 +74,7 @@ do {
* losing a connection or the object going away.
*/
VIR_FREE(doc_reread);
- doc_reread = (EDIT_GET_XML);
+ doc_reread = (*editCtl->virshEditGetXML)(editCtl->virshEditArgs);
if (!doc_reread)
goto edit_cleanup;
@@ -114,7 +86,7 @@ do {
}
/* Everything checks out, so redefine the object. */
- if (!msg && !(EDIT_DEFINE))
+ if (!msg && !((*editCtl->virshEditDefine)(editCtl->virshEditArgs, doc_edited, doc)))
msg = _("Failed.");
if (msg) {
@@ -132,16 +104,14 @@ do {
goto edit_cleanup;
break;
-#ifdef EDIT_RELAX
case 'i':
if (relax_avail) {
- EDIT_RELAX;
+ (*editCtl->virshEditRelax)(editCtl->virshEditArgs);
relax_avail = false;
goto redefine;
break;
}
/* fall-through */
-#endif
default:
vshError(ctl, "%s", msg);
@@ -161,11 +131,6 @@ do {
}
if (!edit_success)
- goto cleanup;
-
-} while (0);
-
-
-#undef EDIT_GET_XML
-#undef EDIT_NOT_CHANGED
-#undef EDIT_DEFINE
+ return false;
+ return true;
+}
diff --git a/tools/virsh-edit.h b/tools/virsh-edit.h
new file mode 100644
index 0000000..9de3456
--- /dev/null
+++ b/tools/virsh-edit.h
@@ -0,0 +1,42 @@
+/*
+ * virsh-edit.h: Definition of generic virsh *-edit interface
+ *
+ * Copyright (C) 2012, 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __VIRSH_EDIT_H_
+#define __VIRSH_EDIT_H_
+
+#include "vsh.h"
+
+typedef char *(virshEditGetXMLCallback)(void *args);
+typedef void (virshEditNotChangedCallback)(void *args);
+typedef bool (virshEditDefineCallback)(void *args, char *doc_edited, char *doc);
+typedef void (virshEditRelaxCallback)(void *args);
+
+typedef struct virshEditControl {
+ virshEditGetXMLCallback *virshEditGetXML;
+ virshEditNotChangedCallback *virshEditNotChanged;
+ virshEditDefineCallback *virshEditDefine;
+ virshEditRelaxCallback *virshEditRelax;
+ void *virshEditArgs;
+} virshEditControl;
+
+bool virshEdit(vshControl *ctl, virshEditControl *editCtl);
+
+#endif // __VIRSH_EDIT_H_
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index b69c685..28b15c4 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -39,6 +39,7 @@
#include "virutil.h"
#include "virxml.h"
#include "virstring.h"
+#include "virsh-edit.h"
virInterfacePtr
virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
@@ -108,6 +109,42 @@ static const vshCmdOptDef opts_interface_edit[] = {
{.name = NULL}
};
+typedef struct virshEditInterfaceStruct
+{
+ vshControl *ctl;
+ virshControlPtr priv;
+ virInterfacePtr iface;
+ virInterfacePtr *iface_edited;
+ unsigned int flags;
+ bool *ret;
+} virshEditInterfaceStruct;
+
+static char *
+virshEditInterfaceGetXML(void *args)
+{
+ virshEditInterfaceStruct *str = (virshEditInterfaceStruct*)args;
+ return virInterfaceGetXMLDesc(str->iface, str->flags);
+}
+
+static void
+virshEditInterfaceNotChanged(void *args)
+{
+ virshEditInterfaceStruct *str = (virshEditInterfaceStruct*)args;
+ vshPrint(str->ctl, _("Interface %s XML configuration not changed.\n"),
+ virInterfaceGetName(str->iface));
+ *(str->ret) = true;
+}
+
+static bool
+virshEditInterfaceDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditInterfaceStruct *str = (virshEditInterfaceStruct*)args;
+ return (*(str->iface_edited) = virInterfaceDefineXML(str->priv->conn,
+ doc_edited, 0));
+}
+
static bool
cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -120,19 +157,20 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
iface = virshCommandOptInterface(ctl, cmd, NULL);
if (iface == NULL)
goto cleanup;
-
-#define EDIT_GET_XML virInterfaceGetXMLDesc(iface, flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Interface %s XML configuration not changed.\n"), \
- virInterfaceGetName(iface)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (iface_edited = virInterfaceDefineXML(priv->conn, doc_edited, 0))
-#include "virsh-edit.c"
-
+ {
+ virshEditInterfaceStruct editInterfaceArgs = {
+ ctl, priv, iface, &iface_edited, flags, &ret
+ };
+ virshEditControl editCtl = {
+ &virshEditInterfaceGetXML,
+ &virshEditInterfaceNotChanged,
+ &virshEditInterfaceDefine,
+ NULL,
+ &editInterfaceArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Interface %s XML configuration edited.\n"),
virInterfaceGetName(iface_edited));
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index a0f7707..0118adc 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -32,6 +32,7 @@
#include "virfile.h"
#include "virstring.h"
#include "conf/network_conf.h"
+#include "virsh-edit.h"
virNetworkPtr
virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
@@ -1121,6 +1122,41 @@ static char *virshNetworkGetXMLDesc(virNetworkPtr network)
return doc;
}
+typedef struct virshEditNetworkStruct
+{
+ vshControl *ctl;
+ virNetworkPtr network;
+ virNetworkPtr *network_edited;
+ virshControlPtr priv;
+ bool *ret;
+} virshEditNetworkStruct;
+
+static char *
+virshEditNetworkGetXML(void *args)
+{
+ virshEditNetworkStruct *str = (virshEditNetworkStruct*)args;
+ return virshNetworkGetXMLDesc(str->network);
+}
+
+static void
+virshEditNetworkNotChanged(void *args)
+{
+ virshEditNetworkStruct *str = (virshEditNetworkStruct*)args;
+ vshPrint(str->ctl, _("Network %s XML configuration not changed.\n"),
+ virNetworkGetName(str->network));
+ *(str->ret) = true;
+}
+
+static bool
+virshEditNetworkDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditNetworkStruct *str = (virshEditNetworkStruct*)args;
+ *(str->network_edited) = virNetworkDefineXML(str->priv->conn, doc_edited);
+ return *(str->network_edited);
+}
+
static bool
cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -1133,18 +1169,20 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
if (network == NULL)
goto cleanup;
-#define EDIT_GET_XML virshNetworkGetXMLDesc(network)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
- virNetworkGetName(network)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (network_edited = virNetworkDefineXML(priv->conn, doc_edited))
-#include "virsh-edit.c"
-
+ {
+ virshEditNetworkStruct editNetworkArgs = {
+ ctl, network, &network_edited, priv, &ret
+ };
+ virshEditControl editCtl = {
+ &virshEditNetworkGetXML,
+ &virshEditNetworkNotChanged,
+ &virshEditNetworkDefine,
+ NULL,
+ &editNetworkArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Network %s XML configuration edited.\n"),
virNetworkGetName(network_edited));
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index 7732da8..36677ca 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -31,6 +31,7 @@
#include "viralloc.h"
#include "virfile.h"
#include "virutil.h"
+#include "virsh-edit.h"
virNWFilterPtr
virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
@@ -404,6 +405,41 @@ static const vshCmdOptDef opts_nwfilter_edit[] = {
{.name = NULL}
};
+typedef struct virshEditNWFilterStruct
+{
+ vshControl *ctl;
+ virNWFilterPtr nwfilter;
+ virNWFilterPtr *nwfilter_edited;
+ virshControlPtr priv;
+ bool *ret;
+} virshEditNWFilterStruct;
+
+static char *
+virshEditNWFilterGetXML(void *args)
+{
+ virshEditNWFilterStruct *str = (virshEditNWFilterStruct*)args;
+ return virNWFilterGetXMLDesc(str->nwfilter, 0);
+}
+
+static void
+virshEditNWFilterNotChanged(void *args)
+{
+ virshEditNWFilterStruct *str = (virshEditNWFilterStruct*)args;
+ vshPrint(str->ctl, _("Network filter %s XML configuration not changed.\n"),
+ virNWFilterGetName(str->nwfilter));
+ *(str->ret) = true;
+}
+
+static bool
+virshEditNWFilterDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditNWFilterStruct *str = (virshEditNWFilterStruct*)args;
+ *(str->nwfilter_edited) = virNWFilterDefineXML(str->priv->conn, doc_edited);
+ return *(str->nwfilter_edited);
+}
+
static bool
cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -415,20 +451,20 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL);
if (nwfilter == NULL)
goto cleanup;
-
-#define EDIT_GET_XML virNWFilterGetXMLDesc(nwfilter, 0)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Network filter %s XML " \
- "configuration not changed.\n"), \
- virNWFilterGetName(nwfilter)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (nwfilter_edited = virNWFilterDefineXML(priv->conn, doc_edited))
-#include "virsh-edit.c"
-
+ {
+ virshEditNWFilterStruct editNWFilterArgs = {
+ ctl, nwfilter, &nwfilter_edited, priv, &ret
+ };
+ virshEditControl editCtl = {
+ &virshEditNWFilterGetXML,
+ &virshEditNWFilterNotChanged,
+ &virshEditNWFilterDefine,
+ NULL,
+ &editNWFilterArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Network filter %s XML configuration edited.\n"),
virNWFilterGetName(nwfilter_edited));
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index cf5a8f3..740a130 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -32,6 +32,7 @@
#include "virfile.h"
#include "conf/storage_conf.h"
#include "virstring.h"
+#include "virsh-edit.h"
virStoragePoolPtr
virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
@@ -1791,6 +1792,42 @@ static const vshCmdOptDef opts_pool_edit[] = {
{.name = NULL}
};
+typedef struct virshEditStoragePoolStruct
+{
+ vshControl *ctl;
+ virStoragePoolPtr pool;
+ virStoragePoolPtr *pool_edited;
+ virshControlPtr priv;
+ bool *ret;
+ unsigned int flags;
+} virshEditStoragePoolStruct;
+
+static char *
+virshEditStoragePoolGetXML(void *args)
+{
+ virshEditStoragePoolStruct *str = (virshEditStoragePoolStruct*)args;
+ return virStoragePoolGetXMLDesc(str->pool, str->flags);
+}
+
+static void
+virshEditStoragePoolNotChanged(void *args)
+{
+ virshEditStoragePoolStruct *str = (virshEditStoragePoolStruct*)args;
+ vshPrint(str->ctl, _("Pool %s XML configuration not changed.\n"),
+ virStoragePoolGetName(str->pool));
+ *(str->ret) = true;
+}
+
+static bool
+virshEditStoragePoolDefine(void *args, char *doc_edited, char *doc)
+{
+ if (!doc)
+ return false;
+ virshEditStoragePoolStruct *str = (virshEditStoragePoolStruct*)args;
+ return (*(str->pool_edited) =
+ virStoragePoolDefineXML(str->priv->conn, doc_edited, 0));
+}
+
static bool
cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -1816,19 +1853,20 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd)
} else {
VIR_FREE(tmp_desc);
}
-
-#define EDIT_GET_XML virStoragePoolGetXMLDesc(pool, flags)
-#define EDIT_NOT_CHANGED \
- do { \
- vshPrint(ctl, _("Pool %s XML configuration not changed.\n"), \
- virStoragePoolGetName(pool)); \
- ret = true; \
- goto edit_cleanup; \
- } while (0)
-#define EDIT_DEFINE \
- (pool_edited = virStoragePoolDefineXML(priv->conn, doc_edited, 0))
-#include "virsh-edit.c"
-
+ {
+ virshEditStoragePoolStruct editStoragePoolArgs = {
+ ctl, pool, &pool_edited, priv, &ret, flags
+ };
+ virshEditControl editCtl = {
+ &virshEditStoragePoolGetXML,
+ &virshEditStoragePoolNotChanged,
+ &virshEditStoragePoolDefine,
+ NULL,
+ &editStoragePoolArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
vshPrint(ctl, _("Pool %s XML configuration edited.\n"),
virStoragePoolGetName(pool_edited));
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 3ab2104..908dcfd 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -41,6 +41,7 @@
#include "virstring.h"
#include "virxml.h"
#include "conf/snapshot_conf.h"
+#include "virsh-edit.h"
/* Helper for snapshot-create and snapshot-create-as */
static bool
@@ -548,6 +549,47 @@ static const vshCmdOptDef opts_snapshot_edit[] = {
{.name = NULL}
};
+typedef struct virshEditSnapshotStruct
+{
+ vshControl *ctl;
+ virDomainSnapshotPtr snapshot;
+ virDomainSnapshotPtr *edited;
+ virDomainPtr dom;
+ bool *ret;
+ unsigned int getxml_flags;
+ unsigned int *define_flags;
+ const char *name;
+} virshEditSnapshotStruct;
+
+static char *
+virshEditSnapshotGetXML(void *args)
+{
+ virshEditSnapshotStruct *str = (virshEditSnapshotStruct*)args;
+ return virDomainSnapshotGetXMLDesc(str->snapshot, str->getxml_flags);
+}
+
+static void
+virshEditSnapshotNotChanged(void *args)
+{
+ virshEditSnapshotStruct *str = (virshEditSnapshotStruct*)args;
+ /* Depending on flags, we re-edit even if XML is unchanged. */
+ if (!(*(str->define_flags) & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) {
+ vshPrint(str->ctl, _("Snapshot %s XML configuration not changed.\n"),
+ str->name);
+ *(str->ret) = true;
+ }
+}
+
+static bool
+virshEditSnapshotDefine(void *args, char *doc_edited, char *doc)
+{
+ virshEditSnapshotStruct *str = (virshEditSnapshotStruct*)args;
+ (strstr(doc, "<state>disk-snapshot</state>") ?
+ *(str->define_flags) |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY : 0);
+ return (*(str->edited) = virDomainSnapshotCreateXML(str->dom, doc_edited,
+ *(str->define_flags)));
+}
+
static bool
cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
{
@@ -574,26 +616,20 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
if (virshLookupSnapshot(ctl, cmd, "snapshotname", false, dom,
&snapshot, &name) < 0)
goto cleanup;
-
-#define EDIT_GET_XML \
- virDomainSnapshotGetXMLDesc(snapshot, getxml_flags)
-#define EDIT_NOT_CHANGED \
- do { \
- /* Depending on flags, we re-edit even if XML is unchanged. */ \
- if (!(define_flags & VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)) { \
- vshPrint(ctl, \
- _("Snapshot %s XML configuration not changed.\n"), \
- name); \
- ret = true; \
- goto edit_cleanup; \
- } \
- } while (0)
-#define EDIT_DEFINE \
- (strstr(doc, "<state>disk-snapshot</state>") ? \
- define_flags |= VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY : 0), \
- edited = virDomainSnapshotCreateXML(dom, doc_edited, define_flags)
-#include "virsh-edit.c"
-
+ {
+ virshEditSnapshotStruct editSnapshotArgs = {
+ ctl, snapshot, &edited, dom, &ret, getxml_flags, &define_flags, name
+ };
+ virshEditControl editCtl = {
+ &virshEditSnapshotGetXML,
+ &virshEditSnapshotNotChanged,
+ &virshEditSnapshotDefine,
+ NULL,
+ &editSnapshotArgs,
+ };
+ if (!virshEdit(ctl, &editCtl))
+ goto cleanup;
+ }
edited_name = virDomainSnapshotGetName(edited);
if (STREQ(name, edited_name)) {
vshPrint(ctl, _("Snapshot %s edited.\n"), name);
--
2.1.4
9 years, 2 months
[libvirt] [PATCH] virsh: improve waiting for block job readiness
by Michael Chapman
Wait for a block job event after the job has reached 100% only if
exactly one of the BLOCK_JOB and BLOCK_JOB_2 callbacks were successfully
registered.
If neither callback was registered, then no event will ever be received.
If both were registered, then any user-supplied path is guaranteed to
match one of the events.
Signed-off-by: Michael Chapman <mike(a)very.puzzling.org>
---
I have found that even a 2.5 second timeout isn't always sufficiently
long for QEMU to flush a disk at the end of a block job.
I hope I've understood the code properly here, because as far as I can
tell the comment I'm removing in this commit isn't right. The path the
user supplies *has* to be either the <source file='name'/> or <target
dev='name'/> exactly in order for the disk to be matched, and these are
precisely the two strings used by the two events.
tools/virsh-domain.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index edbbc34..60de9ba 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1942,18 +1942,20 @@ virshBlockJobWait(virshBlockJobWaitDataPtr data)
goto cleanup;
}
- /* since virsh can't guarantee that the path provided by the user will
- * later be matched in the event we will need to keep the fallback
- * approach and claim success if the block job finishes or vanishes. */
- if (result == 0)
- break;
+ /* if either event could not be registered we can't guarantee that the
+ * path provided by the user will be matched, so keep the fallback
+ * approach and claim success if the block job finishes or vanishes */
+ if (data->cb_id2 < 0 || data->cb_id2 < 0) {
+ if (result == 0)
+ break;
- /* for two-phase jobs we will try to wait in the synchronized phase
- * for event arrival since 100% completion doesn't necessarily mean that
- * the block job has finished and can be terminated with success */
- if (info.end == info.cur && --retries == 0) {
- ret = VIR_DOMAIN_BLOCK_JOB_READY;
- goto cleanup;
+ /* only wait in the synchronized phase for event arrival if
+ * either callback was registered */
+ if (info.end == info.cur &&
+ ((data->cb_id2 < 0 && data->cb_id2 < 0) || --retries == 0)) {
+ ret = VIR_DOMAIN_BLOCK_JOB_READY;
+ goto cleanup;
+ }
}
if (data->verbose)
--
2.4.3
9 years, 2 months
[libvirt] [PATCH 0/2] Various RHEL 6 bugfixes
by Michael Chapman
This patch set fixes a couple of minor bugs I discovered while building
libvirt v1.3.0 for RHEL 6.
Michael Chapman (2):
spec: fix builds on RHEL <= 6
virtlogd: fix lock file path in initscript
libvirt.spec.in | 8 ++++----
src/logging/virtlogd.init.in | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
--
2.4.3
9 years, 2 months
[libvirt] [PATCH 0/2] qemu: Fix up overflow when aligning memory sizes.
by Peter Krempa
Peter Krempa (2):
schema: Allow > UINT_MAX KiB of memory for NUMA nodes
qemu: domain: Prevent overflows in memory alignment code
docs/schemas/domaincommon.rng | 4 +--
src/qemu/qemu_domain.c | 27 ++++++++++++++++++++
.../qemuxml2argv-memory-align-fail.xml | 29 ++++++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
4 files changed, 58 insertions(+), 3 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-memory-align-fail.xml
--
2.6.2
9 years, 2 months
[libvirt] [PATCHv2 1/3] conf: introduce 'autodeflate' attribute for memballoon device
by Dmitry Andreev
Excessive memory balloon inflation can cause invocation of OOM-killer,
when Linux is under severe memory pressure. QEMU memballoon device
has a feature to release some memory at the last moment before some
process will be get killed by OOM-killer.
Introduced attribute allows to enable or disable this feature.
---
docs/formatdomain.html.in | 10 ++++++++++
docs/schemas/domaincommon.rng | 5 +++++
src/conf/domain_conf.c | 23 +++++++++++++++++++++++
src/conf/domain_conf.h | 1 +
4 files changed, 39 insertions(+)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index a8bd48e..7d04471 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -5954,6 +5954,16 @@ qemu-kvm -net nic,model=? /dev/null
<li>'xen' — default with Xen</li>
</ul>
</dd>
+ <dt><code>autodeflate</code></dt>
+ <dd>
+ <p>
+ The optional <code>autodeflate</code> attribute allows to
+ enable/disable (values "on"/"off", respectively) the ability of the
+ QEMU virtio memory balloon to release some memory at the last moment
+ before a guest's process get killed by OOM-killer.
+ <span class="since">Since 1.3.1, QEMU and KVM only</span>
+ </p>
+ </dd>
<dt><code>period</code></dt>
<dd>
<p>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4804c69..512a268 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3415,6 +3415,11 @@
<value>none</value>
</choice>
</attribute>
+ <optional>
+ <attribute name="autodeflate">
+ <ref name="virOnOff"/>
+ </attribute>
+ </optional>
<interleave>
<optional>
<ref name="alias"/>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5200c27..0786d08 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11312,6 +11312,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
unsigned int flags)
{
char *model;
+ char *deflate;
virDomainMemballoonDefPtr def;
xmlNodePtr save = ctxt->node;
unsigned int period = 0;
@@ -11332,6 +11333,13 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
goto error;
}
+ if ((deflate = virXMLPropString(node, "autodeflate")) &&
+ (def->autodeflate = virTristateSwitchTypeFromString(deflate)) <= 0) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("invalid autodeflate attribute value '%s'"), deflate);
+ goto error;
+ }
+
ctxt->node = node;
if (virXPathUInt("string(./stats/@period)", ctxt, &period) < -1) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -11350,6 +11358,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node,
cleanup:
VIR_FREE(model);
+ VIR_FREE(deflate);
ctxt->node = save;
return def;
@@ -17223,6 +17232,15 @@ virDomainMemballoonDefCheckABIStability(virDomainMemballoonDefPtr src,
return false;
}
+ if (src->autodeflate != dst->autodeflate) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Target balloon autodeflate attribute value "
+ "'%s' does not match source '%s'"),
+ virTristateSwitchTypeToString(dst->autodeflate),
+ virTristateSwitchTypeToString(src->autodeflate));
+ return false;
+ }
+
if (!virDomainDeviceInfoCheckABIStability(&src->info, &dst->info))
return false;
@@ -20400,6 +20418,11 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
}
virBufferAsprintf(buf, "<memballoon model='%s'", model);
+
+ if (def->autodeflate != VIR_TRISTATE_SWITCH_ABSENT)
+ virBufferAsprintf(buf, " autodeflate='%s'",
+ virTristateSwitchTypeToString(def->autodeflate));
+
virBufferAdjustIndent(&childrenBuf, indent + 2);
if (def->period)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 952d3cc..31a0a05 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1634,6 +1634,7 @@ struct _virDomainMemballoonDef {
int model;
virDomainDeviceInfo info;
int period; /* seconds between collections */
+ int autodeflate; /* enum virTristateSwitch */
};
struct _virDomainNVRAMDef {
--
1.8.3.1
9 years, 3 months