[libvirt] [PATCH] cgroup.c: don't leak mem+FD upon OOM
by Jim Meyering
Here's the patch:
(note, no need to test for mapping == NULL in the no_memory block)
>From 91dbe896fff64783df1c68769a57a267441143ae Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 4 Feb 2010 11:22:20 +0100
Subject: [PATCH] cgroup.c: don't leak mem+FD upon OOM
* src/util/cgroup.c (virCgroupDetectPlacement): Close the mapping
FILE* also upon error.
---
src/util/cgroup.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index e6f0270..4446c7f 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -183,6 +183,7 @@ static int virCgroupDetectPlacement(virCgroupPtr group)
return 0;
no_memory:
+ fclose(mapping);
return -ENOMEM;
}
--
1.7.0.rc1.193.ge8618
Here's the (fixed) function:
/*
* Process /proc/self/cgroup figuring out what cgroup
* sub-path the current process is assigned to. ie not
* neccessarily in the root
*/
static int virCgroupDetectPlacement(virCgroupPtr group)
{
int i;
FILE *mapping = NULL;
char line[1024];
mapping = fopen("/proc/self/cgroup", "r");
if (mapping == NULL) {
VIR_ERROR0("Unable to open /proc/self/cgroup");
return -ENOENT;
}
while (fgets(line, sizeof(line), mapping) != NULL) {
char *controllers = strchr(line, ':');
char *path = controllers ? strchr(controllers+1, ':') : NULL;
char *nl = path ? strchr(path, '\n') : NULL;
if (!controllers || !path)
continue;
if (nl)
*nl = '\0';
*path = '\0';
controllers++;
path++;
for (i = 0 ; i < VIR_CGROUP_CONTROLLER_LAST ; i++) {
const char *typestr = virCgroupControllerTypeToString(i);
int typelen = strlen(typestr);
char *tmp = controllers;
while (tmp) {
char *next = strchr(tmp, ',');
int len;
if (next) {
len = next-tmp;
next++;
} else {
len = strlen(tmp);
}
if (typelen == len && STREQLEN(typestr, tmp, len) &&
!(group->controllers[i].placement = strdup(STREQ(path, "/") ? "" : path)))
goto no_memory;
tmp = next;
}
}
}
fclose(mapping);
return 0;
no_memory:
fclose(mapping);
return -ENOMEM;
}
14 years, 10 months
[libvirt] [PATCH 3/5] macvtap support for libvirt -- qemu support
by Stefan Berger
This part adds support for qemu making a macvtap tap device available
via file descriptor passed to qemu command line. This also attempts to
tear down the macvtap device when a VM terminates. This includes support
for attachment and detachment to/from running VM.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
14 years, 10 months
[libvirt] [PATCH 1/5] macvtap support for libvirt -- build support
by Stefan Berger
This patch adds build support for libvirt checking for certain contents
of /usr/include/linux/if_link.h to see whether macvtap support is
compilable on that system. One can disable macvtap support in libvirt
via --without-macvtap passed to configure.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
14 years, 10 months
[libvirt] [PATCH 0/5] macvtap support for Qemu/KVM VMs via libvirt
by Stefan Berger
Hello!
The following patches provide support for making the macvtap
networking device type available to Qemu/KVM VMs. The patches rely on
the macvtap driver that just became available through the Linux net-next
tree (fixes still may be necessary) and make the device available to
Qemu/KVM via a tap file descriptor similar to a 'regular' tap device.
Following up on previous discussions, the libvirt patches allow using
the following XML in the domain description to enable qemu network
connectivity via this type of device:
<interface type='direct'>
<source dev='eth1' mode='vepa'/>
<model type='virtio'/>
</interface>
The above XML indicates that eth1 is the Ethernet interface to link
the macvtap device to and communicate to the network. As a consequence,
libvirt will create an instance of a macvtap device, assign it the same
MAC address as the VM's interface has and open a file descriptor of the
associated character device /dev/tap%d and pass it via command line to
Qemu/kvm. In the above XML the mode can be chosen as 'vepa', 'private'
or 'bridge' and is by default set to 'vepa'(by the driver) if omitted.
Attachment and detachment of macvtap to/from a running VM also works.
Regards,
Stefan
14 years, 10 months
[libvirt] Release of libvirt-0.7.6
by Daniel Veillard
Is finally out with the set of last minute fixes :-)
Available as usual from:
ftp://libvirt.org/libvirt/
The rate of change is really not slowing down, a awful lot of
improvements and changes are in. Some things I listed in improvement
might be considered full new features like support for latest versions
of Xen and ESX. Jim Meyering also went though a lot of automated bug
reports to fill up various holes in the code:
Features:
- Implement support for multi IQN (David Allan)
- Implement CPU topology support for QEMU driver (Jiri Denemark)
- Use QEmu new device adressing when possible (Daniel P. Berrange)
- Implement SCSI controller hotplug/unplug for QEMU (Wolfgang Mauerer)
Documentation:
- Add missing function parameter documentation (Matthias Bolte)
- Add docs about new mailing list (Daniel P. Berrange)
- Document cpu-compare command in virsh man page (Jiri Denemark)
- Document cpu elements in capabilities and domain XML (Jiri Denemark)
- docs: Remove outdated information about remote limitations (Matthias Bolte)
- documentation improvements (David Jorm)
- Minor fixes for API extension doc (Jim Fehlig)
- cpu_shares parameter limit documented (David Jorm)
- Document the domain XML cache attribute for disk devices (Matthias Bolte)
- Replace old CVS references with GIT (Matthias Bolte)
Portability:
- portability to non-glibc: don't use realpath(..., NULL) (Jim Meyering)
- Add some missing include files which break build in certain platforms (Daniel P. Berrange)
- Remove AppArmor compile warnings (Jamie Strandboge)
- Fix compilation of virt-aa-helper.c (Matthias Bolte)
- Fix linkage of virt-aa-helper to libgnu.a (Matthias Bolte)
Bug Fixes:
- Fix restore of QEMU guests with PCI device reservation (Daniel P. Berrange)
- Another fork() log locking cleanup in file creation (Laine Stump)
- Fix log locking problem when using fork() in the library (Cole Robinson)
- Fix locking for udev device add/remove (David Allan)
- interface_conf.c: don't use a negative value as allocation size (Jim Meyering)
- virStoragePoolSourceListNewSource: avoid unconditional leak (Jim Meyering)
- xs_internal.c: don't use a negative value as allocation size (Jim Meyering)
- Ensure QEMU DAC security driver is activated at all times (Daniel P. Berrange)
- udev: Don't let strtoul parse USB busnum and devnum as octal (Matthias Bolte)
- json.c: avoid an unconditional leak from most qemuMonitorJSON* functions (Jim Meyering)
- Fix PCI host reattach on domain detach. (Chris Lalancette)
- Clarify controllers -device string in QEMU driver (Matthew Booth)
- util.c (virGetUserEnt): don't use a negative value as allocation size (Jim Meyering)
- cpu_x86.c: avoid NULL-deref for invalid arguments (Jim Meyering)
- Fix a crash when restarting libvirtd. (Chris Lalancette)
- qemuMonitorTextAttachDrive: avoid two leaks (Jim Meyering)
- usbGetDevice: don't leak a "usbDevice" buffer on failure path (Jim Meyering)
- qemuMonitorTextGetMemoryStats: plug a leak on an error path (Jim Meyering)
- usbFindBusByVendor: don't leak a DIR buffer and FD (Jim Meyering)
- Fix libvirtd restart for domains with PCI passthrough devices (Chris Lalancette)
- qemu: Fix race between device rebind and kvm cleanup (Chris Lalancette)
- Fix device assignment with root devices (Chris Lalancette)
- Corrected log level of WWN path message (David Allan)
- Fix an error when looking for devices in syspath (Daniel Veillard)
- Fix off-by-1 in SCSI drive hotplug (Daniel P. Berrange)
- Fix leak in hotplug code in QEMU driver (Daniel P. Berrange)
- Fix security driver calls in hotplug cleanup paths (Daniel P. Berrange)
- Add missing call to re-attach host devices if VM startup fails (Daniel P. Berrange)
- Pull initial disk labelling out into libvirtd instead of exec hook (Daniel P. Berrange)
- Fix leak of allocated security label (Daniel P. Berrange)
- Create storage pool directories with proper uid/gid/mode (Laine Stump)
- Create storage volumes directly with desired uid/gid (Laine Stump)
- Unset copied environment variables in qemuxml2argvtest (Matthias Bolte)
- qemu: Don't allocate zero bytes (Matthias Bolte)
- node_device_linux_sysfs.c: avoid opendir/fd leak on error path (Jim Meyering)
- domain_conf.c: avoid a leak and the need for "cleanup:" block (Jim Meyering)
- Fix QEMU driver custom domain status XML extensions (Daniel P. Berrange)
- xen_driver: don't leak a parsed-config buffer (Jim Meyering)
- storage_conf: plug a leak on OOM error path (Jim Meyering)
- Tests for ACS in PCIe switches (Jiri Denemark)
- storage_backend_fs.c: do not ignore probe failure (Jim Meyering)
- Avoid free'ing a constant string in chardev lookup code (Daniel P. Berrange)
- Fix build of Xen proxy daemon (Daniel P. Berrange)
- xen: do not report a write-to-Xen-daemon failure as a read failure (Jim Meyering)
- daemon: Don't blindly unregister domain events (Cole Robinson)
- node_device: udev: Fix memory leak (Cole Robinson)
- Fix migration in xend driver (Jim Fehlig)
- Ensure error handling callback functions are called from safe context (Daniel P. Berrange)
- qemu: Fix a memory leak in qemudExtractTTYPath (Matthias Bolte)
- Fix UUID random generator to use /dev/random (Laine Stump)
- let "configure --disable-shared" work once again (Jim Meyering)
- Qemu: ask for memory preallocation with large pages (Daniel Veillard)
- network/bridge_driver.c: avoid potential NULL-dereference (Jim Meyering)
- Don't free an uninitalized pointer in update_driver_name() (Matthias Bolte)
- xend_internal: don't let invalid input provoke NULL dereference (Jim Meyering)
- Don't update vol details after build (David Allan)
- vbox_tmpl.c: don't leak a domain pointer upon failure to create (Jim Meyering)
- vbox_tmpl.c: avoid NULL deref upon vboxDomainCreateXML failure (Jim Meyering)
- qemu_driver.c: avoid NULL dereference upon disk-op failure (Jim Meyering)
- openvz_conf.c: don't dereference NULL upon failure (Jim Meyering)
- Distribute vmx2xml and xml2vmx test data files (Matthias Bolte)
Improvements:
- Tweak USB hostdevice XML handling (Daniel P. Berrange)
- Fix QEMU hotplug device alias assignment (Daniel P. Berrange)
- Disable QEMU monitor IO debugging by default (Daniel P. Berrange)
- Re-arrange QEMU device alias assignment code (Daniel P. Berrange)
- Remove direct storage of hostnet_name & vlan (Daniel P. Berrange)
- Remove use of -netdev arg with QEMU (Daniel P. Berrange)
- Assign PCI addresses before hotplugging devices (Daniel P. Berrange)
- Rewrite way QEMU PCI addresses are allocated (Daniel P. Berrange)
- Introduce generic virDomainDeviceInfo iterator function (Daniel P. Berrange)
- Make hotplug use new device_add where possible (Daniel P. Berrange)
- Introduce internal QEMU monitor APIs for drive + device hotadd (Daniel P. Berrange)
- Split out QEMU code for building PCI/USB hostdev arg values (Daniel P. Berrange)
- Standard internal API syntax for building QEMU command line arguments (Daniel P. Berrange)
- Log flags in virConnectCompareCPU (Jiri Denemark)
- Look in /usr/libexec for the qemu-kvm binary. (Chris Lalancette)
- Support Xen 4.0 sysctl version 7 (Jim Fehlig)
- Add missing sata controller type to domain.rng (Matthew Booth)
- udev: Set the state driver name (Matthias Bolte)
- udev: Remove event handle on shutdown (Matthias Bolte)
- esx: Output error details from libcurl (Matthias Bolte)
- qemu: Search binaries in PATH instead of hardcoding /usr/bin (Matthias Bolte)
- Implement QMP support for extracting CPU thread ID (Daniel P. Berrange)
- Misc fixes to QMP monitor support for QEMU (Daniel P. Berrange)
- Fix setup of compatability serial devices from console device (Daniel P. Berrange)
- Start modernizing configure (Eric Blake)
- Add a rule to check for uses of readlink. (Chris Lalancette)
- Add virConnectGetVersion Python API (Taizo ITO)
- domMemoryStats / qemu: Fix parsing of unknown stats (Adam Litke)
- Allow surrounding whitespace in uuid (Dan Kenigsberg)
- Add configuration option to turn off dynamic permissions management (Daniel P. Berrange)
- Switch QEMU driver over to use the DAC security driver (Daniel P. Berrange)
- Introduce a new DAC security driver for QEMU (Daniel P. Berrange)
- Introduce a stacked security driver impl for QEMU (Daniel P. Berrange)
- Make security drivers responsible for checking dynamic vs static labelling (Daniel P. Berrange)
- New utility functions virFileCreate and virDirCreate (Laine Stump)
- Add virRunWithHook util function (Laine Stump)
- Update interface.rng and xml test files to match netcf 0.1.5 (Laine Stump)
- Support bond interfaces attached to bridges in interface xml. (Laine Stump)
- Allow empty bridges in interface xml. (Laine Stump)
- Support delay property in interface bridge xml. (Laine Stump)
- Use pciDeviceIsAssignable in qemu driver (Jiri Denemark)
- Allow for CPU topology specification without model (Jiri Denemark)
- Add debug messages for CPU incompatibility (Jiri Denemark)
- Take disabled/forced CPU features into account (Jiri Denemark)
- Enhance qemuParseCommandLineKeywords (Jiri Denemark)
- Convert VirtIO balloon over to -device syntax (Daniel P. Berrange)
- uto-assign PCI addresses (Daniel P. Berrange)
- Pass -vga none if no video card specified (Daniel P. Berrange)
- Add support for explicit -sdl flag to QEMU (Daniel P. Berrange)
- Assign device aliases for all devices at startup (Daniel P. Berrange)
- Add device info to serial, parallel, channel, input & fs devices (Daniel P. Berrange)
- Introduce device aliases (Daniel P. Berrange)
- Clear assigned PCI devices at shutdown (Daniel P. Berrange)
- Auto-add disk controllers based on defined disks (Daniel P. Berrange)
- Remove restriction on duplicated sound devices in parser (Daniel P. Berrange)
- Detect PCI addresses at QEMU startup (Daniel P. Berrange)
- Properly support SCSI drive hotplug (Daniel P. Berrange)
- build: update gnulib submodule to latest (Jim Meyering)
- Use closest CPU model when decoding from CPUID (Jiri Denemark)
- Change detection of xen so that it's actually automatic rather than forced. (Diego Elio Pettenò)
- Standardise ./configure --help options reporting. (Diego Elio Pettenò)
- qemu: Use log output for pty assignment if 'info chardev' is unavailable (Matthias Bolte)
- esx: Add VNC support (Matthias Bolte)
- esx: Make the domain part of the hostname optional (Matthias Bolte)
- esx: Add stubs for secondary driver types (Matthias Bolte)
- Specify bus/unit instead of index for disks with QEMU (Daniel P. Berrange)
- Split code for building QEMU -drive arg in separate method (Daniel P. Berrange)
- Convert monitor over to use virDomainDeviceAddress (Daniel P. Berrange)
- Add new domain device: "controller" (Wolfgang Mauerer)
- Set default disk controller/bus/unit props (Daniel P. Berrange)
- Add address info to sound, video and watchdog devices (Daniel P. Berrange)
- Extend the virDomainDeviceAddress struture to allow disk controller addresses (Daniel P. Berrange)
- Introduce a standardized data structure for device addresses (Daniel P. Berrange)
- util: Make sure virExec hook failures are raised (Cole Robinson)
- Implement path lookup for USB by vendor:product (Cole Robinson)
- events: Report errors on failure (Cole Robinson)
- node_device: udev: Enumerate floppy devices (Cole Robinson)
- node_device: udev: Use base 16 for product/vendor (Cole Robinson)
- libvirt.c: Preserve MigratePerform failure (Cole Robinson)
- qemu: migrate: Save MigratePerform error in MigrateFinish. (Cole Robinson)
- virterror: Add virSetError (Cole Robinson)
- Also look for dmi information in /sys/class (Guido Günther)
- proxy_internal.c: mark "request" parameter as nonnull (Jim Meyering)
- esx: Dump the raw response in case of an SOAP fault (Matthias Bolte)
- esx: Warn if the ESX server is in maintenance mode (Matthias Bolte)
- xen hypervisor: xen domctl version 6 (Jim Fehlig)
- virsh: Add persistent history using libreadline (Matthias Bolte)
- esx: Fix 'vpx' MAC address range and allow arbitrary MAC addresses (Matthias Bolte)
- esx: Fix deserialization for VI API calls CancelTask and UnregisterVM (Matthias Bolte)
- esx: Fix and improve the libcurl debug callback (Matthias Bolte)
- esx: Also allow virtualHW version 4 for ESX 4.0 (Matthias Bolte)
- qemu: Always enable the virtio balloon driver (Adam Litke)
- Disable building of static Python module (Diego Elio Pettenò)
- Fix parsing of 'info chardev' line endings (Matthew Booth)
Cleanups:
- xen_hypervisor.c: remove all "domain == NULL" tests, ... (Jim Meyering)
- xen_hypervisor.c: avoid NULL deref for NULL domain argument (Jim Meyering)
- libvirtd.c: avoid closing a negative socket file descriptor (Jim Meyering)
- storage_backend.c: avoid closing a negative file descriptor (Jim Meyering)
- avoid a probable EINVAL from lseek (Jim Meyering)
- util.c (two more): don't use a negative value as allocation size (Jim Meyering)
- avoid format-related warnings (Jim Meyering)
- maint: avoid excess parens in STREQ (Eric Blake)
- Move models/nmodels mismatch checking one level up (Jiri Denemark)
- Fix up a comment in virHashUpdateEntry (Chris Lalancette)
- maint: fix spelling error in hacking (Eric Blake)
- pci.c: correct an erroneous expression (Jim Meyering)
- Remove undefined symbols from libvirt_private.syms (Matthias Bolte)
- Don't call disabled timer callbacks in event-test.c (Matthias Bolte)
- hostusb: closedir only if non-NULL; rename labels: s/error/cleanup/ (Jim Meyering)
- Cleanup of large buffer on stack in virFileMakePath (Laine Stump)
- esx: Stop passing around virConnectPtr for error reporting (Matthias Bolte)
- Revert "Fix libvirtd restart for domains with PCI passthrough devices" (Chris Lalancette)
- Fix two instances of misspelled 'pseudo' (Chris Lalancette)
- Use virFileResolveLink instead of readlink in AppArmor (Chris Lalancette)
- Fix a compile warning in parthelper.c (Chris Lalancette)
- Remove unused PROC_MOUNT_BUF_LEN #define (Chris Lalancette)
- fix "make distcheck" failure (Jim Meyering)
- avoid format-related warnings (Jim Meyering)
- Refactor setup & cleanup of security labels in security driver (Daniel P. Berrange)
- Let make fail when XHTML validation fails (Jiri Denemark)
- Fix uses of virFileMakePath (Laine Stump)
- remove unnecessary closedir call (Jim Meyering)
- Make all bitfields unsigned ints to avoid unexpected values in casts (Daniel P. Berrange)
- logging: confirm that we want to ignore a write error (Jim Meyering)
- Remove superfluous new lines from messages (Jiri Denemark)
- vbox_tmpl.c: remove useless array-is-non-NULL comparisons (Jim Meyering)
- lxc_driver: remove useless comparison (Jim Meyering)
- gnulib added a new syntax-check test: use $(VAR), not @VAR@ (Jim Meyering)
- storage_backend.h: include required headers (Jim Meyering)
- esx_vi_types.c: include required headers (Jim Meyering)
- vbox: include required headers (Jim Meyering)
- cpu_x86_data.h: include required header (Jim Meyering)
- util.c: include required header, no longer masked by gnulib (Jim Meyering)
- Fix validation of news.html (Matthias Bolte)
- Remove obsolete comment in QEMU JSON code (Daniel P. Berrange)
- Make test suite output less verbose (Daniel P. Berrange)
- daemon: Fix various error reporting issues (Cole Robinson)
- util: Remove logging handlers in virExec (Cole Robinson)
- Commit bootstrap .gitignore additions (Cole Robinson)
- qemu: Disable errors in qemudShutdownVMDaemon (Cole Robinson)
- avoid another "make distcheck" failure (Jim Meyering)
- avoid newly-introduced test failure (Jim Meyering)
- don't test "res == NULL" after we've already dereferenced "res" (Jim Meyering)
- fix 7 "make check" test failures in non-srcdir build (Jim Meyering)
- virsh: Use VIR_FREE instead of free (Matthias Bolte)
- esx: Don't warn about an empty URI path (Matthias Bolte)
- qemu_driver.c: remove useless, warning-provoking test (Jim Meyering)
So again, thanks everybody for your contributions !
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel(a)veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
14 years, 10 months
[libvirt] [PATCH] Avoid deadlock on logging mutex due to fork in virFileCreate/virDirCreate.
by Laine Stump
These functions have the same potential problem that Cole found in
virExec - if the log mutex is currently held at the time of the fork,
the child process' logging mutex will be locked, but nobody in the
process to unlock it. If the child process tries to log anything, it
will wait forever for this lock. The solution is to have the parent
acquire the lock before fork, then both parent and child release the
lock right after.
Note that this patch requires Cole's patch to be applied first.
---
src/util/util.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index 901c0d2..d8a2394 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1263,7 +1263,11 @@ int virFileCreate(const char *path, mode_t mode,
* following dance avoids problems caused by root-squashing
* NFS servers. */
- if ((pid = fork()) < 0) {
+ virLogLock();
+ pid = fork();
+ virLogUnlock();
+
+ if (pid < 0) {
ret = errno;
virReportSystemError(NULL, errno,
_("cannot fork o create file '%s'"), path);
@@ -1369,7 +1373,11 @@ int virDirCreate(const char *path, mode_t mode,
return virDirCreateSimple(path, mode, uid, gid, flags);
}
- if ((pid = fork()) < 0) {
+ virLogLock();
+ pid = fork();
+ virLogUnlock();
+
+ if (pid < 0) {
ret = errno;
virReportSystemError(NULL, errno,
_("cannot fork to create directory '%s'"),
--
1.6.6
14 years, 10 months
[libvirt] [PATCH] Fix restore of QEMU guests with PCI device reservation
by Daniel P. Berrange
When restoring from a saved guest image, the XML would already
contain the PCI slot ID of the IDE controller & video card.
The attempt to explicitly reserve this upfront would thus fail
everytime.
* src/qemu/qemu_conf.c: Reserve IDE controller / video card
slot at time of need, rather than upfront
---
src/qemu/qemu_conf.c | 83 ++++++++++++++++++++++++++++++++++++++------------
1 files changed, 63 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 389db7b..3d83a8f 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1797,6 +1797,13 @@ static char *qemuPCIAddressAsString(virDomainDeviceInfoPtr dev)
{
char *addr;
+ if (dev->addr.pci.domain != 0 ||
+ dev->addr.pci.bus != 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Only PCI domain 0 and bus 0 are available"));
+ return NULL;
+ }
+
if (virAsprintf(&addr, "%d:%d:%d",
dev->addr.pci.domain,
dev->addr.pci.bus,
@@ -1817,6 +1824,8 @@ static int qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
if (dev->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
char *addr = qemuPCIAddressAsString(dev);
+ VIR_DEBUG("Remembering PCI addr %s", addr);
+
if (virHashAddEntry(addrs->used, addr, addr) < 0) {
VIR_FREE(addr);
return -1;
@@ -1858,6 +1867,8 @@ int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
if (!addr)
return -1;
+ VIR_DEBUG("Reserving PCI addr %s", addr);
+
if (virHashLookup(addrs->used, addr)) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("unable to reserve PCI address %s"), addr);
@@ -1870,6 +1881,9 @@ int qemuDomainPCIAddressReserveAddr(qemuDomainPCIAddressSetPtr addrs,
return -1;
}
+ if (dev->addr.pci.slot > addrs->nextslot)
+ addrs->nextslot = dev->addr.pci.slot + 1;
+
return 0;
}
@@ -1947,6 +1961,8 @@ int qemuDomainPCIAddressSetNextAddr(qemuDomainPCIAddressSetPtr addrs,
addr = qemuPCIAddressAsString(&maybe);
+ VIR_DEBUG("Allocating PCI addr %s", addr);
+
if (virHashLookup(addrs->used, addr)) {
VIR_FREE(addr);
continue;
@@ -1981,12 +1997,13 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs)
/* Host bridge */
if (qemuDomainPCIAddressReserveSlot(addrs, 0) < 0)
goto error;
- /* PIIX3 (ISA bridge, IDE controller, something else unknown, USB controller) */
- if (qemuDomainPCIAddressReserveSlot(addrs, 1) < 0)
- goto error;
- /* VGA */
- if (qemuDomainPCIAddressReserveSlot(addrs, 2) < 0)
- goto error;
+
+ /* PIIX3 (ISA bridge, IDE controller, something else unknown, USB controller)
+ * at slot 1....reserve it later
+ */
+
+ /* VGA at slot 2.... reserve it later */
+
/* VirtIO Balloon */
if (qemuDomainPCIAddressReserveSlot(addrs, 3) < 0)
goto error;
@@ -2033,23 +2050,34 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs)
goto error;
}
for (i = 0; i < def->nvideos ; i++) {
- if (def->videos[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
- continue;
/* First VGA is hardcoded slot=2 */
if (i == 0) {
- def->videos[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
- def->videos[i]->info.addr.pci.domain = 0;
- def->videos[i]->info.addr.pci.bus = 0;
- def->videos[i]->info.addr.pci.slot = 2;
- def->videos[i]->info.addr.pci.function = 0;
+ if (def->videos[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+ if (def->videos[i]->info.addr.pci.domain != 0 ||
+ def->videos[i]->info.addr.pci.bus != 0 ||
+ def->videos[i]->info.addr.pci.slot != 2 ||
+ def->videos[i]->info.addr.pci.function != 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Primary video card must have PCI address 0:0:2.0"));
+ goto error;
+ }
+ } else {
+ def->videos[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+ def->videos[i]->info.addr.pci.domain = 0;
+ def->videos[i]->info.addr.pci.bus = 0;
+ def->videos[i]->info.addr.pci.slot = 2;
+ def->videos[i]->info.addr.pci.function = 0;
+ if (qemuDomainPCIAddressReserveSlot(addrs, 2) < 0)
+ goto error;
+ }
} else {
+ if (def->videos[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+ continue;
if (qemuDomainPCIAddressSetNextAddr(addrs, &def->videos[i]->info) < 0)
goto error;
}
}
for (i = 0; i < def->ncontrollers ; i++) {
- if (def->controllers[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
- continue;
/* FDC lives behind the ISA bridge */
if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_FDC)
continue;
@@ -2057,12 +2085,27 @@ qemuAssignDevicePCISlots(virDomainDefPtr def, qemuDomainPCIAddressSetPtr addrs)
/* First IDE controller lives on the PIIX3 at slot=1, function=1 */
if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_IDE &&
def->controllers[i]->idx == 0) {
- def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
- def->controllers[i]->info.addr.pci.domain = 0;
- def->controllers[i]->info.addr.pci.bus = 0;
- def->controllers[i]->info.addr.pci.slot = 1;
- def->controllers[i]->info.addr.pci.function = 1;
+ if (def->controllers[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+ if (def->videos[i]->info.addr.pci.domain != 0 ||
+ def->videos[i]->info.addr.pci.bus != 0 ||
+ def->videos[i]->info.addr.pci.slot != 2 ||
+ def->videos[i]->info.addr.pci.function != 0) {
+ qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Primary IDE controller must have PCI address 0:0:1.1"));
+ goto error;
+ }
+ } else {
+ def->controllers[i]->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+ def->controllers[i]->info.addr.pci.domain = 0;
+ def->controllers[i]->info.addr.pci.bus = 0;
+ def->controllers[i]->info.addr.pci.slot = 1;
+ def->controllers[i]->info.addr.pci.function = 1;
+ if (qemuDomainPCIAddressReserveSlot(addrs, 1) < 0)
+ goto error;
+ }
} else {
+ if (def->controllers[i]->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+ continue;
if (qemuDomainPCIAddressSetNextAddr(addrs, &def->controllers[i]->info) < 0)
goto error;
}
--
1.6.6
14 years, 10 months
[libvirt] [PATCH] util: Remove logging handlers in virExec
by Cole Robinson
This allows debug statements and raised errors in hook functions to
actually be logged somewhere (stderr). Users can enable debugging in the
daemon and now see more info in /var/log/libvirt/...
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/util/util.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index 44a4b2f..23d781d 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -334,6 +334,7 @@ __virExec(virConnectPtr conn,
int pipeerr[2] = {-1,-1};
int childout = -1;
int childerr = -1;
+ int logprio;
sigset_t oldmask, newmask;
struct sigaction sig_action;
@@ -452,6 +453,11 @@ __virExec(virConnectPtr conn,
of being seen / logged */
virSetErrorFunc(NULL, NULL);
+ /* Make sure any hook logging is sent to stderr */
+ logprio = virLogGetDefaultPriority();
+ virLogReset();
+ virLogSetDefaultPriority(logprio);
+
/* Clear out all signal handlers from parent so nothing
unexpected can happen in our child once we unblock
signals */
--
1.6.5.2
14 years, 10 months