Commit Graph

2945 Commits

Author SHA1 Message Date
Dustin Xiong
269556e557 qemu: Check for IA64 kvm
ACPI feature bit dropped: I asked internally if the -no-acpi option
had any meaning for IA64, and was told 'probably not'.
2010-02-19 10:56:06 -05:00
Cole Robinson
7c7b194cf0 remote: Print ssh stderr on connection failure 2010-02-19 10:56:05 -05:00
Yuji NISHIDA
ead3410f30 fix multiple veth problem for OpenVZ
Fix multiple veth problem.
NETIF setting was overwritten after first CT because any CT could not be
found by name.
* src/openvz/openvz_conf.c src/openvz/openvz_conf.h: add the
  openvzGetVEID lookup function
* src/openvz/openvz_driver.c: use it in openvzDomainSetNetwork()
2010-02-19 16:49:56 +01:00
Chris Lalancette
b97c24b2e1 Better error reporting for failed migration
If the hostname as returned by "gethostname" resolves
to "localhost" (as it does with the broken Fedora-12
installer), then live migration will fail because the
source will try to migrate to itself.  Detect this
situation up-front and abort the live migration before
we do any real work.

* src/util/util.h src/util/util.c: add a new virGetHostnameLocalhost
  with an optional localhost check, and rewire virGetHostname() to use
  it
* src/libvirt_private.syms: expose the new function
* src/qemu/qemu_driver.c: use it in qemudDomainMigratePrepare2()
2010-02-19 16:15:21 +01:00
Chris Lalancette
8ba9e794e6 Make virDomainObjFormat static
* src/conf/domain_conf.c: make function static
* src/conf/domain_conf.h: remove it from header
2010-02-19 16:06:08 +01:00
Chris Lalancette
ee38d7e089 Make an error message in PCI util code clearer
* src/util/pci.c: update 2 message on pciRead errors
2010-02-19 16:04:35 +01:00
Stefan Berger
b3e7890ada macvtap mac_filter support
This patch adds the mac_filter support to the macvtap device.
2010-02-19 15:41:30 +01:00
Jim Meyering
3f8de891c5 virBufferStrcat: do not skip va_end
* src/util/buf.c (virBufferStrcat): Do not skip va_end due to
an early return.
2010-02-19 11:52:04 +01:00
Jim Meyering
12ed08bc3a qparams.c: do not skip va_end, twice
* src/util/qparams.c (new_qparam_set, append_qparams): Do not skip
va_end due to an early return.
2010-02-19 11:52:04 +01:00
Jim Meyering
37ce5600c0 xenDaemonDomainSetAutostart: avoid appearance of impropriety
* src/xen/xend_internal.c (xenDaemonDomainSetAutostart): Rewrite to
avoid dereferencing the result of sexpr_lookup.  While in this
particular case, it was guaranteed never to be NULL, due to the
preceding "if sexpr_node(...)" guard, it's cleaner to skip the
sexpr_node call altogether, and also saves a lookup.
2010-02-19 11:52:04 +01:00
Stefan Berger
e52687e88f macvtap IFF_VNET_HDR configuration
This patch sets or unsets the IFF_VNET_HDR flag depending on what device
is used in the VM. The manipulation of the flag is done in the open
function and is only fatal if the IFF_VNET_HDR flag could not be cleared
although it has to be (or if an ioctl generally fails). In that case the
macvtap tap is closed again and the macvtap interface torn.

* src/qemu/qemu_conf.c src/qemu/qemu_conf.h: pass qemuCmdFlags to
  qemudPhysIfaceConnect()
* src/util/macvtap.c src/util/macvtap.h: add vnet_hdr boolean to
  openMacvtapTap(), and private function configMacvtapTap()
* src/qemu/qemu_driver.c: add extra qemuCmdFlags when calling
  qemudPhysIfaceConnect()
2010-02-19 11:38:57 +01:00
Laine Stump
61497d958e Use virFork() in __virExec(), virFileCreate() and virDirCreate()
For __virExec() this is a semantic NOP except for when fork()
fails. __virExec() would previously forget to restore the signal mask
in this case; virFork() corrects this behavior.

virFileCreate() and virDirCreate() gain the code to reset the logging
and properly deal with the signal handling race condition.

This also removes a log message that had a typo ("cannot fork o create
file '%s'") - this error is now logged in a more generic manner in
virFork() (more generic, but really just as informative, since the
fact that it's forking to create a file is immaterial to the fact that
it simply can't fork)

* src/util/util.c: use the generic virFork() in the 3 functions
2010-02-18 22:20:07 +01:00
Laine Stump
b4584612b4 Add virFork() function to utils
virFork() contains bookkeeping that must be done any time a process
forks. Currently this includes:

1) Call virLogLock() prior to fork() and virLogUnlock() just after,
   to avoid a deadlock if some other thread happens to hold that lock
   during the fork.

2) Reset the logging hooks and send all child process log messages to
   stderr.

3) Block all signals prior to fork(), then either a) reset the signal
   mask for the parent process, or b) clear the signal mask for the
   child process.

Note that the signal mask handling in __virExec erroneously fails to
restore the signal mask when fork() fails. virFork() fixes this
problem.

Other than this, it attempts to behave as closely to fork() as
possible (including preserving errno for the caller), with a couple
exceptions:

1) The return value is 0 (success) or -1 (failure), while the pid is
   returned via the pid_t* argument. Like fork(), if pid < 0 there is
   no child process, otherwise both the child and the parent will
   return to the caller, and both should look at the return value,
   which will indicate if some of the extra processing outlined above
   encountered an error.

2) If virFork() returns with pid < 0 or with a return value < 0
   indicating an error condition, the error has already been
   reported. You can log an additional message if you like, but it
   isn't necessary, and may be awkwardly extraneous.

Note that virFork()'s child process will *never* call _exit() - if a
child process is created, it will return to the caller.

* util.c util.h: add virFork() function, based on what is currently
                 done in __virExec().
2010-02-18 22:13:48 +01:00
Matthew Booth
3ec09478de Add QEMU support for virtio channel
Support virtio-serial controller and virtio channel in QEMU backend.
Will output
the following for virtio-serial controller:

-device
virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x4,max_ports=16,vectors=4

and the following for a virtio channel:

-chardev pty,id=channel0 \
-device
virtserialport,bus=virtio-serial0.0,chardev=channel0,name=org.linux-kvm.port.0

* src/qemu/qemu_conf.c: Add argument output for virtio
* tests/qemuxml2argvtest.c
  tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args: Add test for
  QEMU command line generation
2010-02-18 17:56:50 +01:00
Matthew Booth
7813a0f81c Add domain support for virtio channel
Add support for virtio-serial by defining a new 'virtio' channel target type
and a virtio-serial controller. Allows the following to be specified in a
domain:

<controller type='virtio-serial' index='0' ports='16' vectors='4'/>
<channel type='pty'>
  <target type='virtio' name='org.linux-kvm.port.0'/>
  <address type='virtio-serial' controller='0' bus='0'/>
</channel>

* docs/schemas/domain.rng: Add virtio-serial controller and virtio
  channel type.
* src/conf/domain_conf.[ch]: Domain parsing/serialization for
  virtio-serial controller and virtio channel.
* tests/qemuxml2xmltest.c
  tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.xml: add domain xml
  parsing test
* src/libvirt_private.syms src/qemu/qemu_conf.c:
  virDomainDefAddDiskControllers() renamed to
  virDomainDefAddImplicitControllers()
2010-02-18 17:52:03 +01:00
Matthew Booth
07e318b3db Remove unused functions from domain_conf
Remove virDomainDevicePCIAddressEqual and virDomainDeviceDriveAddressEqual,
which are defined but not used anywhere.

* src/conf/domain_conf.[ch] src/libvirt_private.syms: Remove
  virDomainDevicePCIAddressEqual and virDomainDeviceDriveAddressEqual.
2010-02-18 16:45:18 +01:00
Matthew Booth
27e63c0037 Fix typo in comment
* src/qemu/qemu_driver.c: qemudStartVMDaemon() fix typo in comment
2010-02-18 16:40:48 +01:00
Jim Meyering
081fd746f0 get_virtual_functions_linux: would mistakenly always return zero
* src/node_device/node_device_linux_sysfs.c(get_virtual_functions_linux):
Return "ret", rather than always returning 0.
2010-02-18 16:22:53 +01:00
Cole Robinson
3f745ebe9f qemu: Explicitly error if guest virtual network is inactive
Currently we just error with ex. 'virbr0: No such device'.

Since we are using public API calls here, we need to ensure that any
raised error is properly saved and restored, since API entry points
always reset messages.
2010-02-18 09:23:05 -05:00
Cole Robinson
6d4bd59cf8 network: bridge: Fix IsActive, IsPersistent
We were accessing the wrong private data structure, which would
cause a segfault.
2010-02-18 09:23:05 -05:00
Cole Robinson
bf6789d913 virterror: Make SetError work if no previous error was set
virGetLastError returns NULL if no error has been set, not on
allocation error like virSetError assumed. Use virLastErrorObject
instead. This fixes virSetError when no error is currently stored.
2010-02-18 09:23:04 -05:00
Cole Robinson
372a7f45c5 libvirt: Update docs for hotplug only commands
The commands updated are SetMem, SetMaxMem, SetVcpus, and PinVcpu.
2010-02-18 09:23:04 -05:00
Stefan Berger
f162252e25 macvtap teardown rework
Rework and simplification of teardown of the macvtap device.

Basically all devices with the same MAC address and link device are kept
alive and not attempted to be torn down. If a macvtap device linked to a
physical interface with a certain MAC address 'M' is to be created it
will automatically fail if the interface is 'up'ed and another macvtap
with the same properties (MAC addr 'M', link dev) happens to be 'up'.
This will prevent the VM from starting or the device from being attached
to a running VM. Stale interfaces are assumed to be there for some
reason and not stem from libvirt.

In the VM shutdown path, it's assuming that an interface name is always
available so that if the device type is DIRECT it can be torn down
using its name.

* src/util/macvtap.h src/libvirt_macvtap.syms: change of deleting routine
* src/util/macvtap.c: cleanups and change of deleting routine
* src/qemu/qemu_driver.c: change cleanup on shutdown
* src/qemu/qemu_conf.c: don't delete Macvtap in qemudPhysIfaceConnect()
2010-02-18 15:13:48 +01:00
Daniel P. Berrange
6fe15e357d Update QEMU JSON balloon command handling
The QEMU JSON monitor changed balloon commands to return/accept
bytes instead of kilobytes. Update libvirt to cope with this

* src/qemu/qemu_monitor_json.c: Expect/use bytes for ballooning
2010-02-18 11:17:14 +00:00
Jim Meyering
294adef356 openvzLoadDomains: don't ignore failing virUUIDFormat
* src/openvz/openvz_conf.c (openvzLoadDomains): Diagnose failure of
virUUIDFormat.
2010-02-18 07:57:31 +01:00
Jim Meyering
7ac2787019 qemuMonitorTextAddUSBDisk: avoid unconditional leak
* src/qemu/qemu_monitor_text.c (qemuMonitorTextAddUSBDisk): Free
command output buffer.
2010-02-16 18:09:13 +01:00
Jim Meyering
309647c81f qemuInitPasswords: avoid unconditional leak
* src/qemu/qemu_driver.c (qemuInitPasswords): Free pass-phrase buffer.
2010-02-16 18:09:13 +01:00
Jim Meyering
bc6a48c6cf qemuMonitorTextAddDevice: avoid unconditional leak
* src/qemu/qemu_monitor_text.c (qemuMonitorTextAddDevice): Free the
device name buffer.
2010-02-16 17:49:05 +01:00
Jim Meyering
dc03ae2c6d vboxDomainDumpXML: avoid a leak on OOM error path
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML): Free vboxCallback buffer
upon OOM.
2010-02-16 17:49:05 +01:00
Jim Meyering
e977f471f1 virNodeDevCapScsiHostParseXML: avoid an unconditional leak
* src/conf/node_device_conf.c (virNodeDevCapScsiHostParseXML):
Free the "nodes" buffer allocated by virXPathNodeSet.
2010-02-16 17:49:05 +01:00
Jim Meyering
59467601c2 uml_driver.c: avoid leak upon failure
* src/uml/uml_driver.c (umlMonitorCommand): This function would
sometimes return -1, yet fail to free the "reply" it had allocated.
Hence, no caller would know to free the corresponding argument.
When returning -1, be sure to free all allocated resources.
2010-02-16 17:49:05 +01:00
Jim Meyering
4a3d1ca3f1 vbox_tmpl.c: avoid an unconditional leak
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML): Free def.
Improved by Matthias Bolte.
2010-02-16 17:49:05 +01:00
Jim Meyering
55e642e586 openvz (openvzFreeDriver): avoid leaks
* src/openvz/openvz_conf.c (openvzFreeDriver): Also free driver buffer.
Based on a suggestion from Matthias Bolte.
2010-02-16 17:49:05 +01:00
Jim Meyering
d15a67fa56 virStorageBackendIsMultipath: avoid dead store
* src/storage/storage_backend_mpath.c (virStorageBackendIsMultipath):
The result of dm_get_next_target was never used (and isn't needed),
so don't store it.
2010-02-16 17:49:05 +01:00
Cole Robinson
8c38b5dc2e qemu: Make SetVcpu command hotplug only
Similar to the Set*Mem commands, this implementation was bogus and
misleading. Make it clear this is a hotplug only operation, and that the
hotplug piece isn't even implemented.

Also drop the overkill maxvcpus validation: we don't perform this check
at XML define time so clearly no one is missing it, and there is
always the risk that our info will be out of date, possibly preventing
legitimate CPU values.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2010-02-16 11:10:40 -05:00
Cole Robinson
09a33fd8a9 qemu: Make Set*Mem commands hotplug only
SetMem and SetMaxMem are hotplug only APIs, any persistent config
changes are supposed to go via XML definition. The original implementation
of these calls were incorrect and had the nasty side effect of making
a psuedo persistent change that would be lost after libvirtd restart
(I didn't know any better).

Fix these APIs to rightly reject non running domains.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2010-02-16 11:10:40 -05:00
Daniel P. Berrange
535db41be8 Treat missing QEMU 'thread_id' as non-fatal in JSON monitor
The plain QEMU tree does not include 'thread_id' in the JSON
output. Thus we need to treat it as non-fatal if missing.

* src/qemu/qemu_monitor_json.c: Treat missing thread_id as non-fatal
2010-02-16 14:33:34 +00:00
Daniel P. Berrange
9ab3fac841 Fix check for primary IDE controller in QEMU PCI slot assignment
A typo in the check for the primary IDE controller could cause
a crash on restore depending on the exact guest config.

* src/qemu/qemu_conf.c: Fix s/video/controller/ typo & slot
  number typo
2010-02-16 14:33:29 +00:00
Daniel P. Berrange
b6b8009548 Make error reporting for QEMU JSON mode more friendly
Current error reporting for JSON mode returns the full JSON
command string and full JSON error string. This is not very
user friendly, so this change makes the error report only
contain the basic command name, and friendly error message
description string. The full JSON data is logged instead.

* src/qemu/qemu_monitor_json.c: Always return the 'desc' field from
  the JSON error message to users.
2010-02-16 14:33:23 +00:00
Daniel P. Berrange
5d72a89442 Run 'qmp_capabilities' command at QEMU monitor startup
When in JSON mode, QEMU requires that 'qmp_capabilities' is run as
the first command in the monitor. This is a no-op when run in the
text mode monitor

* src/qemu/qemu_driver.c: Run capabilities negotiation when
  connecting to the monitor
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h: Add
  support for the 'qmp_capabilities' command, no-op in text mode.
2010-02-16 14:21:25 +00:00
Stefan Berger
a1b1ab1478 macvtap support for libvirt -- qemu support
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.
* src/qemu/qemu_conf.[ch] src/qemu/qemu_driver.c: add support in the
  QEmu driver
2010-02-15 17:47:29 +01:00
Stefan Berger
315baab944 macvtap support for libvirt -- helper code
This part adds the helper code to setup and tear down macvtap devices
using direct communication with the device driver via netlink sockets.
The rather short messages received from the netlink layer are now
written into a dynamically allocated buffer

* src/util/macvtap.h src/util/macvtap.c: provides the new module
* po/POTFILES.in: the module contains translated strings
2010-02-15 17:47:29 +01:00
Stefan Berger
78d1ee295d macvtap support for libvirt -- parse new interface XML
This part adds support to domain_conf.{c|h} for parsing the new
interface XML of type 'direct'. The parsed mode is now stored as
an int.
* src/conf/domain_conf.c src/conf/domain_conf.h: extend parsing code
* src/util/macvtap.h: empty header to not break compilation
2010-02-15 17:47:28 +01:00
Stefan Berger
fd5091db5f macvtap support for libvirt -- build support
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.
* configure.ac src/Makefile.am: new build support
* src/libvirt_macvtap.syms: list of exported symbols
* src/util/macvtap.c: empty module to not break compilation
2010-02-15 17:47:28 +01:00
Matthias Bolte
4b75e4df27 interface: Use proper return codes in the open function
The open function returned -1 in case of an error, but -1 maps
to VIR_DRV_OPEN_DECLINED instead of VIR_DRV_OPEN_ERROR.
2010-02-15 10:59:43 +01:00
Matthias Bolte
cad2a4caed Convert virSecurityReportError into a macro
The virRaiseError macro inside of virSecurityReportError expands to
virRaiseErrorFull and includes the __FILE__, __FUNCTION__ and __LINE__
information. But this three values are always the same for every call
to virSecurityReportError and do not reflect the actual error context.

Converting virSecurityReportError into a macro results in getting the
correct __FILE__, __FUNCTION__ and __LINE__ information.
2010-02-15 10:45:25 +01:00
Daniel P. Berrange
141dea6bc7 Add persistence of PCI addresses to QEMU
Current PCI addresses are allocated at time of VM startup.
To make them truely persistent, it is neccessary to do this
at time of virDomainDefine/virDomainCreate. The code in
qemuStartVMDaemon still remains in order to cope with upgrades
from older libvirt releases

* src/qemu/qemu_driver.c: Rename existing qemuAssignPCIAddresses
  to qemuDetectPCIAddresses. Add new qemuAssignPCIAddresses which
  does auto-allocation upfront. Call qemuAssignPCIAddresses from
  qemuDomainDefine and qemuDomainCreate to assign PCI addresses that
  can then be persisted. Don't clear PCI addresses at shutdown if
  they are intended to be persistent
2010-02-12 17:25:52 +00:00
Daniel P. Berrange
658341189b Fix crash in LXC driver open method when URI has no path
If giving a lxc://  URI instead of lxc:/// the open method
would crash ona NULL pointer

* src/lxc/lxc_driver.c: Cope with a NULL URI path
2010-02-12 17:25:19 +00:00
Daniel P. Berrange
823a684f8d Fix USB device path formatting mixup
* src/util/hostusb.c: The device path for a USB device wants the
  bus/device IDs in decimal not octal
2010-02-12 17:25:12 +00:00
Daniel P. Berrange
c31a116b72 Support 'block_passwd' command for QEMU disk encryption
The old text mode monitor prompts for a password when disks are
encrypted. This interactive approach doesn't work for JSON mode
monitor. Thus there is a new 'block_passwd' command that can be
used.

* src/qemu/qemu_driver.c: Split out code for looking up a disk
  secret from findVolumeQcowPassphrase, into a new method
  getVolumeQcowPassphrase. Enhance qemuInitPasswords() to also
  set the disk encryption password via the monitor
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
  src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
  support for the 'block_passwd' monitor command.
2010-02-12 17:25:02 +00:00
Jiri Denemark
dfab48ac54 Implement cpuBaseline in remote and qemu drivers 2010-02-12 14:30:42 +01:00
Jiri Denemark
a3d22efd77 Wire protocol format and dispatcher for virConnectBaselineCPU 2010-02-12 14:27:20 +01:00
Jiri Denemark
387941fb62 virConnectBaselineCPU public API implementation 2010-02-12 14:25:39 +01:00
Jiri Denemark
53c05341d4 Internal driver API for virConnectBaselineCPU 2010-02-12 14:23:53 +01:00
Jiri Denemark
605542c330 virConnectBaselineCPU public API 2010-02-12 14:21:58 +01:00
Jiri Denemark
5130713ba1 Implement cpuArchBaseline in x86 CPU driver 2010-02-12 14:19:56 +01:00
Jiri Denemark
7b5ae2f077 Implement cpuArchBaseline in generic CPU driver 2010-02-12 14:18:21 +01:00
Jiri Denemark
388f3cb565 Functions for computing baseline CPU from a set of host CPUs
Baseline CPU is the best CPU which can be used for a guest on any of the
hosts.
2010-02-12 14:16:23 +01:00
Matthias Bolte
af7c18f7a2 Fix compliation of AppArmor related code
Broken by the latest commits to remove the virConnectPtr parameter
from internal functions.
2010-02-12 00:09:59 +01:00
Jim Meyering
618e1ab349 qemu_driver.c: honor dname parameter once again
Since c26cb9234f, the dname
parameter has been ignored by these two functions.  Use it.
* src/qemu/qemu_driver.c (qemudDomainMigratePrepareTunnel): Honor dname
parameter once again.
(qemudDomainMigratePrepare2): Likewise.
2010-02-11 17:22:56 +01:00
Jim Meyering
18e0cc7f72 plug four virStoragePoolSourceFree-related leaks
* src/conf/storage_conf.c (virStoragePoolDefParseSourceString):
* src/storage/storage_backend_fs.c:
(virStorageBackendFileSystemNetFindPoolSourcesFunc):
(virStorageBackendFileSystemNetFindPoolSources):
* src/test/test_driver.c (testStorageFindPoolSources):
2010-02-11 17:22:45 +01:00
Jim Meyering
b39ea45292 remote_driver.c: avoid leak on OOM error path
* src/remote/remote_driver.c (doRemoteOpen): Don't leak a qparam_set
buffer upon OOM error.
2010-02-11 16:59:52 +01:00
Jiri Denemark
b2149d03b9 Mark all error messages for translation
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-02-11 16:46:20 +01:00
Jiri Denemark
8efec111fc Swap position of nmodels and models parameters in cpuDecode()
All other libvirt functions use array first and then number of elements
in that array. Let's make cpuDecode follow this rule.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-02-11 16:46:20 +01:00
Chris Lalancette
6daa19da9a Fix up a misspelled comment.
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-02-11 09:02:24 -05:00
Daniel P. Berrange
7357975000 Fix disk stats retrieval with QEMU >= 0.12
With QEMU >= 0.12 the host and guest side of disks no longer have
the same naming convention. Specifically the host side will now
get a 'drive-' prefix added to its name. The 'info blockstats'
monitor command returns the host side name, so it is neccessary
to strip this off when looking up stats since libvirt stores the
guest side name !

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Move 'drive-' prefix
  string to a defined constant
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_text.c: Strip
  off 'drive-' prefix (if found) when looking up disk stats
2010-02-11 12:07:23 +00:00
Cole Robinson
d3024a2cce qemu: Increase guest startup timeout to 30 seconds
Currently the timeout for reading startup output is 3 seconds. If the
host is under any sort of load, we can easily trigger this. Lets bump
it to 30 seconds.

Since the polling loop checks to see if the process has died, we shouldn't
erroneously hit this timeout if qemu bombs (only if it is stuck in some
infinite loop).
2010-02-10 10:51:47 -05:00
Cole Robinson
b65490a312 qemu: Properly report a startup timeout error
The timeout errors were unconditionally being overwritten by the less
helpful 'unable to start guest' error.
2010-02-10 10:51:46 -05:00
Cole Robinson
80de0a8c40 test: Fake security driver support in capabilities
Having some value in capabilities helps testing this stuff in
virt-manager.
2010-02-10 10:51:46 -05:00
Daniel P. Berrange
38536d6f7f Annotate some virConnectPtr as mandatory non-null
Use the ATTRIBUTE_NONNULL annotation to mark some virConnectPtr
args as mandatory non-null so the compiler can warn of mistakes

* src/conf/domain_event.h: All virConnectPtr args must be non-null
* src/qemu/qemu_conf.h: qemudBuildCommandLine and
  qemudNetworkIfaceConnect() must be given non-null connection
* tests/qemuxml2argvtest.c: Provide a non-null (dummy) connection to
  qemudBuildCommandLine()
2010-02-10 13:33:06 +00:00
Daniel P. Berrange
c4dcf043ca Remove virConnectPtr from secret XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in secret_conf.{h,c} and update all callers to
match
2010-02-10 13:32:58 +00:00
Daniel P. Berrange
a70e599d80 Remove virConnectPtr from interface XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in interface_conf.{h,c} and update all callers to
match
2010-02-10 13:32:48 +00:00
Daniel P. Berrange
f430ddb624 Remove virConnectPtr from CPU XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in cpu_conf.{h,c} and update all callers to
match
2010-02-10 13:32:38 +00:00
Daniel P. Berrange
031366383a Remove virConnectPtr from storage APIs & driver
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in storage_conf.{h,c} and storage_encryption_conf.{h,c}
and update all callers to match
2010-02-10 13:32:11 +00:00
Daniel P. Berrange
99edc443e9 Remove virConnectPtr from all node device XML APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in node_device_conf.{h,c} and update all callers to
match
2010-02-10 13:32:01 +00:00
Daniel P. Berrange
0677e11125 Remove virConnectPtr from network XML APis
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in network_conf.{h,c} and update all callers to
match
2010-02-10 13:31:28 +00:00
Daniel P. Berrange
ce71b8654d Remove virConnectPtr from USB/PCI device iterators
All callers now pass a NULL virConnectPtr into the USB/PCi device
iterator functions. Therefore the virConnectPtr arg can now be
removed from these functions

* src/util/hostusb.h, src/util/hostusb.c: Remove virConnectPtr
  from usbDeviceFileIterate
* src/util/pci.c, src/util/pci.h: Remove virConnectPtr arg from
  pciDeviceFileIterate
* src/qemu/qemu_security_dac.c, src/security/security_selinux.c: Update
  to drop redundant virConnectPtr arg
2010-02-10 13:29:57 +00:00
Daniel P. Berrange
9f013d5779 Fix generation of floppy disk arg for QEMU's -global arg
* src/qemu/qemu_conf.c: Fix ',' vs '.' typo in floppy disk arg
2010-02-10 12:51:53 +00:00
Daniel P. Berrange
910b019f93 Convert qemu command line flags to 64-bit int
The QEMU flags are commonly stored as a signed or unsigned int,
allowing only 31 flags. This limit is rather close, so to aid
future patches, change it to a 64-bit int

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h, src/qemu/qemu_driver.c,
  tests/qemuargv2xmltest.c, tests/qemuhelptest.c, tests/qemuxml2argvtest.c:
  Use 'unsigned long long' for QEMU flags
2010-02-10 12:09:41 +00:00
Daniel P. Berrange
d6126f764f Remove use of virConnectPtr from security driver APIs
The virConnectPtr is no longer required for error reporting since
that is recorded in a thread local. Remove use of virConnectPtr
from all APIs in security_driver.{h,c} and update all callers to
match
2010-02-10 11:49:24 +00:00
Daniel P. Berrange
65842bf669 Remove virConnectPtr from all domain XML parsing/formatting APIs 2010-02-10 11:49:23 +00:00
Daniel P. Berrange
c39554bf49 Remove virConnectPtr from LXC driver 2010-02-10 11:49:23 +00:00
Daniel P. Berrange
caa805ea64 Remove passing of virConnectPtr throughout QEMU driver 2010-02-10 11:49:23 +00:00
Daniel P. Berrange
d47ef780f2 Fix security driver configuration
The security driver was mistakenly initialized before the QEMU
config file was loaded. This prevents it being turned off again.
The capabilities XML was also getting the wrong security driver
name, due to the stacked driver arrangement.

* src/qemu/qemu_driver.c: Fix initialization order and capabilities
  model name
2010-02-10 11:49:23 +00:00
Jim Meyering
658952a38a virAsprintf: remove its warn_unused_result attribute
* src/util/util.h (virAsprintf): Remove ATTRIBUTE_RETURN_CHECK, since
it is perfectly fine to ignore the return value, now that the pointer
is guaranteed to be set to NULL upon failure.
* src/util/storage_file.c (absolutePathFromBaseFile): Remove now-
unnecessary use of ignore_value.
2010-02-10 12:30:13 +01:00
Jim Meyering
e3042683bd absolutePathFromBaseFile: avoid an unnecessary use of assert
* src/util/storage_file.c (absolutePathFromBaseFile): While this use
of virAsprintf is slightly cleaner than using stpncpy(stpcpy(...,
it does impose an artificial limitation on the length of the base_file
name.  Rather than asserting that it does not exceed INT_MAX, return
NULL when it does.
2010-02-10 12:30:09 +01:00
Daniel Veillard
69cf62adac Escape strings serialized in XML
* src/conf/node_device_conf.c: string saved into XML should be escaped
  with the use of virBufferEscapeString()
2010-02-10 10:23:30 +01:00
Jiri Denemark
a82a87f26b Create raw storage files with O_DSYNC
When creating preallocated large raw files opening them with O_DSYNC
prevents long delays in reading because cache pages can be immediately
reused without writing them on a disk first.
2010-02-09 16:51:15 +01:00
Daniel P. Berrange
5dee786d7b Re-generate remote protocol files for new APIs
Re-generate remote protocol files for changes in commit
daeb6f6b40

* daemon/remote_dispatch_args.h, daemon/remote_dispatch_prototypes.h,
  daemon/remote_dispatch_table.h, src/remote/remote_protocol.c,
  src/remote/remote_protocol.h: Re-generate files
2010-02-09 12:09:05 +00:00
Matthias Bolte
314ced3951 Remove conn parameter from USB functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
46ef463135 Remove conn parameter from JSON error macro 2010-02-09 01:04:55 +01:00
Matthias Bolte
9140756d30 Remove conn parameter from PCI functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
0a5befc4c0 Remove conn parameter from Linux stats functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
fe46a7e686 Remove conn parameter from storage file functions
It was used for error reporting only.
2010-02-09 01:04:55 +01:00
Matthias Bolte
f972dc2d5c Remove conn parameter from util functions
It was used for error reporting only.
2010-02-09 01:04:54 +01:00
Matthias Bolte
d5c6183def Remove conn parameter from virXPath* functions
It was used for error reporting only.
2010-02-09 01:04:54 +01:00
Matthias Bolte
a5ab900d26 Remove conn parameter from virReportSystemError 2010-02-09 01:04:54 +01:00
Matthias Bolte
8ce5e2c1ab Remove conn parameter from virReportOOMError 2010-02-09 01:04:54 +01:00
Jim Fehlig
ed9c14a7ef domain{Attach,Detach}DeviceFlags handler for drivers
Implementation of domain{Attach,Detach}DeviceFlags handlers
in the drivers.
2010-02-08 10:49:43 -07:00
Jim Fehlig
906b1650b5 Remote driver
Implementation of Domain{Attach,Detach}DeviceFlags in remote driver.
2010-02-08 10:49:43 -07:00
Jim Fehlig
daeb6f6b40 Wire protocol format
Definition of wire protocol format for
virDomain{Attach,Detach}DeviceFlags.
2010-02-08 10:49:43 -07:00
Jim Fehlig
343205d705 Public API Implementation
Implementation of public API for virDomain{Attach,Detach}DeviceFlags.

V2: Don't break remote compatibility with older libvirtd
2010-02-08 10:49:43 -07:00
Jim Fehlig
79ad308781 Internal API
Definition of internal API for virDomain{Attach,Detach}DeviceFlags.
2010-02-08 10:49:42 -07:00
Jim Fehlig
314190a0ad Public API
Definition of public API for virDomain{Attach,Detach}DeviceFlags.

V2: Adjust libvrt_public.syms to anticipated 0.7.7 release.
2010-02-08 10:48:16 -07:00
Jim Fehlig
f0ea7ab328 doc: restrict virDomain{Attach,Detach}Device to active domains
virDomain{Attach,Detach}Device is now only permitted on active
domains.  Explicitly state this restriction in the API
documentation.

V2: Only change doc, dropping the hunk that forced the restriction
    in libvirt frontend.
2010-02-08 10:28:21 -07:00
Jim Meyering
c3e73528f1 (absolutePathFromBaseFile): fix up preceding commit
When configured with --enable-gcc-warnings, it didn't even compile.
* src/util/storage_file.c: Include <assert.h>.
(absolutePathFromBaseFile): Assert that converting size_t to int is valid.
Reverse length/string args to match "%.*s".
Explicitly ignore the return value of virAsprintf.
2010-02-05 15:07:17 +01:00
Jim Meyering
53b7dae139 absolutePathFromBaseFile: don't leak when first arg contains no "/"
* src/util/storage_file.c: Include "dirname.h".
(absolutePathFromBaseFile): Rewrite not to leak, and to require
fewer allocations.
* bootstrap (modules): Add dirname-lgpl.
* .gnulib: Update submodule to the latest.
2010-02-05 12:31:55 +01:00
Jim Meyering
a7e80e6bfd sexpr_string: avoid leak on OOM error path
* src/xen/sexpr.c (sexpr_string): Free sexpr buffer upon allocation
failure.
2010-02-05 09:36:09 +01:00
Jim Meyering
04ebf058d5 virDomainChrDefParseXML: don't leak upon invalid input
* src/conf/domain_conf.c (virDomainChrDefParseXML): Don't leak a
virDomainChrDef buffer upon "unknown target type for char device" error.
2010-02-04 20:00:07 +01:00
Jim Meyering
6eed3feafb virExecWithHook: avoid leak on OOM error path
* src/util/util.c (virExecWithHook): Free argv_str string before
returning upon failure to allocate space for environment.
2010-02-04 20:00:07 +01:00
Jim Meyering
fd10c4e1ee cgroup.c: don't leak mem+FD upon OOM
* src/util/cgroup.c (virCgroupDetectPlacement): Close the mapping
FILE* also upon error.
2010-02-04 20:00:07 +01:00
Jim Meyering
a16a96942d cgroup.c: avoid unconditional leaks
* src/util/cgroup.c (virCgroupCpuSetInherit) [HAVE_MNTENT_H]:
Don't leak CPU-set inheritance value strings.
2010-02-04 20:00:07 +01:00
Matthias Bolte
bfc34dca3b storage: Replace storageLog with VIR_ERROR 2010-02-04 19:09:28 +01:00
Matthias Bolte
3ed42b0098 opennebula: Remove unnecessary casts 2010-02-04 19:09:28 +01:00
Matthias Bolte
af25361762 esx: Remove unnecessary casts 2010-02-04 19:09:28 +01:00
Matthias Bolte
376b311deb cpu conf: Use virBufferFreeAndReset instead of virBufferContentAndReset and VIR_FREE 2010-02-04 19:09:28 +01:00
Matthias Bolte
a6b00cbb16 esx: Cleanup preprocessing structure in esxVI_EnsureSession 2010-02-04 19:09:28 +01:00
Daniel P. Berrange
83acdeaf17 Fix restore of QEMU guests with PCI device reservation
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
2010-02-03 16:45:26 +00:00
Laine Stump
730801d955 Another fork() log locking cleanup in file creation
Similar fix as previous one but for fork() usage when creating
a file or directory

* src/util/util.c: virLogLock() and virLogUnlock() around fork()
  in virFileCreate() and virDirCreateSimple()
2010-02-03 17:19:39 +01:00
Cole Robinson
cd0ef0e09b Fix log locking problem when using fork() in the library
Ad pointed out by Dan Berrange:
So if some thread in libvirtd is currently executing a logging call,
while another thread calls virExec(), that other thread no longer
exists in the child, but its lock is never released. So when the
child then does virLogReset() it deadlocks.

The only way I see to address this, is for the parent process to call
virLogLock(), immediately before fork(), and then virLogUnlock()
afterwards in both parent & child. This will ensure that no other
thread
can be holding the lock across fork().

* src/util/logging.[ch] src/libvirt_private.syms: export virLogLock() and
  virLogUnlock()
* src/util/util.c: lock just before forking and unlock just after - in
  both parent and child.
2010-02-03 17:12:57 +01:00
David Allan
8d42b9b4e8 Fix locking for udev device add/remove
The original udev node device backend neglected to lock the driverState
struct containing the device list when adding and removing devices
* src/node_device/node_device_udev.c: add necessary locks in
  udevRemoveOneDevice() and udevAddOneDevice()
2010-02-03 16:56:33 +01:00
Jim Meyering
fe1183a7cd interface_conf.c: don't use a negative value as allocation size
* src/conf/interface_conf.c (virInterfaceDefParseProtoIPv4): If
virXPathNodeSet returns -1, indicate failure by returning -1 right away.
(virInterfaceDefParseProtoIPv6): Likewise.
2010-02-03 15:47:04 +01:00
Jim Meyering
71c865f4d2 virStoragePoolSourceListNewSource: avoid unconditional leak
* src/conf/storage_conf.c (virStoragePoolSourceListNewSource):
Remove an unused (and leaked) allocation.
2010-02-03 15:46:59 +01:00
Jim Meyering
361e46d6d0 xs_internal.c: don't use a negative value as allocation size
* src/xen/xs_internal.c (xenStoreDomainIntroduced): Don't use -1
as an allocation size upon xenStoreNumOfDomains failure.
(xenStoreDomainReleased): Likewise.
2010-02-03 15:46:54 +01:00
Daniel P. Berrange
9120f00446 Ensure QEMU DAC security driver is activated at all times
If the primary security driver (SELinux/AppArmour) was disabled
then the secondary QEMU DAC security driver was also disabled.
This is mistaken, because the latter must be active at all times

* src/qemu/qemu_driver.c: Ensure DAC driver is always active
2010-02-02 19:14:31 +00:00
Jim Meyering
7efec25964 xen_hypervisor.c: remove all "domain == NULL" tests, ...
* src/xen/xen_hypervisor.c: Remove all "domain == NULL" tests.
* src/xen/xen_hypervisor.h: Instead, use ATTRIBUTE_NONNULL to
mark each "domain" parameter as "known always to be non-NULL".
2010-02-02 18:44:39 +01:00
Jim Meyering
b62bf7a700 xen_hypervisor.c: avoid NULL deref for NULL domain argument
* src/xen/xen_hypervisor.c (xenHypervisorGetVcpus): Don't attempt
to diagnose an unlikely NULL-domain or NULL-domain->conn error.
2010-02-02 18:44:32 +01:00
Daniel P. Berrange
23d6abd23b Tweak USB hostdevice XML handling
When attaching a USB host device based on vendor/product, libvirt
will resolve the vendor/product into a device/bus pair. This means
that when printing XML we should allow device/bus info to be printed
at any time if present

* src/conf/domain_conf.c, docs/schemas/domain.rng: Allow USB device
  bus info alongside vendor/product
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
719c50caf8 Fix QEMU hotplug device alias assignment
To allow devices to be hot(un-)plugged it is neccessary to ensure
they all have a unique device aliases. This fixes the hotplug
methods to assign device aliases before invoking the monitor
commands which need them

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Expose methods
  for assigning device aliases for disks, host devices and
  controllers
* src/qemu/qemu_driver.c: Assign device aliases when hotplugging
  all types of device
* tests/qemuxml2argvdata/qemuxml2argv-hostdev-pci-address-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-address-device.args:
  Update for changed hostdev naming scheme
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
db0b9e7d52 Disable QEMU monitor IO debugging by default 2010-02-02 16:31:47 +00:00
Daniel P. Berrange
16478459da Re-arrange QEMU device alias assignment code
This patch re-arranges the QEMU device alias assignment code to
make it easier to call into the same codeblock when performing
device hotplug. The new code has the ability to skip over already
assigned names to facilitate hotplug

* src/qemu/qemu_driver.c: Call qemuAssignDeviceNetAlias()
  instead of qemuAssignNetNames
* src/qemu/qemu_conf.h: Export qemuAssignDeviceNetAlias()
  instead of qemuAssignNetNames
* src/qemu/qemu_driver.c: Merge the legacy disk/network alias
  assignment code into the main methods
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
0943048ad0 Remove direct storage of hostnet_name & vlan
The current way of assigning names to the host network backend and
NIC device in QEMU was over complicated, by varying naming scheme
based on the NIC model and backend type. This simplifies the naming
to simply be 'net0' and 'hostnet0', allowing code to easily determine
the host network name and vlan based off the primary device alias
name 'net0'. This in turn allows removal of alot of QEMU specific
code from the XML parser, and makes it easier to assign new unique
names for NICs that are hotplugged

* src/conf/domain_conf.c, src/conf/domain_conf.h: Remove hostnet_name
  and vlan fields from virNetworkDefPtr
* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h, src/qemu/qemu_driver.c:
  Use a single network alias naming scheme regardless of NIC type
  or backend type. Determine VLANs from the alias name.
* tests/qemuxml2argvdata/qemuxml2argv-net-eth-names.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-device.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args: Update
  for new simpler naming scheme
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
49a0f6cd99 Remove use of -netdev arg with QEMU
The QEMU 0.12.x tree has the -netdev command line argument, but not
corresponding monitor command. We can't enable the former, without
the latter since it will break hotplug/unplug.

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Disable -netdev usage
  until 0.13 at earliest
* tests/qemuxml2argvtest.c: Add test for -netdev syntax
* tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.args,
  tests/qemuxml2argvdata/qemuxml2argv-net-virtio-netdev.xml: Test
  data files for -netdev syntax
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
d8acc44672 Assign PCI addresses before hotplugging devices
PCI disk, disk controllers, net devices and host devices need to
have PCI addresses assigned before they are hot-plugged

* src/qemu/qemu_conf.c: Add APIs for ensuring a device has an
  address and releasing unused addresses
* src/qemu/qemu_driver.c: Ensure all devices have addresses
  when hotplugging.
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
9258ec0a2e Rewrite way QEMU PCI addresses are allocated
The current QEMU code allocates PCI addresses incrementally starting
at 4. This is not satisfactory because the user may have given some
addresses in their XML config, which need to be skipped over when
allocating addresses to remaining devices.

It is thus neccessary to maintain a list of already allocated PCI
addresses and then only allocate ones that remain unused. This is
also required for domain device hotplug to work properly later.

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Add APIs for creating
  list of existing PCI addresses, and allocating new addresses.
  Refactor address assignment to use this code
* src/qemu/qemu_driver.c: Pull PCI address assignment up into the
  qemuStartVMDaemon() method, as a prelude to moving it into the
  'define' method. Update list of allocated addresses when connecting
  to a running VM at daemon startup.
* tests/qemuxml2argvtest.c, tests/qemuargv2xmltest.c,
  tests/qemuxml2xmltest.c: Remove USB product test since all
  passthrough is done based on address
* tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.args,
  tests/qemuxml2argvdata/qemuxml2argv-hostdev-usb-product.xml: Kil
  unused data files
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
3fdef8cfca Introduce generic virDomainDeviceInfo iterator function
The virDomainDeviceInfoIterate() function will provide a
convenient way to iterate over all devices in a domain.

* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/libvirt_private.syms: Add virDomainDeviceInfoIterate()
  function.
2010-02-02 16:31:47 +00:00
Daniel P. Berrange
264e98d6a8 Make hotplug use new device_add where possible
Since QEMU startup uses the new -device argument, the hotplug
code needs todo the same. This converts disk, network and
host device hotplug to use the device_add command

* src/qemu/qemu_driver.c: Use new device_add monitor APIs
  whereever possible
2010-02-02 16:31:46 +00:00
Daniel P. Berrange
5ec6cf7fb8 Introduce internal QEMU monitor APIs for drive + device hotadd
The way QEMU is started has been changed to use '-device' and
the new style '-drive' syntax. This needs to be mirrored in
the hotplug code, requiring addition of two new APIs.

* src/qemu/qemu_monitor.h, src/qemu/qemu_monitor.c: Define APIs
  qemuMonitorAddDevice() and qemuMonitorAddDrive()
* src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
  src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
  Implement the new monitor APIs
2010-02-02 16:31:42 +00:00
Daniel P. Berrange
96c8608dc5 Split out QEMU code for building PCI/USB hostdev arg values
To allow for better code reuse from hotplug methods, the code for
generating PCI/USB hostdev arg values is split out into separate
methods

* qemu/qemu_conf.h, qemu/qemu_conf.c: Introduce new APis for
  qemuBuildPCIHostdevPCIDevStr, qemuBuildUSBHostdevUsbDevStr
  and qemuBuildUSBHostdevDevStr
2010-02-02 15:41:29 +00:00
Daniel P. Berrange
c129d4fe45 Standard internal API syntax for building QEMU command line arguments
All the helper functions for building command line arguments
now return a 'char *', instead of acepting a 'char **' or
virBufferPtr argument

* qemu/qemu_conf.c: Standardize syntax for building args
* qemu/qemu_conf.h: Export all functions for building args
* qemu/qemu_driver.c: Update for changed syntax for building
  NIC/hostnet args
2010-02-02 15:41:25 +00:00
Jim Meyering
3db3acb94e storage_backend.c: avoid closing a negative file descriptor
* src/storage/storage_backend.c (virStorageBackendRunProgRegex):
Don't close a negative (read-only) file descriptor.
2010-02-02 12:07:19 +01:00
Jim Meyering
9344e6ad1a 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.
2010-02-02 10:35:52 +01:00
Matthias Bolte
33e25a3984 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.
2010-02-02 09:54:29 +01:00
Jim Meyering
c16888a849 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.
2010-02-01 22:19:15 +01:00
Jim Meyering
1cb334efba json.c: avoid an unconditional leak from most qemuMonitorJSON* functions
* src/util/json.c (virJSONValueFree): Free the "value" pointer, too.
2010-02-01 19:48:34 +01:00
Jim Meyering
4cd188d4d5 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.
2010-02-01 18:25:23 +01:00
Eric Blake
6b8d8395b6 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.
2010-02-01 17:21:26 +01:00
Jiri Denemark
1e44c678fa Move models/nmodels mismatch checking one level up
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2010-02-01 17:20:27 +01:00
Jiri Denemark
0ea0128904 Log flags in virConnectCompareCPU
* src/libvirt.c: extend the debug statement to log flags too
2010-02-01 16:23:41 +01:00
Chris Lalancette
29727bacd7 Fix PCI host reattach on domain detach.
Similar to the race fixed by
be34c3c7ef, 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>
2010-02-01 10:14:39 -05:00
Matthew Booth
09080c38d1 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.
2010-02-01 16:08:36 +01:00
Chris Lalancette
62a30a496a Fix up a comment in virHashUpdateEntry
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-02-01 09:39:54 -05:00
Chris Lalancette
b16cd226a2 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>
2010-02-01 09:39:42 -05:00
Jim Meyering
5ec55b4ff0 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.
2010-01-29 21:43:02 +01:00
Jim Fehlig
3bd3d6b0bf 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.
2010-01-27 10:56:18 -07:00
Jim Meyering
3970a2dc86 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.
2010-01-27 13:39:58 +01:00
Jim Meyering
b74aadb3e5 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.
2010-01-27 13:39:46 +01:00
Jim Meyering
950176ec65 pci.c: correct an erroneous expression
* src/util/pci.c (pciDeviceDownstreamLacksACS): Fix a typo
that rendered a subexpression always false.
2010-01-27 08:10:06 +01:00
Matthias Bolte
227f26afdb udev: Set the state driver name 2010-01-26 21:23:18 +01:00
Matthias Bolte
0cdb9a5cfc Remove undefined symbols from libvirt_private.syms 2010-01-26 21:23:18 +01:00
Matthias Bolte
d115ed59e0 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.
2010-01-26 21:23:18 +01:00
Matthias Bolte
ef088ed962 esx: Output error details from libcurl 2010-01-26 21:23:18 +01:00
Matthias Bolte
594ac31b2d Add missing function parameter documentation 2010-01-26 21:23:18 +01:00
Jim Meyering
fb54230b60 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.
2010-01-26 16:11:45 +01:00
Laine Stump
ba1d379ce8 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
2010-01-26 14:48:21 +01:00
Matthias Bolte
854111f97e esx: Stop passing around virConnectPtr for error reporting 2010-01-26 01:19:23 +01:00
Chris Lalancette
9757e10d6d Revert "Fix libvirtd restart for domains with PCI passthrough devices"
This reverts commit cdc42d0a48.
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>
2010-01-25 16:26:54 -05:00
Chris Lalancette
7cc5410bfd 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>
2010-01-25 16:25:47 -05:00
Chris Lalancette
a7d17c6187 Fix two instances of misspelled 'pseudo'
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-01-25 16:25:28 -05:00
Jim Meyering
1af75828a0 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.
2010-01-25 22:06:47 +01:00
Matthias Bolte
731c738652 qemu: Search binaries in PATH instead of hardcoding /usr/bin 2010-01-25 21:38:28 +01:00
Daniel P. Berrange
72a8405a47 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
2010-01-25 17:08:37 +00:00
Daniel P. Berrange
2c7f5ca662 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'.
2010-01-25 17:08:37 +00:00
Daniel P. Berrange
a5a46c6fc2 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>
2010-01-25 17:08:37 +00:00
Daniel P. Berrange
7d8f5eb3bc 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
2010-01-25 17:08:37 +00:00
Jim Meyering
3dc4268669 usbGetDevice: don't leak a "usbDevice" buffer on failure path
* src/util/hostusb.c (usbGetDevice): Free "dev" when returning NULL.
2010-01-25 17:07:06 +01:00
Jim Meyering
9827e0a42c qemuMonitorTextGetMemoryStats: plug a leak on an error path
* src/qemu/qemu_monitor_text.c (qemuMonitorCommandWithHandler):
Always free *reply, upon failure.
2010-01-25 17:04:27 +01:00
Jim Meyering
1f9da29de1 usbFindBusByVendor: don't leak a DIR buffer and FD
* src/util/hostusb.c (usbFindBusByVendor): Don't leak a DIR buffer
and file descriptor.
2010-01-25 16:50:28 +01:00
Chris Lalancette
cdc42d0a48 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()
2010-01-22 18:39:15 +01:00
Chris Lalancette
be34c3c7ef 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>
2010-01-22 12:03:49 -05:00
Chris Lalancette
654dd2902d 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>
2010-01-22 09:42:45 -05:00
Chris Lalancette
b195f20f18 Use virFileResolveLink instead of readlink in AppArmor
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-01-22 09:38:22 -05:00
Chris Lalancette
1f703731d3 Fix a compile warning in parthelper.c
Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-01-22 09:37:09 -05:00
Jamie Strandboge
e09086b074 Remove AppArmor compile warnings
* src/security/security_apparmor.c: unused variable in
  AppArmorSetSecurityAllLabel and unused parameter in
  AppArmorReleaseSecurityLabel
2010-01-22 10:48:34 +01:00
Chris Lalancette
db2ae2044a Remove unused PROC_MOUNT_BUF_LEN #define 2010-01-22 10:25:44 +01:00
Adam Litke
80b4d20dfe 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 ','
2010-01-21 16:28:50 +01:00
David Allan
2dccf5ef07 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
2010-01-21 15:55:13 +01:00
Daniel Veillard
e5df24a11c 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
2010-01-21 15:45:44 +01:00
Dan Kenigsberg
ca18b7108d Allow surrounding whitespace in uuid
* src/util/uuid.c: extend virUUIDParse to allow leading and trailing
  spaces in UUIDs
2010-01-21 15:32:37 +01:00
Jim Meyering
d47b6e54fd avoid more format-related warnings
* src/qemu/qemu_conf.c (qemuBuildDriveStr): Use "%s".
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetGuestPCIAddress):
(qemuMonitorJSONGetGuestDriveAddress): Likewise.
2010-01-21 15:12:12 +01:00
Jim Meyering
dfff67c082 avoid format-related warnings
* src/conf/domain_conf.c (virDomainDeviceInfoParseXML): Use "%s".
2010-01-21 15:08:25 +01:00
Daniel P. Berrange
6512d09cf8 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
2010-01-21 14:00:17 +00:00
Daniel P. Berrange
e3a0c80f1d 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.
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
5b6782f941 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
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
2df1657686 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
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
b2a2ba71b4 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
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
3812c7b42d 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
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
15f5eaa098 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
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
80fd73ca09 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
2010-01-21 14:00:16 +00:00
Daniel P. Berrange
08fd20b04a 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
2010-01-21 14:00:16 +00:00