]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
15 years agolibvirtd.c: avoid closing a negative socket file descriptor
Jim Meyering [Tue, 2 Feb 2010 10:27:25 +0000 (11:27 +0100)]
libvirtd.c: avoid closing a negative socket file descriptor

* daemon/libvirtd.c (qemudListenUnix): Close socket only if non-negative.

15 years agostorage_backend.c: avoid closing a negative file descriptor
Jim Meyering [Tue, 2 Feb 2010 10:11:49 +0000 (11:11 +0100)]
storage_backend.c: avoid closing a negative file descriptor

* src/storage/storage_backend.c (virStorageBackendRunProgRegex):
Don't close a negative (read-only) file descriptor.

15 years agoavoid a probable EINVAL from lseek
Jim Meyering [Mon, 1 Feb 2010 21:17:44 +0000 (22:17 +0100)]
avoid a probable EINVAL from lseek

* src/qemu/qemu_driver.c (qemudLogReadFD): Don't pass a negative
offset (from a preceding failed attempt to seek to EOF) to this use
of lseek.

15 years agoudev: Don't let strtoul parse USB busnum and devnum as octal
Matthias Bolte [Sat, 30 Jan 2010 23:53:40 +0000 (00:53 +0100)]
udev: Don't let strtoul parse USB busnum and devnum as octal

udevGetUintProperty was called with base set to 0 for busnum and devnum.
With base 0 strtoul parses the number as octal if it start with a 0. But
busnum and devnum are decimal and udev returns them padded with leading
zeros. So strtoul parses them as octal. This works for certain decimal
values like 001-007, but fails for values like 008.

Change udevProcessUSBDevice to use base 10 for busnum and devnum.

15 years agoutil.c (two more): don't use a negative value as allocation size
Jim Meyering [Mon, 1 Feb 2010 20:45:06 +0000 (21:45 +0100)]
util.c (two more): don't use a negative value as allocation size

* src/util/util.c (virGetUserID, virGetGroupID): In the unlikely event
that sysconf(_SC_GETPW_R_SIZE_MAX) fails, don't use -1 as the size in
the subsequent allocation.

15 years agojson.c: avoid an unconditional leak from most qemuMonitorJSON* functions
Jim Meyering [Wed, 27 Jan 2010 08:58:12 +0000 (09:58 +0100)]
json.c: avoid an unconditional leak from most qemuMonitorJSON* functions

* src/util/json.c (virJSONValueFree): Free the "value" pointer, too.

15 years agoavoid format-related warnings
Jim Meyering [Mon, 1 Feb 2010 17:25:23 +0000 (18:25 +0100)]
avoid format-related warnings

* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetAllPCIAddresses):
Use %s.
* src/storage/storage_backend_iscsi.c (virStorageBackendCreateIfaceIQN):
Likewise.
* tools/virsh.c (cmdSecretSetValue): Likewise.

15 years agomaint: avoid excess parens in STREQ
Eric Blake [Wed, 27 Jan 2010 13:59:02 +0000 (06:59 -0700)]
maint: avoid excess parens in STREQ

* src/internal.h (STREQ, STRCASEEQ, STRNEQ, STRCASENEQ, STREQLEN)
(STRCASEEQLEN, STRNEQLEN, STRCASENEQLEN, STRPREFIX): Avoid
redundant parenthesis.
* examples/domain-events/events-c/event-test.c (STREQ): Likewise.
* src/storage/parthelper.c (STREQ): Likewise.

15 years agoMove models/nmodels mismatch checking one level up
Jiri Denemark [Mon, 1 Feb 2010 11:42:27 +0000 (12:42 +0100)]
Move models/nmodels mismatch checking one level up

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
15 years agoLog flags in virConnectCompareCPU
Jiri Denemark [Mon, 1 Feb 2010 15:22:33 +0000 (16:22 +0100)]
Log flags in virConnectCompareCPU

* src/libvirt.c: extend the debug statement to log flags too

15 years agoFix PCI host reattach on domain detach.
Chris Lalancette [Tue, 26 Jan 2010 15:01:23 +0000 (10:01 -0500)]
Fix PCI host reattach on domain detach.

Similar to the race fixed by
be34c3c7efbb1ea8999530f98b99c5dde3793f84, make sure
to wait around for KVM to release the resources from
a hot-detached PCI device before attempting to
rebind that device to the host driver.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoClarify controllers -device string in QEMU driver
Matthew Booth [Mon, 1 Feb 2010 15:08:36 +0000 (16:08 +0100)]
Clarify controllers -device string in QEMU driver

The QEMU driver contained code to generate a -device string for piix4-ide, but
wasn't using it. This change removes this string generation. It also adds a
comment explaining why IDE and FDC controllers don't generate -device strings.

The change also generates an error if a sata controller is specified for a QEMU
domain, as this isn't supported.

* src/qemu/qemu_conf.c: Remove VIR_DOMAIN_CONTROLLER_TYPE_IDE handler in
  qemuBuildControllerDevStr(). Ignore IDE and FDC controllers. Error if
  SATA controller is discovered. Add comments.

15 years agoFix up a comment in virHashUpdateEntry
Chris Lalancette [Sun, 31 Jan 2010 02:27:12 +0000 (21:27 -0500)]
Fix up a comment in virHashUpdateEntry

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoLook in /usr/libexec for the qemu-kvm binary.
Chris Lalancette [Mon, 25 Jan 2010 15:01:15 +0000 (10:01 -0500)]
Look in /usr/libexec for the qemu-kvm binary.

On RHEL-5 the qemu-kvm binary is located in /usr/libexec.
To reduce confusion for people trying to run upstream libvirt
on RHEL-5 machines, make the qemu driver look in /usr/libexec
for the qemu-kvm binary.

To make this work, I modified virFindFileInPath to handle an
absolute path correctly.  I also ran into an issue where
NULL was sometimes being passed for the file parameter
to virFindFileInPath; it didn't crash prior to this patch
since it was building paths like /usr/bin/(null).  This
is non-standard behavior, though, so I added a NULL
check at the beginning.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agomaint: fix spelling error in hacking
Eric Blake [Wed, 27 Jan 2010 13:33:58 +0000 (06:33 -0700)]
maint: fix spelling error in hacking

* HACKING: STRCASEEQ is case insensitive.
* docs/hacking.html.in: Likewise.

15 years agoutil.c (virGetUserEnt): don't use a negative value as allocation size
Jim Meyering [Thu, 28 Jan 2010 12:37:05 +0000 (13:37 +0100)]
util.c (virGetUserEnt): don't use a negative value as allocation size

* src/util/util.c (virGetUserEnt): In the unlikely event that
sysconf(_SC_GETPW_R_SIZE_MAX) fails, don't use -1 as the size in
the subsequent allocation.

15 years agoSupport Xen 4.0 sysctl version 7
Jim Fehlig [Wed, 27 Jan 2010 17:56:18 +0000 (10:56 -0700)]
Support Xen 4.0 sysctl version 7

xen-unstable c/s 20762 bumped XEN_SYSCTL_INTERFACE_VERSION to 7.  The
interface change does not affect libvirt, other than xenHypervisorInit()
failing since version 7 is not tried.

The attached patch accommodates the upcoming Xen 4.0 release by checking
for XEN_SYSCTL_INTERFACE_VERSION 7.  If found, it sets
XEN_DOMCTL_INTERFACE_VERSION to 6, which is also new to Xen 4.0.

15 years agoAdd missing sata controller type to domain.rng
Matthew Booth [Wed, 27 Jan 2010 13:26:49 +0000 (14:26 +0100)]
Add missing sata controller type to domain.rng

* docs/schemas/domain.rng: Add sata controller type

15 years agocpu_x86.c: avoid NULL-deref for invalid arguments
Jim Meyering [Tue, 26 Jan 2010 18:58:48 +0000 (19:58 +0100)]
cpu_x86.c: avoid NULL-deref for invalid arguments

* src/cpu/cpu_x86.c (x86Decode): Do not dereference NULL
when "models" is NULL and nmodels is 1 or greater.

15 years agoportability to non-glibc: don't use realpath(..., NULL)
Jim Meyering [Tue, 26 Jan 2010 16:13:45 +0000 (17:13 +0100)]
portability to non-glibc: don't use realpath(..., NULL)

it causes a NULL-dereference on some systems like Solaris 10.
* src/node_device/node_device_linux_sysfs.c. Include <stdlib.h>.
(get_sriov_function): Use canonicalize_file_name, not realpath.
* bootstrap (modules): Add canonicalize-lgpl.

15 years agopci.c: correct an erroneous expression
Jim Meyering [Tue, 26 Jan 2010 19:36:58 +0000 (20:36 +0100)]
pci.c: correct an erroneous expression

* src/util/pci.c (pciDeviceDownstreamLacksACS): Fix a typo
that rendered a subexpression always false.

15 years agoudev: Set the state driver name
Matthias Bolte [Tue, 26 Jan 2010 02:13:08 +0000 (03:13 +0100)]
udev: Set the state driver name

15 years agoRemove undefined symbols from libvirt_private.syms
Matthias Bolte [Tue, 26 Jan 2010 02:07:18 +0000 (03:07 +0100)]
Remove undefined symbols from libvirt_private.syms

15 years agoudev: Remove event handle on shutdown
Matthias Bolte [Tue, 26 Jan 2010 01:58:37 +0000 (02:58 +0100)]
udev: Remove event handle on shutdown

This fixes a segfault when the event handler is called after shutdown
when the global driver state is NULL again.

Also fix a locking issue in an error path.

15 years agoDon't call disabled timer callbacks in event-test.c
Matthias Bolte [Tue, 26 Jan 2010 01:54:34 +0000 (02:54 +0100)]
Don't call disabled timer callbacks in event-test.c

This fixes a segfault in the remote driver that occurs for example when
the event-test is run inside a domain-0 and libvirtd is also running.

15 years agoesx: Output error details from libcurl
Matthias Bolte [Tue, 26 Jan 2010 01:05:45 +0000 (02:05 +0100)]
esx: Output error details from libcurl

15 years agoAdd missing function parameter documentation
Matthias Bolte [Tue, 26 Jan 2010 00:59:48 +0000 (01:59 +0100)]
Add missing function parameter documentation

15 years agohostusb: closedir only if non-NULL; rename labels: s/error/cleanup/
Jim Meyering [Mon, 25 Jan 2010 15:54:06 +0000 (16:54 +0100)]
hostusb: closedir only if non-NULL; rename labels: s/error/cleanup/

* src/util/hostusb.c (usbSysReadFile): Rename labels s/error/cleanup/
(usbFindBusByVendor): Likewise.  And closedir only if non-NULL.

15 years agoCleanup of large buffer on stack in virFileMakePath
Laine Stump [Tue, 26 Jan 2010 13:47:02 +0000 (14:47 +0100)]
Cleanup of large buffer on stack in virFileMakePath

virFileMakePath is a recursive function that was creates a buffer
PATH_MAX bytes long for each recursion (one recursion for each element
in the path). This changes it to have no buffers on the stack, and to
allocate just one buffer total, no matter how many elements are in the
path. Because the modified algorithm requires a char* to be passed in
rather than const char *, it is now 2 functions - a toplevel API
function that remains identical in function, and a 2nd helper function
called for the recursions, which 1) doesn't allocate anything, and 2)
takes a char* arg, so it can modify the contents.
* src/util/util.c: rewrite virFileMakePath

15 years agoesx: Stop passing around virConnectPtr for error reporting
Matthias Bolte [Fri, 15 Jan 2010 22:05:26 +0000 (23:05 +0100)]
esx: Stop passing around virConnectPtr for error reporting

15 years agoRevert "Fix libvirtd restart for domains with PCI passthrough devices"
Chris Lalancette [Mon, 25 Jan 2010 18:35:05 +0000 (13:35 -0500)]
Revert "Fix libvirtd restart for domains with PCI passthrough devices"

This reverts commit cdc42d0a4865199a941d330dbb6ca1ef426323ae.
As DanB pointed out, this patch is actually wrong.  The real
bug that was causing me to see this problem is a bug
introduced in a RHEL-5 libvirt snapshot, and I'm going to
fix the real bug there.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoFix a crash when restarting libvirtd.
Chris Lalancette [Mon, 25 Jan 2010 16:13:41 +0000 (11:13 -0500)]
Fix a crash when restarting libvirtd.

If you shutdown libvirtd while a domain with PCI
devices is running, then try to restart libvirtd,
libvirtd will crash.

This happens because qemuUpdateActivePciHostdevs() is calling
pciDeviceListSteal() with a dev of 0x0 (NULL), and then trying
to dereference it.  This patch fixes it up so that
qemuUpdateActivePciHostdevs() steals the devices after first
Get()'ting them, avoiding the crash.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoFix two instances of misspelled 'pseudo'
Chris Lalancette [Mon, 25 Jan 2010 14:58:40 +0000 (09:58 -0500)]
Fix two instances of misspelled 'pseudo'

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoqemuMonitorTextAttachDrive: avoid two leaks
Jim Meyering [Mon, 25 Jan 2010 19:19:01 +0000 (20:19 +0100)]
qemuMonitorTextAttachDrive: avoid two leaks

* src/qemu/qemu_monitor_text.c (qemuMonitorTextAttachDrive): Most other
failures in this function would "goto cleanup", but one mistakenly
returned directly, skipping the cleanup and resulting in a leak.
In addition, iterating the "try_command" loop would clobber, and
thus leak, the "cmd" allocated on the first iteration,
so be careful to free it in addition to "reply" beforehand.

15 years agoqemu: Search binaries in PATH instead of hardcoding /usr/bin
Matthias Bolte [Tue, 19 Jan 2010 23:24:47 +0000 (00:24 +0100)]
qemu: Search binaries in PATH instead of hardcoding /usr/bin

15 years agoImplement QMP support for extracting CPU thread ID
Daniel P. Berrange [Fri, 22 Jan 2010 14:52:05 +0000 (14:52 +0000)]
Implement QMP support for extracting CPU thread ID

The KVM build of QEMU includs the thread ID of each vCPU in the
'query-cpus' output. This is required for pinning guests to
particular host CPUs

* src/qemu/qemu_monitor_json.c: Extract 'thread_id' from CPU info

15 years agoMisc fixes to QMP monitor support for QEMU
Daniel P. Berrange [Fri, 22 Jan 2010 13:22:53 +0000 (13:22 +0000)]
Misc fixes to QMP monitor support for QEMU

* src/util/json.c, src/util/json.h: Declare returned strings
  to be const
* src/qemu/qemu_monitor.c: Wire up JSON mode for qemuMonitorGetPtyPaths
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h: Fix
  const correctness. Add missing error message in the function
  qemuMonitorJSONGetAllPCIAddresses. Add implementation of the
  qemuMonitorGetPtyPaths function calling 'query-chardev'.

15 years agoAdd some missing include files which break build in certain platforms
Daniel P. Berrange [Fri, 22 Jan 2010 13:21:16 +0000 (13:21 +0000)]
Add some missing include files which break build in certain platforms

Two files were using functions from <sys/stat.h> but not including
in. Most of the time they got this automatically via another header,
but certain build flag combinations can reveal the problem

* src/lxc/lxc_container.c, src/node_device/node_device_linux_sysfs.c:
  Add <sys/stat.h>

15 years agoFix setup of compatability serial devices from console device
Daniel P. Berrange [Fri, 22 Jan 2010 13:19:24 +0000 (13:19 +0000)]
Fix setup of compatability serial devices from console device

The <console> tag is supposed to result in addition of a single
<serial> device for HVM guests. The 'targetType' attribute was
missing though causing the compatibility code to add a second
<console> device

* src/conf/domain_conf.c: Set targetType for serial device

15 years agousbGetDevice: don't leak a "usbDevice" buffer on failure path
Jim Meyering [Mon, 25 Jan 2010 15:44:13 +0000 (16:44 +0100)]
usbGetDevice: don't leak a "usbDevice" buffer on failure path

* src/util/hostusb.c (usbGetDevice): Free "dev" when returning NULL.

15 years agoqemuMonitorTextGetMemoryStats: plug a leak on an error path
Jim Meyering [Wed, 20 Jan 2010 17:24:47 +0000 (18:24 +0100)]
qemuMonitorTextGetMemoryStats: plug a leak on an error path

* src/qemu/qemu_monitor_text.c (qemuMonitorCommandWithHandler):
Always free *reply, upon failure.

15 years agousbFindBusByVendor: don't leak a DIR buffer and FD
Jim Meyering [Mon, 25 Jan 2010 15:36:07 +0000 (16:36 +0100)]
usbFindBusByVendor: don't leak a DIR buffer and FD

* src/util/hostusb.c (usbFindBusByVendor): Don't leak a DIR buffer
and file descriptor.

15 years agoStart modernizing configure
Eric Blake [Mon, 25 Jan 2010 15:00:43 +0000 (16:00 +0100)]
Start modernizing configure

* configure.ac: reanmed configura.in, use AC_CONFIG_HEADERS instead of
  AM_CONFIG_HEADER

15 years agoFix libvirtd restart for domains with PCI passthrough devices
Chris Lalancette [Fri, 22 Jan 2010 17:39:15 +0000 (18:39 +0100)]
Fix libvirtd restart for domains with PCI passthrough devices

When libvirtd shuts down, it places a <state/> tag in the XML
state file it writes out for guests with PCI passthrough
devices.  For devices that are attached at bootup time, the
state tag is empty.  However, at libvirtd startup time, it
ignores anything with a <state/> tag in the XML, effectively
hiding the guest.
This patch remove the check for VIR_DOMAIN_XML_INTERNAL_STATUS
when parsing the XML.
* src/conf/domain_conf.c: remove VIR_DOMAIN_XML_INTERNAL_STATUS
  flag check in virDomainHostdevSubsysPciDefParseXML()

15 years agoqemu: Fix race between device rebind and kvm cleanup
Chris Lalancette [Wed, 20 Jan 2010 20:53:59 +0000 (15:53 -0500)]
qemu: Fix race between device rebind and kvm cleanup

Certain hypervisors (like qemu/kvm) map the PCI bar(s) on
the host when doing device passthrough.  This can lead to a race
condition where the hypervisor is still cleaning up the device while
libvirt is trying to re-attach it to the host device driver.  To avoid
this situation, we look through /proc/iomem, and if the hypervisor is
still holding onto the bar (denoted by the string in the matcher variable),
then we can wait around a bit for that to clear up.

v2: Thanks to review by DV, make sure we wait the full timeout per-device

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoFix device assignment with root devices
Chris Lalancette [Tue, 19 Jan 2010 16:26:54 +0000 (11:26 -0500)]
Fix device assignment with root devices

The patches to add ACS checking to PCI device passthrough
introduced a bug.  With the current code, if you try to
passthrough a device on the root bus (i.e. bus 0), then
it denies the passthrough.  This is because the code in
pciDeviceIsBehindSwitchLackingACS() to check for a parent
device doesn't take into account the possibility of the
root bus.  If we are on the root bus, it means we
legitimately can't find a parent, and it also means that
we don't have to worry about whether ACS is enabled.
Therefore return 0 (indicating we don't lack ACS) from
pciDeviceIsBehindSwitchLackingACS().

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoAdd a rule to check for uses of readlink.
Chris Lalancette [Mon, 21 Dec 2009 19:14:46 +0000 (14:14 -0500)]
Add a rule to check for uses of readlink.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoUse virFileResolveLink instead of readlink in AppArmor
Chris Lalancette [Wed, 20 Jan 2010 21:12:43 +0000 (16:12 -0500)]
Use virFileResolveLink instead of readlink in AppArmor

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoFix a compile warning in parthelper.c
Chris Lalancette [Thu, 10 Dec 2009 16:53:55 +0000 (17:53 +0100)]
Fix a compile warning in parthelper.c

Signed-off-by: Chris Lalancette <clalance@redhat.com>
15 years agoAdd virConnectGetVersion Python API
Taizo ITO [Fri, 22 Jan 2010 10:01:09 +0000 (11:01 +0100)]
Add virConnectGetVersion Python API

adds a new python API call for retrieving the running
hypervisor version used by a connection: virConnectGetVersion

* python/generator.py: skip virConnectGetVersion from autogenerated
* python/libvirt-override-api.xml python/libvirt-override.c: define
  direct native bindings

15 years agoRemove AppArmor compile warnings
Jamie Strandboge [Fri, 22 Jan 2010 09:48:34 +0000 (10:48 +0100)]
Remove AppArmor compile warnings

* src/security/security_apparmor.c: unused variable in
  AppArmorSetSecurityAllLabel and unused parameter in
  AppArmorReleaseSecurityLabel

15 years agoRemove unused PROC_MOUNT_BUF_LEN #define
Chris Lalancette [Fri, 22 Jan 2010 09:25:44 +0000 (10:25 +0100)]
Remove unused PROC_MOUNT_BUF_LEN #define

15 years agoUpdate polish translation and regenerate localizations
Daniel Veillard [Fri, 22 Jan 2010 09:02:16 +0000 (10:02 +0100)]
Update polish translation and regenerate localizations

15 years agoAdd docs about new mailing list
Daniel P. Berrange [Thu, 21 Jan 2010 15:48:11 +0000 (16:48 +0100)]
Add docs about new mailing list

* docs/contact.html.in: Document new users mailing list

15 years agodomMemoryStats / qemu: Fix parsing of unknown stats
Adam Litke [Thu, 21 Jan 2010 15:26:35 +0000 (16:26 +0100)]
domMemoryStats / qemu: Fix parsing of unknown stats

Fix a small problem with the qemu memory stats parsing algorithm.  If qemu
reports a stat that libvirt does not recognize, skip past it so parsing can
continue.  This corrects a potential infinite loop in the parsing code that can
only be triggered if new statistics are added to qemu.

* src/qemu/qemu_monitor_text.c: qemuMonitorParseExtraBalloonInfo add a
  skip for extra ','

15 years agoCorrected log level of WWN path message
David Allan [Thu, 21 Jan 2010 14:55:13 +0000 (15:55 +0100)]
Corrected log level of WWN path message

* src/node_device/node_device_linux_sysfs.c: open_wwn_file() the
  VIR_ERROR resllay should be just a VIR_DEBUG

15 years agoFix an error when looking for devices in syspath
Daniel Veillard [Thu, 21 Jan 2010 14:45:44 +0000 (15:45 +0100)]
Fix an error when looking for devices in syspath

* src/node_device/node_device_udev.c: udevSetupSystemDev() only print the
  error message if lookup failed in both DMI_DEVPATH and DMI_DEVPATH_FALLBACK

15 years agoAllow surrounding whitespace in uuid
Dan Kenigsberg [Thu, 21 Jan 2010 14:28:56 +0000 (15:28 +0100)]
Allow surrounding whitespace in uuid

* src/util/uuid.c: extend virUUIDParse to allow leading and trailing
  spaces in UUIDs

15 years agofix "make distcheck" failure
Jim Meyering [Thu, 21 Jan 2010 14:24:15 +0000 (15:24 +0100)]
fix "make distcheck" failure

* tests/Makefile.am (qemuhelpdata): Add qemu-0.12.1.

15 years agoavoid more format-related warnings
Jim Meyering [Thu, 21 Jan 2010 14:12:12 +0000 (15:12 +0100)]
avoid more format-related warnings

* src/qemu/qemu_conf.c (qemuBuildDriveStr): Use "%s".
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetGuestPCIAddress):
(qemuMonitorJSONGetGuestDriveAddress): Likewise.

15 years agoavoid format-related warnings
Jim Meyering [Thu, 21 Jan 2010 13:39:42 +0000 (14:39 +0100)]
avoid format-related warnings

* src/conf/domain_conf.c (virDomainDeviceInfoParseXML): Use "%s".

15 years agoFix off-by-1 in SCSI drive hotplug
Daniel P. Berrange [Wed, 20 Jan 2010 14:53:30 +0000 (14:53 +0000)]
Fix off-by-1 in SCSI drive hotplug

The loop looking for the controller associated with a SCI drive had
an off by one, causing it to miss the last controller.

* src/qemu/qemu_driver.c: Fix off-by-1 in searching for SCSI
  drive hotplug

15 years agoFix leak in hotplug code in QEMU driver
Daniel P. Berrange [Mon, 18 Jan 2010 18:02:20 +0000 (18:02 +0000)]
Fix leak in hotplug code in QEMU driver

The hotplug code in QEMU was leaking memory because although the
inner device object was being moved into the main virDomainDefPtr
config object, the outer container virDomainDeviceDefPtr was not.

 * src/qemu/qemu_driver.c: Clarify code to show that the inner
   device object is owned by the main domain config upon
   successfull attach.

15 years agoAdd configuration option to turn off dynamic permissions management
Daniel P. Berrange [Wed, 13 Jan 2010 17:41:36 +0000 (17:41 +0000)]
Add configuration option to turn off dynamic permissions management

Add the ability to turn off dynamic management of file permissions
for libvirt guests.

* qemu/libvirtd_qemu.aug: Support 'dynamic_ownership' flag
* qemu/qemu.conf: Document 'dynamic_ownership' flag.
* qemu/qemu_conf.c: Load 'dynamic_ownership' flag
* qemu/test_libvirtd_qemu.aug: Test 'dynamic_ownership' flag

15 years agoFix security driver calls in hotplug cleanup paths
Daniel P. Berrange [Wed, 13 Jan 2010 17:27:19 +0000 (17:27 +0000)]
Fix security driver calls in hotplug cleanup paths

The hotplug code was not correctly invoking the security driver
in error paths. If a hotplug attempt failed, the device would
be left with VM permissions applied, rather than restored to the
original permissions. Also, a CDROM media that is ejected was
not restored to original permissions. Finally there was a bogus
call to set hostdev permissions in the hostdev unplug code

* qemu/qemu_driver.c: Fix security driver usage in hotplug/unplug

15 years agoAdd missing call to re-attach host devices if VM startup fails
Daniel P. Berrange [Wed, 13 Jan 2010 17:09:41 +0000 (17:09 +0000)]
Add missing call to re-attach host devices if VM startup fails

If there is a problem with VM startup, PCI devices may be left
assigned to pci-stub / pci-back. Adding a call to reattach
host devices in the cleanup path is required.

* qemu/qemu_driver.c: qemuDomainReAttachHostDevices() when
  VM startup fails

15 years agoSwitch QEMU driver over to use the DAC security driver
Daniel P. Berrange [Wed, 13 Jan 2010 17:06:57 +0000 (17:06 +0000)]
Switch QEMU driver over to use the DAC security driver

Remove all the QEMU driver calls for setting file ownership and
process uid/gid. Instead wire in the QEMU DAC security driver,
stacking it ontop of the primary SELinux/AppArmour driver.

* qemu/qemu_driver.c: Switch over to new DAC security driver

15 years agoIntroduce a new DAC security driver for QEMU
Daniel P. Berrange [Wed, 13 Jan 2010 16:43:29 +0000 (16:43 +0000)]
Introduce a new DAC security driver for QEMU

This new security driver is responsible for managing UID/GID changes
to the QEMU process, and any files/disks/devices assigned to it.

* qemu/qemu_conf.h: Add flag for disabling automatic file permission
  changes
* qemu/qemu_security_dac.h, qemu/qemu_security_dac.c: New DAC driver
  for QEMU guests
* Makefile.am: Add new files

15 years agoIntroduce a stacked security driver impl for QEMU
Daniel P. Berrange [Wed, 13 Jan 2010 16:26:55 +0000 (16:26 +0000)]
Introduce a stacked security driver impl for QEMU

* qemu/qemu_conf.h: Add securityPrimaryDriver and
  securitySecondaryDriver fields to 'struct qemud_driver'
* Makefile.am: Add new files
* qemu/qemu_security_stacked.c, qemu/qemu_security_stacked.h: A
  simple stacked security driver

15 years agoPull initial disk labelling out into libvirtd instead of exec hook
Daniel P. Berrange [Wed, 13 Jan 2010 16:28:31 +0000 (16:28 +0000)]
Pull initial disk labelling out into libvirtd instead of exec hook

Pulling the disk labelling code out of the exec hook, and into
libvirtd will allow it to access shared state in the daemon. It
will also make debugging & error reporting easier / more reliable.

* qemu/qemu_driver.c: Move initial disk labelling calls up into
  libvirtd. Add cleanup of disk labels upon failure

15 years agoFix leak of allocated security label
Daniel P. Berrange [Wed, 13 Jan 2010 15:30:24 +0000 (15:30 +0000)]
Fix leak of allocated security label

If a VM fails to start, we can't simply free the security label
strings, we must call the domainReleaseSecurityLabel() method
otherwise the reserved 'mcs' level will be leaked in SElinux

* src/qemu/qemu_driver.c: Invoke domainReleaseSecurityLabel()
  when domain fails to start

15 years agoRefactor setup & cleanup of security labels in security driver
Daniel P. Berrange [Mon, 11 Jan 2010 11:04:40 +0000 (11:04 +0000)]
Refactor setup & cleanup of security labels in security driver

The current security driver architecture has the following
split of logic

 * domainGenSecurityLabel

    Allocate the unique label for the domain about to be started

 * domainGetSecurityLabel

    Retrieve the current live security label for a process

 * domainSetSecurityLabel

    Apply the previously allocated label to the current process
    Setup all disk image / device labelling

 * domainRestoreSecurityLabel

    Restore the original disk image / device labelling.
    Release the unique label for the domain

The 'domainSetSecurityLabel' method is special because it runs
in the context of the child process between the fork + exec.

This is require in order to set the process label. It is not
required in order to label disks/devices though. Having the
disk labelling code run in the child process limits what it
can do.

In particularly libvirtd would like to remember the current
disk image label, and only change shared image labels for the
first VM to start. This requires use & update of global state
in the libvirtd daemon, and thus cannot run in the child
process context.

The solution is to split domainSetSecurityLabel into two parts,
one applies process label, and the other handles disk image
labelling. At the same time domainRestoreSecurityLabel is
similarly split, just so that it matches the style. Thus the
previous 4 methods are replaced by the following 6 new methods

 * domainGenSecurityLabel

    Allocate the unique label for the domain about to be started
    No actual change here.

 * domainReleaseSecurityLabel

   Release the unique label for the domain

 * domainGetSecurityProcessLabel

   Retrieve the current live security label for a process
   Merely renamed for clarity.

 * domainSetSecurityProcessLabel

   Apply the previously allocated label to the current process

 * domainRestoreSecurityAllLabel

    Restore the original disk image / device labelling.

 * domainSetSecurityAllLabel

    Setup all disk image / device labelling

The SELinux and AppArmour drivers are then updated to comply with
this new spec. Notice that the AppArmour driver was actually a
little different. It was creating its profile for the disk image
and device labels in the 'domainGenSecurityLabel' method, where as
the SELinux driver did it in 'domainSetSecurityLabel'. With the
new method split, we can have consistency, with both drivers doing
that in the domainSetSecurityAllLabel method.

NB, the AppArmour changes here haven't been compiled so may not
build.

15 years agoMake security drivers responsible for checking dynamic vs static labelling
Daniel P. Berrange [Wed, 13 Jan 2010 14:03:04 +0000 (14:03 +0000)]
Make security drivers responsible for checking dynamic vs static labelling

The QEMU driver is doing 90% of the calls to check for static vs
dynamic labelling. Except it is forgetting todo so in many places,
in particular hotplug is mistakenly assigning disk labels. Move
all this logic into the security drivers themselves, so the HV
drivers don't have to think about it.

* src/security/security_driver.h: Add virDomainObjPtr parameter
  to virSecurityDomainRestoreHostdevLabel and to
  virSecurityDomainRestoreSavedStateLabel
* src/security/security_selinux.c, src/security/security_apparmor.c:
  Add explicit checks for VIR_DOMAIN_SECLABEL_STATIC and skip all
  chcon() code in those cases
* src/qemu/qemu_driver.c: Remove all checks for VIR_DOMAIN_SECLABEL_STATIC
  or VIR_DOMAIN_SECLABEL_DYNAMIC. Add missing checks for possibly NULL
  driver entry points.

15 years agoImplement support for multi IQN
David Allan [Thu, 21 Jan 2010 11:50:52 +0000 (12:50 +0100)]
Implement support for multi IQN

Allows the initiator to use a variety of IQNs rather than just the
system IQN when creating iSCSI pools.
* docs/schemas/storagepool.rng: extends the syntax with <iqn name="..."/>
* src/conf/storage_conf.[ch]: read and stores the iqn name
* src/storage/storage_backend_iscsi.[ch]: implement the IQN selection
  when detected

15 years agoLet make fail when XHTML validation fails
Jiri Denemark [Wed, 20 Jan 2010 13:14:43 +0000 (14:14 +0100)]
Let make fail when XHTML validation fails

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
15 years agoFix uses of virFileMakePath
Laine Stump [Wed, 20 Jan 2010 23:52:13 +0000 (00:52 +0100)]
Fix uses of virFileMakePath

* src/lxc/lxc_container.c src/lxc/lxc_controller.c src/lxc/lxc_driver.c
  src/network/bridge_driver.c src/qemu/qemu_driver.c
  src/uml/uml_driver.c: virFileMakePath returns 0 for success, or the
  value of errno on failure, so error checking should be to test
  if non-zero, not if lower than 0

15 years agoCreate storage pool directories with proper uid/gid/mode
Laine Stump [Wed, 20 Jan 2010 23:46:32 +0000 (00:46 +0100)]
Create storage pool directories with proper uid/gid/mode

Previously the uid/gid/mode in the xml was ignored when creating new
storage pool directories. This commit attempts to honor the requested
permissions, and spits out an error if it can't.

Note that when creating the directory, the rest of the path leading up
to the final element is created using current uid/gid/mode, and the
final element gets the settings from xml. It is NOT an error for the
directory to already exist; in this case, the perms for the existing
directory are just set (if necessary).

* src/storage/storage_backend_fs.c: update the virStorageBackendFileSystemBuild
  function to check the directory hierarchy separately then create the
  leaf directory with the right attributes

15 years agoCreate storage volumes directly with desired uid/gid
Laine Stump [Wed, 20 Jan 2010 23:41:52 +0000 (00:41 +0100)]
Create storage volumes directly with desired uid/gid

In order to avoid problems trying to chown files that were created by
root on a root-squashing nfs server, fork a new process that setuid's
to the desired uid before creating the file. (It's only done this way
if the pool containing the new volume is of type 'netfs', otherwise
the old method of creating the file followed by chown() is used.)

This changes the semantics of the "create_func" slightly - previously
it was assumed that this function just created the file, then the
caller would chown it to the desired uid. Now, create_func does both
operations.

There are multiple functions that can take on the role of create_func:

createFileDir - previously called mkdir(), now calls virDirCreate().
virStorageBackendCreateRaw - previously called open(),
                             now calls virFileCreate().
virStorageBackendCreateQemuImg - use virRunWithHook() to setuid/gid.
virStorageBackendCreateQcowCreate - same.
virStorageBackendCreateBlockFrom - preserve old behavior (but attempt
                                   chown when necessary even if not root)

* src/storage/storage_backend.[ch] src/storage/storage_backend_disk.c
  src/storage/storage_backend_fs.c src/storage/storage_backend_logical.c
  src/storage/storage_driver.c: change the create_func implementations,
  also propagate the pool information to be able to detect NETFS ones.

15 years agoNew utility functions virFileCreate and virDirCreate
Laine Stump [Wed, 20 Jan 2010 23:33:43 +0000 (00:33 +0100)]
New utility functions virFileCreate and virDirCreate

These functions create a new file or directory with the given
uid/gid. If the flag VIR_FILE_CREATE_AS_UID is given, they do this by
forking a new process, calling setuid/setgid in the new process, and
then creating the file. This is better than simply calling open then
fchown, because in the latter case, a root-squashing nfs server would
create the new file as user nobody, then refuse to allow fchown.

If VIR_FILE_CREATE_AS_UID is not specified, the simpler tactic of
creating the file/dir, then chowning is is used. This gives better
results in cases where the parent directory isn't on a root-squashing
NFS server, but doesn't give permission for the specified uid/gid to
create files. (Note that if the fork/setuid method fails to create the
file due to access privileges, the parent process will make a second
attempt using this simpler method.)

If the bit VIR_FILE_CREATE_ALLOW_EXIST is set in the flags, an
existing file/directory will not cause an error; in this case, the
function will simply set the permissions of the file/directory to
those requested. If VIR_FILE_CREATE_ALLOW_EXIST is not specified, an
existing file/directory is considered (and reported as) an error.

Return from both of these functions is 0 on success, or the value of
errno if there was a failure.

* src/util/util.[ch]: add the 2 new util functions

15 years agoAdd virRunWithHook util function
Laine Stump [Wed, 20 Jan 2010 23:30:36 +0000 (00:30 +0100)]
Add virRunWithHook util function

* src/util/util.[ch]: similar to virExecWithHook, but waits for child to
  exit. Useful for doing things like setuid after the fork but before the
  exec.

15 years agoUnset copied environment variables in qemuxml2argvtest
Matthias Bolte [Mon, 28 Dec 2009 15:21:15 +0000 (16:21 +0100)]
Unset copied environment variables in qemuxml2argvtest

The test expected all environment variables copied in qemudBuildCommandLine
to have known values. So all of them have to be either set to a known value
or be unset. SDL_VIDEODRIVER and QEMU_AUDIO_DRV are not handled at all but
should be handled. Unset both, otherwise the test will fail if they are set
in the testing environment.

* src/qemu/qemu_conf.c: add a comment about copied environment variables
  and qemuxml2argvtest
* tests/qemuxml2argvtest.c: unset SDL_VIDEODRIVER and QEMU_AUDIO_DRV

15 years agoqemu: Don't allocate zero bytes
Matthias Bolte [Tue, 19 Jan 2010 21:39:37 +0000 (22:39 +0100)]
qemu: Don't allocate zero bytes

15 years agoclean-up: remove unnecessary closedir call
Jim Meyering [Wed, 20 Jan 2010 20:57:34 +0000 (21:57 +0100)]
clean-up: remove unnecessary closedir call

* src/node_device/node_device_linux_sysfs.c (get_virtual_functions_linux):
Remove unnecessary closedir.  Spotted by Dave Allan.

15 years agonode_device_linux_sysfs.c: avoid opendir/fd leak on error path
Jim Meyering [Wed, 20 Jan 2010 16:49:35 +0000 (17:49 +0100)]
node_device_linux_sysfs.c: avoid opendir/fd leak on error path

* src/node_device/node_device_linux_sysfs.c(get_virtual_functions_linux):
Don't leak a DIR buffer and file descriptor on error path.

15 years agodomain_conf.c: avoid a leak and the need for "cleanup:" block
Jim Meyering [Wed, 20 Jan 2010 18:27:43 +0000 (19:27 +0100)]
domain_conf.c: avoid a leak and the need for "cleanup:" block

* src/conf/domain_conf.c (virDomainChrDefFormat): Plug a leak on
an error path, and at the same time, eliminate the need for a
"cleanup:" block.  Before, the "return -1" after the switch
would leak an "addr" string.  Now, by reversing the port,addr-
getting blocks we can free "addr" immediately and skip the goto.

15 years agoMake all bitfields unsigned ints to avoid unexpected values in casts
Daniel P. Berrange [Tue, 19 Jan 2010 12:07:32 +0000 (12:07 +0000)]
Make all bitfields unsigned ints to avoid unexpected values in casts

The 'int virInterfaceIsActive()' method was directly returning the
value of the 'int active:1' bitfield in virIntefaceDefPtr. A bitfield
with a signed integer, will hold the values 0 and -1, not 0 and +1
as might be expected. This meant that virInterfaceIsActive() was
always returning -1 when the interface was active, not +1 & thus all
callers thought an error had occurred. To protect against this kind
of mistake again, change all bitfields to be unsigned ints

* daemon/libvirtd.h, src/conf/domain_conf.h, src/conf/interface_conf.h,
  src/conf/network_conf.h: Change bitfields to unsigned int.

15 years agoFix QEMU driver custom domain status XML extensions
Daniel P. Berrange [Mon, 18 Jan 2010 16:24:25 +0000 (16:24 +0000)]
Fix QEMU driver custom domain status XML extensions

Invoking the virConnectGetCapabilities() method causes the QEMU
driver to rebuild its internal capabilities object. Unfortunately
it was forgetting to register the custom domain status XML hooks
again.

To avoid this kind of error in the future, the code which builds
capabilities is refactored into one single method, which can be
called from all locations, ensuring reliable rebuilds.

* src/qemu/qemu_driver.c: Fix rebuilding of capabilities XML and
  guarentee it is always consistent

15 years agoDocument cpu-compare command in virsh man page
Jiri Denemark [Wed, 20 Jan 2010 14:16:29 +0000 (15:16 +0100)]
Document cpu-compare command in virsh man page

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
15 years agoDocument <cpu> elements in capabilities and domain XML
Jiri Denemark [Tue, 19 Jan 2010 17:22:45 +0000 (18:22 +0100)]
Document <cpu> elements in capabilities and domain XML

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
15 years agodocs: Remove outdated information about remote limitations
Matthias Bolte [Tue, 19 Jan 2010 20:39:20 +0000 (21:39 +0100)]
docs: Remove outdated information about remote limitations

15 years agologging: confirm that we want to ignore a write error
Jim Meyering [Mon, 18 Jan 2010 10:51:01 +0000 (11:51 +0100)]
logging: confirm that we want to ignore a write error

* src/util/logging.c (virLogMessage): Include "ignore-value.h".
Use it to ignore the return value of safewrite.
Use STDERR_FILENO, rather than "2".
* bootstrap (modules): Add ignore-value.
* gnulib: Update to latest, for ignore-value that is now LGPLv2+.

15 years agoxen_driver: don't leak a parsed-config buffer
Jim Meyering [Mon, 18 Jan 2010 17:02:17 +0000 (18:02 +0100)]
xen_driver: don't leak a parsed-config buffer

* src/xen/xen_driver.c (xenUnifiedDomainXMLFromNative): Also
free "conf" before returning.

15 years agoUpdate interface.rng and xml test files to match netcf 0.1.5
Laine Stump [Sat, 2 Jan 2010 01:40:26 +0000 (20:40 -0500)]
Update interface.rng and xml test files to match netcf 0.1.5

The RNG now supports IPv6 and bonds attached to bridges, along with
some other minor tweaks. All test files from netcf have been copied to
the test directory and added to the xml2xml and schema tests (and they
all pass, of course ;-)

15 years agoSupport bond interfaces attached to bridges in interface xml.
Laine Stump [Sat, 2 Jan 2010 01:40:25 +0000 (20:40 -0500)]
Support bond interfaces attached to bridges in interface xml.

This was accomplished in xml parsing by doing away with the
stripped-down virInterfaceBareDef object, and just always using
virInterfaceDef, but with restrictions in certain places (eg, the type
of subordinate interface allowed in parsing depends on the parent
interface).

xml formatting was similarly adjusted. In addition, the formatting
functions keep track of the level of interface nesting, and insert
extra leading spaces on each line accordingly (using %*s).

The only change in formatted xml from previous (aside frmo supporting
new combinations of interface types) is that the subordinate ethernet
interfaces take up 2 lines rather than one, eg:

   <interface type='ethernet' name='eth0'>
   </interface>

instead of:

   <interface type='ethernet' name='eth0'/>

15 years agoAllow empty bridges in interface xml.
Laine Stump [Sat, 2 Jan 2010 01:40:24 +0000 (20:40 -0500)]
Allow empty bridges in interface xml.

15 years agoSupport delay property in interface bridge xml.
Laine Stump [Sat, 2 Jan 2010 01:40:23 +0000 (20:40 -0500)]
Support delay property in interface bridge xml.

15 years agostorage_conf: plug a leak on OOM error path
Jim Meyering [Mon, 18 Jan 2010 17:40:13 +0000 (18:40 +0100)]
storage_conf: plug a leak on OOM error path

* src/conf/storage_conf.c (virStoragePoolSourceListNewSource):
Free just-allocated "source" upon VIR_REALLOC_N failure.

15 years agoRemove superfluous new lines from messages
Jiri Denemark [Tue, 19 Jan 2010 13:17:20 +0000 (14:17 +0100)]
Remove superfluous new lines from messages

I noticed some debug messages are printed with an empty lines after
them. This patch removes these empty lines from all invocations of the
following macros:
    VIR_DEBUG
    VIR_DEBUG0
    VIR_ERROR
    VIR_ERROR0
    VIR_INFO
    VIR_WARN
    VIR_WARN0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
15 years agoUse pciDeviceIsAssignable in qemu driver
Jiri Denemark [Tue, 22 Dec 2009 17:21:16 +0000 (18:21 +0100)]
Use pciDeviceIsAssignable in qemu driver

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
15 years agoTests for ACS in PCIe switches
Jiri Denemark [Tue, 22 Dec 2009 17:21:15 +0000 (18:21 +0100)]
Tests for ACS in PCIe switches

New pciDeviceIsAssignable() function for checking whether a given PCI
device can be assigned to a guest was added. Currently it only checks
for ACS being enabled on all PCIe switches between root and the PCI
device. In the future, it could be the right place to check whether a
device is unbound or bound to a stub driver.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>