[libvirt] [PATCH v2] fix LSB part of virtlogd runlevel script
by Olaf Hering
Currently pkg build of master branch fails:
[ 300s] + /usr/lib/rpm/brp-boot-scripts
[ 300s] E: File `virtlogd' is missing `Required-Start', please add even if empty!
[ 300s] W: File `virtlogd' is missing `Required-Stop', please add even if empty!
[ 300s] E: File `virtlogd' has empty `Default-Start', please specify default runlevel(s)!
[ 300s] ERROR: found one or more broken init or boot scripts, please fix them.
[ 300s] For more information about LSB headers please read the manual
[ 300s] page of of insserv by executing the command `man 8 insserv'.
[ 300s] If you don't understand this, mailto=werner(a)suse.de
[ 300s] error: Bad exit status from /var/tmp/rpm-tmp.44965 (%install)
Add the required tags, fix the existing tags.
Use soft dependency "Should-Start" because virtlogd may work without network.
Signed-off-by: Olaf Hering <olaf(a)aepfle.de>
---
v2: fix colon in Should-stop
src/logging/virtlogd.init.in | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/logging/virtlogd.init.in b/src/logging/virtlogd.init.in
index 1408236..dadc343 100644
--- a/src/logging/virtlogd.init.in
+++ b/src/logging/virtlogd.init.in
@@ -5,8 +5,12 @@
#
### BEGIN INIT INFO
# Provides: virtlogd
-# Default-Start:
-# Default-Stop: 0 1 2 3 4 5 6
+# Default-Start: 3 5
+# Required-Start:
+# Required-Stop:
+# Should-Start: $network $remote_fs
+# Should-Stop: $network $remote_fs
+# Default-Stop: 0 1 2 4 6
# Short-Description: virtual machine log manager
# Description: This is a daemon for managing logs
# of virtual machine consoles
8 years, 10 months
[libvirt] <interface type='hostdev'>vf configuration cleanup when VM is delete
by Moshe Levi
Hi,
I have a setup with libvirt 1.3.0 and OpenStack trunk.
Before launched the VM ip link command show the following VF mac/vlan configuration [1]
When I launch a VM with <interface type='hostdev'> via openstack api (OpenStack direct port)
I can see that the VF get the mac/vlan according to libvrit xml [2] and ip link command [3], but when I delete the VM the mac/vlan config are still shown as in [3] and not restored to [1]
Shouldn't libvirt restore the mac/vlan to [1].
The same problem exists when using <interface type='direct'> (OpenStack macvtap port) but just for the MAC configuration of the VF.
[1] - 24: enp3s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ovs-system state UP mode DEFAULT group default qlen 1000
link/ether e4:1d:2d:a5:f1:22 brd ff:ff:ff:ff:ff:ff
vf 0 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
vf 1 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
vf 2 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
vf 3 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
[2] - <interface type='hostdev' managed='yes'>
<mac address=' fa:16:3e:11:af:fe '/>
<driver name='kvm'/>
<source>
<address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x7'/>
</source>
<vlan>
<tag id='190'/>
</vlan>
<alias name='hostdev0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</interface>
[3] 24: enp3s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ovs-system state UP mode DEFAULT group default qlen 1000
link/ether e4:1d:2d:a5:f1:22 brd ff:ff:ff:ff:ff:ff
vf 0 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
vf 1 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
vf 2 MAC 00:00:00:00:00:00, spoof checking off, link-state auto
vf 3 MAC fa:16:3e:11:af:fe, vlan 190, spoof checking off, link-state enable
8 years, 10 months
[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
8 years, 10 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
8 years, 10 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
8 years, 10 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
8 years, 10 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
8 years, 10 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
8 years, 10 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
8 years, 10 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
8 years, 10 months