Re: [libvirt] Entering freeze for libvirt-1.0.5
On 04/26/2013 08:19 PM, Ján Tomko wrote: A fix that doesn't assign a PCI address for model=none USB controller is pushed now. I can confirm this is working. Thanks! If we really have to do a workaround, I'd suggest just ignoring the PCI root and assuming one PCI bus is always there. I fear adding PCI roots to machines that don't have them would cause us similar trouble that the implicit USB controller does now. Fully agree. The only reason that I suggested a dummy root as a stop gap measure was to avoid that we rush in potentially untested code. The current code base will carry us a while, but eventually we need to get rid of the implicit devices where they are not applicable. Thanks again for fixing the issues. -- Mit freundlichen Grüßen/Kind Regards Viktor Mihajlovski IBM Deutschland Research Development GmbH Vorsitzender des Aufsichtsrats: Martina Köderitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [Xen-devel] libvirt, libxl and QDISKs
Hi Jim, Thanks for the explanation about the capabilities. On 27/04/13 00:44, Jim Fehlig wrote: Do you have time for an upstream libvirt patch to expose the possible emulators in the capabilities, along with this patch allowing the user to specify one? I'll have a go and send you (cc'ing the libvirt list) what I manage to come up with. Cheers, Dave -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-java] [Patch] remove unused imports
Hi, Clean up all java classes which have imports which are not used. Greetings Stefan Majer --- src/main/java/org/libvirt/Device.java |1 - src/main/java/org/libvirt/Domain.java |1 - src/main/java/org/libvirt/DomainSnapshot.java |1 - src/main/java/org/libvirt/ErrorHandler.java |1 - src/main/java/org/libvirt/Interface.java |1 - src/main/java/org/libvirt/StorageVol.java |1 - 6 files changed, 6 deletions(-) diff --git a/src/main/java/org/libvirt/Device.java b/src/main/java/org/libvirt/Device.java index 416e06a..fe49ce9 100644 --- a/src/main/java/org/libvirt/Device.java +++ b/src/main/java/org/libvirt/Device.java @@ -1,7 +1,6 @@ package org.libvirt; import org.libvirt.jna.DevicePointer; -import org.libvirt.jna.Libvirt; import static org.libvirt.Library.libvirt; /** diff --git a/src/main/java/org/libvirt/Domain.java b/src/main/java/org/libvirt/Domain.java index 12ff7f5..85de9b3 100644 --- a/src/main/java/org/libvirt/Domain.java +++ b/src/main/java/org/libvirt/Domain.java @@ -17,7 +17,6 @@ import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.ptr.IntByReference; -import com.sun.jna.ptr.PointerByReference; /** * A virtual machine defined within libvirt. diff --git a/src/main/java/org/libvirt/DomainSnapshot.java b/src/main/java/org/libvirt/DomainSnapshot.java index 355d9d0..b58fd20 100644 --- a/src/main/java/org/libvirt/DomainSnapshot.java +++ b/src/main/java/org/libvirt/DomainSnapshot.java @@ -1,7 +1,6 @@ package org.libvirt; import org.libvirt.jna.DomainSnapshotPointer; -import org.libvirt.jna.Libvirt; import static org.libvirt.Library.libvirt; public class DomainSnapshot { diff --git a/src/main/java/org/libvirt/ErrorHandler.java b/src/main/java/org/libvirt/ErrorHandler.java index 4dd7c90..434c85d 100644 --- a/src/main/java/org/libvirt/ErrorHandler.java +++ b/src/main/java/org/libvirt/ErrorHandler.java @@ -1,6 +1,5 @@ package org.libvirt; -import org.libvirt.jna.ConnectionPointer; import org.libvirt.jna.Libvirt; import org.libvirt.jna.virError; diff --git a/src/main/java/org/libvirt/Interface.java b/src/main/java/org/libvirt/Interface.java index 71ba3da..7782fb9 100644 --- a/src/main/java/org/libvirt/Interface.java +++ b/src/main/java/org/libvirt/Interface.java @@ -1,7 +1,6 @@ package org.libvirt; import org.libvirt.jna.InterfacePointer; -import org.libvirt.jna.Libvirt; import static org.libvirt.Library.libvirt; import com.sun.jna.Pointer; diff --git a/src/main/java/org/libvirt/StorageVol.java b/src/main/java/org/libvirt/StorageVol.java index 39776b2..561cb4d 100644 --- a/src/main/java/org/libvirt/StorageVol.java +++ b/src/main/java/org/libvirt/StorageVol.java @@ -1,6 +1,5 @@ package org.libvirt; -import org.libvirt.jna.Libvirt; import org.libvirt.jna.StoragePoolPointer; import org.libvirt.jna.StorageVolPointer; import org.libvirt.jna.virStorageVolInfo; -- 1.7.9.5 -- Stefan Majer -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] qemu: Error out if spice port autoallocation is requested, but disabled
When a user requests auto-allocation of the spice TLS port but spice TLS is disabled in qemu.conf, we start the machine and let qemu fail instead of erroring out sooner. Add an error message so that this doesn't happen. --- src/qemu/qemu_process.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index f12d7d5..e81e57f 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3292,8 +3292,14 @@ qemuProcessSPICEAllocatePorts(virQEMUDriverPtr driver, graphics-data.spice.port = port; } -if (cfg-spiceTLS -(needTLSPort || graphics-data.spice.tlsPort == -1)) { +if (needTLSPort || graphics-data.spice.tlsPort == -1) { +if (!cfg-spiceTLS) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s, + _(Auto allocation of spice TLS port requested + but spice is disabled in qemu.conf)); +goto error; +} + if (virPortAllocatorAcquire(driver-remotePorts, tlsPort) 0) goto error; -- 1.8.2.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] network: Don't remove transient network if creating of config file fails
On 04/22/13 11:32, Peter Krempa wrote: On the off-chance that creation of persistent configuration file would fail when defining a network that is already started as transient, the code would remove the transient data structure and thus the network. This patch changes the code so that in such case, the network is again marked as transient and left behind. --- src/network/bridge_driver.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) Could somebody please have a look on this patch? Thanks. Peter -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-java] [Patch] remove unused imports
Hi. At Mon, 29 Apr 2013 12:36:20 +0200, Stefan Majer wrote: Hi, Clean up all java classes which have imports which are not used. Greetings Stefan Majer This part would be directly included in the git commit message. You (most likely) don't want that. Could you send your patches using git send-email the next time, or at least stop sending HTML email to the list? It's easier to review that way. Thanks. Apart from that, this patch is a quite trivial cleanup and the code still compiles. So, ACK and pushed with the above comment removed, plus capitalized first word in the subject. - Claudio -- AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany Phone: +49 341 265 310 19 Web:http://www.av-test.org Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076) Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Resolve valgrind error
As a result of commit id '19c345f2', 'make -C tests valgrind' has the following for qemuxml2argvtest: ==22482== 197 (80 direct, 117 indirect) bytes in 1 blocks are definitely lost in loss record 101 of 120 ==22482==at 0x4A06B6F: calloc (vg_replace_malloc.c:593) ==22482==by 0x4C6F301: virAlloc (viralloc.c:124) ==22482==by 0x4C840FC: virSaveLastError (virerror.c:308) ==22482==by 0x431882: qemuBuildCommandLine (qemu_command.c:8204) ==22482==by 0x41E8F0: testCompareXMLToArgvHelper (qemuxml2argvtest.c:155) ==22482==by 0x41FE9F: virtTestRun (testutils.c:157) ==22482==by 0x419DEB: mymain (qemuxml2argvtest.c:654) ==22482==by 0x4204DA: virtTestMain (testutils.c:719) ==22482==by 0x39D0821A04: (below main) (libc-start.c:225) ==22482== --- src/qemu/qemu_command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..421a93c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8205,6 +8205,7 @@ error: for (i = 0; i = last_good_net; i++) virDomainConfNWFilterTeardown(def-nets[i]); virSetError(originalError); +virFreeError(originalError); virCommandFree(cmd); return NULL; } -- 1.8.1.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] qemu: Do fake auto-allocation of ports when generating native command
When attempting to generate the native command line from an XML file that uses graphics port auto allocation, the generated commandline wouldn't be valid. This patch adds fake autoallocation of ports as done when starting the actual machine. --- src/qemu/qemu_driver.c | 51 ++ 1 file changed, 51 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..cec4a7a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,57 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, if (qemuAssignDeviceAliases(def, qemuCaps) 0) goto cleanup; +/* do fake auto-alloc of graphics ports, if such config is used */ +for (i = 0 ; i vm-def-ngraphics; ++i) { +virDomainGraphicsDefPtr graphics = vm-def-graphics[i]; +if (graphics-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC +!graphics-data.vnc.socket graphics-data.vnc.autoport) { +graphics-data.vnc.port = 5900; +} else if (graphics-type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { +int j; +bool needTLSPort = false; +bool needPort = false; + +if (graphics-data.spice.autoport) { +/* check if tlsPort or port need allocation */ +for (j = 0 ; j VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST ; j++) { +switch (graphics-data.spice.channels[j]) { +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE: +needTLSPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE: +needPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY: +switch (defaultMode) { +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE: +needTLSPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE: +needPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY: +needTLSPort = true; +needPort = true; +break; +} +break; +} +} +} + +if (needPort || graphics-data.spice.port == -1) +graphics-data.spice.port = 5901; + +if (needTLSPort || graphics-data.spice.tlsPort == -1) +graphics-data.spice.tlsPort = 5902; +} +} + if (!(cmd = qemuBuildCommandLine(conn, driver, def, monConfig, monitor_json, qemuCaps, NULL, -1, NULL, VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) -- 1.8.2.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCHv2] qemu: Do fake auto-allocation of ports when generating native command
When attempting to generate the native command line from an XML file that uses graphics port auto allocation, the generated commandline wouldn't be valid. This patch adds fake autoallocation of ports as done when starting the actual machine. --- src/qemu/qemu_driver.c | 52 ++ 1 file changed, 52 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..068d6c4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,58 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, if (qemuAssignDeviceAliases(def, qemuCaps) 0) goto cleanup; +/* do fake auto-alloc of graphics ports, if such config is used */ +for (i = 0 ; i def-ngraphics; ++i) { +virDomainGraphicsDefPtr graphics = def-graphics[i]; +if (graphics-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC +!graphics-data.vnc.socket graphics-data.vnc.autoport) { +graphics-data.vnc.port = 5900; +} else if (graphics-type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) { +int j; +bool needTLSPort = false; +bool needPort = false; +int defaultMode = graphics-data.spice.defaultMode; + +if (graphics-data.spice.autoport) { +/* check if tlsPort or port need allocation */ +for (j = 0 ; j VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_LAST ; j++) { +switch (graphics-data.spice.channels[j]) { +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE: +needTLSPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE: +needPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY: +switch (defaultMode) { +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_SECURE: +needTLSPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_INSECURE: +needPort = true; +break; + +case VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE_ANY: +needTLSPort = true; +needPort = true; +break; +} +break; +} +} +} + +if (needPort || graphics-data.spice.port == -1) +graphics-data.spice.port = 5901; + +if (needTLSPort || graphics-data.spice.tlsPort == -1) +graphics-data.spice.tlsPort = 5902; +} +} + if (!(cmd = qemuBuildCommandLine(conn, driver, def, monConfig, monitor_json, qemuCaps, NULL, -1, NULL, VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) -- 1.8.2.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Do fake auto-allocation of ports when generating native command
On 04/29/13 14:39, Peter Krempa wrote: When attempting to generate the native command line from an XML file that uses graphics port auto allocation, the generated commandline wouldn't be valid. This patch adds fake autoallocation of ports as done when starting the actual machine. --- src/qemu/qemu_driver.c | 51 ++ 1 file changed, 51 insertions(+) Self NACK. I forgot to commit a few changes. Peter -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Resolve valgrind error
On 29.04.2013 14:35, John Ferlan wrote: As a result of commit id '19c345f2', 'make -C tests valgrind' has the following for qemuxml2argvtest: ==22482== 197 (80 direct, 117 indirect) bytes in 1 blocks are definitely lost in loss record 101 of 120 ==22482==at 0x4A06B6F: calloc (vg_replace_malloc.c:593) ==22482==by 0x4C6F301: virAlloc (viralloc.c:124) ==22482==by 0x4C840FC: virSaveLastError (virerror.c:308) ==22482==by 0x431882: qemuBuildCommandLine (qemu_command.c:8204) ==22482==by 0x41E8F0: testCompareXMLToArgvHelper (qemuxml2argvtest.c:155) ==22482==by 0x41FE9F: virtTestRun (testutils.c:157) ==22482==by 0x419DEB: mymain (qemuxml2argvtest.c:654) ==22482==by 0x4204DA: virtTestMain (testutils.c:719) ==22482==by 0x39D0821A04: (below main) (libc-start.c:225) ==22482== --- src/qemu/qemu_command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..421a93c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8205,6 +8205,7 @@ error: for (i = 0; i = last_good_net; i++) virDomainConfNWFilterTeardown(def-nets[i]); virSetError(originalError); +virFreeError(originalError); virCommandFree(cmd); return NULL; } ACK Although, I think there are some other places where virSetError is not followed by virFreeError, e.g. src/network/bridge_driver.c:2143 Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv2] qemu: Do fake auto-allocation of ports when generating native command
On 29.04.2013 14:42, Peter Krempa wrote: When attempting to generate the native command line from an XML file that uses graphics port auto allocation, the generated commandline wouldn't be valid. This patch adds fake autoallocation of ports as done when starting the actual machine. --- src/qemu/qemu_driver.c | 52 ++ 1 file changed, 52 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..068d6c4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,58 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, ... + +if (needPort || graphics-data.spice.port == -1) +graphics-data.spice.port = 5901; + +if (needTLSPort || graphics-data.spice.tlsPort == -1) +graphics-data.spice.tlsPort = 5902; Shouldn't we be using virPortAllocator to set these ports instead of hardcoding these values? What if these ports are already taken (by previously started domain for instance)? Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv2] qemu: Do fake auto-allocation of ports when generating native command
On Mon, Apr 29, 2013 at 02:48:54PM +0200, Michal Privoznik wrote: On 29.04.2013 14:42, Peter Krempa wrote: When attempting to generate the native command line from an XML file that uses graphics port auto allocation, the generated commandline wouldn't be valid. This patch adds fake autoallocation of ports as done when starting the actual machine. --- src/qemu/qemu_driver.c | 52 ++ 1 file changed, 52 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..068d6c4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,58 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, ... + +if (needPort || graphics-data.spice.port == -1) +graphics-data.spice.port = 5901; + +if (needTLSPort || graphics-data.spice.tlsPort == -1) +graphics-data.spice.tlsPort = 5902; Shouldn't we be using virPortAllocator to set these ports instead of hardcoding these values? What if these ports are already taken (by previously started domain for instance)? Ensuring the ports are not in use, is outside the scope of the XMLToNative API, so I think hardcoding them is correct. Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCHv2] qemu: Do fake auto-allocation of ports when generating native command
On 04/29/13 14:48, Michal Privoznik wrote: On 29.04.2013 14:42, Peter Krempa wrote: When attempting to generate the native command line from an XML file that uses graphics port auto allocation, the generated commandline wouldn't be valid. This patch adds fake autoallocation of ports as done when starting the actual machine. --- src/qemu/qemu_driver.c | 52 ++ 1 file changed, 52 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..068d6c4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,58 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, ... + +if (needPort || graphics-data.spice.port == -1) +graphics-data.spice.port = 5901; + +if (needTLSPort || graphics-data.spice.tlsPort == -1) +graphics-data.spice.tlsPort = 5902; Shouldn't we be using virPortAllocator to set these ports instead of hardcoding these values? What if these ports are already taken (by previously started domain for instance)? This is in domxml-to-native. I don't think we care if the ports are taken when that API is used. (I'm not even sure if we care enough to work around auto allocation there). Michal Peter -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Resolve valgrind error
On 04/29/2013 08:45 AM, Michal Privoznik wrote: On 29.04.2013 14:35, John Ferlan wrote: As a result of commit id '19c345f2', 'make -C tests valgrind' has the following for qemuxml2argvtest: ==22482== 197 (80 direct, 117 indirect) bytes in 1 blocks are definitely lost in loss record 101 of 120 ==22482==at 0x4A06B6F: calloc (vg_replace_malloc.c:593) ==22482==by 0x4C6F301: virAlloc (viralloc.c:124) ==22482==by 0x4C840FC: virSaveLastError (virerror.c:308) ==22482==by 0x431882: qemuBuildCommandLine (qemu_command.c:8204) ==22482==by 0x41E8F0: testCompareXMLToArgvHelper (qemuxml2argvtest.c:155) ==22482==by 0x41FE9F: virtTestRun (testutils.c:157) ==22482==by 0x419DEB: mymain (qemuxml2argvtest.c:654) ==22482==by 0x4204DA: virtTestMain (testutils.c:719) ==22482==by 0x39D0821A04: (below main) (libc-start.c:225) ==22482== --- src/qemu/qemu_command.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..421a93c 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8205,6 +8205,7 @@ error: for (i = 0; i = last_good_net; i++) virDomainConfNWFilterTeardown(def-nets[i]); virSetError(originalError); +virFreeError(originalError); virCommandFree(cmd); return NULL; } ACK Although, I think there are some other places where virSetError is not followed by virFreeError, e.g. src/network/bridge_driver.c:2143 Michal Right I saw that one too, but since it wasn't directly related to this particular error I passed for now, but can generate a separate patch for that. Unless of course it's felt I should use this opportunity to handle both. I also noted there's some inconsistent uses - some places check the return of virSaveLastError() before calling virSetError() although it doesn't seem to cause issues since virCopyError() will do the right thing if the buffer is empty... John -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 00/37] Change OOM reporting
Previously, the first version dropped virReportOOMError from almost everywhere. This series don't set such high goal yet. It just prepares ground for doing so. The worst case scenario is the OOM error is reported twice. Once in VIR_ALLOC, VIR_STRDUP, virAsprintf (or similar), then in virReportOOMError itself. However, once this is pushed, it's easy to get rid of the latter one. Patches available at: git://gitorious.org/~zippy2/libvirt/michal-staging.git branch oom3 Remember, this will not be pushed until we are after the freeze. But the freeze creates a nice steady HEAD which is needed in such a giant change like this one. Michal Privoznik (37): virutil: Move string related functions to virstring.c virstring: Introduce VIR_STRUP and VIR_STRNDUP Adapt to VIR_STRDUP in daemon/* Adapt to VIR_STRDUP in src/conf/* Adapt to VIR_STRDUP in src/cpu/* Adapt to VIR_STRDUP in src/esx/* Adapt to VIR_STRDUP in src/hyperv/* Adapt to VIR_STRDUP in src/libxl/* Adapt to VIR_STRDUP in src/locking/* Adapt to VIR_STRDUP in src/lxc/* Adapt to VIR_STRDUP in src/network/* Adapt to VIR_STRDUP in src/node_device/* Adapt to VIR_STRDUP in src/interface/ Adapt to VIR_STRDUP in src/nwfilter/* Adapt to VIR_STRDUP in src/openvz/* Adapt to VIR_STRDUP in src/parallels/* Adapt to VIR_STRDUP in src/phyp/* Adapt to VIR_STRDUP in src/qemu/* Adapt to VIR_STRDUP in src/remote/* Adapt to VIR_STRDUP in src/rpc/* Adapt to VIR_STRDUP in src/secret/* Adapt to VIR_STRDUP in src/security/* Adapt to VIR_STRDUP in src/storage/* Adapt to VIR_STRDUP in src/test/* Adapt to VIR_STRDUP in src/uml/* Adapt to VIR_STRDUP in src/util/* Adapt to VIR_STRDUP in src/vbox/* Adapt to VIR_STRDUP in src/vmware/* Adapt to VIR_STRDUP in src/vmx/* Adapt to VIR_STRDUP in src/xen/* Adapt to VIR_STRDUP in src/xenapi/* Adapt to VIR_STRDUP in src/xenxs/* Adapt to VIR_STRDUP in tests/* Adapt to VIR_STRDUP in src/* Introduce syntax-check rule to prefer VIR_STRDUP over strdup virstring: Introduce virAsprintfQuiet and virVasprintfQuiet viralloc.c: Do report OOM error in VIR_ALLOC and friends HACKING | 19 ++ cfg.mk| 12 +- daemon/libvirtd-config.c | 39 +-- daemon/libvirtd.c | 19 +- daemon/remote.c | 97 +++ docs/hacking.html.in | 26 ++ include/libvirt/libvirt.h.in | 10 +- po/POTFILES.in| 1 + python/libvirt-override.c | 103 +++ src/conf/capabilities.c | 27 +- src/conf/cpu_conf.c | 14 +- src/conf/device_conf.c| 2 +- src/conf/domain_audit.c | 1 + src/conf/domain_conf.c| 66 ++--- src/conf/domain_conf.h| 1 - src/conf/domain_event.c | 31 +- src/conf/interface_conf.c | 1 - src/conf/netdev_bandwidth_conf.c | 2 +- src/conf/netdev_vport_profile_conf.c | 1 + src/conf/network_conf.c | 2 +- src/conf/node_device_conf.c | 29 +- src/conf/nwfilter_conf.c | 20 +- src/conf/nwfilter_conf.h | 1 - src/conf/nwfilter_params.c| 23 +- src/conf/secret_conf.c| 1 - src/conf/snapshot_conf.c | 8 +- src/conf/storage_conf.c | 11 +- src/conf/storage_conf.h | 1 - src/conf/storage_encryption_conf.c| 1 - src/conf/virchrdev.c | 7 +- src/cpu/cpu_generic.c | 6 +- src/cpu/cpu_map.c | 3 +- src/cpu/cpu_powerpc.c | 11 +- src/cpu/cpu_x86.c | 9 +- src/datatypes.c | 26 +- src/driver.c | 2 +- src/esx/esx_device_monitor.c | 1 - src/esx/esx_driver.c | 35 +-- src/esx/esx_interface_driver.c| 6 +- src/esx/esx_network_driver.c | 21 +- src/esx/esx_nwfilter_driver.c | 1 - src/esx/esx_secret_driver.c | 1 - src/esx/esx_storage_backend_iscsi.c | 15 +- src/esx/esx_storage_backend_vmfs.c| 10 +- src/esx/esx_util.c| 39 +-- src/esx/esx_vi.c | 54 +--- src/esx/esx_vi_types.c| 24 +- src/fdstream.c| 1 + src/hyperv/hyperv_device_monitor.c| 1 - src/hyperv/hyperv_driver.c| 37 +-- src/hyperv/hyperv_interface_driver.c | 1 - src/hyperv/hyperv_network_driver.c| 1 - src/hyperv/hyperv_nwfilter_driver.c | 1 - src/hyperv/hyperv_secret_driver.c | 1 - src/hyperv/hyperv_storage_driver.c| 1 -
[libvirt] [PATCH v2 10/37] Adapt to VIR_STRDUP in src/lxc/*
--- src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_conf.c | 18 +- src/lxc/lxc_container.c | 8 src/lxc/lxc_controller.c | 6 +++--- src/lxc/lxc_driver.c | 7 ++- src/lxc/lxc_process.c| 4 ++-- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index bc3b0d1..2df8ba8 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -538,7 +538,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, bool startup) goto cleanup; } -if (!(res-partition = strdup(/machine))) { +if (VIR_STRDUP(res-partition, /machine) 0) { virReportOOMError(); VIR_FREE(res); goto cleanup; diff --git a/src/lxc/lxc_conf.c b/src/lxc/lxc_conf.c index 13c0d97..2971c08 100644 --- a/src/lxc/lxc_conf.c +++ b/src/lxc/lxc_conf.c @@ -37,7 +37,7 @@ #include configmake.h #include lxc_container.h #include virnodesuspend.h - +#include virstring.h #define VIR_FROM_THIS VIR_FROM_LXC @@ -119,9 +119,9 @@ virCapsPtr lxcCapsInit(virLXCDriverPtr driver) if (VIR_ALLOC(caps-host.secModels) 0) goto no_memory; caps-host.nsecModels = 1; -if (!(caps-host.secModels[0].model = strdup(model))) +if (VIR_STRDUP(caps-host.secModels[0].model, model) 0) goto no_memory; -if (!(caps-host.secModels[0].doi = strdup(doi))) +if (VIR_STRDUP(caps-host.secModels[0].doi, doi) 0) goto no_memory; } @@ -161,17 +161,17 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) driver-securityRequireConfined = false; /* Set the container configuration directory */ -if ((driver-configDir = strdup(LXC_CONFIG_DIR)) == NULL) +if (VIR_STRDUP(driver-configDir,LXC_CONFIG_DIR) 0) goto no_memory; -if ((driver-stateDir = strdup(LXC_STATE_DIR)) == NULL) +if (VIR_STRDUP(driver-stateDir, LXC_STATE_DIR) 0) goto no_memory; -if ((driver-logDir = strdup(LXC_LOG_DIR)) == NULL) +if (VIR_STRDUP(driver-logDir, LXC_LOG_DIR) 0) goto no_memory; -if ((driver-autostartDir = strdup(LXC_AUTOSTART_DIR)) == NULL) +if (VIR_STRDUP(driver-autostartDir, LXC_AUTOSTART_DIR) 0) goto no_memory; -if ((filename = strdup(SYSCONFDIR /libvirt/lxc.conf)) == NULL) +if (VIR_STRDUP(filename, SYSCONFDIR /libvirt/lxc.conf) 0) goto no_memory; /* Avoid error from non-existant or unreadable file. */ @@ -196,7 +196,7 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) p = virConfGetValue(conf, security_driver); CHECK_TYPE(security_driver, VIR_CONF_STRING); if (p p-str) { -if (!(driver-securityDriverName = strdup(p-str))) { +if (VIR_STRDUP(driver-securityDriverName, p-str) 0) { virReportOOMError(); virConfFree(conf); return -1; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index ff4069a..6bf9916 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -439,7 +439,7 @@ static int lxcContainerGetSubtree(const char *prefix, virReportOOMError(); goto cleanup; } -if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) { +if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) 0) { virReportOOMError(); goto cleanup; } @@ -1041,7 +1041,7 @@ lxcContainerMountDetectFilesystem(const char *src, char **type) goto cleanup; } -if (!(*type = strdup(data))) { +if (VIR_STRDUP(*type, data) 0) { virReportOOMError(); goto cleanup; } @@ -1948,13 +1948,13 @@ static int lxcContainerChild(void *data) goto cleanup; } } else { -if (!(ttyPath = strdup(argv-ttyPaths[0]))) { +if (VIR_STRDUP(ttyPath, argv-ttyPaths[0]) 0) { virReportOOMError(); goto cleanup; } } } else { -if (!(ttyPath = strdup(/dev/null))) { +if (VIR_STRDUP(ttyPath, /dev/null) 0) { virReportOOMError(); goto cleanup; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index f1800eb..855a6d1 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -156,7 +156,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name) ctrl-timerShutdown = -1; ctrl-firstClient = true; -if (!(ctrl-name = strdup(name))) +if (VIR_STRDUP(ctrl-name, name) 0) goto no_memory; if ((caps = lxcCapsInit(NULL)) == NULL) @@ -1566,7 +1566,7 @@ int main(int argc, char *argv[]) break; case 'n': -if ((name = strdup(optarg)) == NULL) { +if (VIR_STRDUP(name, optarg) 0) { virReportOOMError(); goto cleanup; } @@ -1577,7 +1577,7 @@ int
[libvirt] [PATCH v2 07/37] Adapt to VIR_STRDUP in src/hyperv/*
--- src/hyperv/hyperv_driver.c | 35 +++ src/hyperv/hyperv_util.c | 15 +-- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 7031fdb..23d30e1 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -140,9 +140,7 @@ hypervConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags /* Request credentials */ if (conn-uri-user != NULL) { -username = strdup(conn-uri-user); - -if (username == NULL) { +if (VIR_STRDUP(username, conn-uri-user) 0) { virReportOOMError(); goto cleanup; } @@ -257,9 +255,7 @@ hypervConnectGetHostname(virConnectPtr conn) goto cleanup; } -hostname = strdup(computerSystem-data-DNSHostName); - -if (hostname == NULL) { +if (VIR_STRDUP(hostname, computerSystem-data-DNSHostName) 0) { virReportOOMError(); goto cleanup; } @@ -652,9 +648,9 @@ hypervDomainDestroy(virDomainPtr domain) static char * hypervDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { -char *osType = strdup(hvm); +char *osType; -if (osType == NULL) { +if (VIR_STRDUP(osType, hvm) 0) { virReportOOMError(); return NULL; } @@ -908,20 +904,15 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return NULL; } -def-name = strdup(computerSystem-data-ElementName); - -if (def-name == NULL) { +if (VIR_STRDUP(def-name, computerSystem-data-ElementName) 0) { virReportOOMError(); goto cleanup; } -if (virtualSystemSettingData-data-Notes != NULL) { -def-description = strdup(virtualSystemSettingData-data-Notes); - -if (def-description == NULL) { -virReportOOMError(); -goto cleanup; -} +if (virtualSystemSettingData-data-Notes +VIR_STRDUP(def-description, virtualSystemSettingData-data-Notes) 0) { +virReportOOMError(); +goto cleanup; } def-mem.max_balloon = memorySettingData-data-Limit * 1024; /* megabyte to kilobyte */ @@ -930,9 +921,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) def-vcpus = processorSettingData-data-VirtualQuantity; def-maxvcpus = processorSettingData-data-VirtualQuantity; -def-os.type = strdup(hvm); - -if (def-os.type == NULL) { +if (VIR_STRDUP(def-os.type, hvm) 0) { virReportOOMError(); goto cleanup; } @@ -981,9 +970,7 @@ hypervConnectListDefinedDomains(virConnectPtr conn, char **const names, int maxn for (computerSystem = computerSystemList; computerSystem != NULL; computerSystem = computerSystem-next) { -names[count] = strdup(computerSystem-data-ElementName); - -if (names[count] == NULL) { +if (VIR_STRDUP(names[count], computerSystem-data-ElementName) 0) { virReportOOMError(); goto cleanup; } diff --git a/src/hyperv/hyperv_util.c b/src/hyperv/hyperv_util.c index a55b939..6d5f79a 100644 --- a/src/hyperv/hyperv_util.c +++ b/src/hyperv/hyperv_util.c @@ -27,6 +27,7 @@ #include viralloc.h #include virlog.h #include viruuid.h +#include virstring.h #include hyperv_private.h #include hyperv_util.h @@ -56,9 +57,7 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) if (STRCASEEQ(queryParam-name, transport)) { VIR_FREE((*parsedUri)-transport); -(*parsedUri)-transport = strdup(queryParam-value); - -if ((*parsedUri)-transport == NULL) { +if (VIR_STRDUP((*parsedUri)-transport, queryParam-value) 0) { virReportOOMError(); goto cleanup; } @@ -77,13 +76,9 @@ hypervParseUri(hypervParsedUri **parsedUri, virURIPtr uri) } } -if ((*parsedUri)-transport == NULL) { -(*parsedUri)-transport = strdup(https); - -if ((*parsedUri)-transport == NULL) { -virReportOOMError(); -goto cleanup; -} +if (!(*parsedUri)-transport VIR_STRDUP((*parsedUri)-transport, https) 0) { +virReportOOMError(); +goto cleanup; } result = 0; -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 05/37] Adapt to VIR_STRDUP in src/cpu/*
--- src/cpu/cpu_generic.c | 6 +++--- src/cpu/cpu_map.c | 3 ++- src/cpu/cpu_powerpc.c | 10 +- src/cpu/cpu_x86.c | 6 +++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cpu/cpu_generic.c b/src/cpu/cpu_generic.c index 9d5117f..e907269 100644 --- a/src/cpu/cpu_generic.c +++ b/src/cpu/cpu_generic.c @@ -28,7 +28,7 @@ #include virhash.h #include cpu.h #include cpu_generic.h - +#include virstring.h #define VIR_FROM_THIS VIR_FROM_CPU @@ -131,7 +131,7 @@ genericBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC(cpu) 0 || -!(cpu-model = strdup(cpus[0]-model)) || +VIR_STRDUP(cpu-model, cpus[0]-model) 0 || VIR_ALLOC_N(features, cpus[0]-nfeatures) 0) goto no_memory; @@ -183,7 +183,7 @@ genericBaseline(virCPUDefPtr *cpus, if (!features[i].name) continue; -if (!(cpu-features[j++].name = strdup(features[i].name))) +if (VIR_STRDUP(cpu-features[j++].name, features[i].name) 0) goto no_memory; } diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index 015be2e..7c2bdec 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -27,6 +27,7 @@ #include cpu.h #include cpu_map.h #include configmake.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_CPU @@ -149,7 +150,7 @@ cpuMapOverride(const char *path) { char *map; -if (!(map = strdup(path))) +if (VIR_STRDUP(map, path) 0) return -1; VIR_FREE(cpumap); diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c index b253db2..3aa7395 100644 --- a/src/cpu/cpu_powerpc.c +++ b/src/cpu/cpu_powerpc.c @@ -29,9 +29,9 @@ #include virlog.h #include viralloc.h #include cpu.h - #include cpu_map.h #include virbuffer.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_CPU @@ -333,8 +333,8 @@ ppcDecode(virCPUDefPtr cpu, goto cleanup; } -if (!(cpu-model = strdup(model-name)) || -(model-vendor !(cpu-vendor = strdup(model-vendor-name { +if (VIR_STRDUP(cpu-model, model-name) 0 || +(model-vendor VIR_STRDUP(cpu-vendor, model-vendor-name) 0)) { virReportOOMError(); goto cleanup; } @@ -449,10 +449,10 @@ ppcBaseline(virCPUDefPtr *cpus, } if (VIR_ALLOC(cpu) 0 || -!(cpu-model = strdup(model-name))) +VIR_STRDUP(cpu-model, model-name) 0) goto no_memory; -if (vendor !(cpu-vendor = strdup(vendor-name))) +if (vendor VIR_STRDUP(cpu-vendor, vendor-name) 0) goto no_memory; cpu-type = VIR_CPU_TYPE_GUEST; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 14d525e..009c2c0 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -449,13 +449,13 @@ x86DataToCPU(const union cpuData *data, const struct x86_vendor *vendor; if (VIR_ALLOC(cpu) 0 || -!(cpu-model = strdup(model-name)) || +VIR_STRDUP(cpu-model, model-name) 0 || !(copy = x86DataCopy(data)) || !(modelData = x86DataCopy(model-data))) goto no_memory; if ((vendor = x86DataToVendor(copy, map)) -!(cpu-vendor = strdup(vendor-name))) +VIR_STRDUP(cpu-vendor, vendor-name) 0) goto no_memory; x86DataSubtract(copy, modelData); @@ -767,7 +767,7 @@ x86ModelCopy(const struct x86_model *model) struct x86_model *copy; if (VIR_ALLOC(copy) 0 -|| !(copy-name = strdup(model-name)) +|| VIR_STRDUP(copy-name, model-name) 0 || !(copy-data = x86DataCopy(model-data))) { x86ModelFree(copy); return NULL; -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 04/37] Adapt to VIR_STRDUP in src/conf/*
--- src/conf/capabilities.c | 26 -- src/conf/cpu_conf.c | 12 - src/conf/domain_conf.c | 64 - src/conf/domain_event.c | 31 +++--- src/conf/node_device_conf.c | 28 +--- src/conf/nwfilter_conf.c| 18 + src/conf/nwfilter_params.c | 22 +++- src/conf/snapshot_conf.c| 6 ++--- src/conf/storage_conf.c | 9 +++ src/conf/virchrdev.c| 6 ++--- 10 files changed, 98 insertions(+), 124 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 5340b63..4b4b670 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -31,7 +31,7 @@ #include viruuid.h #include cpu_conf.h #include virerror.h - +#include virstring.h #define VIR_FROM_THIS VIR_FROM_CAPABILITIES @@ -228,7 +228,7 @@ virCapabilitiesAddHostFeature(virCapsPtr caps, caps-host.nfeatures, 1) 0) return -1; -if ((caps-host.features[caps-host.nfeatures] = strdup(name)) == NULL) +if (VIR_STRDUP(caps-host.features[caps-host.nfeatures], name) 0) return -1; caps-host.nfeatures++; @@ -250,7 +250,7 @@ virCapabilitiesAddHostMigrateTransport(virCapsPtr caps, caps-host.nmigrateTrans, 1) 0) return -1; -if ((caps-host.migrateTrans[caps-host.nmigrateTrans] = strdup(name)) == NULL) +if (VIR_STRDUP(caps-host.migrateTrans[caps-host.nmigrateTrans], name) 0) return -1; caps-host.nmigrateTrans++; @@ -334,7 +334,7 @@ virCapabilitiesAllocMachines(const char *const *names, int nnames) for (i = 0; i nnames; i++) { if (VIR_ALLOC(machines[i]) 0 || -!(machines[i]-name = strdup(names[i]))) { +VIR_STRDUP(machines[i]-name, names[i]) 0) { virCapabilitiesFreeMachines(machines, nnames); return NULL; } @@ -392,17 +392,15 @@ virCapabilitiesAddGuest(virCapsPtr caps, if (VIR_ALLOC(guest) 0) goto no_memory; -if ((guest-ostype = strdup(ostype)) == NULL) +if (VIR_STRDUP(guest-ostype, ostype) 0) goto no_memory; guest-arch.id = arch; guest-arch.wordsize = virArchGetWordSize(arch); -if (emulator -(guest-arch.defaultInfo.emulator = strdup(emulator)) == NULL) +if (emulator VIR_STRDUP(guest-arch.defaultInfo.emulator, emulator) 0) goto no_memory; -if (loader -(guest-arch.defaultInfo.loader = strdup(loader)) == NULL) +if (loader VIR_STRDUP(guest-arch.defaultInfo.loader, loader) 0) goto no_memory; if (VIR_RESIZE_N(caps-guests, caps-nguests_max, @@ -448,14 +446,12 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, if (VIR_ALLOC(dom) 0) goto no_memory; -if ((dom-type = strdup(hvtype)) == NULL) +if (VIR_STRDUP(dom-type, hvtype) 0) goto no_memory; -if (emulator -(dom-info.emulator = strdup(emulator)) == NULL) +if (emulator VIR_STRDUP(dom-info.emulator, emulator) 0) goto no_memory; -if (loader -(dom-info.loader = strdup(loader)) == NULL) +if (loader VIR_STRDUP(dom-info.loader, loader) 0) goto no_memory; if (VIR_RESIZE_N(guest-arch.domains, guest-arch.ndomains_max, @@ -497,7 +493,7 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, if (VIR_ALLOC(feature) 0) goto no_memory; -if ((feature-name = strdup(name)) == NULL) +if (VIR_STRDUP(feature-name, name) 0) goto no_memory; feature-defaultOn = defaultOn; feature-toggle = toggle; diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 6aaee75..7a50d76 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -99,9 +99,9 @@ virCPUDefCopyModel(virCPUDefPtr dst, { unsigned int i; -if ((src-model !(dst-model = strdup(src-model))) -|| (src-vendor !(dst-vendor = strdup(src-vendor))) -|| (src-vendor_id !(dst-vendor_id = strdup(src-vendor_id))) +if ((src-model VIR_STRDUP(dst-model, src-model) 0) +|| (src-vendor VIR_STRDUP(dst-vendor, src-vendor) 0) +|| (src-vendor_id VIR_STRDUP(dst-vendor_id, src-vendor_id) 0) || VIR_ALLOC_N(dst-features, src-nfeatures) 0) goto no_memory; dst-nfeatures_max = dst-nfeatures = src-nfeatures; @@ -118,7 +118,7 @@ virCPUDefCopyModel(virCPUDefPtr dst, dst-features[i].policy = src-features[i].policy; } -if (!(dst-features[i].name = strdup(src-features[i].name))) +if (VIR_STRDUP(dst-features[i].name, src-features[i].name) 0) goto no_memory; } @@ -167,7 +167,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) if (!copy-cells[i].cpumask) goto no_memory; -if (!(copy-cells[i].cpustr = strdup(cpu-cells[i].cpustr))) +if (VIR_STRDUP(copy-cells[i].cpustr, cpu-cells[i].cpustr) 0)
[libvirt] [PATCH v2 21/37] Adapt to VIR_STRDUP in src/secret/*
--- src/secret/secret_driver.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c index 377b9f4..cfd5b6a 100644 --- a/src/secret/secret_driver.c +++ b/src/secret/secret_driver.c @@ -1097,8 +1097,7 @@ secretStateInitialize(bool privileged, secretDriverLock(driverState); if (privileged) { -base = strdup(SYSCONFDIR /libvirt); -if (base == NULL) +if (VIR_STRDUP(base, SYSCONFDIR /libvirt) 0) goto out_of_memory; } else { base = virGetUserConfigDirectory(); -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 12/37] Adapt to VIR_STRDUP in src/node_device/*
--- src/node_device/node_device_driver.c | 28 -- src/node_device/node_device_hal.c| 13 ++--- src/node_device/node_device_udev.c | 102 +++ 3 files changed, 60 insertions(+), 83 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index 95df2e5..2ef05ab 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -36,6 +36,7 @@ #include node_device_conf.h #include node_device_hal.h #include node_device_driver.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_NODEDEV @@ -88,12 +89,9 @@ static int update_driver_name(virNodeDeviceObjPtr dev) } p = strrchr(devpath, '/'); -if (p) { -dev-def-driver = strdup(p+1); -if (!dev-def-driver) { -virReportOOMError(); -goto cleanup; -} +if (p VIR_STRDUP(dev-def-driver, p+1) 0) { +virReportOOMError(); +goto cleanup; } ret = 0; @@ -161,7 +159,7 @@ nodeListDevices(virConnectPtr conn, virNodeDeviceObjLock(driver-devs.objs[i]); if (cap == NULL || virNodeDeviceHasCap(driver-devs.objs[i], cap)) { -if ((names[ndevs++] = strdup(driver-devs.objs[i]-def-name)) == NULL) { +if (VIR_STRDUP(names[ndevs++], driver-devs.objs[i]-def-name) 0) { virNodeDeviceObjUnlock(driver-devs.objs[i]); virReportOOMError(); goto failure; @@ -321,8 +319,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) } if (obj-def-parent) { -ret = strdup(obj-def-parent); -if (!ret) +if (VIR_STRDUP(ret, obj-def-parent) 0) virReportOOMError(); } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -388,8 +385,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) } for (caps = obj-def-caps; caps ncaps maxnames; caps = caps-next) { -names[ncaps] = strdup(virNodeDevCapTypeToString(caps-type)); -if (names[ncaps++] == NULL) { +if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps-type)) 0) { virReportOOMError(); goto cleanup; } @@ -554,7 +550,10 @@ nodeDeviceDestroy(virNodeDevicePtr dev) goto out; } -parent_name = strdup(obj-def-parent); +if (VIR_STRDUP(parent_name, obj-def-parent) 0) { +virReportOOMError(); +goto out; +} /* virNodeDeviceGetParentHost will cause the device object's lock to be * taken, so we have to dup the parent's name and drop the lock @@ -563,11 +562,6 @@ nodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjUnlock(obj); obj = NULL; -if (parent_name == NULL) { -virReportOOMError(); -goto out; -} - if (virNodeDeviceGetParentHost(driver-devs, dev-name, parent_name, diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c index 63245a9..1077445 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -445,10 +445,10 @@ static void dev_create(const char *udi) virNodeDeviceDefPtr def = NULL; const char *name = hal_name(udi); int rv; -char *privData = strdup(udi); +char *privData; char *devicePath = NULL; -if (!privData) +if (VIR_STRDUP(privDatam udi) 0) return; nodeDeviceLock(driverState); @@ -457,14 +457,15 @@ static void dev_create(const char *udi) if (VIR_ALLOC(def) 0) goto failure; -if ((def-name = strdup(name)) == NULL) +if (VIR_STRDUP(def-name, name) 0) goto failure; if (get_str_prop(ctx, udi, info.parent, parent_key) == 0) { -def-parent = strdup(hal_name(parent_key)); -VIR_FREE(parent_key); -if (def-parent == NULL) +if (VIR_STRDUP(def-parent, hal_name(parent_key)) 0) { +VIR_FREE(parent_key); goto failure; +} +VIR_FREE(parent_key); } rv = gather_capabilities(ctx, udi, def-caps); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index c3c97d7..9bc4496 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -125,8 +125,7 @@ static int udevGetDeviceProperty(struct udev_device *udev_device, /* If this allocation is changed, the comment at the beginning * of the function must also be changed. */ -*property_value = strdup(udev_value); -if (*property_value == NULL) { +if (VIR_STRDUP(*property_value, udev_value) 0) { VIR_ERROR(_(Failed to allocate memory for property value for property key '%s' on device with sysname '%s'), property_key, udev_device_get_sysname(udev_device)); @@ -214,8 +213,7 @@ static int udevGetDeviceSysfsAttr(struct udev_device
[libvirt] [PATCH v2 02/37] virstring: Introduce VIR_STRUP and VIR_STRNDUP
The code adaptation is not done right now, but in subsequent patches. Hence I am not implementing syntax-check rule as it would break compilation. Developers are strongly advised to use these new macros. They are similar to VIR_ALLOC() logic: VIR_STRDUP(dst, src) returns zero on success, -1 otherwise. In case you don't want to report OOM error, use _QUIET variant of a macro. --- HACKING | 11 +++ docs/hacking.html.in | 14 + src/libvirt_private.syms | 2 ++ src/util/virstring.c | 74 src/util/virstring.h | 20 + 5 files changed, 121 insertions(+) diff --git a/HACKING b/HACKING index e8bebd4..842f476 100644 --- a/HACKING +++ b/HACKING @@ -719,6 +719,17 @@ sizeof(dest) returns something meaningful). Note that this is a macro, so arguments could be evaluated more than once. This is equivalent to virStrncpy(dest, src, strlen(src), sizeof(dest)). + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); + +You should avoid using strdup or strndup directly as the does not report +out-of-memory error. Use VIR_STRDUP() or VIR_STRNDUP macros instead. Note, +that these two behave in similar way to VIR_ALLOC: on success zero is +returned, otherwise caller is left with negative one. In very specific case, +when you don't want to report the out-of-memory error, you can use +VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare and usually +considered a flaw. + Variable length string buffer = diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 99933d1..1263607 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -853,6 +853,20 @@ virStrncpy(dest, src, strlen(src), sizeof(dest)). /p +pre + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); +/pre +p + You should avoid using strdup or strndup directly as the does not report + out-of-memory error. Use VIR_STRDUP() or VIR_STRNDUP macros instead. + Note, that these two behave in similar way to VIR_ALLOC: on success zero + is returned, otherwise caller is left with negative one. In very specific + case, when you don't want to report the out-of-memory error, you can use + VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare and + usually considered a flaw. +/p + h2a name=strbufVariable length string buffer/a/h2 p diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 98660dc..d4cb4a3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1751,11 +1751,13 @@ virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; virStrcpy; +virStrdup; virStringArrayHasString; virStringFreeList; virStringJoin; virStringSplit; virStrncpy; +virStrndup; virStrToDouble; virStrToLong_i; virStrToLong_l; diff --git a/src/util/virstring.c b/src/util/virstring.c index 9b4cb01..4a55873 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -515,3 +515,77 @@ virArgvToString(const char *const *argv) return ret; } + +/** + * virStrdup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @report: whether to report OOM error, if there's a one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strdup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider + * using VIR_STRDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise. + */ +int +virStrdup(char **dest, + const char *src, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ +if (!(*dest = strdup(src))) { +if (report) +virReportOOMErrorFull(domcode, filename, funcname, linenr); +return -1; +} + +return 0; +} + +/** + * virStrndup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @n: how many bytes to copy + * @report: whether to report OOM error, if there's a one + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strndup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider + * using VIR_STRNDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise. + */ +int +virStrndup(char **dest, + const char *src, + size_t n, + bool report, +
[libvirt] [PATCH v2 15/37] Adapt to VIR_STRDUP in src/openvz/*
--- src/openvz/openvz_conf.c | 31 +++ src/openvz/openvz_driver.c | 30 +++--- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 49fae28..9dbdc74 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -135,9 +135,9 @@ openvzParseBarrierLimit(const char* value, { char *token; char *saveptr = NULL; -char *str = strdup(value); +char *str; -if (str == NULL) { +if (VIR_STRDUP(str, value) 0) { virReportOOMError(); goto error; } @@ -230,9 +230,7 @@ openvzReadNetworkConf(virDomainDefPtr def, goto no_memory; net-type = VIR_DOMAIN_NET_TYPE_ETHERNET; -net-data.ethernet.ipaddr = strdup(token); - -if (net-data.ethernet.ipaddr == NULL) +if (VIR_STRDUP(net-data.ethernet.ipaddr, token) 0) goto no_memory; if (VIR_REALLOC_N(def-nets, def-nnets + 1) 0) @@ -405,7 +403,8 @@ openvzReadFSConf(virDomainDefPtr def, goto no_memory; fs-type = VIR_DOMAIN_FS_TYPE_TEMPLATE; -fs-src = strdup(temp); +if (VIR_STRDUP(fs-src, temp) 0) +goto no_memory; } else { /* OSTEMPLATE was not found, VE was booted from a private dir directly */ ret = openvzReadVPSConfigParam(veid, VE_PRIVATE, temp); @@ -428,7 +427,8 @@ openvzReadFSConf(virDomainDefPtr def, VIR_FREE(veid_str); } -fs-dst = strdup(/); +if (VIR_STRDUP(fs-dst, /) 0) +goto no_memory; param = DISKSPACE; ret = openvzReadVPSConfigParam(veid, param, temp); @@ -451,9 +451,6 @@ openvzReadFSConf(virDomainDefPtr def, } } -if (fs-src == NULL || fs-dst == NULL) -goto no_memory; - if (VIR_REALLOC_N(def-fss, def-nfss + 1) 0) goto no_memory; def-fss[def-nfss++] = fs; @@ -607,9 +604,9 @@ int openvzLoadDomains(struct openvz_driver *driver) { goto cleanup; } -if (!(def-os.type = strdup(exe))) +if (VIR_STRDUP(def-os.type, exe) 0) goto no_memory; -if (!(def-os.init = strdup(/sbin/init))) +if (VIR_STRDUP(def-os.init, /sbin/init) 0) goto no_memory; ret = openvzReadVPSConfigParam(veid, CPUS, temp); @@ -800,8 +797,7 @@ openvzReadConfigParam(const char *conf_file, const char *param, char **value) saveptr = NULL; if ((token = strtok_r(sf, \\t\n, saveptr)) != NULL) { VIR_FREE(*value); -*value = strdup(token); -if (*value == NULL) { +if (VIR_STRDUP(*value, token) 0) { err = 1; break; } @@ -952,10 +948,13 @@ openvzLocateConfDir(void) { const char *conf_dir_list[] = {/etc/vz/conf, /usr/local/etc/conf, NULL}; int i=0; +char *ret = NULL; while (conf_dir_list[i]) { -if (!access(conf_dir_list[i], F_OK)) -return strdup(conf_dir_list[i]); +if (!access(conf_dir_list[i], F_OK)) { +ignore_value(VIR_STRDUP(ret, conf_dir_list[i])); +return ret; +} i++; } diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index e6d7146..027cda8 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -88,7 +88,7 @@ static void openvzDriverUnlock(struct openvz_driver *driver) struct openvz_driver ovz_driver; -static void cmdExecFree(const char *cmdExec[]) +static void cmdExecFree(char *cmdExec[]) { int i=-1; while (cmdExec[++i]) { @@ -104,7 +104,7 @@ openvzDomainDefPostParse(virDomainDefPtr def, { /* fill the init path */ if (STREQ(def-os.type, exe) !def-os.init) { -if (!(def-os.init = strdup(/sbin/init))) { +if (VIR_STRDUP(def-os.init, /sbin/init) 0) { virReportOOMError(); return -1; } @@ -358,7 +358,7 @@ static char *openvzDomainGetOSType(virDomainPtr dom) goto cleanup; } -if (!(ret = strdup(vm-def-os.type))) +if (VIR_STRDUP(ret, vm-def-os.type) 0) virReportOOMError(); cleanup: @@ -772,12 +772,14 @@ openvzGenerateVethName(int veid, char *dev_name_ve) { chardev_name[32]; int ifNo = 0; +char*ret; if (sscanf(dev_name_ve, %*[^0-9]%d, ifNo) != 1) return NULL; if (snprintf(dev_name, sizeof(dev_name), veth%d.%d, veid, ifNo) 7) return NULL; -return strdup(dev_name); +ignore_value(VIR_STRDUP(ret, dev_name)); +return ret; } static char * @@ -788,7 +790,8 @@ openvzGenerateContainerVethName(int veid) /* try to get line ^NETIF=... from config */ if (openvzReadVPSConfigParam(veid, NETIF, temp) = 0) { -name = strdup(eth0); +if (VIR_STRDUP(name, eth0) 0) +virReportOOMError(); } else { char *saveptr = NULL;
[libvirt] [PATCH v2 08/37] Adapt to VIR_STRDUP in src/libxl/*
--- src/libxl/libxl_conf.c | 59 ++-- src/libxl/libxl_driver.c | 13 ++- 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..19d40f3 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -302,7 +302,7 @@ libxlMakeDomCreateInfo(libxlDriverPrivatePtr driver, else c_info-type = LIBXL_DOMAIN_TYPE_PV; -if ((c_info-name = strdup(def-name)) == NULL) { +if (VIR_STRDUP(c_info-name, def-name) 0) { virReportOOMError(); goto error; } @@ -403,7 +403,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) else { bootorder[def-os.nBootDevs] = '\0'; } -if ((b_info-u.hvm.boot = strdup(bootorder)) == NULL) { +if (VIR_STRDUP(b_info-u.hvm.boot, bootorder) 0) { virReportOOMError(); goto error; } @@ -418,36 +418,33 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, libxl_domain_config *d_config) b_info-shadow_memkb = 4 * (256 * libxl_bitmap_count_set(b_info-avail_vcpus) + 2 * (b_info-max_memkb / 1024)); } else { -if (def-os.bootloader) { -if ((b_info-u.pv.bootloader = strdup(def-os.bootloader)) == NULL) { -virReportOOMError(); -goto error; -} +if (def-os.bootloader +VIR_STRDUP(b_info-u.pv.bootloader, def-os.bootloader) 0) { +virReportOOMError(); +goto error; } if (def-os.bootloaderArgs) { if (!(b_info-u.pv.bootloader_args = virStringSplit(def-os.bootloaderArgs, \t\n, 0))) goto error; } -if (def-os.cmdline) { -if ((b_info-u.pv.cmdline = strdup(def-os.cmdline)) == NULL) { -virReportOOMError(); -goto error; -} +if (def-os.cmdline +VIR_STRDUP(b_info-u.pv.cmdline, def-os.cmdline) 0) { +virReportOOMError(); +goto error; } if (def-os.kernel) { -/* libxl_init_build_info() sets kernel.path = strdup(hvmloader) */ +/* libxl_init_build_info() sets VIR_STRDUP(kernel.path, hvmloader) */ VIR_FREE(b_info-u.pv.kernel); -if ((b_info-u.pv.kernel = strdup(def-os.kernel)) == NULL) { +if (VIR_STRDUP(b_info-u.pv.kernel, def-os.kernel) 0) { virReportOOMError(); goto error; } } -if (def-os.initrd) { -if ((b_info-u.pv.ramdisk = strdup(def-os.initrd)) == NULL) { -virReportOOMError(); -goto error; -} +if (def-os.initrd +VIR_STRDUP(b_info-u.pv.ramdisk, def-os.initrd) 0) { +virReportOOMError(); +goto error; } } @@ -461,12 +458,12 @@ error: int libxlMakeDisk(virDomainDiskDefPtr l_disk, libxl_device_disk *x_disk) { -if (l_disk-src (x_disk-pdev_path = strdup(l_disk-src)) == NULL) { +if (l_disk-src VIR_STRDUP(x_disk-pdev_path, l_disk-src) 0) { virReportOOMError(); return -1; } -if (l_disk-dst (x_disk-vdev = strdup(l_disk-dst)) == NULL) { +if (l_disk-dst VIR_STRDUP(x_disk-vdev, l_disk-dst) 0) { virReportOOMError(); return -1; } @@ -575,7 +572,7 @@ libxlMakeNic(virDomainNetDefPtr l_nic, libxl_device_nic *x_nic) virMacAddrGetRaw(l_nic-mac, x_nic-mac); if (l_nic-model !STREQ(l_nic-model, netfront)) { -if ((x_nic-model = strdup(l_nic-model)) == NULL) { +if (VIR_STRDUP(x_nic-model, l_nic-model) 0) { virReportOOMError(); return -1; } @@ -584,19 +581,19 @@ libxlMakeNic(virDomainNetDefPtr l_nic, libxl_device_nic *x_nic) x_nic-nictype = LIBXL_NIC_TYPE_VIF; } -if (l_nic-ifname (x_nic-ifname = strdup(l_nic-ifname)) == NULL) { +if (l_nic-ifname VIR_STRDUP(x_nic-ifname, l_nic-ifname) 0) { virReportOOMError(); return -1; } if (l_nic-type == VIR_DOMAIN_NET_TYPE_BRIDGE) { if (l_nic-data.bridge.brname -(x_nic-bridge = strdup(l_nic-data.bridge.brname)) == NULL) { +VIR_STRDUP(x_nic-bridge, l_nic-data.bridge.brname) 0) { virReportOOMError(); return -1; } if (l_nic-script -(x_nic-script = strdup(l_nic-script)) == NULL) { +VIR_STRDUP(x_nic-script, l_nic-script) 0) { virReportOOMError(); return -1; } @@ -656,13 +653,12 @@ libxlMakeVfb(libxlDriverPrivatePtr driver, case VIR_DOMAIN_GRAPHICS_TYPE_SDL: libxl_defbool_set(x_vfb-sdl.enable, 1); if (l_vfb-data.sdl.display -(x_vfb-sdl.display =
[libvirt] [PATCH v2 36/37] virstring: Introduce virAsprintfQuiet and virVasprintfQuiet
Moreover, the original virVasprintf and virAsprintf functions will report OOM error. The new behaviour is not enabled for now as the rest of code needs to be adapted so we don't report an error twice. --- HACKING | 4 docs/hacking.html.in | 6 ++ src/libvirt_private.syms | 2 ++ src/util/viraudit.c | 4 +--- src/util/vircommand.c| 4 ++-- src/util/virerror.c | 2 +- src/util/virlog.c| 2 +- src/util/virstring.c | 44 src/util/virstring.h | 4 tools/virsh.c| 6 +++--- 10 files changed, 64 insertions(+), 14 deletions(-) diff --git a/HACKING b/HACKING index 842f476..0f681ce 100644 --- a/HACKING +++ b/HACKING @@ -818,6 +818,10 @@ virAsprintf, in util.h: This makes it so gcc's -Wformat and -Wformat-security options can do their jobs and cross-check format strings with the number and types of arguments. +Moreover, this function automatically reports out-of-memory error if there's +any. In case you want to suppress such behaviour, which should be very rare +case, you can use virAspritnfQuiet() or virVasprintfQuiet(). + When printing to a string, consider using virBuffer for incremental allocations, virAsprintf for a one-shot allocation, and snprintf for fixed-width buffers. Do not use sprintf, even if you can prove the buffer diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 1263607..a9b78ba 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -973,6 +973,12 @@ /p p + Moreover, this function automatically reports out-of-memory error if + there's any. In case you want to suppress such behaviour, which should be + very rare case, you can use virAspritnfQuiet() or virVasprintfQuiet(). +/p + +p When printing to a string, consider using virBuffer for incremental allocations, virAsprintf for a one-shot allocation, and snprintf for fixed-width buffers. Do not use sprintf, even diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d4cb4a3..8c1d3ab 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1747,6 +1747,7 @@ virStorageFileResize; # util/virstring.h virArgvToString; virAsprintf; +virAsprintfQuiet; virSkipSpaces; virSkipSpacesAndBackslash; virSkipSpacesBackwards; @@ -1767,6 +1768,7 @@ virStrToLong_ul; virStrToLong_ull; virTrimSpaces; virVasprintf; +virVasprintfQuiet; # util/virsysinfo.h diff --git a/src/util/viraudit.c b/src/util/viraudit.c index 5dd4e1f..f05547e 100644 --- a/src/util/viraudit.c +++ b/src/util/viraudit.c @@ -96,10 +96,8 @@ void virAuditSend(const char *filename, #endif va_start(args, fmt); -if (virVasprintf(str, fmt, args) 0) { +if (virVasprintfQuiet(str, fmt, args) 0) VIR_WARN(Out of memory while formatting audit message); -str = NULL; -} va_end(args); if (auditlog str) { diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 460e25b..b611048 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1163,7 +1163,7 @@ virCommandAddEnvFormat(virCommandPtr cmd, const char *format, ...) return; va_start(list, format); -if (virVasprintf(env, format, list) 0) { +if (virVasprintfQuiet(env, format, list) 0) { cmd-has_error = ENOMEM; va_end(list); return; @@ -1377,7 +1377,7 @@ virCommandAddArgFormat(virCommandPtr cmd, const char *format, ...) return; va_start(list, format); -if (virVasprintf(arg, format, list) 0) { +if (virVasprintfQuiet(arg, format, list) 0) { cmd-has_error = ENOMEM; va_end(list); return; diff --git a/src/util/virerror.c b/src/util/virerror.c index 8761a72..2b3a910 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -650,7 +650,7 @@ virRaiseErrorFull(const char *filename ATTRIBUTE_UNUSED, } else { va_list ap; va_start(ap, fmt); -ignore_value(virVasprintf(str, fmt, ap)); +virVasprintfQuiet(str, fmt, ap); va_end(ap); } diff --git a/src/util/virlog.c b/src/util/virlog.c index 921ffc5..cc3cfa7 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -828,7 +828,7 @@ virLogVMessage(virLogSource source, /* * serialize the error message, add level and timestamp */ -if (virVasprintf(str, fmt, vargs) 0) { +if (virVasprintfQuiet(str, fmt, vargs) 0) { goto cleanup; } diff --git a/src/util/virstring.c b/src/util/virstring.c index 2f672bc..2416c43 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -325,12 +325,12 @@ virStrToDouble(char const *s, } /** - * virVasprintf + * virVasprintfQuiet * * like glibc's vasprintf but makes sure *strp == NULL on failure */ int -virVasprintf(char **strp, const char *fmt, va_list list) +virVasprintfQuiet(char **strp, const char *fmt, va_list list) { int ret; @@ -341,9 +341,27 @@
[libvirt] [PATCH v2 17/37] Adapt to VIR_STRDUP in src/phyp/*
--- src/phyp/phyp_driver.c | 34 -- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 85eb650..1cb92d2 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -954,9 +954,7 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth, } if (conn-uri-user != NULL) { -username = strdup(conn-uri-user); - -if (username == NULL) { +if (VIR_STRDUP(username, conn-uri-user) 0) { virReportOOMError(); goto err; } @@ -1141,12 +1139,10 @@ phypConnectOpen(virConnectPtr conn, if (conn-uri-path) { /* need to shift one byte in order to remove the first / of URI component */ -if (conn-uri-path[0] == '/') -managed_system = strdup(conn-uri-path + 1); -else -managed_system = strdup(conn-uri-path); - -if (!managed_system) { +if ((conn-uri-path[0] == '/' + VIR_STRDUP(managed_system, conn-uri-path + 1) 0) || +(conn-uri-path[0] != '/' + VIR_STRDUP(managed_system, conn-uri-path) 0)) { virReportOOMError(); goto failure; } @@ -1498,9 +1494,7 @@ phypGetBackingDevice(virConnectPtr conn, const char *managed_system, else goto cleanup; -backing_device = strdup(char_ptr); - -if (backing_device == NULL) { +if (VIR_STRDUP(backing_device, char_ptr) 0) { virReportOOMError(); goto cleanup; } @@ -1731,9 +1725,7 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml) goto cleanup; } -def-os.type = strdup(aix); - -if (def-os.type == NULL) { +if (VIR_STRDUP(def-os.type, aix) 0) { virReportOOMError(); goto cleanup; } @@ -2281,9 +2273,7 @@ phypStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags) goto cleanup; } -voldef.key = strdup(vol-key); - -if (voldef.key == NULL) { +if (VIR_STRDUP(voldef.key, vol-key) 0) { virReportOOMError(); goto cleanup; } @@ -2399,7 +2389,7 @@ phypStoragePoolListVolumes(virStoragePoolPtr pool, char **const volumes, if (char_ptr) { *char_ptr = '\0'; -if ((volumes[got++] = strdup(volumes_list)) == NULL) { +if (VIR_STRDUP(volumes[got++], volumes_list) 0) { virReportOOMError(); goto cleanup; } @@ -2600,7 +2590,7 @@ phypConnectListStoragePools(virConnectPtr conn, char **const pools, int npools) if (char_ptr) { *char_ptr = '\0'; -if ((pools[got++] = strdup(storage_pools)) == NULL) { +if (VIR_STRDUP(pools[got++], storage_pools) 0) { virReportOOMError(); goto cleanup; } @@ -3067,7 +3057,7 @@ phypConnectListInterfaces(virConnectPtr conn, char **const names, int nnames) if (char_ptr) { *char_ptr = '\0'; -if ((names[got++] = strdup(networks)) == NULL) { +if (VIR_STRDUP(names[got++], networks) 0) { virReportOOMError(); goto cleanup; } @@ -3234,7 +3224,7 @@ phypConnectListDefinedDomains(virConnectPtr conn, char **const names, int nnames if (char_ptr) { *char_ptr = '\0'; -if ((names[got++] = strdup(domains)) == NULL) { +if (VIR_STRDUP(names[got++], domains) 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 20/37] Adapt to VIR_STRDUP in src/rpc/*
--- src/rpc/gendispatch.pl | 13 + src/rpc/virnetclient.c | 8 src/rpc/virnetmessage.c | 11 ++- src/rpc/virnetsaslcontext.c | 3 ++- src/rpc/virnetserver.c | 4 ++-- src/rpc/virnetserverclient.c | 6 ++ src/rpc/virnetservermdns.c | 4 ++-- src/rpc/virnetsocket.c | 6 -- src/rpc/virnetsshsession.c | 22 +++--- src/rpc/virnettlscontext.c | 13 ++--- 10 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index 7b93062..f1ddeed 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -610,9 +610,9 @@ elsif ($mode eq server) { # SPECIAL: virConnectGetType returns a constant string that must # not be freed. Therefore, duplicate the string here. push(@vars_list, const char *$1); -push(@ret_list, /* We have to strdup because remoteDispatchClientRequest will); +push(@ret_list, /* We have to VIR_STRDUP because remoteDispatchClientRequest will); push(@ret_list, * free this string after it's been serialised. */); -push(@ret_list, if (!(ret-type = strdup(type))) {); +push(@ret_list, if (VIR_STRDUP(ret-type, type) 0) {); push(@ret_list, virReportOOMError();); push(@ret_list, goto cleanup;); push(@ret_list, }); @@ -636,8 +636,7 @@ elsif ($mode eq server) { goto cleanup;\n . }\n . \n . - *$1_p = strdup($1);\n . - if (*$1_p == NULL) {\n . + if (VIR_STRDUP(*$1_p, $1) 0) {\n . virReportOOMError();\n . goto cleanup;\n . }\n); @@ -1562,12 +1561,10 @@ elsif ($mode eq client) { print \n; print /* This call is caller-frees (although that isn't clear from\n; print * the documentation). However xdr_free will free up both the\n; -print * names and the list of pointers, so we have to strdup the\n; +print * names and the list of pointers, so we have to VIR_STRDUP the\n; print * names here. */\n; print for (i = 0; i ret.$single_ret_list_name.${single_ret_list_name}_len; ++i) {\n; -print ${single_ret_list_name}[i] = strdup(ret.$single_ret_list_name.${single_ret_list_name}_val[i]);\n; -print \n; -print if (${single_ret_list_name}[i] == NULL) {\n; +print if (VIR_STRDUP(${single_ret_list_name}[i], ret.$single_ret_list_name.${single_ret_list_name}_val[i]) 0) {\n; print for (--i; i = 0; --i)\n; print VIR_FREE(${single_ret_list_name}[i]);\n; print \n; diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 1d228f0..edeb597 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -36,6 +36,7 @@ #include virlog.h #include virutil.h #include virerror.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_RPC @@ -317,8 +318,7 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock, client-wakeupSendFD = wakeupFD[1]; wakeupFD[0] = wakeupFD[1] = -1; -if (hostname -!(client-hostname = strdup(hostname))) +if (hostname VIR_STRDUP(client-hostname, hostname) 0) goto no_memory; PROBE(RPC_CLIENT_NEW, @@ -414,7 +414,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, goto no_memory; } } else { -if (!(knownhosts = strdup(knownHostsPath))) +if (VIR_STRDUP(knownhosts, knownHostsPath) 0) goto no_memory; } } @@ -438,7 +438,7 @@ virNetClientPtr virNetClientNewLibSSH2(const char *host, VIR_FREE(privkey); } } else { -if (!(privkey = strdup(privkeyPath))) +if (VIR_STRDUP(privkey, privkeyPath) 0) goto no_memory; } } diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 647fef7..6b2aa47 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -29,6 +29,7 @@ #include virlog.h #include virfile.h #include virutil.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_RPC @@ -485,21 +486,21 @@ void virNetMessageSaveError(virNetMessageErrorPtr rerr) rerr-code = verr-code; rerr-domain = verr-domain; if (verr-message VIR_ALLOC(rerr-message) == 0) -*rerr-message = strdup(verr-message); +
[libvirt] [PATCH v2 24/37] Adapt to VIR_STRDUP in src/test/*
--- src/test/test_driver.c | 82 +++--- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index f60f106..b7c121e 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -219,12 +219,10 @@ testBuildCapabilities(virConnectPtr conn) { caps-host.nsecModels = 1; if (VIR_ALLOC_N(caps-host.secModels, caps-host.nsecModels) 0) goto no_memory; -caps-host.secModels[0].model = strdup(testSecurity); -if (!caps-host.secModels[0].model) +if (VIR_STRDUP(caps-host.secModels[0].model, testSecurity) 0) goto no_memory; -caps-host.secModels[0].doi = strdup(); -if (!caps-host.secModels[0].doi) +if (VIR_STRDUP(caps-host.secModels[0].doi, ) 0) goto no_memory; return caps; @@ -673,10 +671,14 @@ static char *testBuildFilename(const char *relativeTo, const char *filename) { char *offset; int baseLen; +char *ret = NULL; + if (!filename || filename[0] == '\0') return NULL; -if (filename[0] == '/') -return strdup(filename); +if (filename[0] == '/') { +ignore_value(VIR_STRDUP(ret, filename)); +return ret; +} offset = strrchr(relativeTo, '/'); if ((baseLen = (offset-relativeTo+1))) { @@ -691,7 +693,8 @@ static char *testBuildFilename(const char *relativeTo, strcat(absFile, filename); return absFile; } else { -return strdup(filename); +ignore_value(VIR_STRDUP(ret, filename)); +return ret; } } @@ -754,12 +757,9 @@ static int testOpenVolumesForPool(xmlDocPtr xml, } } -if (def-key == NULL) { -def-key = strdup(def-target.path); -if (def-key == NULL) { -virReportOOMError(); -goto error; -} +if (!def-key VIR_STRDUP(def-key, def-target.path) 0) { +virReportOOMError(); +goto error; } pool-def-allocation += def-allocation; @@ -826,7 +826,7 @@ static int testOpenFromFile(virConnectPtr conn, privconn-nextDomID = 1; privconn-numCells = 0; -if ((privconn-path = strdup(file)) == NULL) { +if (VIR_STRDUP(privconn-path, file) 0) { virReportOOMError(); goto error; } @@ -2060,8 +2060,9 @@ cleanup: } static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { -char *ret = strdup(linux); -if (!ret) +char *ret; + +if (VIR_STRDUP(ret, linux) 0) virReportOOMError(); return ret; } @@ -2720,8 +2721,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, if (nparams) *nparams = 1; -type = strdup(fair); -if (!type) +if (VIR_STRDUP(type, fair) 0) virReportOOMError(); return type; @@ -3020,7 +3020,7 @@ static int testConnectListNetworks(virConnectPtr conn, char **const names, int n for (i = 0 ; i privconn-networks.count n nnames ; i++) { virNetworkObjLock(privconn-networks.objs[i]); if (virNetworkObjIsActive(privconn-networks.objs[i]) -!(names[n++] = strdup(privconn-networks.objs[i]-def-name))) { +VIR_STRDUP(names[n++], privconn-networks.objs[i]-def-name) 0) { virNetworkObjUnlock(privconn-networks.objs[i]); goto no_memory; } @@ -3063,7 +3063,7 @@ static int testConnectListDefinedNetworks(virConnectPtr conn, char **const names for (i = 0 ; i privconn-networks.count n nnames ; i++) { virNetworkObjLock(privconn-networks.objs[i]); if (!virNetworkObjIsActive(privconn-networks.objs[i]) -!(names[n++] = strdup(privconn-networks.objs[i]-def-name))) { +VIR_STRDUP(names[n++], privconn-networks.objs[i]-def-name) 0) { virNetworkObjUnlock(privconn-networks.objs[i]); goto no_memory; } @@ -3381,7 +3381,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) { goto cleanup; } -if (!(bridge = strdup(privnet-def-bridge))) { +if (VIR_STRDUP(bridge, privnet-def-bridge) 0) { virReportOOMError(); goto cleanup; } @@ -3494,7 +3494,7 @@ static int testConnectListInterfaces(virConnectPtr conn, char **const names, int for (i = 0 ; (i privconn-ifaces.count) (n nnames); i++) { virInterfaceObjLock(privconn-ifaces.objs[i]); if (virInterfaceObjIsActive(privconn-ifaces.objs[i])) { -if (!(names[n++] = strdup(privconn-ifaces.objs[i]-def-name))) { +if (VIR_STRDUP(names[n++], privconn-ifaces.objs[i]-def-name) 0) { virInterfaceObjUnlock(privconn-ifaces.objs[i]); goto no_memory; } @@ -3540,7 +3540,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam for (i = 0 ; (i
[libvirt] [PATCH v2 14/37] Adapt to VIR_STRDUP in src/nwfilter/*
--- src/nwfilter/nwfilter_dhcpsnoop.c | 15 +++ src/nwfilter/nwfilter_driver.c| 4 ++-- src/nwfilter/nwfilter_ebiptables_driver.c | 10 +- src/nwfilter/nwfilter_gentech_driver.c| 4 ++-- src/nwfilter/nwfilter_learnipaddr.c | 3 +-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c index df11e89..3047d4d 100644 --- a/src/nwfilter/nwfilter_dhcpsnoop.c +++ b/src/nwfilter/nwfilter_dhcpsnoop.c @@ -133,11 +133,11 @@ struct _virNWFilterSnoopReq { virNWFilterTechDriverPtr techdriver; char*ifname; int ifindex; -const char *linkdev; +char*linkdev; enum virDomainNetTypenettype; char ifkey[VIR_IFKEY_LEN]; virMacAddr macaddr; -const char *filtername; +char*filtername; virNWFilterHashTablePtr vars; virNWFilterDriverStatePtrdriver; /* start and end of lease list, ordered by lease time */ @@ -1408,7 +1408,7 @@ virNWFilterDHCPSnoopThread(void *req0) fds[i].fd = pcap_fileno(pcapConf[i].handle); } tmp = virNetDevGetIndex(req-ifname, ifindex); -threadkey = strdup(req-threadkey); +ignore_value(VIR_STRDUP(threadkey, req-threadkey)); worker = virThreadPoolNew(1, 1, 0, virNWFilterDHCPDecodeWorker, req); @@ -1631,15 +1631,14 @@ virNWFilterDHCPSnoopReq(virNWFilterTechDriverPtr techdriver, req-driver = driver; req-techdriver = techdriver; tmp = virNetDevGetIndex(ifname, req-ifindex); -req-linkdev = linkdev ? strdup(linkdev) : NULL; +req-linkdev = NULL; req-nettype = nettype; -req-ifname = strdup(ifname); virMacAddrSet(req-macaddr, macaddr); -req-filtername = strdup(filtername); req-vars = virNWFilterHashTableCreate(0); -if (!req-ifname || !req-filtername || !req-vars || tmp 0 || -(linkdev != NULL req-linkdev == NULL)) { +if ((linkdev VIR_STRDUP(req-linkdev, linkdev) 0) || +VIR_STRDUP(req-ifname, ifname) 0 || +VIR_STRDUP(req-filtername, filtername) 0 || !req-vars || tmp 0) { virReportOOMError(); goto exit_snoopreqput; } diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 7eec3de..0a3c24f 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -221,7 +221,7 @@ nwfilterStateInitialize(bool privileged, goto error; } -if ((base = strdup(SYSCONFDIR /libvirt)) == NULL) +if (VIR_STRDUP(base, SYSCONFDIR /libvirt) 0) goto out_of_memory; if (virAsprintf(driverState-configDir, @@ -454,7 +454,7 @@ nwfilterConnectListNWFilters(virConnectPtr conn, nwfilterDriverLock(driver); for (i = 0 ; i driver-nwfilters.count got nnames ; i++) { virNWFilterObjLock(driver-nwfilters.objs[i]); -if (!(names[got] = strdup(driver-nwfilters.objs[i]-def-name))) { +if (VIR_STRDUP(names[got], driver-nwfilters.objs[i]-def-name) 0) { virNWFilterObjUnlock(driver-nwfilters.objs[i]); virReportOOMError(); goto cleanup; diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index ac94355..5d1c8d7 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -2975,6 +2975,7 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, char chainPrefix = (incoming) ? CHAINPREFIX_HOST_IN_TEMP : CHAINPREFIX_HOST_OUT_TEMP; char *protostr = NULL; +int rc; PRINT_ROOT_CHAIN(rootchain, chainPrefix, ifname); PRINT_CHAIN(chain, chainPrefix, ifname, @@ -2982,18 +2983,17 @@ ebtablesCreateTmpSubChain(ebiptablesRuleInstPtr *inst, switch (protoidx) { case L2_PROTO_MAC_IDX: -protostr = strdup(); +rc = VIR_STRDUP(protostr, ); break; case L2_PROTO_STP_IDX: -ignore_value(virAsprintf(protostr, -d NWFILTER_MAC_BGA )); +rc = virAsprintf(protostr, -d NWFILTER_MAC_BGA ); break; default: -ignore_value(virAsprintf(protostr, -p 0x%04x , - l3_protocols[protoidx].attr)); +rc = virAsprintf(protostr, -p 0x%04x , l3_protocols[protoidx].attr); break; } -if (!protostr) { +if (rc 0) { virReportOOMError(); return -1; } diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 958f47a..90f38f3 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++
[libvirt] [PATCH v2 16/37] Adapt to VIR_STRDUP in src/parallels/*
--- src/parallels/parallels_driver.c | 34 +- src/parallels/parallels_network.c | 12 ++-- src/parallels/parallels_storage.c | 38 +++--- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index c29a5ba..fd3e3bc 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -186,7 +186,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } -if (!(chr-source.data.file.path = strdup(tmp))) +if (VIR_STRDUP(chr-source.data.file.path, tmp) 0) goto no_memory; } else if (virJSONValueObjectHasKey(value, socket)) { chr-source.type = VIR_DOMAIN_CHR_TYPE_UNIX; @@ -197,7 +197,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } -if (!(chr-source.data.nix.path = strdup(tmp))) +if (VIR_STRDUP(chr-source.data.nix.path, tmp) 0) goto no_memory; chr-source.data.nix.listen = false; } else if (virJSONValueObjectHasKey(value, real)) { @@ -209,7 +209,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr, return -1; } -if (!(chr-source.data.file.path = strdup(tmp))) +if (VIR_STRDUP(chr-source.data.file.path, tmp) 0) goto no_memory; } else { parallelsParseError(); @@ -318,7 +318,7 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } -if (!(disk-src = strdup(tmp))) { +if (VIR_STRDUP(disk-src, tmp) 0) { virReportOOMError(); return -1; } @@ -330,7 +330,7 @@ parallelsGetHddInfo(virDomainDefPtr def, return -1; } -if (!(disk-src = strdup(tmp))) { +if (VIR_STRDUP(disk-src, tmp) 0) { virReportOOMError(); return -1; } @@ -454,7 +454,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net, /* use device name, shown by prlctl as target device * for identifying network adapter in virDomainDefineXML */ -if (!(net-ifname = strdup(key))) { +if (VIR_STRDUP(net-ifname, key) 0) { virReportOOMError(); goto error; } @@ -478,7 +478,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } -if (!(net-data.network.name = strdup(tmp))) { +if (VIR_STRDUP(net-data.network.name, tmp) 0) { virReportOOMError(); goto error; } @@ -493,7 +493,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net, goto error; } -if (!(net-data.network.name = strdup(PARALLELS_ROUTED_NETWORK_NAME))) { +if (VIR_STRDUP(net-data.network.name, PARALLELS_ROUTED_NETWORK_NAME) 0) { virReportOOMError(); goto error; } @@ -641,7 +641,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root) gr-nListens = 1; -if (!(gr-listens[0].address = strdup(tmp))) +if (VIR_STRDUP(gr-listens[0].address, tmp) 0) goto no_memory; gr-listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; @@ -686,7 +686,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } -if (!(def-name = strdup(tmp))) +if (VIR_STRDUP(def-name, tmp) 0) goto no_memory; if (!(tmp = virJSONValueObjectGetString(jobj, ID))) { @@ -704,7 +704,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } -if (!(def-description = strdup(tmp))) +if (VIR_STRDUP(def-description, tmp) 0) goto no_memory; if (!(jobj2 = virJSONValueObjectGet(jobj, Hardware))) { @@ -771,12 +771,12 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) } if (STREQ(tmp, CT)) { -if (!(def-os.type = strdup(exe))) +if (VIR_STRDUP(def-os.type, exe) 0) goto no_memory; -if (!(def-os.init = strdup(/sbin/init))) +if (VIR_STRDUP(def-os.init, /sbin/init) 0) goto no_memory; } else if (STREQ(tmp, VM)) { -if (!(def-os.type = strdup(hvm))) +if (VIR_STRDUP(def-os.type, hvm) 0) goto no_memory; } @@ -792,7 +792,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) parallelsParseError(); goto cleanup; } -if (!(pdom-uuid = strdup(tmp))) +if (VIR_STRDUP(pdom-uuid, tmp) 0) goto no_memory; if (!(tmp = virJSONValueObjectGetString(jobj, Home))) { @@ -800,7 +800,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj) goto cleanup; } -if (!(pdom-home = strdup(tmp))) +if (VIR_STRDUP(pdom-home, tmp) 0) goto no_memory; if (!(state =
[libvirt] [PATCH v2 06/37] Adapt to VIR_STRDUP in src/esx/*
--- src/esx/esx_driver.c| 33 + src/esx/esx_interface_driver.c | 5 ++-- src/esx/esx_network_driver.c| 20 ++- src/esx/esx_storage_backend_iscsi.c | 14 --- src/esx/esx_storage_backend_vmfs.c | 8 ++ src/esx/esx_util.c | 37 +--- src/esx/esx_vi.c| 49 + src/esx/esx_vi_types.c | 22 + 8 files changed, 58 insertions(+), 130 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index dcf64b8..a5caafe 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -669,9 +669,7 @@ esxConnectToHost(esxPrivate *priv, } if (conn-uri-user != NULL) { -username = strdup(conn-uri-user); - -if (username == NULL) { +if (VIR_STRDUP(username, conn-uri-user) 0) { virReportOOMError(); goto cleanup; } @@ -751,13 +749,10 @@ esxConnectToHost(esxPrivate *priv, VIR_WARN(The server is in maintenance mode); } -if (*vCenterIpAddress != NULL) { -*vCenterIpAddress = strdup(*vCenterIpAddress); - -if (*vCenterIpAddress == NULL) { -virReportOOMError(); -goto cleanup; -} +if (*vCenterIpAddress +VIR_STRDUP(*vCenterIpAddress, *vCenterIpAddress) 0) { +virReportOOMError(); +goto cleanup; } result = 0; @@ -801,9 +796,7 @@ esxConnectToVCenter(esxPrivate *priv, } if (conn-uri-user != NULL) { -username = strdup(conn-uri-user); - -if (username == NULL) { +if (VIR_STRDUP(username, conn-uri-user) 0) { virReportOOMError(); goto cleanup; } @@ -1278,9 +1271,7 @@ esxConnectGetHostname(virConnectPtr conn) } if (domainName == NULL || strlen(domainName) 1) { -complete = strdup(hostName); - -if (complete == NULL) { +if (VIR_STRDUP(complete, hostName) 0) { virReportOOMError(); goto cleanup; } @@ -1294,7 +1285,7 @@ esxConnectGetHostname(virConnectPtr conn) cleanup: /* * If we goto cleanup in case of an error then complete is still NULL, - * either strdup returned NULL or virAsprintf failed. When virAsprintf + * either VIR_STRDUP returned NULL or virAsprintf failed. When virAsprintf * fails it guarantees setting complete to NULL */ esxVI_String_Free(propertyNameList); @@ -2016,9 +2007,9 @@ esxDomainDestroy(virDomainPtr dom) static char * esxDomainGetOSType(virDomainPtr domain ATTRIBUTE_UNUSED) { -char *osType = strdup(hvm); +char *osType; -if (osType == NULL) { +if (VIR_STRDUP(osType, hvm) 0) { virReportOOMError(); return NULL; } @@ -3577,9 +3568,9 @@ esxDomainSetAutostart(virDomainPtr domain, int autostart) static char * esxDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED, int *nparams) { -char *type = strdup(allocation); +char *type; -if (type == NULL) { +if (VIR_STRDUP(type, allocation) 0) { virReportOOMError(); return NULL; } diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c index fe5194c..ba006a2 100644 --- a/src/esx/esx_interface_driver.c +++ b/src/esx/esx_interface_driver.c @@ -35,6 +35,7 @@ #include esx_vi.h #include esx_vi_methods.h #include esx_util.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_ESX @@ -114,9 +115,7 @@ esxConnectListInterfaces(virConnectPtr conn, char **const names, int maxnames) for (physicalNic = physicalNicList; physicalNic != NULL; physicalNic = physicalNic-_next) { -names[count] = strdup(physicalNic-device); - -if (names[count] == NULL) { +if (VIR_STRDUP(names[count], physicalNic-device) 0) { virReportOOMError(); goto cleanup; } diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c index fd57b61..cb6a806 100644 --- a/src/esx/esx_network_driver.c +++ b/src/esx/esx_network_driver.c @@ -35,6 +35,7 @@ #include esx_vi.h #include esx_vi_methods.h #include esx_util.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_ESX @@ -122,9 +123,7 @@ esxConnectListNetworks(virConnectPtr conn, char **const names, int maxnames) for (hostVirtualSwitch = hostVirtualSwitchList; hostVirtualSwitch != NULL; hostVirtualSwitch = hostVirtualSwitch-_next) { -names[count] = strdup(hostVirtualSwitch-name); - -if (names[count] == NULL) { +if (VIR_STRDUP(names[count], hostVirtualSwitch-name) 0) { virReportOOMError(); goto cleanup; } @@ -713,9 +712,7 @@ esxNetworkGetXMLDesc(virNetworkPtr network_, unsigned int flags) md5_buffer(hostVirtualSwitch-key, strlen(hostVirtualSwitch-key), def-uuid); -def-name = strdup(hostVirtualSwitch-name); - -
[libvirt] [PATCH v2 11/37] Adapt to VIR_STRDUP in src/network/*
--- src/network/bridge_driver.c | 28 +++- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index b561e85..1a4029c 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -378,7 +378,7 @@ networkStateInitialize(bool privileged, %s/log/libvirt/qemu, LOCALSTATEDIR) == -1) goto out_of_memory; -if ((base = strdup(SYSCONFDIR /libvirt)) == NULL) +if (VIR_STRDUP(base, SYSCONFDIR /libvirt) 0) goto out_of_memory; } else { char *userdir = virGetUserCacheDirectory(); @@ -2820,7 +2820,7 @@ static int networkConnectListNetworks(virConnectPtr conn, char **const names, in for (i = 0 ; i driver-networks.count got nnames ; i++) { virNetworkObjLock(driver-networks.objs[i]); if (virNetworkObjIsActive(driver-networks.objs[i])) { -if (!(names[got] = strdup(driver-networks.objs[i]-def-name))) { +if (VIR_STRDUP(names[got], driver-networks.objs[i]-def-name) 0) { virNetworkObjUnlock(driver-networks.objs[i]); virReportOOMError(); goto cleanup; @@ -2864,7 +2864,7 @@ static int networkConnectListDefinedNetworks(virConnectPtr conn, char **const na for (i = 0 ; i driver-networks.count got nnames ; i++) { virNetworkObjLock(driver-networks.objs[i]); if (!virNetworkObjIsActive(driver-networks.objs[i])) { -if (!(names[got] = strdup(driver-networks.objs[i]-def-name))) { +if (VIR_STRDUP(names[got], driver-networks.objs[i]-def-name) 0) { virNetworkObjUnlock(driver-networks.objs[i]); virReportOOMError(); goto cleanup; @@ -3489,8 +3489,7 @@ static char *networkGetBridgeName(virNetworkPtr net) { goto cleanup; } -bridge = strdup(network-def-bridge); -if (!bridge) +if (VIR_STRDUP(bridge, network-def-bridge) 0) virReportOOMError(); cleanup: @@ -3678,14 +3677,11 @@ networkCreateInterfacePool(virNetworkDefPtr netdef) { (netdef-forward.type == VIR_NETWORK_FORWARD_VEPA) || (netdef-forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) { netdef-forward.ifs[ii].type = VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV; -if (vfname[ii]) { -netdef-forward.ifs[ii].device.dev = strdup(vfname[ii]); -if (!netdef-forward.ifs[ii].device.dev) { -virReportOOMError(); -goto finish; -} -} -else { +if (vfname[ii] +VIR_STRDUP(netdef-forward.ifs[ii].device.dev, vfname[ii]) 0) { +virReportOOMError(); +goto finish; +} else { virReportError(VIR_ERR_INTERNAL_ERROR, %s, _(Direct mode types require interface names)); goto finish; @@ -3828,8 +3824,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) } iface-data.network.actual-type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE; -iface-data.network.actual-data.bridge.brname = strdup(netdef-bridge); -if (!iface-data.network.actual-data.bridge.brname) { +if (VIR_STRDUP(iface-data.network.actual-data.bridge.brname, netdef-bridge) 0) { virReportOOMError(); goto error; } @@ -4049,8 +4044,7 @@ networkAllocateActualDevice(virDomainNetDefPtr iface) netdef-name); goto error; } -iface-data.network.actual-data.direct.linkdev = strdup(dev-device.dev); -if (!iface-data.network.actual-data.direct.linkdev) { +if (VIR_STRDUP(iface-data.network.actual-data.direct.linkdev, dev-device.dev) 0) { virReportOOMError(); goto error; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 03/37] Adapt to VIR_STRDUP in daemon/*
--- daemon/libvirtd-config.c | 37 ++- daemon/libvirtd.c| 17 + daemon/remote.c | 94 3 files changed, 66 insertions(+), 82 deletions(-) diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index efb564e..df2bc7b 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -59,15 +59,14 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, key); return -1; } -list[0] = strdup(p-str); -list[1] = NULL; -if (list[0] == NULL) { +if (VIR_STRDUP(list[0], p-str) 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(failed to allocate memory for %s config list value), key); VIR_FREE(list); return -1; } +list[1] = NULL; break; case VIR_CONF_LIST: { @@ -90,8 +89,7 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, VIR_FREE(list); return -1; } -list[i] = strdup(pp-str); -if (list[i] == NULL) { +if (VIR_STRDUP(list[i], pp-str) 0) { int j; for (j = 0 ; j i ; j++) VIR_FREE(list[j]); @@ -136,8 +134,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and goto the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do {\ @@ -146,7 +144,7 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) 0) \ goto error; \ VIR_FREE(data-var_name); \ -if (!(data-var_name = strdup(p-str))) { \ +if (VIR_STRDUP(data-var_name, p-str) 0) { \ virReportOOMError();\ goto error; \ } \ @@ -200,7 +198,7 @@ int daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { -if (!(*configfile = strdup(SYSCONFDIR /libvirt/libvirtd.conf))) +if (VIR_STRDUP(*configfile, SYSCONFDIR /libvirt/libvirtd.conf) 0) goto no_memory; } else { char *configdir = NULL; @@ -238,9 +236,9 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) data-listen_tls = 1; data-listen_tcp = 0; -if (!(data-tls_port = strdup(LIBVIRTD_TLS_PORT))) +if (VIR_STRDUP(data-tls_port, LIBVIRTD_TLS_PORT) 0) goto no_memory; -if (!(data-tcp_port = strdup(LIBVIRTD_TCP_PORT))) +if (VIR_STRDUP(data-tcp_port, LIBVIRTD_TCP_PORT) 0) goto no_memory; /* Only default to PolicyKit if running as root */ @@ -256,13 +254,14 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) } #endif -if (data-auth_unix_rw == REMOTE_AUTH_POLKIT) -data-unix_sock_rw_perms = strdup(0777); /* Allow world */ -else -data-unix_sock_rw_perms = strdup(0700); /* Allow user only */ -data-unix_sock_ro_perms = strdup(0777); /* Always allow world */ -if (!data-unix_sock_ro_perms || -!data-unix_sock_rw_perms) +if (data-auth_unix_rw == REMOTE_AUTH_POLKIT) { +if (VIR_STRDUP(data-unix_sock_rw_perms, 0777) 0) +goto no_memory; +} else { +if (VIR_STRDUP(data-unix_sock_rw_perms, 0700) 0) +goto no_memory; +} +if (VIR_STRDUP(data-unix_sock_ro_perms, 0777) 0) goto no_memory; #if WITH_SASL @@ -382,7 +381,7 @@ daemonConfigLoadOptions(struct daemonConfig *data, */ if (data-auth_unix_rw == REMOTE_AUTH_POLKIT) { VIR_FREE(data-unix_sock_rw_perms); -if (!(data-unix_sock_rw_perms = strdup(0777))) { +if (VIR_STRDUP(data-unix_sock_rw_perms, 0777) 0) { virReportOOMError(); goto error; } diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 9f81a0f..07c064d 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -241,7 +241,7 @@ daemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { -if (!(*pidfile = strdup(LOCALSTATEDIR /run/libvirtd.pid))) +
[libvirt] [PATCH v2 32/37] Adapt to VIR_STRDUP in src/xenxs/*
--- src/xenxs/xen_sxpr.c | 107 +-- src/xenxs/xen_xm.c | 43 ++--- 2 files changed, 65 insertions(+), 85 deletions(-) diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 9a76d04..7ebaa30 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -192,8 +192,7 @@ xenParseSxprChar(const char *value, if (value[0] == '/') { def-source.type = VIR_DOMAIN_CHR_TYPE_DEV; -def-source.data.file.path = strdup(value); -if (!def-source.data.file.path) +if (VIR_STRDUP(def-source.data.file.path, value) 0) goto no_memory; } else { if ((tmp = strchr(value, ':')) != NULL) { @@ -216,13 +215,13 @@ xenParseSxprChar(const char *value, switch (def-source.type) { case VIR_DOMAIN_CHR_TYPE_PTY: if (tty != NULL -!(def-source.data.file.path = strdup(tty))) +VIR_STRDUP(def-source.data.file.path, tty) 0) goto no_memory; break; case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PIPE: -if (!(def-source.data.file.path = strdup(value))) +if (VIR_STRDUP(def-source.data.file.path, value) 0) goto no_memory; break; @@ -238,17 +237,14 @@ xenParseSxprChar(const char *value, } if (offset != value -(def-source.data.tcp.host = strndup(value, - offset - value)) == NULL) +VIR_STRNDUP(def-source.data.tcp.host, value, offset - value) 0) goto no_memory; offset2 = strchr(offset, ','); -if (offset2 == NULL) -def-source.data.tcp.service = strdup(offset+1); -else -def-source.data.tcp.service = strndup(offset+1, - offset2-(offset+1)); -if (def-source.data.tcp.service == NULL) + +if ((offset2 VIR_STRNDUP(def-source.data.tcp.service, offset + 1, +offset2 - (offset + 1)) 0) || +(!offset2 VIR_STRDUP(def-source.data.tcp.service, offset + 1) 0)) goto no_memory; if (offset2 strstr(offset2, ,server)) @@ -268,14 +264,12 @@ xenParseSxprChar(const char *value, } if (offset != value -(def-source.data.udp.connectHost - = strndup(value, offset - value)) == NULL) +VIR_STRNDUP(def-source.data.udp.connectHost, value, offset - value) 0) goto no_memory; offset2 = strchr(offset, '@'); if (offset2 != NULL) { -if ((def-source.data.udp.connectService - = strndup(offset + 1, offset2-(offset+1))) == NULL) +if (VIR_STRNDUP(def-source.data.udp.connectService, offset + 1, offset2-(offset+1)) 0) goto no_memory; offset3 = strchr(offset2, ':'); @@ -286,16 +280,13 @@ xenParseSxprChar(const char *value, } if (offset3 (offset2 + 1) -(def-source.data.udp.bindHost - = strndup(offset2 + 1, offset3 - (offset2+1))) == NULL) +VIR_STRNDUP(def-source.data.udp.bindHost, offset2 + 1, offset3 - (offset2+1)) 0) goto no_memory; -if ((def-source.data.udp.bindService - = strdup(offset3 + 1)) == NULL) +if (VIR_STRDUP(def-source.data.udp.bindService, offset3 + 1) 0) goto no_memory; } else { -if ((def-source.data.udp.connectService - = strdup(offset + 1)) == NULL) +if (VIR_STRDUP(def-source.data.udp.connectService, offset + 1) 0) goto no_memory; } } @@ -304,11 +295,9 @@ xenParseSxprChar(const char *value, case VIR_DOMAIN_CHR_TYPE_UNIX: { const char *offset = strchr(value, ','); -if (offset) -def-source.data.nix.path = strndup(value, (offset - value)); -else -def-source.data.nix.path = strdup(value); -if (def-source.data.nix.path == NULL) + +if ((offset VIR_STRNDUP(def-source.data.nix.path, value, (offset - value)) 0) || +(!offset VIR_STRDUP(def-source.data.nix.path, value) 0)) goto no_memory; if (offset != NULL @@ -411,7 +400,7 @@ xenParseSxprDisks(virDomainDefPtr def, if (sexpr_lookup(node, device/tap2) STRPREFIX(src, tap:)) { -if (!(disk-driverName = strdup(tap2))) +if (VIR_STRDUP(disk-driverName, tap2) 0) goto no_memory; } else { if (VIR_ALLOC_N(disk-driverName, (offset-src)+1) 0) @@ -438,7 +427,7 @@ xenParseSxprDisks(virDomainDefPtr def, goto error; } -if (!(driverType = strndup(src, offset - src))) +
[libvirt] [PATCH v2 19/37] Adapt to VIR_STRDUP in src/remote/*
--- src/remote/remote_driver.c | 79 -- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 97be2a0..89e0e96 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -368,7 +368,7 @@ remoteClientCloseFunc(virNetClientPtr client ATTRIBUTE_UNUSED, #define EXTRACT_URI_ARG_STR(ARG_NAME, ARG_VAR) \ if (STRCASEEQ(var-name, ARG_NAME)) { \ VIR_FREE(ARG_VAR); \ -if (!(ARG_VAR = strdup(var-value)))\ +if (VIR_STRDUP(ARG_VAR, var-value) 0)\ goto no_memory; \ var-ignore = 1;\ continue; \ @@ -497,23 +497,20 @@ doRemoteOpen(virConnectPtr conn, if (virAsprintf(port, %d, conn-uri-port) 0) goto no_memory; } else if (transport == trans_tls) { -if (!(port = strdup(LIBVIRTD_TLS_PORT))) +if (VIR_STRDUP(port, LIBVIRTD_TLS_PORT) 0) goto no_memory; } else if (transport == trans_tcp) { -if (!(port = strdup(LIBVIRTD_TCP_PORT))) +if (VIR_STRDUP(port, LIBVIRTD_TCP_PORT) 0) goto no_memory; } /* Port not used for unix, ext., default for ssh */ -if (conn-uri conn-uri-server) -priv-hostname = strdup(conn-uri-server); -else -priv-hostname = strdup(localhost); - -if (!priv-hostname) +if (VIR_STRDUP(priv-hostname, + conn-uri conn-uri-server ? + conn-uri-server : localhost) 0) goto no_memory; if (conn-uri conn-uri-user -!(username = strdup(conn-uri-user))) +VIR_STRDUP(username, conn-uri-user) 0) goto no_memory; /* Get the variables from the query string. @@ -557,7 +554,7 @@ doRemoteOpen(virConnectPtr conn, (STREQ(conn-uri-scheme, remote) || STRPREFIX(conn-uri-scheme, remote+))) { /* Allow remote serve to probe */ -if (!(name = strdup())) +if (VIR_STRDUP(name, ) 0) goto no_memory; } else { virURI tmpuri = { @@ -587,7 +584,7 @@ doRemoteOpen(virConnectPtr conn, } } else { /* Probe URI server side */ -if (!(name = strdup())) +if (VIR_STRDUP(name, ) 0) goto no_memory; } @@ -636,12 +633,10 @@ doRemoteOpen(virConnectPtr conn, case trans_libssh2: if (!sockname) { -if (flags VIR_DRV_OPEN_REMOTE_RO) -sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); -else -sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); - -if (sockname == NULL) +if (VIR_STRDUP(sockname, + flags VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) 0) goto no_memory; } @@ -678,11 +673,10 @@ doRemoteOpen(virConnectPtr conn, } VIR_FREE(userdir); } else { -if (flags VIR_DRV_OPEN_REMOTE_RO) -sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); -else -sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); -if (sockname == NULL) +if (VIR_STRDUP(sockname, + flags VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) 0) goto no_memory; } VIR_DEBUG(Proceeding with sockname %s, sockname); @@ -705,15 +699,14 @@ doRemoteOpen(virConnectPtr conn, break; case trans_ssh: -if (!command !(command = strdup(ssh))) +if (!command VIR_STRDUP(command, ssh) 0) goto no_memory; if (!sockname) { -if (flags VIR_DRV_OPEN_REMOTE_RO) -sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET_RO); -else -sockname = strdup(LIBVIRTD_PRIV_UNIX_SOCKET); -if (!sockname) +if (VIR_STRDUP(sockname, + flags VIR_DRV_OPEN_REMOTE_RO ? + LIBVIRTD_PRIV_UNIX_SOCKET_RO : + LIBVIRTD_PRIV_UNIX_SOCKET) 0) goto no_memory; } @@ -1493,8 +1486,7 @@ remoteSerializeTypedParameters(virTypedParameterPtr params, for (i = 0; i nparams; ++i) { /* call() will free this: */ -val[i].field = strdup(params[i].field); -if (val[i].field == NULL) { +if (VIR_STRDUP(val[i].field, params[i].field) 0) { virReportOOMError(); goto cleanup; } @@
[libvirt] [PATCH v2 23/37] Adapt to VIR_STRDUP in src/storage/*
--- src/storage/parthelper.c | 7 --- src/storage/storage_backend.c | 16 ++-- src/storage/storage_backend_disk.c| 14 +++--- src/storage/storage_backend_fs.c | 17 - src/storage/storage_backend_iscsi.c | 14 ++ src/storage/storage_backend_logical.c | 24 src/storage/storage_backend_mpath.c | 3 +-- src/storage/storage_backend_rbd.c | 3 +-- src/storage/storage_backend_scsi.c| 16 +++- src/storage/storage_driver.c | 11 +-- 10 files changed, 57 insertions(+), 68 deletions(-) diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index c4af48f..a1fd516 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -44,6 +44,9 @@ #include virutil.h #include c-ctype.h #include configmake.h +#include virstring.h + +#define VIR_FROM_THIS VIR_FROM_NONE /* we don't need to include the full internal.h just for this */ #define STREQ(a,b) (strcmp(a,b) == 0) @@ -86,10 +89,8 @@ int main(int argc, char **argv) path = argv[1]; if (virIsDevMapperDevice(path)) { partsep = p; -canonical_path = strdup(path); -if (canonical_path == NULL) { +if (VIR_STRDUP(canonical_path, path) 0) return 2; -} } else { if (virFileResolveLink(path, canonical_path) != 0) { return 2; diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index b85a5a9..f14de87 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -486,8 +486,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn, goto cleanup; def-usage_type = VIR_SECRET_USAGE_TYPE_VOLUME; -def-usage.volume = strdup(vol-target.path); -if (def-usage.volume == NULL) { +if (VIR_STRDUP(def-usage.volume, vol-target.path) 0) { virReportOOMError(); goto cleanup; } @@ -1261,12 +1260,12 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target, target-perms.label = NULL; } } else { -target-perms.label = strdup(filecon); -freecon(filecon); -if (target-perms.label == NULL) { +if (VIR_STRDUP(target-perms.label, filecon) 0) { +freecon(filecon); virReportOOMError(); return -1; } +freecon(filecon); } #else target-perms.label = NULL; @@ -1451,9 +1450,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool, * the original non-stable dev path */ -stablepath = strdup(devpath); - -if (stablepath == NULL) +if (VIR_STRDUP(stablepath, devpath) 0) virReportOOMError(); return stablepath; @@ -1556,8 +1553,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, for (j = 0 ; j nvars[i] ; j++) { /* NB vars[0] is the full pattern, so we offset j by 1 */ p[vars[j+1].rm_eo] = '\0'; -if ((groups[ngroup++] = - strdup(p + vars[j+1].rm_so)) == NULL) { +if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) 0) { virReportOOMError(); goto cleanup; } diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 6da2d12..c996416 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -66,14 +66,14 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, * strip the path to form a reasonable pool-unique name */ tmp = strrchr(groups[0], '/'); -if ((vol-name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) { +if (VIR_STRDUP(vol-name, tmp ? tmp + 1 : groups[0]) 0) { virReportOOMError(); return -1; } } if (vol-target.path == NULL) { -if ((devpath = strdup(groups[0])) == NULL) { +if (VIR_STRDUP(devpath, groups[0]) 0) { virReportOOMError(); return -1; } @@ -92,7 +92,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, if (vol-key == NULL) { /* XXX base off a unique key of the underlying disk */ -if ((vol-key = strdup(vol-target.path)) == NULL) { +if (VIR_STRDUP(vol-key, vol-target.path) 0) { virReportOOMError(); return -1; } @@ -119,8 +119,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool, return -1; } -if ((vol-source.extents[0].path = - strdup(pool-def-source.devices[0].path)) == NULL) { +if (VIR_STRDUP(vol-source.extents[0].path, + pool-def-source.devices[0].path) 0) { virReportOOMError(); return -1; } @@ -485,7 +485,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
[libvirt] [PATCH v2 31/37] Adapt to VIR_STRDUP in src/xenapi/*
--- src/xenapi/xenapi_driver.c | 32 +++- src/xenapi/xenapi_utils.c | 20 ++-- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 7e64df6..86abab8 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -135,9 +135,7 @@ xenapiConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, } if (conn-uri-user != NULL) { -username = strdup(conn-uri-user); - -if (username == NULL) { +if (VIR_STRDUP(username, conn-uri-user) 0) { virReportOOMError(); goto error; } @@ -320,7 +318,7 @@ xenapiConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) if (result result-size 0) { for (i = 0; i result-size; i++) { if (STREQ(result-contents[i].key, xen)) { -if (!(version = strdup(result-contents[i].val))) { +if (VIR_STRDUP(version, result-contents[i].val) 0) { xen_string_string_map_free(result); virReportOOMError(); return -1; @@ -952,7 +950,7 @@ xenapiDomainGetOSType(virDomainPtr dom) xenapiSessionErrorHandler(dom-conn, VIR_ERR_INTERNAL_ERROR, NULL); goto cleanup; } -if (!(ostype = (STREQ(boot_policy,BIOS order) ? strdup(hvm) : strdup(xen +if (VIR_STRDUP(ostype, STREQ(boot_policy, BIOS order) ? hvm : xen) 0) virReportOOMError(); VIR_FREE(boot_policy); } else @@ -1268,7 +1266,7 @@ xenapiDomainGetVcpus(virDomainPtr dom, } for (i = 0; i vcpu_params-size; i++) { if (STREQ(vcpu_params-contents[i].key, mask)) { -if (!(mask = strdup(vcpu_params-contents[i].val))){ +if (VIR_STRDUP(mask, vcpu_params-contents[i].val) 0){ xen_vm_set_free(vms); xen_string_string_map_free(vcpu_params); virReportOOMError(); @@ -1386,11 +1384,11 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) defPtr-virtType = VIR_DOMAIN_VIRT_XEN; defPtr-id = dom-id; memcpy(defPtr-uuid, dom-uuid, VIR_UUID_BUFLEN); -if (!(defPtr-name = strdup(dom-name))) +if (VIR_STRDUP(defPtr-name, dom-name) 0) goto error_cleanup; xen_vm_get_hvm_boot_policy(session, boot_policy, vm); if (STREQ(boot_policy,BIOS order)) { -if (!(defPtr-os.type = strdup(hvm))) { +if (VIR_STRDUP(defPtr-os.type, hvm) 0) { VIR_FREE(boot_policy); goto error_cleanup; } @@ -1413,17 +1411,17 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) VIR_FREE(boot_policy); } else { char *value = NULL; -if (!(defPtr-os.type = strdup(xen))) { +if (VIR_STRDUP(defPtr-os.type, xen) 0) { VIR_FREE(boot_policy); goto error_cleanup; } -if (!(defPtr-os.loader = strdup(pygrub))) { +if (VIR_STRDUP(defPtr-os.loader, pygrub) 0) { VIR_FREE(boot_policy); goto error_cleanup; } xen_vm_get_pv_kernel(session, value, vm); if (STRNEQ(value, )) { -if (!(defPtr-os.kernel = strdup(value))) { +if (VIR_STRDUP(defPtr-os.kernel, value) 0) { VIR_FREE(boot_policy); VIR_FREE(value); goto error_cleanup; @@ -1432,7 +1430,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) } xen_vm_get_pv_ramdisk(session, value, vm); if (STRNEQ(value, )) { -if (!(defPtr-os.initrd = strdup(value))) { +if (VIR_STRDUP(defPtr-os.initrd, value) 0) { VIR_FREE(boot_policy); VIR_FREE(value); goto error_cleanup; @@ -1441,7 +1439,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) } xen_vm_get_pv_args(session, value, vm); if (STRNEQ(value, )) { -if (!(defPtr-os.cmdline = strdup(value))) { +if (VIR_STRDUP(defPtr-os.cmdline, value) 0) { VIR_FREE(boot_policy); VIR_FREE(value); goto error_cleanup; @@ -1449,12 +1447,12 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) VIR_FREE(value); } VIR_FREE(boot_policy); -if (!(defPtr-os.bootloader = strdup(pygrub))) +if (VIR_STRDUP(defPtr-os.bootloader, pygrub) 0) goto error_cleanup; } xen_vm_get_pv_bootloader_args(session, val, vm); if (STRNEQ(val, )) { -if (!(defPtr-os.bootloaderArgs = strdup(val))) { +if (VIR_STRDUP(defPtr-os.bootloaderArgs, val) 0) { VIR_FREE(val); goto error_cleanup; } @@ -1569,7 +1567,7 @@ xenapiConnectListDefinedDomains(virConnectPtr conn, char **const names, if (record != NULL) {
[libvirt] [PATCH v2 27/37] Adapt to VIR_STRDUP in src/vbox/*
--- src/vbox/vbox_XPCOMCGlue.c | 4 +- src/vbox/vbox_tmpl.c | 190 +++-- 2 files changed, 98 insertions(+), 96 deletions(-) diff --git a/src/vbox/vbox_XPCOMCGlue.c b/src/vbox/vbox_XPCOMCGlue.c index e0b606f..c5500b9 100644 --- a/src/vbox/vbox_XPCOMCGlue.c +++ b/src/vbox/vbox_XPCOMCGlue.c @@ -105,9 +105,7 @@ tryLoadOne(const char *dir, bool setAppHome, bool ignoreMissing, return -1; } } else { -name = strdup(DYNLIB_NAME); - -if (name == NULL) { +if (VIR_STRDUP(name, DYNLIB_NAME) 0) { virReportOOMError(); return -1; } diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 43ddac8..0e80194 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -1840,9 +1840,9 @@ static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { * is supposed to pass the ABI name and not the domain * operating system driver as I had imagined ;) */ -char *osType = strdup(hvm); +char *osType; -if (osType == NULL) +if (VIR_STRDUP(osType, hvm) 0) virReportOOMError(); return osType; @@ -2290,7 +2290,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def-virtType = VIR_DOMAIN_VIRT_VBOX; def-id = dom-id; memcpy(def-uuid, dom-uuid, VIR_UUID_BUFLEN); -def-name = strdup(dom-name); +ignore_value(VIR_STRDUP(def-name, dom-name)); machine-vtbl-GetMemorySize(machine, memorySize); def-mem.cur_balloon = memorySize * 1024; @@ -2325,7 +2325,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */ -def-os.type = strdup(hvm); +ignore_value(VIR_STRDUP(def-os.type, hvm)); def-os.arch = virArchFromHost(); @@ -2460,9 +2460,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (STREQ(valueTypeUtf8, sdl)) { sdlPresent = 1; -if (valueDisplayUtf8) -sdlDisplay = strdup(valueDisplayUtf8); -if (sdlDisplay == NULL) { +if (valueDisplayUtf8 +VIR_STRDUP(sdlDisplay, valueDisplayUtf8) 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * sdlDisplay as NULL and we check it below if it @@ -2474,9 +2473,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (STREQ(valueTypeUtf8, gui)) { guiPresent = 1; -if (valueDisplayUtf8) -guiDisplay = strdup(valueDisplayUtf8); -if (guiDisplay == NULL) { +if (valueDisplayUtf8 +VIR_STRDUP(guiDisplay, valueDisplayUtf8) 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * guiDisplay as NULL and we check it below if it @@ -2513,8 +2511,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def-graphics[def-ngraphics]-type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP; tmp = getenv(DISPLAY); if (tmp != NULL) { - def-graphics[def-ngraphics]-data.desktop.display = strdup(tmp); -if (def-graphics[def-ngraphics]-data.desktop.display == NULL) { +if (VIR_STRDUP(def-graphics[def-ngraphics]-data.desktop.display, tmp) 0) { virReportOOMError(); /* just don't go to cleanup yet as it is ok to have * display as NULL @@ -2649,8 +2646,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (hddType == HardDiskType_Immutable) def-disks[hddNum]-readonly = true; -def-disks[hddNum]-src = strdup(hddlocation); -def-disks[hddNum]-dst = strdup(hda); +if (VIR_STRDUP(def-disks[hddNum]-src, hddlocation) 0 || +VIR_STRDUP(def-disks[hddNum]-dst, hda) 0) +virReportOOMError(); hddNum++; VBOX_UTF8_FREE(hddlocation); @@ -2670,8 +2668,9 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if (hddType == HardDiskType_Immutable) def-disks[hddNum]-readonly = true; -
[libvirt] [PATCH v2 29/37] Adapt to VIR_STRDUP in src/vmx/*
--- src/vmx/vmx.c | 25 +++-- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index c6c2f0d..4ccb0cd 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -682,9 +682,7 @@ virVMXGetConfigString(virConfPtr conf, const char *name, char **string, return -1; } -*string = strdup(value-str); - -if (*string == NULL) { +if (VIR_STRDUP(*string, value-str) 0) { virReportOOMError(); return -1; } @@ -1526,9 +1524,7 @@ virVMXParseConfig(virVMXContext *ctx, def-onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY; /* def:os */ -def-os.type = strdup(hvm); - -if (def-os.type == NULL) { +if (VIR_STRDUP(def-os.type, hvm) 0) { virReportOOMError(); goto cleanup; } @@ -2579,9 +2575,7 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) if (STRCASEEQ(virtualDev, vmxnet) features == 15) { VIR_FREE(virtualDev); -virtualDev = strdup(vmxnet2); - -if (virtualDev == NULL) { +if (VIR_STRDUP(virtualDev, vmxnet2) 0) { virReportOOMError(); goto cleanup; } @@ -2596,12 +2590,9 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def) true) 0) goto cleanup; -if (networkName == NULL) { -networkName = strdup(); -if (networkName == NULL) { -virReportOOMError(); -goto cleanup; -} +if (!networkName VIR_STRDUP(networkName, ) 0) { +virReportOOMError(); +goto cleanup; } } @@ -2797,9 +2788,7 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port, goto cleanup; } -(*def)-source.data.tcp.host = strdup(parsedUri-server); - -if ((*def)-source.data.tcp.host == NULL) { +if (VIR_STRDUP((*def)-source.data.tcp.host, parsedUri-server) 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 37/37] viralloc.c: Do report OOM error in VIR_ALLOC and friends
For cases where caller doesn't want to repor an OOM error, he should use VIR_ALLOC_QUIET or variants. --- HACKING | 4 ++ docs/hacking.html.in| 6 +++ po/POTFILES.in | 1 + python/libvirt-override.c | 102 ++-- src/esx/esx_vi.c| 3 +- src/util/viralloc.c | 95 +++-- src/util/viralloc.h | 54 --- src/util/virbuffer.c| 8 ++-- src/util/virerror.c | 4 +- src/util/virthreadpthread.c | 2 +- tests/networkxml2conftest.c | 2 + tests/test_conf.c | 2 +- tests/xmconfigtest.c| 2 + 13 files changed, 196 insertions(+), 89 deletions(-) diff --git a/HACKING b/HACKING index 0f681ce..b7b2798 100644 --- a/HACKING +++ b/HACKING @@ -595,6 +595,10 @@ size: +These memory allocation macros report out-of-memory error automatically. In +case, you want to suppress such behavior, use their _QUIET variant, e.g. +VIR_ALLOC_QUIET, VIR_REALLOC_N_QUIET etc. + File handling = diff --git a/docs/hacking.html.in b/docs/hacking.html.in index a9b78ba..2d9e1cd 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -712,6 +712,12 @@ /li /ul +p + These memory allocation macros report out-of-memory error automatically. + In case, you want to suppress such behavior, use their _QUIET variant, e.g. + VIR_ALLOC_QUIET, VIR_REALLOC_N_QUIET etc. +/p + h2a name=file_handlingFile handling/a/h2 p diff --git a/po/POTFILES.in b/po/POTFILES.in index bf5a864..7450642 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -139,6 +139,7 @@ src/test/test_driver.c src/uml/uml_conf.c src/uml/uml_driver.c src/util/iohelper.c +src/util/viralloc.c src/util/viraudit.c src/util/virauth.c src/util/virauthconfig.c diff --git a/python/libvirt-override.c b/python/libvirt-override.c index 856789a..df40ae3 100644 --- a/python/libvirt-override.c +++ b/python/libvirt-override.c @@ -167,7 +167,7 @@ setPyVirTypedParameter(PyObject *info, return NULL; } -if (VIR_ALLOC_N(ret, size) 0) { +if (VIR_ALLOC_N_QUIET(ret, size) 0) { PyErr_NoMemory(); return NULL; } @@ -353,7 +353,7 @@ libvirt_virDomainBlockStatsFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -419,7 +419,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) sumparams = nparams * MIN(ncpus, 128); -if (VIR_ALLOC_N(params, sumparams) 0) { +if (VIR_ALLOC_N_QUIET(params, sumparams) 0) { error = PyErr_NoMemory(); goto error; } @@ -471,7 +471,7 @@ libvirt_virDomainGetCPUStats(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) if (nparams) { sumparams = nparams; -if (VIR_ALLOC_N(params, nparams) 0) { +if (VIR_ALLOC_N_QUIET(params, nparams) 0) { error = PyErr_NoMemory(); goto error; } @@ -651,7 +651,7 @@ libvirt_virDomainGetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -699,7 +699,7 @@ libvirt_virDomainGetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -759,7 +759,7 @@ libvirt_virDomainSetSchedulerParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -835,7 +835,7 @@ libvirt_virDomainSetSchedulerParametersFlags(PyObject *self ATTRIBUTE_UNUSED, return NULL; } -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -909,7 +909,7 @@ libvirt_virDomainSetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, return NULL; } -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory(); LIBVIRT_BEGIN_ALLOW_THREADS; @@ -969,7 +969,7 @@ libvirt_virDomainGetBlkioParameters(PyObject *self ATTRIBUTE_UNUSED, if (!nparams) return PyDict_New(); -if (VIR_ALLOC_N(params, nparams) 0) +if (VIR_ALLOC_N_QUIET(params, nparams) 0) return PyErr_NoMemory();
[libvirt] [PATCH v2 22/37] Adapt to VIR_STRDUP in src/security/*
--- src/security/security_apparmor.c | 11 - src/security/security_dac.c | 6 ++--- src/security/security_nop.c | 4 ++-- src/security/security_selinux.c | 49 src/security/virt-aa-helper.c| 4 ++-- 5 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c index a2deafb..e75886e 100644 --- a/src/security/security_apparmor.c +++ b/src/security/security_apparmor.c @@ -446,21 +446,18 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, if ((profile_name = get_profile_name(def)) == NULL) return rc; -secdef-label = strndup(profile_name, strlen(profile_name)); -if (!secdef-label) { +if (VIR_STRNDUP(secdef-label, profile_name, strlen(profile_name)) 0) { virReportOOMError(); goto clean; } /* set imagelabel the same as label (but we won't use it) */ -secdef-imagelabel = strndup(profile_name, - strlen(profile_name)); -if (!secdef-imagelabel) { +if (VIR_STRNDUP(secdef-imagelabel, profile_name, strlen(profile_name)) 0) { virReportOOMError(); goto err; } -if (!secdef-model !(secdef-model = strdup(SECURITY_APPARMOR_NAME))) { +if (!secdef-model VIR_STRDUP(secdef-model, SECURITY_APPARMOR_NAME) 0) { virReportOOMError(); goto err; } @@ -931,7 +928,7 @@ AppArmorGetMountOptions(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED, { char *opts; -if (!(opts = strdup())) { +if (VIR_STRDUP(opts, ) 0) { virReportOOMError(); return NULL; } diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 4143495..850b9d4 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -76,8 +76,7 @@ int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr) char *owner = NULL; char *group = NULL; -tmp_label = strdup(label); -if (tmp_label == NULL) { +if (VIR_STRDUP(tmp_label, label) 0) { virReportOOMError(); goto cleanup; } @@ -1051,8 +1050,7 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr, if (!seclabel-norelabel) { if (seclabel-imagelabel == NULL seclabel-label != NULL) { -seclabel-imagelabel = strdup(seclabel-label); -if (seclabel-imagelabel == NULL) { +if (VIR_STRDUP(seclabel-imagelabel, seclabel-label) 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _(cannot generate dac user and group id for domain %s), def-name); diff --git a/src/security/security_nop.c b/src/security/security_nop.c index 2b9767e..00f4d67 100644 --- a/src/security/security_nop.c +++ b/src/security/security_nop.c @@ -20,7 +20,7 @@ #include config.h #include security_nop.h - +#include virstring.h #include virerror.h #define VIR_FROM_THIS VIR_FROM_SECURITY @@ -182,7 +182,7 @@ static char *virSecurityDomainGetMountOptionsNop(virSecurityManagerPtr mgr ATTRI { char *opts; -if (!(opts = strdup())) { +if (VIR_STRDUP(opts, ) 0) { virReportOOMError(); return NULL; } diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 201fff6..13f0601 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -202,7 +202,7 @@ virSecuritySELinuxMCSGetProcessRange(char **sens, goto cleanup; } -if (!(*sens = strdup(context_range_get(ourContext { +if (VIR_STRDUP(*sens, context_range_get(ourContext)) 0) { virReportOOMError(); goto cleanup; } @@ -312,7 +312,7 @@ virSecuritySELinuxContextAddRange(security_context_t src, goto cleanup; } -if (!(ret = strdup(str))) { +if (VIR_STRDUP(ret, str) 0) { virReportOOMError(); goto cleanup; } @@ -385,7 +385,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext, _(Unable to format SELinux context)); goto cleanup; } -if (!(ret = strdup(str))) { +if (VIR_STRDUP(ret, str) 0) { virReportOOMError(); goto cleanup; } @@ -451,12 +451,9 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr) goto error; } -data-domain_context = strdup(scon-str); -data-file_context = strdup(tcon-str); -data-content_context = strdup(dcon-str); -if (!data-domain_context || -!data-file_context || -!data-content_context) { +if (VIR_STRDUP(data-domain_context, scon-str) 0 || +VIR_STRDUP(data-file_context, tcon-str) 0 || +VIR_STRDUP(data-content_context, dcon-str) 0) { virReportSystemError(errno, _(cannot allocate memory for LXC SELinux contexts '%s'), selinux_lxc_contexts_path()); @@ -520,8
[libvirt] [PATCH v2 34/37] Adapt to VIR_STRDUP in src/*
--- src/datatypes.c | 25 + src/libvirt.c | 9 + src/nodeinfo.c | 3 +-- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/datatypes.c b/src/datatypes.c index d3cf5f2..71aab04 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -27,6 +27,7 @@ #include virlog.h #include viralloc.h #include viruuid.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_NONE @@ -225,7 +226,7 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) if (!(ret = virObjectNew(virDomainClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -297,7 +298,7 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) if (!(ret = virObjectNew(virNetworkClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -372,9 +373,9 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) if (!(ret = virObjectNew(virInterfaceClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; -if (!(ret-mac = strdup(mac))) +if (VIR_STRDUP(ret-mac, mac) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -446,7 +447,7 @@ virGetStoragePool(virConnectPtr conn, const char *name, if (!(ret = virObjectNew(virStoragePoolClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -530,11 +531,11 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, if (!(ret = virObjectNew(virStorageVolClass))) return NULL; -if (!(ret-pool = strdup(pool))) +if (VIR_STRDUP(ret-pool, pool) 0) goto no_memory; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; -if (!(ret-key = strdup(key))) +if (VIR_STRDUP(ret-key, key) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -610,7 +611,7 @@ virGetNodeDevice(virConnectPtr conn, const char *name) if (!(ret = virObjectNew(virNodeDeviceClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -680,7 +681,7 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid, memcpy((ret-uuid[0]), uuid, VIR_UUID_BUFLEN); ret-usageType = usageType; -if (!(ret-usageID = strdup(usageID))) +if (VIR_STRDUP(ret-usageID, usageID) 0) goto no_memory; ret-conn = virObjectRef(conn); @@ -775,7 +776,7 @@ virGetNWFilter(virConnectPtr conn, const char *name, if (!(ret = virObjectNew(virNWFilterClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; memcpy((ret-uuid[0]), uuid, VIR_UUID_BUFLEN); @@ -832,7 +833,7 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name) if (!(ret = virObjectNew(virDomainSnapshotClass))) return NULL; -if (!(ret-name = strdup(name))) +if (VIR_STRDUP(ret-name, name) 0) goto no_memory; ret-domain = virObjectRef(domain); diff --git a/src/libvirt.c b/src/libvirt.c index 15b37a3..1ebb2c5 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -212,11 +212,12 @@ static int virConnectAuthCallbackDefault(virConnectCredentialPtr cred, } if (cred[i].type != VIR_CRED_EXTERNAL) { +int rc; if (STREQ(bufptr, ) cred[i].defresult) -cred[i].result = strdup(cred[i].defresult); +rc = VIR_STRDUP(cred[i].result, cred[i].defresult); else -cred[i].result = strdup(bufptr); -if (!cred[i].result) +rc = VIR_STRDUP(cred[i].result, bufptr); +if (rc 0) return -1; cred[i].resultlen = strlen(cred[i].result); } @@ -1045,7 +1046,7 @@ virConnectOpenFindURIAliasMatch(virConfValuePtr value, const char *alias, char * STREQLEN(entry-str, alias, alias_len)) { VIR_DEBUG(Resolved alias '%s' to '%s', alias, offset+1); -if (!(*uri = strdup(offset+1))) { +if (VIR_STRDUP(*uri, offset+1) 0) { virReportOOMError(); return -1; } diff --git a/src/nodeinfo.c b/src/nodeinfo.c index 95c2f33..e3a0329 100644 --- a/src/nodeinfo.c +++ b/src/nodeinfo.c @@ -984,8 +984,7 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, FILE *meminfo; if (cellNum == VIR_NODE_MEMORY_STATS_ALL_CELLS) { -meminfo_path = strdup(MEMINFO_PATH); -
[libvirt] [PATCH v2 09/37] Adapt to VIR_STRDUP in src/locking/*
--- src/locking/lock_daemon.c | 12 ++-- src/locking/lock_daemon_config.c | 8 src/locking/lock_daemon_dispatch.c | 3 ++- src/locking/lock_driver_lockd.c| 22 +++--- src/locking/lock_driver_sanlock.c | 8 src/locking/lock_manager.c | 2 +- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 0d8ef39..2ace573 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -370,7 +370,7 @@ virLockDaemonPidFilePath(bool privileged, char **pidfile) { if (privileged) { -if (!(*pidfile = strdup(LOCALSTATEDIR /run/virtlockd.pid))) +if (VIR_STRDUP(*pidfile, LOCALSTATEDIR /run/virtlockd.pid) 0) goto no_memory; } else { char *rundir = NULL; @@ -408,7 +408,7 @@ virLockDaemonUnixSocketPaths(bool privileged, char **sockfile) { if (privileged) { -if (!(*sockfile = strdup(LOCALSTATEDIR /run/libvirt/virtlockd-sock))) +if (VIR_STRDUP(*sockfile, LOCALSTATEDIR /run/libvirt/virtlockd-sock) 0) goto no_memory; } else { char *rundir = NULL; @@ -867,7 +867,7 @@ virLockDaemonClientNewPostExecRestart(virNetServerClientPtr client, _(Missing ownerName data in JSON document)); goto error; } -if (!(priv-ownerName = strdup(ownerName))) { +if (VIR_STRDUP(priv-ownerName, ownerName) 0) { virReportOOMError(); goto error; } @@ -1221,13 +1221,13 @@ int main(int argc, char **argv) { case 'p': VIR_FREE(pid_file); -if (!(pid_file = strdup(optarg))) +if (VIR_STRDUP(pid_file, optarg) 0) exit(EXIT_FAILURE); break; case 'f': VIR_FREE(remote_config_file); -if (!(remote_config_file = strdup(optarg))) +if (VIR_STRDUP(remote_config_file, optarg) 0) exit(EXIT_FAILURE); break; @@ -1312,7 +1312,7 @@ int main(int argc, char **argv) { /* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { -if (!(run_dir = strdup(LOCALSTATEDIR /run/libvirt))) { +if (VIR_STRDUP(run_dir, LOCALSTATEDIR /run/libvirt) 0) { virReportOOMError(); goto cleanup; } diff --git a/src/locking/lock_daemon_config.c b/src/locking/lock_daemon_config.c index c3d59bd..972e7cf 100644 --- a/src/locking/lock_daemon_config.c +++ b/src/locking/lock_daemon_config.c @@ -53,8 +53,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and goto the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do {\ @@ -63,7 +63,7 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) 0) \ goto error; \ VIR_FREE(data-var_name); \ -if (!(data-var_name = strdup(p-str))) { \ +if (VIR_STRDUP(data-var_name, p-str) 0) { \ virReportOOMError();\ goto error; \ } \ @@ -85,7 +85,7 @@ int virLockDaemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { -if (!(*configfile = strdup(SYSCONFDIR /libvirt/virtlockd.conf))) +if (VIR_STRDUP(*configfile, SYSCONFDIR /libvirt/virtlockd.conf) 0) goto no_memory; } else { char *configdir = NULL; diff --git a/src/locking/lock_daemon_dispatch.c b/src/locking/lock_daemon_dispatch.c index 8a92802..472b6e6 100644 --- a/src/locking/lock_daemon_dispatch.c +++ b/src/locking/lock_daemon_dispatch.c @@ -30,6 +30,7 @@ #include lock_protocol.h #include lock_daemon_dispatch_stubs.h #include virerror.h +#include virstring.h #define VIR_FROM_THIS VIR_FROM_RPC @@ -275,7 +276,7 @@ virLockSpaceProtocolDispatchRegister(virNetServerPtr server ATTRIBUTE_UNUSED, goto cleanup; } -if (!(priv-ownerName = strdup(args-owner.name))) { +if (VIR_STRDUP(priv-ownerName, args-owner.name) 0) { virReportOOMError(); goto cleanup; } diff --git
[libvirt] [PATCH v2 33/37] Adapt to VIR_STRDUP in tests/*
--- tests/commandhelper.c | 14 +++--- tests/commandtest.c| 2 +- tests/openvzutilstest.c| 6 -- tests/qemumonitortestutils.c | 8 tests/qemuxml2argvtest.c | 27 --- tests/qemuxmlnstest.c | 4 +++- tests/securityselinuxhelper.c | 7 +-- tests/securityselinuxlabeltest.c | 2 +- tests/securityselinuxtest.c| 6 ++ tests/storagebackendsheepdogtest.c | 6 ++ tests/testutils.c | 4 +++- tests/testutilsqemu.c | 5 - tests/vircgrouptest.c | 2 +- tests/virnetmessagetest.c | 21 + tests/vmx2xmltest.c| 10 +- tests/xml2vmxtest.c| 10 +- 16 files changed, 76 insertions(+), 58 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index 92f031f..8012424 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -31,6 +31,9 @@ #include viralloc.h #include virfile.h #include testutils.h +#include virstring.h + +#define VIR_FROM_THIS VIR_FROM_NONE #ifndef WIN32 @@ -42,9 +45,14 @@ static int envsort(const void *a, const void *b) { const char *bstr = *bstrptr; char *aeq = strchr(astr, '='); char *beq = strchr(bstr, '='); -char *akey = strndup(astr, aeq - astr); -char *bkey = strndup(bstr, beq - bstr); -int ret = strcmp(akey, bkey); +char *akey, *bkey; +int ret; + +if (VIR_STRNDUP(akey, astr, aeq - astr) 0 || +VIR_STRNDUP(bkey, bstr, beq - bstr) 0) +ret = 0; +else +ret = strcmp(akey, bkey); VIR_FREE(akey); VIR_FREE(bkey); return ret; diff --git a/tests/commandtest.c b/tests/commandtest.c index 6cb88c5..097e605 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -685,7 +685,7 @@ static int test17(const void *unused ATTRIBUTE_UNUSED) goto cleanup; } VIR_FREE(outbuf); -if ((outbuf = strdup(should not be leaked)) == NULL) { +if (VIR_STRDUP(outbuf, should not be leaked) 0) { puts(test framework failure); goto cleanup; } diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c index be0c74c..3cfbfb9 100644 --- a/tests/openvzutilstest.c +++ b/tests/openvzutilstest.c @@ -13,6 +13,8 @@ # include openvz/openvz_conf.h # include virstring.h +# define VIR_FROM_THIS VIR_FROM_NONE + static int testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile, const char *ext ATTRIBUTE_UNUSED) @@ -103,8 +105,8 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED) /domain\n; if (VIR_ALLOC(def) 0 || -!(def-os.type = strdup(exe)) || -!(def-os.init = strdup(/sbin/init))) +VIR_STRDUP(def-os.type, exe) 0 || +VIR_STRDUP(def-os.init, /sbin/init) 0) goto cleanup; def-virtType = VIR_DOMAIN_VIRT_OPENVZ; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index c24a37f..2f00cb7 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -159,7 +159,7 @@ static int qemuMonitorTestProcessCommandText(qemuMonitorTestPtr test, char *cmdname; int ret = -1; -if (!(cmdname = strdup(cmdstr))) { +if (VIR_STRDUP(cmdname, cmdstr) 0) { virReportOOMError(); return -1; } @@ -407,8 +407,8 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test, if (VIR_ALLOC(item) 0) goto no_memory; -if (!(item-command_name = strdup(command_name)) || -!(item-response = strdup(response))) +if (VIR_STRDUP(item-command_name, command_name) 0 || +VIR_STRDUP(item-response, response) 0) goto no_memory; virMutexLock(test-lock); @@ -467,7 +467,7 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt) return NULL; } -if (!(tmpdir_template = strdup(/tmp/libvirt_XX))) +if (VIR_STRDUP(tmpdir_template, /tmp/libvirt_XX) 0) goto no_memory; if (!(test-tmpdir = mkdtemp(tmpdir_template))) { diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 1286273..df53c2e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -20,9 +20,10 @@ # include datatypes.h # include cpu/cpu_map.h # include virstring.h - # include testutilsqemu.h +# define VIR_FROM_THIS VIR_FROM_NONE + static const char *abs_top_srcdir; static virQEMUDriver driver; @@ -32,8 +33,9 @@ fakeSecretGetValue(virSecretPtr obj ATTRIBUTE_UNUSED, unsigned int fakeflags ATTRIBUTE_UNUSED, unsigned int internalFlags ATTRIBUTE_UNUSED) { -char *secret = strdup(AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A); -if (!secret) { +char *secret; + +if (VIR_STRDUP(secret, AQCVn5hO6HzFAhAAq0NCv8jtJcIcE+HOBlMQ1A) 0) { return NULL; } *value_size = strlen(secret); @@ -129,7 +131,7 @@ static int
[libvirt] [PATCH v2 28/37] Adapt to VIR_STRDUP in src/vmware/*
--- src/vmware/vmware_conf.c | 13 ++--- src/vmware/vmware_driver.c | 12 +--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c index 4fb61a8..f7cd3bb 100644 --- a/src/vmware/vmware_conf.c +++ b/src/vmware/vmware_conf.c @@ -174,8 +174,7 @@ vmwareLoadDomains(struct vmware_driver *driver) pDomain = vm-privateData; -pDomain-vmxPath = strdup(vmxPath); -if (pDomain-vmxPath == NULL) { +if (VIR_STRDUP(pDomain-vmxPath, vmxPath) 0) { virReportOOMError(); goto cleanup; } @@ -297,15 +296,15 @@ vmwareParsePath(char *path, char **directory, char **filename) return -1; } -if ((*directory = strdup(path)) == NULL) +if (VIR_STRDUP(*directory, path) 0) goto no_memory; -if ((*filename = strdup(separator)) == NULL) { +if (VIR_STRDUP(*filename, separator) 0) { VIR_FREE(*directory); goto no_memory; } } else { -if ((*filename = strdup(path)) == NULL) +if (VIR_STRDUP(*filename, path) 0) goto no_memory; } @@ -492,9 +491,9 @@ cleanup: char * vmwareCopyVMXFileName(const char *datastorePath, void *opaque ATTRIBUTE_UNUSED) { -char *path = strdup(datastorePath); +char *path; -if (path == NULL) { +if (VIR_STRDUP(path, datastorePath) 0) { virReportOOMError(); return NULL; } diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index 1e2634e..fc01321 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -33,6 +33,9 @@ #include vmx.h #include vmware_conf.h #include vmware_driver.h +#include virstring.h + +#define VIR_FROM_THIS VIR_FROM_VMWARE static const char *vmw_types[] = { player, ws }; @@ -352,7 +355,7 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml) goto cleanup; pDomain = vm-privateData; -if ((pDomain-vmxPath = strdup(vmxPath)) == NULL) { +if (VIR_STRDUP(pDomain-vmxPath, vmxPath) 0) { virReportOOMError(); goto cleanup; } @@ -636,7 +639,10 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml, goto cleanup; pDomain = vm-privateData; -pDomain-vmxPath = strdup(vmxPath); +if (VIR_STRDUP(pDomain-vmxPath, vmxPath) 0) { +virReportOOMError(); +goto cleanup; +} vmwareDomainConfigDisplay(pDomain, vmdef); vmdef = NULL; @@ -800,7 +806,7 @@ vmwareDomainGetOSType(virDomainPtr dom) goto cleanup; } -if (!(ret = strdup(vm-def-os.type))) +if (VIR_STRDUP(ret, vm-def-os.type) 0) virReportOOMError(); cleanup: -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 25/37] Adapt to VIR_STRDUP in src/uml/*
--- src/uml/uml_conf.c | 4 ++-- src/uml/uml_driver.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c index a55b5b1..47e0fc0 100644 --- a/src/uml/uml_conf.c +++ b/src/uml/uml_conf.c @@ -114,7 +114,7 @@ umlConnectTapDevice(virConnectPtr conn, STRPREFIX(net-ifname, VIR_NET_GENERATED_PREFIX) || strchr(net-ifname, '%')) { VIR_FREE(net-ifname); -if (!(net-ifname = strdup(VIR_NET_GENERATED_PREFIX %d))) +if (VIR_STRDUP(net-ifname, VIR_NET_GENERATED_PREFIX %d) 0) goto no_memory; /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; @@ -463,7 +463,7 @@ virCommandPtr umlBuildCommandLine(virConnectPtr conn, if (vm-def-os.cmdline) { char *args, *next_arg; char *cmdline; -if ((cmdline = strdup(vm-def-os.cmdline)) == NULL) +if (VIR_STRDUP(cmdline, vm-def-os.cmdline) 0) goto no_memory; args = cmdline; diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 66c00b2..709edf1 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -248,7 +248,7 @@ requery: if (res STRPREFIX(res, pts:)) { VIR_FREE(def-source.data.file.path); -if ((def-source.data.file.path = strdup(res + 4)) == NULL) { +if (VIR_STRDUP(def-source.data.file.path, res + 4) 0) { virReportOOMError(); VIR_FREE(res); VIR_FREE(cmd); @@ -491,7 +491,7 @@ umlStateInitialize(bool privileged, %s/log/libvirt/uml, LOCALSTATEDIR) == -1) goto out_of_memory; -if ((base = strdup(SYSCONFDIR /libvirt)) == NULL) +if (VIR_STRDUP(base, SYSCONFDIR /libvirt) 0) goto out_of_memory; if (virAsprintf(uml_driver-monitorDir, @@ -1665,7 +1665,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) { goto cleanup; } -if (!(type = strdup(vm-def-os.type))) +if (VIR_STRDUP(type, vm-def-os.type) 0) virReportOOMError(); cleanup: -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 35/37] Introduce syntax-check rule to prefer VIR_STRDUP over strdup
--- cfg.mk | 8 1 file changed, 8 insertions(+) diff --git a/cfg.mk b/cfg.mk index d499ded..4c6d85c 100644 --- a/cfg.mk +++ b/cfg.mk @@ -383,6 +383,11 @@ sc_prohibit_asprintf: halt='use virAsprintf, not as'printf\ $(_sc_search_regexp) +sc_prohibit_strdup: + @prohibit='\strn?dup\ *\('\ + halt='use VIR_STRUP, not strdup'\ + $(_sc_search_regexp) + # Prefer virSetUIDGID. sc_prohibit_setuid: @prohibit='\set(re)?[ug]id\ *\(' \ @@ -860,6 +865,9 @@ exclude_file_name_regexp--sc_prohibit_always_true_header_tests = \ exclude_file_name_regexp--sc_prohibit_asprintf = \ ^(bootstrap.conf$$|src/util/virstring\.c$$|examples/domain-events/events-c/event-test\.c$$|tests/vircgroupmock\.c$$) +exclude_file_name_regexp--sc_prohibit_strdup = \ + ^(docs/|examples/|python/|src/util/virstring\.c$$|tools/virsh\.c$$) + exclude_file_name_regexp--sc_prohibit_close = \ (\.p[yl]$$|^docs/|^(src/util/virfile\.c|src/libvirt\.c|tests/vircgroupmock\.c)$$) -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 30/37] Adapt to VIR_STRDUP in src/xen/*
--- src/xen/xen_driver.c | 2 +- src/xen/xen_hypervisor.c | 15 +- src/xen/xen_inotify.c| 11 -- src/xen/xend_internal.c | 53 +++- src/xen/xm_internal.c| 6 +++--- src/xen/xs_internal.c| 22 6 files changed, 37 insertions(+), 72 deletions(-) diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 526786b..25d5394 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2504,7 +2504,7 @@ xenUnifiedAddDomainInfo(xenUnifiedDomainInfoListPtr list, if (VIR_ALLOC(info) 0) goto memory_error; -if (!(info-name = strdup(name))) +if (VIR_STRDUP(info-name, name) 0) goto memory_error; memcpy(info-uuid, uuid, VIR_UUID_BUFLEN); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index e15f7f2..c5f6c0f 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1199,15 +1199,13 @@ xenHypervisorGetSchedulerType(virDomainPtr domain, int *nparams) switch (op.u.getschedulerid.sched_id){ case XEN_SCHEDULER_SEDF: -schedulertype = strdup(sedf); -if (schedulertype == NULL) +if (VIR_STRDUP(schedulertype, sedf) 0) virReportOOMError(); if (nparams) *nparams = XEN_SCHED_SEDF_NPARAM; break; case XEN_SCHEDULER_CREDIT: -schedulertype = strdup(credit); -if (schedulertype == NULL) +if (VIR_STRDUP(schedulertype, credit) 0) virReportOOMError(); if (nparams) *nparams = XEN_SCHED_CRED_NPARAM; @@ -2894,12 +2892,9 @@ xenHypervisorDomainGetOSType(virDomainPtr dom) return NULL; } -if (XEN_GETDOMAININFO_FLAGS(dominfo) DOMFLAGS_HVM) -ostype = strdup(hvm); -else -ostype = strdup(linux); - -if (ostype == NULL) +if (VIR_STRDUP(ostype, + XEN_GETDOMAININFO_FLAGS(dominfo) DOMFLAGS_HVM ? + hvm : linux) 0) virReportOOMError(); return ostype; diff --git a/src/xen/xen_inotify.c b/src/xen/xen_inotify.c index d83708c..3d0d094 100644 --- a/src/xen/xen_inotify.c +++ b/src/xen/xen_inotify.c @@ -39,7 +39,7 @@ #include virlog.h #include viruuid.h #include virfile.h - +#include virstring.h #include xm_internal.h /* for xenXMDomainConfigParse */ #define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY @@ -62,10 +62,8 @@ xenInotifyXenCacheLookup(virConnectPtr conn, return -1; } -*name = strdup(entry-def-name); memcpy(uuid, entry-def-uuid, VIR_UUID_BUFLEN); - -if (!*name) { +if (VIR_STRDUP(*name, entry-def-name) 0) { VIR_DEBUG(Error getting dom from def); virReportOOMError(); return -1; @@ -107,8 +105,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, list info */ for (i = 0 ; i priv-configInfoList-count ; i++) { if (!memcmp(rawuuid, priv-configInfoList-doms[i]-uuid, VIR_UUID_BUFLEN)) { -*name = strdup(priv-configInfoList-doms[i]-name); -if (!*name) { +if (VIR_STRDUP(*name, priv-configInfoList-doms[i]-name) 0) { virReportOOMError(); return -1; } @@ -122,7 +119,7 @@ xenInotifyXendDomainsDirLookup(virConnectPtr conn, return -1; } -if (!(*name = strdup(dom-name))) { +if (VIR_STRDUP(*name, dom-name) 0) { virReportOOMError(); virDomainFree(dom); return -1; diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 97f44ab..4081050 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -761,8 +761,7 @@ xenDaemonListDomainsOld(virConnectPtr xend) _for_i = _for_i-u.s.cdr, node = _for_i-u.s.car) { if (node-kind != SEXPR_VALUE) continue; -ret[i] = strdup(node-u.value); -if (!ret[i]) +if (VIR_STRDUP(ret[i], node-u.value) 0) goto no_memory; i++; } @@ -887,12 +886,9 @@ xenDaemonDomainLookupByID(virConnectPtr xend, %s, _(domain information incomplete, missing name)); goto error; } -if (domname) { - *domname = strdup(name); - if (*domname == NULL) { - virReportOOMError(); - goto error; - } +if (domname VIR_STRDUP(*domname, name) 0) { +virReportOOMError(); +goto error; } if (sexpr_uuid(uuid, root, domain/uuid) 0) { @@ -1454,13 +1450,7 @@ xenDaemonDomainGetOSType(virDomainPtr domain) if (root == NULL) return NULL; -if (sexpr_lookup(root, domain/image/hvm)) { -type = strdup(hvm); -} else { -type = strdup(linux); -} - -if (type == NULL) +if (VIR_STRDUP(type, sexpr_lookup(root, domain/image/hvm) ? hvm : linux) 0)
[libvirt] [PATCH v2 13/37] Adapt to VIR_STRDUP in src/interface/
--- src/interface/interface_backend_udev.c | 24 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c index 7daad16..65c8c31 100644 --- a/src/interface/interface_backend_udev.c +++ b/src/interface/interface_backend_udev.c @@ -227,14 +227,12 @@ udevListInterfacesByStatus(virConnectPtr conn, path = udev_list_entry_get_name(dev_entry); dev = udev_device_new_from_syspath(udev, path); -names[count] = strdup(udev_device_get_sysname(dev)); -udev_device_unref(dev); - -/* If strdup() failed, we are out of memory */ -if (!names[count]) { +if (VIR_STRDUP(names[count], udev_device_get_sysname(dev)) 0) { virReportOOMError(); +udev_device_unref(dev); goto err; } +udev_device_unref(dev); count++; } @@ -751,8 +749,7 @@ udevGetIfaceDefBond(struct udev *udev, _(Could not retrieve 'bonding/arp_ip_target' for '%s'), name); goto cleanup; } -ifacedef-data.bond.target = strdup(tmp_str); -if (!ifacedef-data.bond.target) { +if (VIR_STRDUP(ifacedef-data.bond.target, tmp_str) 0) { virReportOOMError(); goto cleanup; } @@ -839,8 +836,7 @@ udevGetIfaceDefBridge(struct udev *udev, goto error; } -ifacedef-data.bridge.delay = strdup(tmp_str); -if (!ifacedef-data.bridge.delay) { +if (VIR_STRDUP(ifacedef-data.bridge.delay, tmp_str) 0) { virReportOOMError(); goto error; } @@ -938,8 +934,7 @@ udevGetIfaceDefVlan(struct udev *udev ATTRIBUTE_UNUSED, char *vid; char *vlan_parent_dev = NULL; -vlan_parent_dev = strdup(name); -if (!vlan_parent_dev) { +if (VIR_STRDUP(vlan_parent_dev, name) 0) { virReportOOMError(); goto cleanup; } @@ -987,9 +982,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) /* Clear our structure and set safe defaults */ ifacedef-startmode = VIR_INTERFACE_START_UNSPECIFIED; -ifacedef-name = strdup(name); - -if (!ifacedef-name) { +if (VIR_STRDUP(ifacedef-name, name) 0) { virReportOOMError(); goto cleanup; } @@ -1003,8 +996,7 @@ udevGetIfaceDef(struct udev *udev, const char *name) } /* MAC address */ -ifacedef-mac = strdup(udev_device_get_sysattr_value(dev, address)); -if (!ifacedef-mac) { +if (VIR_STRDUP(ifacedef-mac, udev_device_get_sysattr_value(dev, address)) 0) { virReportOOMError(); goto cleanup; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] qemu: honor allowDiskFormatProbing when parsing command line
My commit 024e9af broke this. --- src/qemu/qemu_command.c | 3 --- tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.xml | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-boot-network.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-clock-utc.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-console-compat.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom-empty.xml | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml| 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-disk-drive-boot-cdrom.xml | 4 ++-- tests/qemuxml2argvdata/qemuxml2argv-disk-drive-boot-disk.xml | 4 ++-- .../qemuxml2argv-disk-drive-network-rbd-ceph-env.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.xml | 6 +++--- tests/qemuxml2argvdata/qemuxml2argv-disk-many.xml | 8 tests/qemuxml2argvdata/qemuxml2argv-disk-usb.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-disk-virtio.xml | 8 tests/qemuxml2argvdata/qemuxml2argv-disk-xenvbd.xml | 8 tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl-fullscreen.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-sasl.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-socket.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-tls.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-machine-core-off.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-machine-core-on.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-migrate.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-misc-disable-s3.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-misc-disable-suspends.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-misc-enable-s4.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-net-eth-ifname.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-net-user.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-nographics-vga.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-parallel-tcp.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-qemu-ns-no-env.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-restore-v1.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-restore-v2.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-dev.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-file.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-many.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-pty.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-telnet.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-tcp.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-udp.xml| 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-unix.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-serial-vc.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-smp.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-sound.xml | 2 +- tests/qemuxml2argvdata/qemuxml2argv-watchdog.xml | 2 +- 57 files changed, 72 insertions(+), 75 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..d161b56 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8540,7 +8540,6 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, def-bus = VIR_DOMAIN_DISK_BUS_IDE; def-device = VIR_DOMAIN_DISK_DEVICE_DISK; def-type = VIR_DOMAIN_DISK_TYPE_FILE; -def-format = VIR_STORAGE_FILE_AUTO; for (i = 0 ; i nkeywords ; i++) { if (STREQ(keywords[i], file)) { @@ -9788,8 +9787,6 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_ALLOC(disk) 0) goto no_memory; -
Re: [libvirt] [PATCH 1/1][RESEND] ppc64 cpu features
On Mon, Apr 22, 2013 at 17:38:23 +0800, Li Zhang wrote: On 2013年04月22日 17:10, Jiri Denemark wrote: If you want to add powernv feature just because you need to distinguish if the host supports KVM or not, there's much better way... In guest section of capabilities XML, KVM support is indicated by domain type='kvm' element. And that's what existing apps already use to detect KVM presence/absence. As my understanding, there is still some difference from 'kvm' capability. 'powernv' is only considered as one CPU feature of PPC64. If other PPC platforms support KVM in the future, this feature can be used to identify whether migration can be executed . :) Well, as I already said, unless there is a way to explicitly enable/disable powernv feature in guest CPU, I don't see any reason for exposing the feature to users/apps. We definitely don't want apps/users to detect support for migration (or anything else) by checking host CPU features. If migration is not supported, then any migration API can fail with VIR_ERR_OPERATION_UNSUPPORTED. That said, powernv feature can be used internally by libvirt to check if some configurations/operations are supported but it doesn't have to be exposed to users/apps. The CPU driver stuff is there for configuring *guest* CPU. Jirka -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] libxl: expose and control xen device model versions
Hi, These patches expose multiple xen device model options in the capabilities XML and allow the user to select a specific device model via the domain XML's emulator tag. It is important to control the device model per VM, since the default is changing from xen-4.2 qemu traditional to xen-4.3 qemu upstream. In this proposal, the capabilities XML now has multiple domain elements per arch as follows: arch name='i686' wordsize32/wordsize machinexenfv/machine domain type='xen' emulator/usr/lib64/xen/bin/qemu-dm/emulator loader/usr/lib/xen/boot/hvmloader/loader /domain domain type='xen' emulator/usr/lib64/xen/bin/qemu-system-i386/emulator loader/usr/lib/xen/boot/hvmloader/loader /domain /arch -- is it valid/ sensible to have multiple domain's with the same 'type'? Let me know if you can think of a better mapping. Comments, criticism welcome. Cheers, Dave -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/2] libxl: expose multiple emulators per guest in the capabilities XML
libxl allows users to choose between two standard emulators: 1. (default in xen-4.2): qemu traditional (aka qemu-dm) 2. (default in xen-4.3): qemu upstream (aka qemu-system-i386) The person who builds and packages xen gets to choose which emulators are built. We examine the filesystem for the emulators at runtime and expose them as separate domains within the same guest architecture. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 87 --- 1 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..472d116 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -29,6 +29,8 @@ #include libxl.h #include sys/types.h #include sys/socket.h +#include sys/stat.h +#include unistd.h #include internal.h #include virlog.h @@ -50,6 +52,28 @@ /* see xen-unstable.hg/xen/include/asm-x86/cpufeature.h */ #define LIBXL_X86_FEATURE_PAE_MASK 0x40 +enum emulator_type { +emulator_traditional = 0, +emulator_upstream= 1, +emulator_last= 2, +/* extend with specific qemu versions later */ +}; + +#define EMULATOR_LIB64 /usr/lib64/xen/bin/ +#define EMULATOR_LIB32 /usr/lib/xen/bin/ + +#define EMULATOR_TRADITIONAL qemu-dm +#define EMULATOR_UPSTREAMqemu-system-i386 + +static const char* emulator_lib64_path [] = { +EMULATOR_LIB64 EMULATOR_TRADITIONAL, +EMULATOR_LIB64 EMULATOR_UPSTREAM, +}; + +static const char* emulator_lib32_path [] = { +EMULATOR_LIB32 EMULATOR_TRADITIONAL, +EMULATOR_LIB32 EMULATOR_UPSTREAM, +}; struct guest_arch { virArch arch; @@ -68,10 +92,11 @@ static virCapsPtr libxlBuildCapabilities(virArch hostarch, int host_pae, struct guest_arch *guest_archs, - int nr_guest_archs) + int nr_guest_archs, + int emulators_found[]) { virCapsPtr caps; -int i; +int i, j; if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL) goto no_memory; @@ -91,12 +116,8 @@ libxlBuildCapabilities(virArch hostarch, if ((guest = virCapabilitiesAddGuest(caps, guest_archs[i].hvm ? hvm : xen, guest_archs[i].arch, - ((hostarch == VIR_ARCH_X86_64) ? - /usr/lib64/xen/bin/qemu-dm : - /usr/lib/xen/bin/qemu-dm), - (guest_archs[i].hvm ? - /usr/lib/xen/boot/hvmloader : - NULL), + NULL, + NULL, 1, machines)) == NULL) { virCapabilitiesFreeMachines(machines, 1); @@ -104,13 +125,21 @@ libxlBuildCapabilities(virArch hostarch, } machines = NULL; -if (virCapabilitiesAddGuestDomain(guest, - xen, - NULL, - NULL, - 0, - NULL) == NULL) -goto no_memory; +for (j = 0; j emulator_last; ++j) { +if (emulators_found[j] == -1) /* failure from stat(2) */ +continue; +if (virCapabilitiesAddGuestDomain(guest, + xen, + ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[j] : + emulator_lib32_path[j]), + (guest_archs[i].hvm ? + /usr/lib/xen/boot/hvmloader : + NULL), + 0, + NULL) == NULL) +goto no_memory; +} if (guest_archs[i].pae virCapabilitiesAddGuestFeature(guest, @@ -163,7 +192,8 @@ libxlBuildCapabilities(virArch hostarch, static virCapsPtr libxlMakeCapabilitiesInternal(virArch hostarch, libxl_physinfo *phy_info, - char *capabilities) + char *capabilities, + int emulators_found[]) { char *str, *token; regmatch_t subs[4]; @@ -243,7 +273,7 @@ libxlMakeCapabilitiesInternal(virArch hostarch, continue; } -/* Search for existing matching (model,hvm) tuple
[libvirt] [PATCH 0/2] [RFC] Support for VNC WebSocket
This series, which is meant to be applied _after_ 1.0.5 release, is adding support for the VNC WebSocket to be configured for QEMU. I tagged this with [RFC] because this is the fastest way I managed to code it and I'd welcome any opinions on naming changes etc. Documentation from qemu_options.hx: qemu -vnc ...,websocket[=port] Opens an additional TCP listening port dedicated to VNC Websocket connections. By definition the Websocket port is 5700+@var{display}. If @var{host} is specified connections will only be allowed from this host. As an alternative the Websocket port could be specified by using @code{websocket}=@var{port}. Martin Kletzander (2): Add VNC WebSocket support qemu: Add VNC WebSocket support docs/formatdomain.html.in | 5 ++ docs/schemas/domaincommon.rng | 5 ++ src/conf/domain_conf.c | 18 +++ src/conf/domain_conf.h | 1 + src/qemu/libvirtd_qemu.aug | 4 +- src/qemu/qemu.conf | 7 +++ src/qemu/qemu_capabilities.c | 5 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c| 60 +- src/qemu/qemu_command.h| 5 +- src/qemu/qemu_conf.c | 32 src/qemu/qemu_conf.h | 6 +++ src/qemu/qemu_driver.c | 5 ++ src/qemu/qemu_process.c| 31 --- src/qemu/test_libvirtd_qemu.aug.in | 2 + tests/qemuargv2xmltest.c | 1 + .../qemuxml2argv-graphics-vnc-websocket.args | 4 ++ .../qemuxml2argv-graphics-vnc-websocket.xml| 35 + tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmltest.c| 1 + 20 files changed, 219 insertions(+), 10 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.xml -- 1.8.2.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] qemu: Add VNC WebSocket support
Adding a VNC WebSocket support for QEMU driver. This funcitonality is in upstream qemu from commit described as v1.3.0-982-g7536ee4, so the capability is being recognized based on QEMU version for now. Signed-off-by: Martin Kletzander mklet...@redhat.com --- src/qemu/libvirtd_qemu.aug | 4 +- src/qemu/qemu.conf | 7 +++ src/qemu/qemu_capabilities.c | 5 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c| 60 +- src/qemu/qemu_command.h| 5 +- src/qemu/qemu_conf.c | 32 src/qemu/qemu_conf.h | 6 +++ src/qemu/qemu_driver.c | 5 ++ src/qemu/qemu_process.c| 31 --- src/qemu/test_libvirtd_qemu.aug.in | 2 + tests/qemuargv2xmltest.c | 1 + .../qemuxml2argv-graphics-vnc-websocket.args | 4 ++ .../qemuxml2argv-graphics-vnc-websocket.xml| 35 + tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmltest.c| 1 + 16 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.xml diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 61740a9..5344125 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -41,6 +41,8 @@ module Libvirtd_qemu = let remote_display_entry = int_entry remote_display_port_min | int_entry remote_display_port_max + | int_entry remote_websocket_port_min + | int_entry remote_websocket_port_max let security_entry = str_entry security_driver | bool_entry security_default_confined @@ -74,7 +76,7 @@ module Libvirtd_qemu = | int_entry keepalive_interval | int_entry keepalive_count - (* Each enty in the config is one of the following three ... *) + (* Each entry in the config is one of the following ... *) let entry = vnc_entry | spice_entry | remote_display_entry diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 87bdf70..809e254 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -153,6 +153,13 @@ #remote_display_port_min = 5900 #remote_display_port_max = 65535 +# VNC WebSocket port policies, same rules apply as with remote display +# ports. VNC WebSockets use similar display - port mappings, with +# the exception being that ports starts from 5700 instead of 5900. +# This is what may have be changed here. +# +#remote_websocket_port_min = 5700 +#remote_websocket_port_max = 65535 # The default security driver is SELinux. If SELinux is disabled # on the host, then the security driver will automatically disable diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2acf535..2ddeb8c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -225,6 +225,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, pci-bridge, /* 141 */ vfio-pci, /* 142 */ vfio-pci.bootindex, /* 143 */ + vnc-websocket, /* 143 */ ); struct _virQEMUCaps { @@ -2520,6 +2521,10 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, if (qemuCaps-version = 1003000) virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT); +/* WebSockets were intriduced between 1.3.0 and 1.3.1 */ +if (qemuCaps-version = 1003001) +virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET); + if (!(archstr = qemuMonitorGetTargetArch(mon))) goto cleanup; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 213f63c..c647274 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -182,6 +182,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_DEVICE_PCI_BRIDGE = 141, /* -device pci-bridge */ QEMU_CAPS_DEVICE_VFIO_PCI= 142, /* -device vfio-pci */ QEMU_CAPS_VFIO_PCI_BOOTINDEX = 143, /* bootindex param for vfio-pci device */ +QEMU_CAPS_VNC_WEBSOCKET = 144, /* bootindex param for vfio-pci device */ QEMU_CAPS_LAST, /* this must always be the last item */ }; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..1f74d26 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5900,6 +5900,17 @@ qemuBuildGraphicsVNCCommandLine(virQEMUDriverConfigPtr cfg, } } +if (graphics-data.vnc.websocket) { +if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET)) { +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s, + _(VNC websockets are not supported +
[libvirt] [PATCH 1/2] Add VNC WebSocket support
Adding support for new attribute 'websocket' in the 'graphics' element, the attribute value is the port to listen on with '-1' meaning auto-allocation, '0' meaning no websockets. Signed-off-by: Martin Kletzander mklet...@redhat.com --- docs/formatdomain.html.in | 5 + docs/schemas/domaincommon.rng | 5 + src/conf/domain_conf.c| 18 ++ src/conf/domain_conf.h| 1 + 4 files changed, 29 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f325c3c..dfea434 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -3530,6 +3530,11 @@ qemu-kvm -net nic,model=? /dev/null Rather than using listen/port, QEMU supports a codesocket/code attribute for listening on a unix domain socket path.span class=sinceSince 0.8.8/span + +For VNC WebSocket functionality, codewebsocket/code +attribute may be used to specify port to listen on (with -1 +meaning auto-allocation). span class=sinceSince +1.0.6/span /dd dtcodespice/code/dt dd diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 10596dc..5a1 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2071,6 +2071,11 @@ /attribute /optional optional +attribute name=websocket + ref name=PortNumber/ +/attribute + /optional + optional attribute name=listen ref name=addrIPorName/ /attribute diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a8b5dfd..026a737 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7546,6 +7546,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if (def-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { char *port = virXMLPropString(node, port); +char *websocket = virXMLPropString(node, websocket); char *autoport; if (port) { @@ -7576,6 +7577,20 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, VIR_FREE(autoport); } +if (websocket) { +if (virStrToLong_i(websocket, + NULL, 10, + def-data.vnc.websocket) 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, + _(cannot parse vnc websocket port %s), port); +VIR_FREE(websocket); +goto error; +} +VIR_FREE(websocket); +} else { +def-data.vnc.websocket = 0; +} + def-data.vnc.socket = virXMLPropString(node, socket); def-data.vnc.keymap = virXMLPropString(node, keymap); @@ -14980,6 +14995,9 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virBufferAsprintf(buf, autoport='%s', def-data.vnc.autoport ? yes : no); +if (def-data.vnc.websocket) +virBufferAsprintf(buf, websocket='%d', def-data.vnc.websocket); + if (listenAddr) virBufferAsprintf(buf, listen='%s', listenAddr); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3a0f23a..79deaf3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1401,6 +1401,7 @@ struct _virDomainGraphicsDef { union { struct { int port; +int websocket; bool autoport; char *keymap; char *socket; -- 1.8.2.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] libxl: allow an emulator to be selected in the domain config XML
We cross-check the given path against the capabilties, and translate it into a libxl_device_model_version. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 41 + 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 472d116..868d0cf 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -75,6 +75,11 @@ static const char* emulator_lib32_path [] = { EMULATOR_LIB32 EMULATOR_UPSTREAM, }; +static const libxl_device_model_version emulator_to_device_model [] = { +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL, +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN, +}; + struct guest_arch { virArch arch; int bits; @@ -833,6 +838,38 @@ libxlMakeCapabilities(libxl_ctx *ctx) } int +libxlMakeEmulator(virDomainDefPtr def, libxl_domain_config *d_config) +{ +virArch hostarch; +const char *path; +int i; + +/* No explicit override means use the default */ +if (!def-emulator) { +return 0; +} + +hostarch = virArchFromHost(); + +for (i = 0; i emulator_last; ++i) { + path = ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[i] : + emulator_lib32_path[i]); + if (STREQ(path, def-emulator)) { + d_config-b_info.device_model_version = + emulator_to_device_model[i]; + return 0; + } +} + +virReportError(VIR_ERR_INTERNAL_ERROR, + _(libxenlight doesn't support emulator '%s'), + def-emulator); +return -1; +} + + +int libxlBuildDomainConfig(libxlDriverPrivatePtr driver, virDomainDefPtr def, libxl_domain_config *d_config) { @@ -856,6 +893,10 @@ libxlBuildDomainConfig(libxlDriverPrivatePtr driver, goto error; } +if (libxlMakeEmulator(def, d_config) 0) { +goto error; +} + d_config-on_reboot = def-onReboot; d_config-on_poweroff = def-onPoweroff; d_config-on_crash = def-onCrash; -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] Add VNC WebSocket support
On 29.04.2013 16:52, Martin Kletzander wrote: Adding support for new attribute 'websocket' in the 'graphics' element, the attribute value is the port to listen on with '-1' meaning auto-allocation, '0' meaning no websockets. Signed-off-by: Martin Kletzander mklet...@redhat.com --- docs/formatdomain.html.in | 5 + docs/schemas/domaincommon.rng | 5 + src/conf/domain_conf.c| 18 ++ src/conf/domain_conf.h| 1 + 4 files changed, 29 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f325c3c..dfea434 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -3530,6 +3530,11 @@ qemu-kvm -net nic,model=? /dev/null Rather than using listen/port, QEMU supports a codesocket/code attribute for listening on a unix domain socket path.span class=sinceSince 0.8.8/span + +For VNC WebSocket functionality, codewebsocket/code +attribute may be used to specify port to listen on (with -1 +meaning auto-allocation). span class=sinceSince +1.0.6/span /dd dtcodespice/code/dt dd diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 10596dc..5a1 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2071,6 +2071,11 @@ /attribute /optional optional +attribute name=websocket + ref name=PortNumber/ +/attribute + /optional + optional attribute name=listen ref name=addrIPorName/ /attribute diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a8b5dfd..026a737 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7546,6 +7546,7 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, if (def-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { char *port = virXMLPropString(node, port); +char *websocket = virXMLPropString(node, websocket); char *autoport; if (port) { @@ -7576,6 +7577,20 @@ virDomainGraphicsDefParseXML(xmlNodePtr node, VIR_FREE(autoport); } +if (websocket) { +if (virStrToLong_i(websocket, + NULL, 10, + def-data.vnc.websocket) 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, + _(cannot parse vnc websocket port %s), port); +VIR_FREE(websocket); +goto error; +} +VIR_FREE(websocket); +} else { +def-data.vnc.websocket = 0; This shouldn't be needed. Newly allocated memory is always set to zero. But I see you just copy already existing pattern. +} + def-data.vnc.socket = virXMLPropString(node, socket); def-data.vnc.keymap = virXMLPropString(node, keymap); @@ -14980,6 +14995,9 @@ virDomainGraphicsDefFormat(virBufferPtr buf, virBufferAsprintf(buf, autoport='%s', def-data.vnc.autoport ? yes : no); +if (def-data.vnc.websocket) +virBufferAsprintf(buf, websocket='%d', def-data.vnc.websocket); + if (listenAddr) virBufferAsprintf(buf, listen='%s', listenAddr); } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 3a0f23a..79deaf3 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1401,6 +1401,7 @@ struct _virDomainGraphicsDef { union { struct { int port; +int websocket; bool autoport; char *keymap; char *socket; Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: Add VNC WebSocket support
On 29.04.2013 16:52, Martin Kletzander wrote: Adding a VNC WebSocket support for QEMU driver. This funcitonality is in upstream qemu from commit described as v1.3.0-982-g7536ee4, so the capability is being recognized based on QEMU version for now. Signed-off-by: Martin Kletzander mklet...@redhat.com --- src/qemu/libvirtd_qemu.aug | 4 +- src/qemu/qemu.conf | 7 +++ src/qemu/qemu_capabilities.c | 5 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c| 60 +- src/qemu/qemu_command.h| 5 +- src/qemu/qemu_conf.c | 32 src/qemu/qemu_conf.h | 6 +++ src/qemu/qemu_driver.c | 5 ++ src/qemu/qemu_process.c| 31 --- src/qemu/test_libvirtd_qemu.aug.in | 2 + tests/qemuargv2xmltest.c | 1 + .../qemuxml2argv-graphics-vnc-websocket.args | 4 ++ .../qemuxml2argv-graphics-vnc-websocket.xml| 35 + tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmltest.c| 1 + 16 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.xml diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug index 61740a9..5344125 100644 --- a/src/qemu/libvirtd_qemu.aug +++ b/src/qemu/libvirtd_qemu.aug @@ -41,6 +41,8 @@ module Libvirtd_qemu = let remote_display_entry = int_entry remote_display_port_min | int_entry remote_display_port_max + | int_entry remote_websocket_port_min + | int_entry remote_websocket_port_max let security_entry = str_entry security_driver | bool_entry security_default_confined @@ -74,7 +76,7 @@ module Libvirtd_qemu = | int_entry keepalive_interval | int_entry keepalive_count - (* Each enty in the config is one of the following three ... *) + (* Each entry in the config is one of the following ... *) Typo worth 1.0.5 release. let entry = vnc_entry | spice_entry | remote_display_entry diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 87bdf70..809e254 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -153,6 +153,13 @@ #remote_display_port_min = 5900 #remote_display_port_max = 65535 +# VNC WebSocket port policies, same rules apply as with remote display +# ports. VNC WebSockets use similar display - port mappings, with +# the exception being that ports starts from 5700 instead of 5900. +# This is what may have be changed here. +# +#remote_websocket_port_min = 5700 +#remote_websocket_port_max = 65535 # The default security driver is SELinux. If SELinux is disabled # on the host, then the security driver will automatically disable diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2acf535..2ddeb8c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -225,6 +225,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, pci-bridge, /* 141 */ vfio-pci, /* 142 */ vfio-pci.bootindex, /* 143 */ + vnc-websocket, /* 143 */ ); struct _virQEMUCaps { @@ -2520,6 +2521,10 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, if (qemuCaps-version = 1003000) virQEMUCapsSet(qemuCaps, QEMU_CAPS_MACHINE_USB_OPT); +/* WebSockets were intriduced between 1.3.0 and 1.3.1 */ s/intriduced/introduced/ +if (qemuCaps-version = 1003001) +virQEMUCapsSet(qemuCaps, QEMU_CAPS_VNC_WEBSOCKET); + if (!(archstr = qemuMonitorGetTargetArch(mon))) goto cleanup; Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 0/2] [RFC] Support for VNC WebSocket
On 29.04.2013 16:52, Martin Kletzander wrote: This series, which is meant to be applied _after_ 1.0.5 release, is adding support for the VNC WebSocket to be configured for QEMU. I tagged this with [RFC] because this is the fastest way I managed to code it and I'd welcome any opinions on naming changes etc. Documentation from qemu_options.hx: qemu -vnc ...,websocket[=port] Opens an additional TCP listening port dedicated to VNC Websocket connections. By definition the Websocket port is 5700+@var{display}. If @var{host} is specified connections will only be allowed from this host. As an alternative the Websocket port could be specified by using @code{websocket}=@var{port}. Martin Kletzander (2): Add VNC WebSocket support qemu: Add VNC WebSocket support docs/formatdomain.html.in | 5 ++ docs/schemas/domaincommon.rng | 5 ++ src/conf/domain_conf.c | 18 +++ src/conf/domain_conf.h | 1 + src/qemu/libvirtd_qemu.aug | 4 +- src/qemu/qemu.conf | 7 +++ src/qemu/qemu_capabilities.c | 5 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c| 60 +- src/qemu/qemu_command.h| 5 +- src/qemu/qemu_conf.c | 32 src/qemu/qemu_conf.h | 6 +++ src/qemu/qemu_driver.c | 5 ++ src/qemu/qemu_process.c| 31 --- src/qemu/test_libvirtd_qemu.aug.in | 2 + tests/qemuargv2xmltest.c | 1 + .../qemuxml2argv-graphics-vnc-websocket.args | 4 ++ .../qemuxml2argv-graphics-vnc-websocket.xml| 35 + tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmltest.c| 1 + 20 files changed, 219 insertions(+), 10 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc-websocket.xml I've found some tiny nits. But I like the idea overall. Michal -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH-v4.2] Support for static routes on a virtual bridge
On 04/26/2013 07:22 PM, Gene Czarcinski wrote: network: static route support for network This patch adds the route subelement of network to define a static route. the address and prefix (or netmask) attribute identify the destination network, and the gateway attribute specifies the next hop address (which must be directly reachable from the containing network) which is to receive the packets destined for address/(prefix|netmask). Tests are done to validate that the input definitions are correct. For example, for a static route ip definition, the address must be a network address and not a host address. Additional checks are added to ensure that the specified gateway is directly reachable via a network defined on this bridge. Whan a static route is added to a bridge, there is a slight possibility that the gateway address will be incorrect. If this is handled as an error, that bridge becomes unusable and can only be recovered by rebooting. If the error is ignored, then that network can be destroyed and the network definition file edited to correct the problem. Unfortunately, the error message only appears in syslog. However, with the checks performed when the network definition file is parsed, it is unlikely that this condition will ever occur. Handling of errors in this manner is consistent with other uses of the CommandRun interface. The command used is of the following form: ip route add address/prefix via gateway dev virbr-bridge \ proto static metric 1 While family='ipv4' address='0.0.0.0' netmask='0.0.0.0' or prefix='0' is supported and does work, the same cannot be said for ipv6. Therefore, if address='::' prefix='0' is specified for family='ipv6' an error message is issued stating that this is not currently supported. . Signed-off-by: Gene Czarcinski g...@czarc.net --- docs/formatnetwork.html.in | 71 + docs/schemas/network.rng | 19 ++ src/conf/network_conf.c| 318 - src/conf/network_conf.h| 22 ++ src/libvirt_private.syms | 1 + src/network/bridge_driver.c| 78 + src/util/virnetdev.c | 44 +++ src/util/virnetdev.h | 5 + .../networkxml2xmlin/dhcp6host-routed-network.xml | 2 + .../networkxml2xmlout/dhcp6host-routed-network.xml | 2 + 10 files changed, 561 insertions(+), 1 deletion(-) diff --git a/docs/formatnetwork.html.in b/docs/formatnetwork.html.in index 4dd0415..15dce3a 100644 --- a/docs/formatnetwork.html.in +++ b/docs/formatnetwork.html.in @@ -529,6 +529,50 @@ starting. /p +h5a name=elementsStaticrouteStatic Routes/a/h5 +p + Static route definitions are used to provide routing + information to the virtualization host for networks which are not + defined as a network on one of the virtual bridges so that such + networks can be reachable from the virtualization + host span class=sinceSince 1.0.5/span. +/p + +p + As shown in a href=formatnetwork.html#examplesNoGatewaythis example/a, + it is possible to define a virtual bridge interface with no + IPv4 or IPv6 networks. Such interfaces are useful in supporting + networks which have no visibility or direct connectivity with the + virtualization host, but can be used to support + virtual networks which only have guest connectivity. A guest + with connectivity to the guest-only network and another network + that is directly reachable from the host can act as a gateway between the + networks. A static route added to the visible network definition + provides the routing information so that IP packets can be sent + from the virtualization host to guests on the hidden network. +/p + +p + Here is a fragment of a definition which shows the static + route specification as well as the IPv4 and IPv6 definitions + for network addresses which are referred to in the + codegateway/code gateway address specifications. +/p + +pre + ... +lt;ip address=192.168.122.1 netmask=255.255.255.0gt; + lt;dhcpgt; +lt;range start=192.168.122.128 end=192.168.122.254 /gt; + lt;/dhcpgt; +lt;/ipgt; +lt;route address=192.168.222.0 prefix=24 gateway=192.168.122.2 /gt; +lt;ip family=ipv6 address=2001:db8:ca2:2::1 prefix=64 /gt; +lt;route family=ipv6 address=2001:db8:ca2:3:: prefix=64 gateway=2001:db8:ca2:2::2gt; +lt;/routegt; + ... +/pre + h3a name=elementsAddressAddressing/a/h3 p @@ -560,6 +604,7 @@ lt;/dhcpgt; lt;/ipgt; lt;ip family=ipv6 address=2001:db8:ca2:2::1 prefix=64 /gt; +lt;route family=ipv6
Re: [libvirt] [PATCH-v4.2] Support for static routes on a virtual bridge
(I wanted a separate message to comment on this part...) On 04/26/2013 07:22 PM, Gene Czarcinski wrote: +/* add an IP (static) route to a bridge */ +static int +networkAddRouteToBridge(virNetworkObjPtr network, +virNetworkRouteDefPtr routedef) +{ +bool done = false; +int prefix = 0; +virSocketAddrPtr addr = routedef-address; +virSocketAddrPtr mask = routedef-netmask; + +if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET)) { +long val4 = ntohl(addr-data.inet4.sin_addr.s_addr); +long msk4 = -1; +if (VIR_SOCKET_ADDR_IS_FAMILY(mask, AF_INET)) { +msk4 = ntohl(mask-data.inet4.sin_addr.s_addr); +} +if (msk4 == -1) { +if (val4 == 0 routedef-prefix == 0) +done = true; +} else { +if (val4 == 0 msk4 == 0) +done = true; +} +} I'll try and decode this... if ((address == 0.0.0.0) and netmask is unspecified) and (prefix is (0 or unspecified))) or (netmask is 0.0.0.0))) then use 0 for prefix when adding the route Is that correct? First - I would like to avoid references to the internal data structures of a virSocketAddr, and calling ntohnl at this level. virSocketAddr should be able to handle any bit twiddling we need. Now, let's see how much of that we can get rid of: 1) If netmask is 0.0.0.0, virSocketAddrGetIpPrefix will anyway return virSocketAddrGetNumNetmaskBits(0.0.0.0), which is conveniently 0. 2) if neither netmask nor prefix is specified, virSocketAddrGetIpPrefix will return 0 anyway (regardless of address), *but only if address wasn't specified*. If an address *was* specified and it was 0.0.0.0, it returns 8 (treating it as a Class A network) I had actually intended that my modification to virSocketAddrGetIpPrefix() to return 0 would eliminate the need for such code in bridge_driver.c, but didn't do it quite right, and it's just as well, because I just checked and RFCs say that there *is* some valid use for 0.0.0.0/8. +else if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6)) { +int i, val6 = 0; +for (i = 0;i 4;i++) { +val6 += ((addr-data.inet6.sin6_addr.s6_addr[2 * i] 8) | + addr-data.inet6.sin6_addr.s6_addr[2 * i + 1]); +} +if (val6 == 0 routedef-prefix == 0) { +char *addr = virSocketAddrFormat(routedef-address); +virReportError(VIR_ERR_INTERNAL_ERROR, + _(bridge '%s' has prefix=0 for address='%s' which is not supported), + network-def-bridge, addr); +VIR_FREE(addr); +return -1; +} +} and here - if the address is 0 and the prefix is 0/unspecified, then log an error. But if this is really something that's always illegal according to the IPv6 RFCs, then we can/should do that validation in the parser, not here. + +if (done) { +prefix = 0; +} else { +prefix = virSocketAddrGetIpPrefix(routedef-address, + routedef-netmask, + routedef-prefix); + +if (prefix 0) { +virReportError(VIR_ERR_INTERNAL_ERROR, + _(bridge '%s' has an invalid netmask or IP address for route definition), + network-def-bridge); +return -1; +} +} + +if (virNetDevSetGateway(network-def-bridge, +routedef-address, +prefix, +routedef-gateway) 0) +return -1; +return 0; +} So here's my opinion: 1) remove all that code above (I did that in my interdiff to your patch) 2) Make a new patch that adds something like this: virSocketAddr zero; /* this creates an all-0 address of the appropriate family */ ignore_value(virSocketAddrParse(zero, (VIR_SOCKET_ADDR_IS_FAMILY(addr,AF_INET) ? 0.0.0.0 : ::), VIR_SOCKET_ADDR_FAMILY(addr)); if (routedef-prefix || VIR_SOCKET_ADDR_IS_FAMILY(mask, AF_INET) || virSocketAddrEqual(addr, zero)) { prefix = virSocketAddrGetIpPrefix(addr, mask, routedef-prefix); } else { /* neither specified. check for a match with an address of all 0's */ if (virSocketAddrEqual(addr, zero)) prefix = 0; else prefix = virSocketAddrGetIpPrefix(addr, mask, routedef-prefix); } virReportError(VIR_ERR_INTERNAL_ERROR, _(bridge '%s' has prefix=0 for address='%s' which is not supported), network-def-bridge, addr); } } else { /* no prefix given, but address was non-zero, so get default
Re: [libvirt] [PATCH] network: Don't remove transient network if creating of config file fails
On 04/22/2013 05:32 AM, Peter Krempa wrote: On the off-chance that creation of persistent configuration file would fail when defining a network that is already started as transient, the code would remove the transient data structure and thus the network. This patch changes the code so that in such case, the network is again marked as transient and left behind. --- src/network/bridge_driver.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 27dd230..64c71af 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -3160,8 +3160,13 @@ static virNetworkPtr networkDefine(virConnectPtr conn, const char *xml) { freeDef = false; if (virNetworkSaveConfig(driver-networkConfigDir, def) 0) { -virNetworkRemoveInactive(driver-networks, network); -network = NULL; +if (!virNetworkObjIsActive(network)) { +virNetworkRemoveInactive(driver-networks, network); +network = NULL; +goto cleanup; +} +network-persistent = 0; +virNetworkDefFree(network-newDef); You also need to set network-newDef = NULL here. (It took some perusal of the code to figure out that this was the correct way to reset to the pre-networkDefine() state. The reason it works is that up above we've called virNetworkObjAssignDef(network, def, false); in that case, virNetworkObjAssignDef() just frees any existing network-newDef and sets network-newDef = def. ACK with that nit fixed. This should go in before 1.0.5. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 0/2] Get rid of default USB controller on S390
QEMU for S390 has presently no USB controllers nor a PCI bus. Both are created by the default in the libvirt domain definition. Although this can be suppressed by explicitly specifying an USB controller with model='none', it's a real bad default. With Jan's recent patch we can reliably suppress the USB controller (including it's bogus PCI address) if the source XML has no usb controller element. Explicitly set addresses are still honored. Viktor Mihajlovski (2): S390: Mention changed USB behavior S390: Do not generate a default USB controller docs/formatdomain.html.in |5 +++-- src/qemu/qemu_domain.c |8 .../qemuxml2argv-console-sclp.args |2 +- .../qemuxml2argv-console-virtio-ccw.args |2 +- .../qemuxml2argv-console-virtio-s390.args |2 +- .../qemuxml2argv-disk-virtio-ccw-many.args |2 +- .../qemuxml2argv-disk-virtio-ccw.args |2 +- .../qemuxml2argv-disk-virtio-s390.args |2 +- .../qemuxml2argv-disk-virtio-scsi-ccw.args |2 +- .../qemuxml2argv-net-virtio-ccw.args |2 +- .../qemuxml2argv-net-virtio-s390.args |2 +- .../qemuxml2argv-virtio-rng-ccw.args |2 +- 12 files changed, 21 insertions(+), 12 deletions(-) -- 1.7.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/2] S390: Mention changed USB behavior
Add a line saying that no USB controllers are generated by default on s390. --- docs/formatdomain.html.in |5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index f325c3c..8870e46 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2141,8 +2141,9 @@ pci-ohci or nec-xhci. Additionally, span class=sincesince 0.10.0/span, if the USB bus needs to be explicitly disabled for the guest, codemodel='none'/code may be - used. The PowerPC64 spapr-vio addresses do not have an associated - controller. + used. span class=sinceSince 1.0.5/span, no default USB controller + will be built on s390. The PowerPC64 spapr-vio addresses do not have an + associated controller. /p p -- 1.7.9.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] S390: Do not generate a default USB controller
For s390 we don't want to have a default USB device generated even if QEMU is silently tolerating -usb on the command line. This may change in the future. Another reason to avoid the USB controller is that it implies a PCI bus which might cause a regression at some later point in time. The following change will set the USB controller model to 'none' unless a model or address has been specified, which can be the case if a legacy definition is loaded or the XML writer knows what she/he's doing. Requiring the user to explicitly disable USB on systems not supporting it seems cumbersome. Signed-off-by: Viktor Mihajlovski mihaj...@linux.vnet.ibm.com --- src/qemu/qemu_domain.c |8 .../qemuxml2argv-console-sclp.args |2 +- .../qemuxml2argv-console-virtio-ccw.args |2 +- .../qemuxml2argv-console-virtio-s390.args |2 +- .../qemuxml2argv-disk-virtio-ccw-many.args |2 +- .../qemuxml2argv-disk-virtio-ccw.args |2 +- .../qemuxml2argv-disk-virtio-s390.args |2 +- .../qemuxml2argv-disk-virtio-scsi-ccw.args |2 +- .../qemuxml2argv-net-virtio-ccw.args |2 +- .../qemuxml2argv-net-virtio-s390.args |2 +- .../qemuxml2argv-virtio-rng-ccw.args |2 +- 11 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d927716..62c3382 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -784,6 +784,14 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, (def-os.arch == VIR_ARCH_S390 || def-os.arch == VIR_ARCH_S390X)) dev-data.chr-targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO; +/* set the default USB model to none for s390 unless an address is found */ +if (dev-type == VIR_DOMAIN_DEVICE_CONTROLLER +dev-data.controller-type == VIR_DOMAIN_CONTROLLER_TYPE_USB +dev-data.controller-model == -1 +dev-data.controller-info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE +(def-os.arch == VIR_ARCH_S390 || def-os.arch == VIR_ARCH_S390X)) +dev-data.controller-model = VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE; + ret = 0; cleanup: diff --git a/tests/qemuxml2argvdata/qemuxml2argv-console-sclp.args b/tests/qemuxml2argvdata/qemuxml2argv-console-sclp.args index 7dc1c49..86bd82d 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-console-sclp.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-console-sclp.args @@ -2,7 +2,7 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ s390-virtio -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \ socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \ chardev=charmonitor,id=monitor,mode=readline -no-acpi -boot c \ --usb -drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-virtio-disk0 -device \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-virtio-disk0 -device \ virtio-blk-s390,drive=drive-virtio-disk0,id=virtio-disk0 \ -chardev pty,id=charconsole0 \ -device sclpconsole,chardev=charconsole0,id=console0 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-ccw.args b/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-ccw.args index 6660a30..3e6f9f1 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-ccw.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-ccw.args @@ -3,7 +3,7 @@ s390-ccw -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \ socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \ chardev=charmonitor,id=monitor,mode=readline -no-acpi \ -device virtio-serial-ccw,id=virtio-serial0,devno=fe.0.0001 \ --usb -drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-virtio-disk0 \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-virtio-disk0 \ -device virtio-blk-ccw,devno=fe.0.,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \ -chardev pty,id=charconsole0 \ -device virtconsole,chardev=charconsole0,id=console0 \ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-s390.args b/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-s390.args index bf7b180..7b7f8f3 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-s390.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-console-virtio-s390.args @@ -3,7 +3,7 @@ s390-virtio -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev \ socket,id=charmonitor,path=/tmp/test-monitor,server,nowait -mon \ chardev=charmonitor,id=monitor,mode=readline -no-acpi \ -device virtio-serial-s390,id=virtio-serial0 \ --usb -drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-virtio-disk0 \ +-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-virtio-disk0 \ -device virtio-blk-s390,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1 \ -chardev pty,id=charconsole0 \ -device virtconsole,chardev=charconsole0,id=console0 diff --git
Re: [libvirt] [PATCH] qemu: honor allowDiskFormatProbing when parsing command line
On 04/29/2013 07:56 AM, Ján Tomko wrote: My commit 024e9af broke this. --- src/qemu/qemu_command.c | 3 --- diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d23bdfc..d161b56 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8540,7 +8540,6 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, def-bus = VIR_DOMAIN_DISK_BUS_IDE; def-device = VIR_DOMAIN_DISK_DEVICE_DISK; def-type = VIR_DOMAIN_DISK_TYPE_FILE; -def-format = VIR_STORAGE_FILE_AUTO; for (i = 0 ; i nkeywords ; i++) { if (STREQ(keywords[i], file)) { @@ -9788,8 +9787,6 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_ALLOC(disk) 0) goto no_memory; -disk-format = VIR_STORAGE_FILE_AUTO; - ACK. Using VIR_STORAGE_FILE_AUTO would be a security hole if it contradicts the user's configuration. Thanks for fixing this pre-release. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: Error out if spice port autoallocation is requested, but disabled
On 04/29/2013 05:50 AM, Peter Krempa wrote: When a user requests auto-allocation of the spice TLS port but spice TLS is disabled in qemu.conf, we start the machine and let qemu fail instead of erroring out sooner. Add an error message so that this doesn't happen. --- src/qemu/qemu_process.c | 10 -- 1 file changed, 8 insertions(+), 2 deletions(-) ACK. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 02/37] virstring: Introduce VIR_STRUP and VIR_STRNDUP
On 04/29/2013 07:50 AM, Michal Privoznik wrote: s/STRUP/STRDUP/ in the subject line. The code adaptation is not done right now, but in subsequent patches. Hence I am not implementing syntax-check rule as it would break compilation. Developers are strongly advised to use these new macros. They are similar to VIR_ALLOC() logic: VIR_STRDUP(dst, src) returns zero on success, -1 otherwise. In case you don't want to report OOM error, use _QUIET variant of a macro. s/use/use the/ Thinking about backportability - it looks like Fedora 19 will probably be based on libvirt 1.0.5 + patches. I'm hoping that if we backport this patch, but not the syntax check or the general cleanups of using VIR_STRDUP everywhere, then further backports of any new code that uses VIR_STRDUP can be done by using this interface, and any merge conflicts of code that used to use strdup should be fairly easy to resolve during the backport process (of course, the IDEAL situation is that 1.0.5 doesn't have any bugs that require backporting across this refactoring, right? :) +++ b/docs/hacking.html.in @@ -853,6 +853,20 @@ virStrncpy(dest, src, strlen(src), sizeof(dest)). /p +pre + VIR_STRDUP(char *dst, const char *src); + VIR_STRNDUP(char *dst, const char *src, size_t n); +/pre +p + You should avoid using strdup or strndup directly as the does not report s/the does/they do/ + out-of-memory error. Use VIR_STRDUP() or VIR_STRNDUP macros instead. + Note, that these two behave in similar way to VIR_ALLOC: on success zero s/in similar way/similar/ + is returned, otherwise caller is left with negative one. In very specific s/caller is left with negative one/the result is -1 and dst is guaranteed to be NULL/ + case, when you don't want to report the out-of-memory error, you can use s/case/cases/ + VIR_STRDUP_QUIET or VIR_STRNDUP_QUIET, but such usage is very rare and + usually considered a flaw. +/p + h2a name=strbufVariable length string buffer/a/h2 +++ b/src/util/virstring.c @@ -515,3 +515,77 @@ virArgvToString(const char *const *argv) return ret; } + +/** + * virStrdup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @report: whether to report OOM error, if there's a one s/there's a/there is/ + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strdup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider + * using VIR_STRDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise. s/othervise/otherwise/ + */ +int +virStrdup(char **dest, + const char *src, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ +if (!(*dest = strdup(src))) { +if (report) +virReportOOMErrorFull(domcode, filename, funcname, linenr); +return -1; +} + +return 0; +} + +/** + * virStrndup: + * @dest: where to store duplicated string + * @src: the source string to duplicate + * @n: how many bytes to copy + * @report: whether to report OOM error, if there's a one s/there's a/there is/ + * @domcode: error domain code + * @filename: caller's filename + * @funcname: caller's funcname + * @linenr: caller's line number + * + * Wrapper over strndup, which reports OOM error if told so, + * in which case callers wants to pass @domcode, @filename, + * @funcname and @linenr which should represent location in + * caller's body where virStrdup is called from. Consider s/virStrdup/virStrndup/ + * using VIR_STRNDUP which sets these automatically. + * + * Returns: 0 on success, -1 othervise. s/othervise/otherwise/ + */ +int +virStrndup(char **dest, + const char *src, + size_t n, + bool report, + int domcode, + const char *filename, + const char *funcname, + size_t linenr) +{ +if (!(*dest = strndup(src, n))) { +if (report) +virReportOOMErrorFull(domcode, filename, funcname, linenr); +return -1; +} + + return 0; +} Implementation of the helper functions looks correct. diff --git a/src/util/virstring.h b/src/util/virstring.h index 457caa2..620efba 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -87,4 +87,24 @@ char *virStrncpy(char *dest, const char *src, size_t n, size_t destbytes) char *virStrcpy(char *dest, const char *src, size_t destbytes) ATTRIBUTE_RETURN_CHECK; # define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) + +int virStrdup(char **dest, const char
Re: [libvirt] [PATCH v2 01/37] virutil: Move string related functions to virstring.c
On 04/29/2013 07:50 AM, Michal Privoznik wrote: The source code base needs to be adapted as well. Some files include virutil.h just for the string related functions (here, the include is substituted to match the new file), some include virutil.h without any need (here, the include is removed), and some require both. --- cfg.mk| 4 +- src/util/virstoragefile.c | 2 + src/util/virstring.c | 335 ++ src/util/virstring.h | 50 + src/util/virsysinfo.c | 2 +- src/util/virtime.c| 1 - src/util/virtpm.c | 2 +- src/util/virtypedparam.c | 1 + src/util/viruri.c | 2 +- src/util/virusb.c | 1 + src/util/virutil.c| 334 + Hmm, I guess git rename detection only kicks in for entire files, not for big chunks of code motion between existing files. 242 files changed, 590 insertions(+), 557 deletions(-) Growth is explainable by the number of new #include needed, I hope. The fact that things still compile is good; I'm not reviewing too closely, as the compiler should catch whether the motion was accurate. I'm guessing you just removed #include virutil.h everywhere, then compiled and fixed compiler errors for missing usage, until you had the correct set of includes added back in? +++ b/src/libvirt_private.syms @@ -1745,10 +1745,26 @@ virStorageFileResize; # util/virstring.h +virArgvToString; +virAsprintf; +virSkipSpaces; +virSkipSpacesAndBackslash; +virSkipSpacesBackwards; +virStrcpy; virStringArrayHasString; virStringFreeList; virStringJoin; virStringSplit; +virStrncpy; +virStrToDouble; +virStrToLong_i; +virStrToLong_l; +virStrToLong_ll; +virStrToLong_ui; +virStrToLong_ul; +virStrToLong_ull; +virTrimSpaces; +virVasprintf; Looks like a reasonable set to be moved. +++ b/src/util/virstring.c @@ -21,6 +21,10 @@ #include config.h +#include stdlib.h +#include stdio.h + +#include c-ctype.h #include virstring.h #include viralloc.h #include virbuffer.h @@ -180,3 +184,334 @@ virStringArrayHasString(char **strings, const char *needle) return false; } + +/* Like strtol, but produce an int result, and check more carefully. + Return 0 upon success; return -1 to indicate failure. + When END_PTR is NULL, the byte after the final valid digit must be NUL. + Otherwise, it's like strtol and lets the caller check any suffix for + validity. This function is careful to return -1 when the string S + represents a number that is not representable as an int. */ +int +virStrToLong_i(char const *s, char **end_ptr, int base, int *result) +{ +long int val; +char *p; +int err; + +errno = 0; +val = strtol(s, p, base); /* exempt from syntax-check */ +err = (errno || (!end_ptr *p) || p == s || (int) val != val); +if (end_ptr) +*end_ptr = p; +if (err) +return -1; +*result = val; +return 0; +} I did a spot check that this function did straight code motion; I'm assuming that for all the others, you did likewise. +++ b/src/util/virutil.c -/* Like strtol, but produce an int result, and check more carefully. - Return 0 upon success; return -1 to indicate failure. - When END_PTR is NULL, the byte after the final valid digit must be NUL. - Otherwise, it's like strtol and lets the caller check any suffix for - validity. This function is careful to return -1 when the string S - represents a number that is not representable as an int. */ -int -virStrToLong_i(char const *s, char **end_ptr, int base, int *result) -{ -long int val; -char *p; -int err; - -errno = 0; -val = strtol(s, p, base); /* exempt from syntax-check */ -err = (errno || (!end_ptr *p) || p == s || (int) val != val); -if (end_ptr) -*end_ptr = p; -if (err) -return -1; -*result = val; -return 0; -} ACK. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2] virsh: fix incorrect argument errors for long options
For long options, print: * the option as specified by the user if it's unknown * the cannoncial long option if its argument is not a number (and should be) And for missing arguments, print both the short and the long option name. (Doing only one of those would require either parsing argv ourselves or let getopt print the errors, since we can't tell long and short options apart by optopt or longindex) https://bugzilla.redhat.com/show_bug.cgi?id=949373 --- v1: https://www.redhat.com/archives/libvir-list/2013-April/msg01653.html tools/virsh.c | 23 +-- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 6ec2f7b..ac86608 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2978,7 +2978,8 @@ vshAllowedEscapeChar(char c) static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { -int arg, len, debug; +int arg, len, debug, i; +int longindex = -1; struct option opt[] = { {debug, required_argument, NULL, 'd'}, {help, no_argument, NULL, 'h'}, @@ -2995,11 +2996,12 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) /* Standard (non-command) options. The leading + ensures that no * argument reordering takes place, so that command options are * not confused with top-level virsh options. */ -while ((arg = getopt_long(argc, argv, +:d:hqtc:vVrl:e:, opt, NULL)) != -1) { +while ((arg = getopt_long(argc, argv, +:d:hqtc:vVrl:e:, opt, longindex)) != -1) { switch (arg) { case 'd': if (virStrToLong_i(optarg, NULL, 10, debug) 0) { -vshError(ctl, %s, _(option -d takes a numeric argument)); +vshError(ctl, _(option %s takes a numeric argument), + longindex == -1 ? -d : --debug); exit(EXIT_FAILURE); } if (debug VSH_ERR_DEBUG || debug VSH_ERR_ERROR) @@ -3050,15 +3052,24 @@ vshParseArgv(vshControl *ctl, int argc, char **argv) } break; case ':': -vshError(ctl, _(option '-%c' requires an argument), optopt); -exit(EXIT_FAILURE); +for (i = 0; opt[i].name != NULL; i++) { +if (opt[i].val == optopt) { +vshError(ctl, _(option '-%c'/'--%s' requires an argument), + optopt, opt[i].name); +exit(EXIT_FAILURE); +} +} case '?': -vshError(ctl, _(unsupported option '-%c'. See --help.), optopt); +if (optopt) +vshError(ctl, _(unsupported option '-%c'. See --help.), optopt); +else +vshError(ctl, _(unsupported option '%s'. See --help.), argv[optind - 1]); exit(EXIT_FAILURE); default: vshError(ctl, _(unknown option)); exit(EXIT_FAILURE); } +longindex = -1; } if (argc optind) { -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: honor allowDiskFormatProbing when parsing command line
On 04/29/2013 06:16 PM, Eric Blake wrote: On 04/29/2013 07:56 AM, Ján Tomko wrote: My commit 024e9af broke this. --- src/qemu/qemu_command.c | 3 --- ... ACK. Using VIR_STORAGE_FILE_AUTO would be a security hole if it contradicts the user's configuration. Thanks for fixing this pre-release. Thanks, I've pushed it now. Jan -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: Add VNC WebSocket support
On Mon, Apr 29, 2013 at 4:52 PM, Martin Kletzander mklet...@redhat.comwrote: diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2acf535..2ddeb8c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -225,6 +225,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, pci-bridge, /* 141 */ vfio-pci, /* 142 */ vfio-pci.bootindex, /* 143 */ + vnc-websocket, /* 143 */ 144 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [RFC PATCH 5/4] qemu: detect -machine mem-merge capability
* src/qemu/qemu_capabilities.h: New capability bit. * src/qemu/qemu_capabilities.c (virQEMUCapsProbeQMPCommandLine): New function; use it to set new capability bit. (virQEMUCapsInitQMP): Use new function. --- As promised, here is how I would set the new capability for use in Osier's series here: https://www.redhat.com/archives/libvir-list/2013-April/msg01833.html src/qemu/qemu_capabilities.c | 46 src/qemu/qemu_capabilities.h | 1 + 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2acf535..40b824c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -222,9 +222,10 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, tpm-tis, nvram, /* 140 */ - pci-bridge, /* 141 */ - vfio-pci, /* 142 */ - vfio-pci.bootindex, /* 143 */ + pci-bridge, + vfio-pci, + vfio-pci.bootindex, + mem-merge, ); struct _virQEMUCaps { @@ -1441,7 +1442,6 @@ static struct virQEMUCapsObjectTypeProps virQEMUCapsObjectProps[] = { ARRAY_CARDINALITY(virQEMUCapsObjectPropsUsbHost) }, }; - static void virQEMUCapsProcessStringFlags(virQEMUCapsPtr qemuCaps, size_t nflags, @@ -2225,6 +2225,42 @@ virQEMUCapsProbeQMPKVMState(virQEMUCapsPtr qemuCaps, } +struct virQEMUCapsCommandLineProps { +const char *option; +const char *param; +int flag; +}; + +static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = { +{ machine, mem-merge, QEMU_CAPS_MEM_MERGE }, +}; + +static int +virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps, + qemuMonitorPtr mon) +{ +int nvalues; +char **values; +size_t i, j; + +for (i = 0; i ARRAY_CARDINALITY(virQEMUCapsCommandLine); i++) { +if ((nvalues = qemuMonitorGetCommandLineOptionParameters(mon, + virQEMUCapsCommandLine[i].option, + values)) 0) +return -1; +for (j = 0; j nvalues; j++) { +if (STREQ(virQEMUCapsCommandLine[i].param, values[j])) { +virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); +break; +} +} +virStringFreeList(values); +} + +return 0; +} + + int virQEMUCapsProbeQMP(virQEMUCapsPtr qemuCaps, qemuMonitorPtr mon) { @@ -2552,6 +2588,8 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, goto cleanup; if (virQEMUCapsProbeQMPTPM(qemuCaps, mon) 0) goto cleanup; +if (virQEMUCapsProbeQMPCommandLine(qemuCaps, mon) 0) +goto cleanup; ret = 0; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 213f63c..c9c7fc9 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -182,6 +182,7 @@ enum virQEMUCapsFlags { QEMU_CAPS_DEVICE_PCI_BRIDGE = 141, /* -device pci-bridge */ QEMU_CAPS_DEVICE_VFIO_PCI= 142, /* -device vfio-pci */ QEMU_CAPS_VFIO_PCI_BOOTINDEX = 143, /* bootindex param for vfio-pci device */ +QEMU_CAPS_MEM_MERGE = 144, /* -machine mem-merge */ QEMU_CAPS_LAST, /* this must always be the last item */ }; -- 1.8.1.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] portability: handle ifreq differences in virnetdev
On 04/27/2013 09:50 AM, Roman Bogorodskiy wrote: FreeBSD (and maybe other BSDs) have different member names in struct ifreq when compared to Linux, such as: - uses ifr_data instead of ifr_newname for setting interface names - uses ifr_index instead of ifr_ifindex for interface index Also, add a check for SIOCGIFHWADDR for virNetDevValidateConfig(). Use AF_LOCAL if AF_PACKET is not available. --- configure.ac | 8 src/util/virnetdev.c | 23 +-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 23c24d2..4a32f8c 100644 --- a/configure.ac +++ b/configure.ac @@ -2363,6 +2363,14 @@ AM_CONDITIONAL([HAVE_LIBNL], [test $have_libnl = yes]) AC_SUBST([LIBNL_CFLAGS]) AC_SUBST([LIBNL_LIBS]) +AC_CHECK_MEMBERS([struct ifreq.ifr_newname, + struct ifreq.ifr_ifindex, + struct ifreq.ifr_index], + [], [], + [#include sys/ioctl.h + #include net/if.h + ]) This is good, although a dnl'd comment explaining why we probe might be nice. +++ b/src/util/virnetdev.c @@ -38,7 +38,10 @@ #ifdef __linux__ # include linux/sockios.h # include linux/if_vlan.h -#elif !defined(AF_PACKET) +# define VIR_NETDEV_FAMILY AF_PACKET +#elif defined(HAVE_STRUCT_IFREQ) defined(AF_LOCAL) +# define VIR_NETDEV_FAMILY AF_LOCAL +#else I like this one. @@ -478,12 +481,16 @@ int virNetDevSetName(const char* ifname, const char *newifname) if ((fd = virNetDevSetupControl(ifname, ifr)) 0) return -1; +#if !defined(HAVE_STRUCT_IFREQ_IFR_NEWNAME) +ifr.ifr_data = (caddr_t)newifname; +#else if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) { virReportSystemError(ERANGE, _(Network interface name '%s' is too long), newifname); goto cleanup; } +#endif This one reads awkwardly. I would have done: #ifdef HAVE_STRUCT_IFREQ_IFR_NEWNAME existing ifr_newname code #else ifr_data code #endif @@ -654,7 +661,11 @@ int virNetDevGetIndex(const char *ifname, int *ifindex) goto cleanup; } +#if defined(HAVE_STRUCT_IFREQ_IFR_INDEX) #ifdef is shorter than #if defined(). +*ifindex = ifreq.ifr_index; +#else *ifindex = ifreq.ifr_ifindex; +#endif ret = 0; Overall, looks sane; I'll probably apply the touchups mentioned and push later today after testing on my own FreeBSD VM. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: Add VNC WebSocket support
On 04/29/2013 11:34 AM, Ruben Kerkhof wrote: On Mon, Apr 29, 2013 at 4:52 PM, Martin Kletzander mklet...@redhat.comwrote: diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2acf535..2ddeb8c 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -225,6 +225,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, pci-bridge, /* 141 */ vfio-pci, /* 142 */ vfio-pci.bootindex, /* 143 */ + vnc-websocket, /* 143 */ 144 Or even better, omitted. The rest of the file lists a comment only every 5 enum values; the 141, 142, and 143 are present due to someone not following the pattern. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] libxl: expose multiple emulators per guest in the capabilities XML
David Scott wrote: libxl allows users to choose between two standard emulators: 1. (default in xen-4.2): qemu traditional (aka qemu-dm) 2. (default in xen-4.3): qemu upstream (aka qemu-system-i386) The person who builds and packages xen gets to choose which emulators are built. We examine the filesystem for the emulators at runtime and expose them as separate domains within the same guest architecture. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 87 --- 1 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..472d116 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -29,6 +29,8 @@ #include libxl.h #include sys/types.h #include sys/socket.h +#include sys/stat.h +#include unistd.h #include internal.h #include virlog.h @@ -50,6 +52,28 @@ /* see xen-unstable.hg/xen/include/asm-x86/cpufeature.h */ #define LIBXL_X86_FEATURE_PAE_MASK 0x40 +enum emulator_type { +emulator_traditional = 0, +emulator_upstream= 1, +emulator_last= 2, +/* extend with specific qemu versions later */ +}; Do you think this will need to be extended in the future? As 'qemu-traditional' goes by way of the Dodo, this won't be needed right? + +#define EMULATOR_LIB64 /usr/lib64/xen/bin/ +#define EMULATOR_LIB32 /usr/lib/xen/bin/ + +#define EMULATOR_TRADITIONAL qemu-dm +#define EMULATOR_UPSTREAMqemu-system-i386 I think this could be made quite a bit simpler with something like #define LIBXL_EMULATOR_TRADITIONAL_PATH LIBDIR /xen/bin/qemu-dm #define LIBXL_EMULATOR_UPSTREAM_PATH LIBDIR /xen/bin/qemu-sytstem-i386 + +static const char* emulator_lib64_path [] = { +EMULATOR_LIB64 EMULATOR_TRADITIONAL, +EMULATOR_LIB64 EMULATOR_UPSTREAM, +}; + +static const char* emulator_lib32_path [] = { +EMULATOR_LIB32 EMULATOR_TRADITIONAL, +EMULATOR_LIB32 EMULATOR_UPSTREAM, +}; struct guest_arch { virArch arch; @@ -68,10 +92,11 @@ static virCapsPtr libxlBuildCapabilities(virArch hostarch, int host_pae, struct guest_arch *guest_archs, - int nr_guest_archs) + int nr_guest_archs, + int emulators_found[]) { virCapsPtr caps; -int i; +int i, j; if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL) goto no_memory; @@ -91,12 +116,8 @@ libxlBuildCapabilities(virArch hostarch, if ((guest = virCapabilitiesAddGuest(caps, guest_archs[i].hvm ? hvm : xen, guest_archs[i].arch, - ((hostarch == VIR_ARCH_X86_64) ? - /usr/lib64/xen/bin/qemu-dm : - /usr/lib/xen/bin/qemu-dm), - (guest_archs[i].hvm ? - /usr/lib/xen/boot/hvmloader : - NULL), + NULL, + NULL, 1, machines)) == NULL) { virCapabilitiesFreeMachines(machines, 1); @@ -104,13 +125,21 @@ libxlBuildCapabilities(virArch hostarch, } machines = NULL; -if (virCapabilitiesAddGuestDomain(guest, - xen, - NULL, - NULL, - 0, - NULL) == NULL) -goto no_memory; +for (j = 0; j emulator_last; ++j) { +if (emulators_found[j] == -1) /* failure from stat(2) */ +continue; +if (virCapabilitiesAddGuestDomain(guest, + xen, + ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[j] : + emulator_lib32_path[j]), + (guest_archs[i].hvm ? + /usr/lib/xen/boot/hvmloader : + NULL), + 0, + NULL) == NULL) +goto no_memory; +} and then just add the emulators here. E.g. if (virFileExists(LIBXL_EMULATOR_TRADITIONAL_PATH) { if (virCapabilitiesAddGuestDomain(guest,
[libvirt] [PATCH v2 0/2] qemu: xml-native memballoon fixes
v1: https://www.redhat.com/archives/libvir-list/2013-April/msg01910.html v2: Instead of assuming 'pci' as the default memballoon device, assign the addresses when doing xml-native conversion and add an error message for the wrong address type. Ján Tomko (2): qemu: assign addresses when converting xml to native qemu: report an error if memballoon has wrong address type src/qemu/qemu_command.c | 3 +++ src/qemu/qemu_driver.c | 3 +++ 2 files changed, 6 insertions(+) -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 1/2] qemu: assign addresses when converting xml to native
This adds addresses to domxml-to-native output and chooses the correct virtio devices for ccw and s390 machines. https://bugzilla.redhat.com/show_bug.cgi?id=957077 --- src/qemu/qemu_driver.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..296efe3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, if (qemuAssignDeviceAliases(def, qemuCaps) 0) goto cleanup; +if (qemuDomainAssignAddresses(def, qemuCaps, NULL) 0) +goto cleanup; + if (!(cmd = qemuBuildCommandLine(conn, driver, def, monConfig, monitor_json, qemuCaps, NULL, -1, NULL, VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH v2 2/2] qemu: report an error if memballoon has wrong address type
qemuBuildMemballoonDevStr returns NULL if memballoon doesn't have the right address type, but it doesn't report an error, leading to: error: An error occurred, but the cause is unknown Report a helpful error message instead, e.g.: error: XML error: memballoon unsupported with address type 'usb' --- src/qemu/qemu_command.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d161b56..3184e5b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4175,6 +4175,9 @@ qemuBuildMemballoonDevStr(virDomainMemballoonDefPtr dev, virBufferAddLit(buf, virtio-balloon-ccw); break; default: +virReportError(VIR_ERR_XML_ERROR, + _(memballoon unsupported with address type '%s'), + virDomainDeviceAddressTypeToString(dev-info.type)); goto error; } -- 1.8.1.5 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] libxl: expose multiple emulators per guest in the capabilities XML
On Mon, Apr 29, 2013 at 12:18:56PM -0600, Jim Fehlig wrote: David Scott wrote: libxl allows users to choose between two standard emulators: 1. (default in xen-4.2): qemu traditional (aka qemu-dm) 2. (default in xen-4.3): qemu upstream (aka qemu-system-i386) The person who builds and packages xen gets to choose which emulators are built. We examine the filesystem for the emulators at runtime and expose them as separate domains within the same guest architecture. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 87 --- 1 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..472d116 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -29,6 +29,8 @@ #include libxl.h #include sys/types.h #include sys/socket.h +#include sys/stat.h +#include unistd.h #include internal.h #include virlog.h @@ -50,6 +52,28 @@ /* see xen-unstable.hg/xen/include/asm-x86/cpufeature.h */ #define LIBXL_X86_FEATURE_PAE_MASK 0x40 +enum emulator_type { +emulator_traditional = 0, +emulator_upstream= 1, +emulator_last= 2, +/* extend with specific qemu versions later */ +}; Do you think this will need to be extended in the future? As 'qemu-traditional' goes by way of the Dodo, this won't be needed right? + +#define EMULATOR_LIB64 /usr/lib64/xen/bin/ +#define EMULATOR_LIB32 /usr/lib/xen/bin/ + +#define EMULATOR_TRADITIONAL qemu-dm +#define EMULATOR_UPSTREAMqemu-system-i386 I think this could be made quite a bit simpler with something like #define LIBXL_EMULATOR_TRADITIONAL_PATH LIBDIR /xen/bin/qemu-dm #define LIBXL_EMULATOR_UPSTREAM_PATH LIBDIR /xen/bin/qemu-sytstem-i386 + +static const char* emulator_lib64_path [] = { +EMULATOR_LIB64 EMULATOR_TRADITIONAL, +EMULATOR_LIB64 EMULATOR_UPSTREAM, +}; + +static const char* emulator_lib32_path [] = { +EMULATOR_LIB32 EMULATOR_TRADITIONAL, +EMULATOR_LIB32 EMULATOR_UPSTREAM, +}; struct guest_arch { virArch arch; @@ -68,10 +92,11 @@ static virCapsPtr libxlBuildCapabilities(virArch hostarch, int host_pae, struct guest_arch *guest_archs, - int nr_guest_archs) + int nr_guest_archs, + int emulators_found[]) { virCapsPtr caps; -int i; +int i, j; if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL) goto no_memory; @@ -91,12 +116,8 @@ libxlBuildCapabilities(virArch hostarch, if ((guest = virCapabilitiesAddGuest(caps, guest_archs[i].hvm ? hvm : xen, guest_archs[i].arch, - ((hostarch == VIR_ARCH_X86_64) ? - /usr/lib64/xen/bin/qemu-dm : - /usr/lib/xen/bin/qemu-dm), - (guest_archs[i].hvm ? - /usr/lib/xen/boot/hvmloader : - NULL), + NULL, + NULL, 1, machines)) == NULL) { virCapabilitiesFreeMachines(machines, 1); @@ -104,13 +125,21 @@ libxlBuildCapabilities(virArch hostarch, } machines = NULL; -if (virCapabilitiesAddGuestDomain(guest, - xen, - NULL, - NULL, - 0, - NULL) == NULL) -goto no_memory; +for (j = 0; j emulator_last; ++j) { +if (emulators_found[j] == -1) /* failure from stat(2) */ +continue; +if (virCapabilitiesAddGuestDomain(guest, + xen, + ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[j] : + emulator_lib32_path[j]), + (guest_archs[i].hvm ? + /usr/lib/xen/boot/hvmloader : + NULL), + 0, + NULL) == NULL) +
Re: [libvirt] [PATCH 2/2] libxl: allow an emulator to be selected in the domain config XML
On Mon, Apr 29, 2013 at 03:49:41PM +0100, David Scott wrote: We cross-check the given path against the capabilties, and translate it into a libxl_device_model_version. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 41 + 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 472d116..868d0cf 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -75,6 +75,11 @@ static const char* emulator_lib32_path [] = { EMULATOR_LIB32 EMULATOR_UPSTREAM, }; +static const libxl_device_model_version emulator_to_device_model [] = { +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL, +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN, +}; + struct guest_arch { virArch arch; int bits; @@ -833,6 +838,38 @@ libxlMakeCapabilities(libxl_ctx *ctx) } int +libxlMakeEmulator(virDomainDefPtr def, libxl_domain_config *d_config) +{ +virArch hostarch; +const char *path; +int i; + +/* No explicit override means use the default */ +if (!def-emulator) { +return 0; +} + +hostarch = virArchFromHost(); + +for (i = 0; i emulator_last; ++i) { + path = ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[i] : + emulator_lib32_path[i]); + if (STREQ(path, def-emulator)) { + d_config-b_info.device_model_version = + emulator_to_device_model[i]; + return 0; + } +} + +virReportError(VIR_ERR_INTERNAL_ERROR, + _(libxenlight doesn't support emulator '%s'), + def-emulator); +return -1; This check is bogus. The capabilities XML is only intended to list the recommended default emulator. It is perfectly aceptable for apps to pass emulator paths that are not present in the capabilities. Daniel -- |: http://berrange.com -o-http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] libxl: allow an emulator to be selected in the domain config XML
David Scott wrote: We cross-check the given path against the capabilties, and translate it into a libxl_device_model_version. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 41 + 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 472d116..868d0cf 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -75,6 +75,11 @@ static const char* emulator_lib32_path [] = { EMULATOR_LIB32 EMULATOR_UPSTREAM, }; +static const libxl_device_model_version emulator_to_device_model [] = { +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL, +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN, +}; + struct guest_arch { virArch arch; int bits; @@ -833,6 +838,38 @@ libxlMakeCapabilities(libxl_ctx *ctx) } int +libxlMakeEmulator(virDomainDefPtr def, libxl_domain_config *d_config) +{ +virArch hostarch; +const char *path; +int i; + +/* No explicit override means use the default */ +if (!def-emulator) { +return 0; +} + +hostarch = virArchFromHost(); + +for (i = 0; i emulator_last; ++i) { + path = ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[i] : + emulator_lib32_path[i]); + if (STREQ(path, def-emulator)) { I thought there was a virCapabilitiesSupportsGuestEmulator() or similar, but I don't see it in src/conf/capabilities.c. I think it makes sense to add such a function to the capabilities and then just call it here, passing the requested emulator. Perhaps other libvirt developers can comment on the usefulness of virCapabilitiesSupportGuestEmulator(). + d_config-b_info.device_model_version = + emulator_to_device_model[i]; + return 0; + } +} + +virReportError(VIR_ERR_INTERNAL_ERROR, + _(libxenlight doesn't support emulator '%s'), + def-emulator); +return -1; +} + + +int libxlBuildDomainConfig(libxlDriverPrivatePtr driver, virDomainDefPtr def, libxl_domain_config *d_config) { @@ -856,6 +893,10 @@ libxlBuildDomainConfig(libxlDriverPrivatePtr driver, goto error; } +if (libxlMakeEmulator(def, d_config) 0) { The capabilities created when the libxl driver is loaded are available in libxlDriverPrivatePtr and could be passed to libxlMakeEmulator() libxlMakeEmulator(driver-caps, def, d_config) Regards, Jim +goto error; +} + d_config-on_reboot = def-onReboot; d_config-on_poweroff = def-onPoweroff; d_config-on_crash = def-onCrash; -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 10/37] Adapt to VIR_STRDUP in src/lxc/*
On 04/29/2013 09:50 AM, Michal Privoznik wrote: --- src/lxc/lxc_cgroup.c | 2 +- src/lxc/lxc_conf.c | 18 +- src/lxc/lxc_container.c | 8 src/lxc/lxc_controller.c | 6 +++--- src/lxc/lxc_driver.c | 7 ++- src/lxc/lxc_process.c| 4 ++-- 6 files changed, 21 insertions(+), 24 deletions(-) @@ -161,17 +161,17 @@ int lxcLoadDriverConfig(virLXCDriverPtr driver) driver-securityRequireConfined = false; /* Set the container configuration directory */ -if ((driver-configDir = strdup(LXC_CONFIG_DIR)) == NULL) +if (VIR_STRDUP(driver-configDir,LXC_CONFIG_DIR) 0) Missing a space ^^^ goto no_memory; -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 12/37] Adapt to VIR_STRDUP in src/node_device/*
On 04/29/2013 09:50 AM, Michal Privoznik wrote: --- src/node_device/node_device_driver.c | 28 -- src/node_device/node_device_hal.c| 13 ++--- src/node_device/node_device_udev.c | 102 +++ 3 files changed, 60 insertions(+), 83 deletions(-) ... @@ -388,8 +385,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) } for (caps = obj-def-caps; caps ncaps maxnames; caps = caps-next) { -names[ncaps] = strdup(virNodeDevCapTypeToString(caps-type)); -if (names[ncaps++] == NULL) { +if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps-type)) 0) { Lost the autoincrement ^^^ virReportOOMError(); goto cleanup; } ... --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -445,10 +445,10 @@ static void dev_create(const char *udi) virNodeDeviceDefPtr def = NULL; const char *name = hal_name(udi); int rv; -char *privData = strdup(udi); +char *privData; char *devicePath = NULL; -if (!privData) +if (VIR_STRDUP(privDatam udi) 0) s/m/,/ ... -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/2] libxl: expose multiple emulators per guest in the capabilities XML
Daniel P. Berrange wrote: On Mon, Apr 29, 2013 at 12:18:56PM -0600, Jim Fehlig wrote: David Scott wrote: libxl allows users to choose between two standard emulators: 1. (default in xen-4.2): qemu traditional (aka qemu-dm) 2. (default in xen-4.3): qemu upstream (aka qemu-system-i386) The person who builds and packages xen gets to choose which emulators are built. We examine the filesystem for the emulators at runtime and expose them as separate domains within the same guest architecture. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 87 --- 1 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..472d116 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -29,6 +29,8 @@ #include libxl.h #include sys/types.h #include sys/socket.h +#include sys/stat.h +#include unistd.h #include internal.h #include virlog.h @@ -50,6 +52,28 @@ /* see xen-unstable.hg/xen/include/asm-x86/cpufeature.h */ #define LIBXL_X86_FEATURE_PAE_MASK 0x40 +enum emulator_type { +emulator_traditional = 0, +emulator_upstream= 1, +emulator_last= 2, +/* extend with specific qemu versions later */ +}; Do you think this will need to be extended in the future? As 'qemu-traditional' goes by way of the Dodo, this won't be needed right? + +#define EMULATOR_LIB64 /usr/lib64/xen/bin/ +#define EMULATOR_LIB32 /usr/lib/xen/bin/ + +#define EMULATOR_TRADITIONAL qemu-dm +#define EMULATOR_UPSTREAMqemu-system-i386 I think this could be made quite a bit simpler with something like #define LIBXL_EMULATOR_TRADITIONAL_PATH LIBDIR /xen/bin/qemu-dm #define LIBXL_EMULATOR_UPSTREAM_PATH LIBDIR /xen/bin/qemu-sytstem-i386 + +static const char* emulator_lib64_path [] = { +EMULATOR_LIB64 EMULATOR_TRADITIONAL, +EMULATOR_LIB64 EMULATOR_UPSTREAM, +}; + +static const char* emulator_lib32_path [] = { +EMULATOR_LIB32 EMULATOR_TRADITIONAL, +EMULATOR_LIB32 EMULATOR_UPSTREAM, +}; struct guest_arch { virArch arch; @@ -68,10 +92,11 @@ static virCapsPtr libxlBuildCapabilities(virArch hostarch, int host_pae, struct guest_arch *guest_archs, - int nr_guest_archs) + int nr_guest_archs, + int emulators_found[]) { virCapsPtr caps; -int i; +int i, j; if ((caps = virCapabilitiesNew(hostarch, 1, 1)) == NULL) goto no_memory; @@ -91,12 +116,8 @@ libxlBuildCapabilities(virArch hostarch, if ((guest = virCapabilitiesAddGuest(caps, guest_archs[i].hvm ? hvm : xen, guest_archs[i].arch, - ((hostarch == VIR_ARCH_X86_64) ? - /usr/lib64/xen/bin/qemu-dm : - /usr/lib/xen/bin/qemu-dm), - (guest_archs[i].hvm ? - /usr/lib/xen/boot/hvmloader : - NULL), + NULL, + NULL, 1, machines)) == NULL) { virCapabilitiesFreeMachines(machines, 1); @@ -104,13 +125,21 @@ libxlBuildCapabilities(virArch hostarch, } machines = NULL; -if (virCapabilitiesAddGuestDomain(guest, - xen, - NULL, - NULL, - 0, - NULL) == NULL) -goto no_memory; +for (j = 0; j emulator_last; ++j) { +if (emulators_found[j] == -1) /* failure from stat(2) */ +continue; +if (virCapabilitiesAddGuestDomain(guest, + xen, + ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[j] : + emulator_lib32_path[j]), + (guest_archs[i].hvm ? + /usr/lib/xen/boot/hvmloader : + NULL), + 0, + NULL) == NULL) +goto no_memory; +} and then just add the
Re: [libvirt] [PATCH 2/2] libxl: allow an emulator to be selected in the domain config XML
Jim Fehlig wrote: David Scott wrote: We cross-check the given path against the capabilties, and translate it into a libxl_device_model_version. Signed-off-by: David Scott dave.sc...@eu.citrix.com --- src/libxl/libxl_conf.c | 41 + 1 files changed, 41 insertions(+), 0 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 472d116..868d0cf 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -75,6 +75,11 @@ static const char* emulator_lib32_path [] = { EMULATOR_LIB32 EMULATOR_UPSTREAM, }; +static const libxl_device_model_version emulator_to_device_model [] = { +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL, +LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN, +}; + struct guest_arch { virArch arch; int bits; @@ -833,6 +838,38 @@ libxlMakeCapabilities(libxl_ctx *ctx) } int +libxlMakeEmulator(virDomainDefPtr def, libxl_domain_config *d_config) +{ +virArch hostarch; +const char *path; +int i; + +/* No explicit override means use the default */ +if (!def-emulator) { +return 0; +} + +hostarch = virArchFromHost(); + +for (i = 0; i emulator_last; ++i) { + path = ((hostarch == VIR_ARCH_X86_64) ? + emulator_lib64_path[i] : + emulator_lib32_path[i]); + if (STREQ(path, def-emulator)) { I thought there was a virCapabilitiesSupportsGuestEmulator() or similar, but I don't see it in src/conf/capabilities.c. I think it makes sense to add such a function to the capabilities and then just call it here, passing the requested emulator. Perhaps other libvirt developers can comment on the usefulness of virCapabilitiesSupportGuestEmulator(). Daniel already clarified this, so no need to do even more work David :). As mentioned in my other response [1], your original patch (with a check to verify the requested emulator exists) should be sufficient. Regards, Jim [1] https://www.redhat.com/archives/libvir-list/2013-April/msg02087.html -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 12/37] Adapt to VIR_STRDUP in src/node_device/*
On 04/29/2013 12:51 PM, John Ferlan wrote: On 04/29/2013 09:50 AM, Michal Privoznik wrote: --- src/node_device/node_device_driver.c | 28 -- src/node_device/node_device_hal.c| 13 ++--- src/node_device/node_device_udev.c | 102 +++ 3 files changed, 60 insertions(+), 83 deletions(-) ... @@ -388,8 +385,7 @@ nodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) } for (caps = obj-def-caps; caps ncaps maxnames; caps = caps-next) { -names[ncaps] = strdup(virNodeDevCapTypeToString(caps-type)); -if (names[ncaps++] == NULL) { +if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps-type)) 0) { Lost the autoincrement ^^^ Except that you probably don't want an increment inside VIR_STRDUP, since as an all-caps macro name, you aren't guaranteed that the destination will be evaluated exactly once if we didn't document it that way in virstring.h. (Hmm, it looks like the implementation is actually safe in evaluating exactly once, but we ought to make that part of the contract.) -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] qemu: put usb cgroup setup in common function
The USB-specific cgroup setup had been inserted inline in qemuDomainAttachHostUsbDevice and qemuSetupCgroup, but now there is a common cgroup setup function called for all hostdevs, so it makes sens to put the usb-specific setup there and just rely on that function being called. The one thing I'm uncertain of here (and a reason for not pushing until after release) is that previously hostdev-missing was checked only when starting a domain (and cgroup setup for the device skipped if missing was true), but with this consolidation, it is now checked in the case of hotplug as well. I don't know if this will have any practical effect (does it make sense to hotplug a missing usb device?) --- src/qemu/qemu_cgroup.c | 61 ++--- src/qemu/qemu_cgroup.h | 3 --- src/qemu/qemu_hotplug.c | 16 - 3 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 92c53d9..7a7824d 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -191,9 +191,10 @@ qemuSetupTPMCgroup(virDomainDefPtr def, } -int qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED, - const char *path, - void *opaque) +static int +qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED, + const char *path, + void *opaque) { virDomainObjPtr vm = opaque; qemuDomainObjPrivatePtr priv = vm-privateData; @@ -221,6 +222,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm, int ret = -1; qemuDomainObjPrivatePtr priv = vm-privateData; virPCIDevicePtr pci = NULL; +virUSBDevicePtr usb = NULL; char *path = NULL; /* currently this only does something for PCI devices using vfio @@ -263,6 +265,28 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm, } } break; + +case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: +/* NB: hostdev-missing wasn't previously checked in the + * case of hotplug, only when starting a domain. Now it is + * always checked, and the cgroup setup skipped if true. + */ +if (dev-missing) +break; +if ((usb = virUSBDeviceNew(dev-source.subsys.u.usb.bus, + dev-source.subsys.u.usb.device, + NULL)) == NULL) { +goto cleanup; +} + +/* oddly, qemuSetupHostUsbDeviceCgroup doesn't ever + * reference the usb object we just created + */ +if (virUSBDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup, +vm) 0) { +goto cleanup; +} +break; default: break; } @@ -271,6 +295,7 @@ qemuSetupHostdevCGroup(virDomainObjPtr vm, ret = 0; cleanup: virPCIDeviceFree(pci); +virUSBDeviceFree(usb); VIR_FREE(path); return ret; } @@ -326,6 +351,9 @@ qemuTeardownHostdevCgroup(virDomainObjPtr vm, } } break; +case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: +/* nothing to tear down for USB */ +break; default: break; } @@ -545,33 +573,8 @@ int qemuSetupCgroup(virQEMUDriverPtr driver, goto cleanup; for (i = 0; i vm-def-nhostdevs; i++) { -virDomainHostdevDefPtr hostdev = vm-def-hostdevs[i]; -virUSBDevicePtr usb; - -if (qemuSetupHostdevCGroup(vm, hostdev) 0) +if (qemuSetupHostdevCGroup(vm, vm-def-hostdevs[i]) 0) goto cleanup; - -/* NB: the code below here should be moved into - * qemuSetupHostdevCGroup() - */ -if (hostdev-mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) -continue; -if (hostdev-source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) -continue; -if (hostdev-missing) -continue; - -if ((usb = virUSBDeviceNew(hostdev-source.subsys.u.usb.bus, - hostdev-source.subsys.u.usb.device, - NULL)) == NULL) -goto cleanup; - -if (virUSBDeviceFileIterate(usb, qemuSetupHostUsbDeviceCgroup, -vm) 0) { -virUSBDeviceFree(usb); -goto cleanup; -} -virUSBDeviceFree(usb); } } diff --git a/src/qemu/qemu_cgroup.h b/src/qemu/qemu_cgroup.h index 64d71a5..048c2fa 100644 --- a/src/qemu/qemu_cgroup.h +++ b/src/qemu/qemu_cgroup.h @@ -33,9 +33,6 @@ int qemuSetupDiskCgroup(virDomainObjPtr vm, virDomainDiskDefPtr disk); int
[libvirt] [PATCH 0/2] fix cgroup setup for vfio hostdevs
The first patch is required for vfio hostdev to work. The 2nd is just a refactor to eliminate duplicated code for usb hostdev cgroup setup. Laine Stump (2): qemu: add vfio devices to cgroup ACL when appropriate qemu: put usb cgroup setup in common function src/qemu/qemu.conf | 2 +- src/qemu/qemu_cgroup.c | 182 - src/qemu/qemu_cgroup.h | 9 +- src/qemu/qemu_hotplug.c| 26 ++ src/qemu/test_libvirtd_qemu.aug.in | 1 + 5 files changed, 174 insertions(+), 46 deletions(-) -- 1.7.11.7 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/2] qemu: add vfio devices to cgroup ACL when appropriate
PCIO device assignment using VFIO requires read/write access by the qemu process to /dev/vfio/vfio, and /dev/vfio/nn, where nn is the VFIO group number that the assigned device belongs to (and can be found with the function virPCIDeviceGetVFIOGroupDev) /dev/vfio/vfio can be accessible to any guest without danger (according to vfio developers), so it is added to the static ACL. The group device must be dynamically added to the cgroup ACL for each vfio hostdev in two places: 1) for any devices in the persistent config when the domain is started (done during qemuSetupCgroup()) 2) at device attach time for any hotplug devices (done in qemuDomainAttachHostDevice) The group device must be removed from the ACL when a device it hot-unplugged (in qemuDomainDetachHostDevice()) Note that USB devices are already doing their own cgroup setup and teardown in the hostdev-usb specific function. I chose to make the new functions generic and call them in a common location though. We can then move the USB-specific code (which is duplicated in two locations) to this single location. I'll be posting a followup patch to do that. --- src/qemu/qemu.conf | 2 +- src/qemu/qemu_cgroup.c | 133 - src/qemu/qemu_cgroup.h | 6 +- src/qemu/qemu_hotplug.c| 10 ++- src/qemu/test_libvirtd_qemu.aug.in | 1 + 5 files changed, 148 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 87bdf70..0f0a24c 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -241,7 +241,7 @@ #/dev/null, /dev/full, /dev/zero, #/dev/random, /dev/urandom, #/dev/ptmx, /dev/kvm, /dev/kqemu, -#/dev/rtc,/dev/hpet +#/dev/rtc,/dev/hpet, /dev/vfio/vfio #] diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 891984a..92c53d9 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -39,7 +39,7 @@ static const char *const defaultDeviceACL[] = { /dev/null, /dev/full, /dev/zero, /dev/random, /dev/urandom, /dev/ptmx, /dev/kvm, /dev/kqemu, -/dev/rtc, /dev/hpet, +/dev/rtc, /dev/hpet, /dev/vfio/vfio, NULL, }; #define DEVICE_PTY_MAJOR 136 @@ -214,6 +214,131 @@ int qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev ATTRIBUTE_UNUSED, } +int +qemuSetupHostdevCGroup(virDomainObjPtr vm, + virDomainHostdevDefPtr dev) +{ +int ret = -1; +qemuDomainObjPrivatePtr priv = vm-privateData; +virPCIDevicePtr pci = NULL; +char *path = NULL; + +/* currently this only does something for PCI devices using vfio + * for device assignment, but it is called for *all* hostdev + * devices. + */ + +if (!virCgroupHasController(priv-cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) +return 0; + +if (dev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + +switch (dev-source.subsys.type) { +case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: +if (dev-source.subsys.u.pci.backend +!= VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO) { +int rc; + +pci = virPCIDeviceNew(dev-source.subsys.u.pci.addr.domain, + dev-source.subsys.u.pci.addr.bus, + dev-source.subsys.u.pci.addr.slot, + dev-source.subsys.u.pci.addr.function); +if (!pci) +goto cleanup; + +if (!(path = virPCIDeviceGetVFIOGroupDev(pci))) +goto cleanup; + +VIR_DEBUG(Cgroup allow %s for PCI device assignment, path); +rc = virCgroupAllowDevicePath(priv-cgroup, path, + VIR_CGROUP_DEVICE_RW); +virDomainAuditCgroupPath(vm, priv-cgroup, + allow, path, rw, rc); +if (rc 0) { +virReportSystemError(-rc, + _(Unable to allow access + for device path %s), + path); +goto cleanup; +} +} +break; +default: +break; +} +} + +ret = 0; +cleanup: +virPCIDeviceFree(pci); +VIR_FREE(path); +return ret; +} + + + +int +qemuTeardownHostdevCgroup(virDomainObjPtr vm, + virDomainHostdevDefPtr dev) +{ +int ret = -1; +qemuDomainObjPrivatePtr priv = vm-privateData; +virPCIDevicePtr pci = NULL; +char *path = NULL; + +/* currently this only does something for PCI devices using vfio + * for device assignment, but it is called for *all* hostdev + * devices. + */ + +if (!virCgroupHasController(priv-cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) +return 0; + +if (dev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) { + +switch
Re: [libvirt] [PATCH v2] virsh: fix incorrect argument errors for long options
On 04/29/2013 11:27 AM, Ján Tomko wrote: For long options, print: * the option as specified by the user if it's unknown * the cannoncial long option if its argument is not s/cannonical/canonical/ a number (and should be) And for missing arguments, print both the short and the long option name. (Doing only one of those would require either parsing argv ourselves or let getopt print the errors, since we can't tell long and short options apart by optopt or longindex) https://bugzilla.redhat.com/show_bug.cgi?id=949373 Listing some before-and-after in the commit message would be very helpful. Here's what I tried: Unknown option: Before: $ virsh -x error: unsupported option '-x'. See --help. $ virsh --x error: unsupported option '- $ virsh -rx error: unsupported option '-x'. See --help. After: $ tools/virsh -x error: unsupported option '-x'. See --help. $ tools/virsh --x error: unsupported option '--x'. See --help. $ tools/virsh -rx error: unsupported option '-x'. See --help. No worse behavior, and definite improvement on the unknown long option. Incorrect argument: Before: $ virsh --d=a error: option -d takes a numeric argument $ virsh --deb=a error: option -d takes a numeric argument After: $ tools/virsh -da error: option -d takes a numeric argument $ tools/virsh --deb=a error: option --debug takes a numeric argument Much nicer on the long option :) Missing argument: Before: $ virsh -d error: option '-d' requires an argument $ virsh --deb error: option '-d' requires an argument After: $ tools/virsh -d error: option '-d'/'--debug' requires an argument $ tools/virsh --deb error: option '-d'/'--debug' requires an argument A bit more verbose, but now it is obvious when a long option was typed, rather than making you figure out what short option matches your long option. And I agree that improving it would require reimplementing too much of getopt_long, so I can live with it. ACK. Reasonable for 1.0.5 -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 03/37] Adapt to VIR_STRDUP in daemon/*
On 04/29/2013 07:50 AM, Michal Privoznik wrote: --- daemon/libvirtd-config.c | 37 ++- daemon/libvirtd.c| 17 + daemon/remote.c | 94 3 files changed, 66 insertions(+), 82 deletions(-) diff --git a/daemon/libvirtd-config.c b/daemon/libvirtd-config.c index efb564e..df2bc7b 100644 --- a/daemon/libvirtd-config.c +++ b/daemon/libvirtd-config.c @@ -59,15 +59,14 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, key); return -1; } -list[0] = strdup(p-str); -list[1] = NULL; -if (list[0] == NULL) { +if (VIR_STRDUP(list[0], p-str) 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(failed to allocate memory for %s config list value), key); We should just nuke this error, and let VIR_STRDUP's OOM error suffice. This whole function could probably use a cleanup pass to use virReportOOMError() as appropriate. VIR_FREE(list); return -1; } +list[1] = NULL; break; case VIR_CONF_LIST: { @@ -90,8 +89,7 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg, VIR_FREE(list); return -1; } -list[i] = strdup(pp-str); -if (list[i] == NULL) { +if (VIR_STRDUP(list[i], pp-str) 0) { int j; for (j = 0 ; j i ; j++) VIR_FREE(list[j]); Yep, here's another case where we should nuke the virReportError(VIR_ERR_CONFIG_UNSUPPORTED) and rely on VIR_STRDUP's OOM error instead. @@ -136,8 +134,8 @@ checkType(virConfValuePtr p, const char *filename, } /* If there is no config data for the key, #var_name, then do nothing. - If there is valid data of type VIR_CONF_STRING, and strdup succeeds, - store the result in var_name. Otherwise, (i.e. invalid type, or strdup + If there is valid data of type VIR_CONF_STRING, and VIR_STRDUP succeeds, + store the result in var_name. Otherwise, (i.e. invalid type, or VIR_STRDUP failure), give a diagnostic and goto the cleanup-and-fail label. */ #define GET_CONF_STR(conf, filename, var_name) \ do {\ @@ -146,7 +144,7 @@ checkType(virConfValuePtr p, const char *filename, if (checkType(p, filename, #var_name, VIR_CONF_STRING) 0) \ goto error; \ VIR_FREE(data-var_name); \ -if (!(data-var_name = strdup(p-str))) { \ +if (VIR_STRDUP(data-var_name, p-str) 0) { \ virReportOOMError();\ Drop the virReportOOMError here; since VIR_STRDUP is documented to do the work for you. goto error; \ } \ @@ -200,7 +198,7 @@ int daemonConfigFilePath(bool privileged, char **configfile) { if (privileged) { -if (!(*configfile = strdup(SYSCONFDIR /libvirt/libvirtd.conf))) +if (VIR_STRDUP(*configfile, SYSCONFDIR /libvirt/libvirtd.conf) 0) goto no_memory; You can drop the no_memory label and just use the error label. } else { char *configdir = NULL; @@ -238,9 +236,9 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) data-listen_tls = 1; data-listen_tcp = 0; -if (!(data-tls_port = strdup(LIBVIRTD_TLS_PORT))) +if (VIR_STRDUP(data-tls_port, LIBVIRTD_TLS_PORT) 0) goto no_memory; -if (!(data-tcp_port = strdup(LIBVIRTD_TCP_PORT))) +if (VIR_STRDUP(data-tcp_port, LIBVIRTD_TCP_PORT) 0) goto no_memory; Hmm. Here, the no_memory label does additional cleanup... /* Only default to PolicyKit if running as root */ @@ -256,13 +254,14 @@ daemonConfigNew(bool privileged ATTRIBUTE_UNUSED) } #endif -if (data-auth_unix_rw == REMOTE_AUTH_POLKIT) -data-unix_sock_rw_perms = strdup(0777); /* Allow world */ -else -data-unix_sock_rw_perms = strdup(0700); /* Allow user only */ -data-unix_sock_ro_perms = strdup(0777); /* Always allow world */ -if (!data-unix_sock_ro_perms || -!data-unix_sock_rw_perms) +if (data-auth_unix_rw == REMOTE_AUTH_POLKIT) { +if (VIR_STRDUP(data-unix_sock_rw_perms, 0777) 0) +goto no_memory; +} else { +if (VIR_STRDUP(data-unix_sock_rw_perms, 0700) 0) +goto no_memory; +} +if (VIR_STRDUP(data-unix_sock_ro_perms, 0777) 0) goto no_memory; ...and one of the
Re: [libvirt] [PATCH 1/2] qemu: add vfio devices to cgroup ACL when appropriate
On 04/29/2013 02:28 PM, Laine Stump wrote: PCIO device assignment using VFIO requires read/write access by the qemu process to /dev/vfio/vfio, and /dev/vfio/nn, where nn is the VFIO group number that the assigned device belongs to (and can be found with the function virPCIDeviceGetVFIOGroupDev) /dev/vfio/vfio can be accessible to any guest without danger (according to vfio developers), so it is added to the static ACL. The group device must be dynamically added to the cgroup ACL for each vfio hostdev in two places: 1) for any devices in the persistent config when the domain is started (done during qemuSetupCgroup()) 2) at device attach time for any hotplug devices (done in qemuDomainAttachHostDevice) The group device must be removed from the ACL when a device it hot-unplugged (in qemuDomainDetachHostDevice()) Note that USB devices are already doing their own cgroup setup and teardown in the hostdev-usb specific function. I chose to make the new functions generic and call them in a common location though. We can then move the USB-specific code (which is duplicated in two locations) to this single location. I'll be posting a followup patch to do that. --- src/qemu/qemu.conf | 2 +- src/qemu/qemu_cgroup.c | 133 - src/qemu/qemu_cgroup.h | 6 +- src/qemu/qemu_hotplug.c| 10 ++- src/qemu/test_libvirtd_qemu.aug.in | 1 + 5 files changed, 148 insertions(+), 4 deletions(-) @@ -36,6 +36,10 @@ int qemuTeardownDiskCgroup(virDomainObjPtr vm, int qemuSetupHostUsbDeviceCgroup(virUSBDevicePtr dev, const char *path, void *opaque); +int qemuSetupHostdevCGroup(virDomainObjPtr vm, + virDomainHostdevDefPtr dev) ATTRIBUTE_RETURN_CHECK; +int qemuTeardownHostdevCgroup(virDomainObjPtr vm, + virDomainHostdevDefPtr dev); A bit odd that setup is ATTRIBUTE_RETURN_CHECK but teardown is not. I'd rather see both require a use... @@ -1257,6 +1260,9 @@ error: vm-def, hostdev, NULL) 0) VIR_WARN(Unable to restore host device labelling on hotplug fail); +teardown_cgroup: +qemuTeardownHostdevCgroup(vm, hostdev); ...and here, on cleanup paths after an earlier error, stick a VIR_WARN() that logs any failure trying to clean up (as we already did on the line before). + cleanup: virObjectUnref(list); if (usb) @@ -2499,6 +2505,8 @@ int qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver, } if (!ret) { +qemuTeardownHostdevCgroup(vm, detach); + if (virSecurityManagerRestoreHostdevLabel(driver-securityManager, vm-def, detach, NULL) 0) { VIR_WARN(Failed to restore host device labelling); ...here's another place where a VIR_WARN on failure to clean up is appropriate. ACK with that fixed. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] LXC: user namespaces
Hi! We'd like to use libvirt for managing our lxc machines. Currently libvirt lacks of user namespace support. Is anyone working on that? Otherwise David and I will implement it and send patches very soon. Thanks, //richard -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] qemu: put usb cgroup setup in common function
On 04/29/2013 02:28 PM, Laine Stump wrote: The USB-specific cgroup setup had been inserted inline in qemuDomainAttachHostUsbDevice and qemuSetupCgroup, but now there is a common cgroup setup function called for all hostdevs, so it makes sens to put the usb-specific setup there and just rely on that function being called. The one thing I'm uncertain of here (and a reason for not pushing until after release) is that previously hostdev-missing was checked only when starting a domain (and cgroup setup for the device skipped if missing was true), but with this consolidation, it is now checked in the case of hotplug as well. I don't know if this will have any practical effect (does it make sense to hotplug a missing usb device?) Good question - and yeah, that uncertainty makes me also wonder if it makes more sense to delay this patch until after 1.0.5 so we aren't invalidating testing done on rc1. On the other hand, the point of hostdev-missing is to gracefully ignore devices that are called out in XML but might not always exist; you are probably right that no one has tried doing a hotplug while specifying that a missing device do nothing. I could live with this patch as part of 1.0.5 if it makes it into rc2 so that it gets a few more days of testing. ACK. -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 2/2] qemu: report an error if memballoon has wrong address type
On 04/29/2013 12:20 PM, Ján Tomko wrote: qemuBuildMemballoonDevStr returns NULL if memballoon doesn't have the right address type, but it doesn't report an error, leading to: error: An error occurred, but the cause is unknown Report a helpful error message instead, e.g.: error: XML error: memballoon unsupported with address type 'usb' --- src/qemu/qemu_command.c | 3 +++ 1 file changed, 3 insertions(+) ACK. Both worth including in 1.0.5 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d161b56..3184e5b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4175,6 +4175,9 @@ qemuBuildMemballoonDevStr(virDomainMemballoonDefPtr dev, virBufferAddLit(buf, virtio-balloon-ccw); break; default: +virReportError(VIR_ERR_XML_ERROR, + _(memballoon unsupported with address type '%s'), + virDomainDeviceAddressTypeToString(dev-info.type)); goto error; } -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 1/2] qemu: assign addresses when converting xml to native
On 04/29/2013 12:20 PM, Ján Tomko wrote: This adds addresses to domxml-to-native output and chooses the correct virtio devices for ccw and s390 machines. https://bugzilla.redhat.com/show_bug.cgi?id=957077 --- src/qemu/qemu_driver.c | 3 +++ 1 file changed, 3 insertions(+) ACK. diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2d3b24a..296efe3 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5271,6 +5271,9 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, if (qemuAssignDeviceAliases(def, qemuCaps) 0) goto cleanup; +if (qemuDomainAssignAddresses(def, qemuCaps, NULL) 0) +goto cleanup; + if (!(cmd = qemuBuildCommandLine(conn, driver, def, monConfig, monitor_json, qemuCaps, NULL, -1, NULL, VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) -- Eric Blake eblake redhat com+1-919-301-3266 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] libxl: Fix double-dispose of libxl domain config
libxlBuildDomainConfig() was disposing the libxl_domain_config object on error, only to have it disposed again by libxlBuildDomainConfig()'s caller, which resulted in a segfault. Leave disposing of the config object to it's owner. --- src/libxl/libxl_conf.c | 12 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 7e0753a..3de642b 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -796,19 +796,19 @@ libxlBuildDomainConfig(libxlDriverPrivatePtr driver, return -1; if (libxlMakeDomBuildInfo(def, d_config) 0) { -goto error; +return -1; } if (libxlMakeDiskList(def, d_config) 0) { -goto error; +return -1; } if (libxlMakeNicList(def, d_config) 0) { -goto error; +return -1; } if (libxlMakeVfbList(driver, def, d_config) 0) { -goto error; +return -1; } d_config-on_reboot = def-onReboot; @@ -816,8 +816,4 @@ libxlBuildDomainConfig(libxlDriverPrivatePtr driver, d_config-on_crash = def-onCrash; return 0; - -error: -libxl_domain_config_dispose(d_config); -return -1; } -- 1.8.0.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list