Commit Graph

5366 Commits

Author SHA1 Message Date
Cole Robinson
a7e2dd1c32 lxc: controller: Improve container error reporting
Add a handshake with the cloned container process to try and detect
if it fails to start.
2011-06-07 14:38:54 -04:00
Cole Robinson
965a957ccc lxc: Improve guest startup error reporting
Add a simple handshake with the lxc_controller process so we can detect
process startup failures. We do this by adding a new --handshake cli arg
to lxc_controller for passing a file descriptor. If the process fails to
launch, we scrape all output from the logfile and report it to the user.
2011-06-07 14:38:39 -04:00
Cole Robinson
af1e180f48 lxc: Refactor controller command building
Arranges things similar to the qemu driver. Will allow us to more easily
report command error output.
2011-06-07 14:36:38 -04:00
Cole Robinson
6973594ca8 lxc: Don't report error in Wait/SendContinue
We will reuse these shortly, and each use should have a different error
message.
2011-06-07 14:32:03 -04:00
Cole Robinson
eee1763c8c lxc: Drop container stdio as late as possible
Makes it more likely we get useful error output in the logs
2011-06-07 14:32:03 -04:00
Cole Robinson
02e86910e2 Move virRun, virExec*, virFork to util/command
Seems reasonable to have all command wrappers in the same place

v2:
    Dont move SetInherit

v3:
    Comment spelling fix
    Adjust WARN0 comment
    Remove spurious #include movement
    Don't include sys/types.h
    Combine virExec enums

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2011-06-07 14:06:11 -04:00
Cole Robinson
3c269b51a6 util: Implement virRun as a wrapper around virCommand
v2:
    Simplify command building
    Handle command building failure

v3:
    Remove unneeded NULL check

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2011-06-07 11:24:52 -04:00
Cole Robinson
d886ed9597 util: Remove unused virExec wrapper
v3:
    Remove obsolete comment

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2011-06-07 11:12:58 -04:00
Cole Robinson
1ba75cf9aa qemu: Convert virExec usage to virCommand
v2:
    Have virCommand cleanup intermediate process for us

v3:
    Preserve original FD closing behavior

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2011-06-07 11:11:02 -04:00
Matthias Bolte
0068b58c71 esx: Remove duplicated invalid-argument checks
Those checks are already performed at the public API level.
2011-06-07 15:21:47 +02:00
Osier Yang
ebf6b11ac1 Use VIR_USE_CPU instead of new wheel 2011-06-07 16:51:51 +08:00
Matthias Bolte
b10bca09f9 Avoid virGetVersion failure on specific driver support configurations
virGetVersion itself doesn't take a virConnectPtr, but in order to obtain
the hypervisor version against which libvirt was compiled it is used in
combination with virConnectGetType like this:

hvType = virConnectGetType(conn)
virGetVersion(&libVer, hvType, &typeVer)

When virConnectGetType is called on a remote connection then the remote
driver returns the type of the underlying driver on the server side, for
example QEMU. Then virGetVersion compares hvType to a set of strings that
depend on configure options and returns LIBVIR_VERSION_NUMBER in most
cases. Now this fails in case libvirt on the client side is just compiled
with the remote driver enabled only and the server side has the actual
driver such as the QEMU driver. It just happens to work when the actual
driver is enabled on client and server side. But that's not always true.
I noticed this on FreeBSD:

freebsd# virsh -c qemu+tcp://192.168.178.22/system version
Compiled against library: libvir 0.9.2
error: failed to get the library version
error: this function is not supported by the connection driver: virGetVersion

This is not FreeBSD specific, happens on Windows as well due to the
similar driver support configuration. The problem is that virConnectGetType
returns QEMU, but virGetVersion on the client side only accepts Remote
as hvType due to all other drivers being disabled on the client side.

Daniel P. Berrange suggested to get rid of all the conditional code in
virGetVersion, ignoring the hvType and always setting typeVer to
LIBVIR_VERSION_NUMBER. virConnectGetVersion is supposed to be used to
obtain the hypervisor version.
2011-06-07 09:41:35 +02:00
Matthias Bolte
4bf1f33b7e docs: Make hvsupport.pl pick up the host device drivers
Annotate the ESX device driver dummy.

Refactor the udev and hal device driver strcuts to match the
common annotation pattern.
2011-06-06 10:45:59 +02:00
Matthias Bolte
33cb519417 esx: Fix driver method version annotations
Change the driver comments for proper extraction and values by
the scripts used for documentation
2011-06-06 11:08:06 +08:00
Daniel P. Berrange
3e87a3901a Fix QEMU p2p v2 migration when run from a v3 client
When peer-2-peer migration was invoked by a client supporting
v3, but where the target server only supported v2, we'd not
correctly shutdown the guest.

* src/qemu/qemu_migration.c: Ensure guest is shutdown in
  v2 peer 2 peer migration
2011-06-06 11:05:34 +08:00
Matthias Bolte
cc79a4c52e vbox: Fix typo in error message 2011-06-04 22:41:49 +02:00
Daniel P. Berrange
a50f5f6faa Don't raise an error if the migration cookie is NULL
The v2 migration protocol doesn't use cookies, so we should not
be raising an error if the cookie parameters are NULL.

* src/qemu/qemu_migration.c: Don't raise error if cookie is NULL
2011-06-04 07:26:32 -04:00
Daniel P. Berrange
a018c0b910 Fix check of virKillProcess return status
The error code for virKillProcess is returned in the errno variable
not the return value. THis mistake caused the logs to be filled with
errors when shutting down QEMU processes

* src/qemu/qemu_process.c: Fix process kill check.
2011-06-04 07:26:07 -04:00
Matthias Bolte
eb2664cbe6 vbox: Fix version extraction on Windows for newer VirtualBox versions
VirtualBox 4.0.8 changed the registry key layout. Before the version
number was in a Version key. Now the Version key contains %VER% and
the actual version number is in VersionExt now.

Move value lookup code into its own function: vboxLookupRegistryValue.
2011-06-04 10:50:36 +02:00
Eric Blake
33d90bafe7 API: consolidate common unreleased enums
This commit is safe precisely because there has been no release
for any of the enum values being deleted (they were added post-0.9.1).

After the 0.9.2 release, we can then take advantage of
virDomainModificationImpact in more places.

* include/libvirt/libvirt.h.in (virDomainModificationImpact): New
enum.
(virDomainSchedParameterFlags, virMemoryParamFlags): Delete, since
these were never released, and the new enum works fine here.
* src/libvirt.c	(virDomainGetMemoryParameters)
(virDomainSetMemoryParameters)
(virDomainGetSchedulerParametersFlags)
(virDomainSetSchedulerParametersFlags): Update documentation.
* src/qemu/qemu_driver.c (qemuDomainSetMemoryParameters)
(qemuDomainGetMemoryParameters, qemuSetSchedulerParametersFlags)
(qemuSetSchedulerParameters, qemuGetSchedulerParametersFlags)
(qemuGetSchedulerParameters): Adjust clients.
* tools/virsh.c (cmdSchedinfo, cmdMemtune): Likewise.
Based on ideas by Daniel Veillard and Hu Tao.
2011-06-04 09:58:53 +02:00
Jiri Denemark
aeed51f775 qemu: Avoid use after free in qemuCaps parsing 2011-06-03 19:58:43 +02:00
Laine Stump
62ed801c13 security driver: ignore EINVAL when chowning an image file
This fixes:

  https://bugzilla.redhat.com/show_bug.cgi?id=702044
  https://bugzilla.redhat.com/show_bug.cgi?id=709454

Both of these complain of a failure to use an image file that resides
on a read-only NFS volume. The function in the DAC security driver
that chowns image files to the qemu user:group before using them
already has special cases to ignore failure of chown on read-only file
systems, and in a few other cases, but it hadn't been checking for
EINVAL, which is what is returned if the qemu user doesn't even exist
on the NFS server.

Since the explanation of EINVAL in the chown man page almost exactly
matches the log message already present for the case of EOPNOTSUPP,
I've just added EINVAL to that same conditional.
2011-06-03 12:27:05 -04:00
Matthias Bolte
6b5c589d84 Make dlopen usage in lock manager conditional
This fixes a build failure on MinGW, due to MinGW not supporting dlopen.
2011-06-03 16:46:09 +02:00
Eric Blake
32ce66f5ea build: silence coverity false positive
Coverity couldn't see that priv is NULL on failure.  But on failure,
we might as well guarantee that callers don't try to free uninitialized
memory.

* src/remote/remote_driver.c (remoteGenericOpen): Even on failure,
pass priv back to caller.
2011-06-03 08:23:32 -06:00
Eric Blake
89e651fa76 build: silence coverity false positive
Coverity complained that infd could be -1 at the point where it is
passed to write, when in reality, this code can only be reached if
infd is non-negative.

* src/util/command.c (virCommandProcessIO): Help out coverity.
2011-06-03 08:23:29 -06:00
Eric Blake
d391661ae4 migrate: detect xml incompatibility
Detected by Coverity.  Bug introduced in 08106e2044 (unreleased).

* src/conf/domain_conf.c (virDomainChannelDefCheckABIStability):
Use correct sizeof operand.
2011-06-03 08:23:28 -06:00
Eric Blake
278a050a52 event: avoid memory leak on cleanup
Detected by Coverity.  Introduced in commit aaf2b70, and turned into
a regression in the next few commits through 4e6e6672 (unreleased).

* src/conf/domain_event.c (virDomainEventStateFree): Free object,
per documentation.
2011-06-03 08:11:43 -06:00
Eric Blake
2834d57175 qemu: avoid memory leak on vcpupin
Detected by Coverity.  This leaked a cpumap on every iteration
of the loop.  Leak introduced in commit 1cc4d02 (v0.9.0).

* src/qemu/qemu_process.c (qemuProcessSetVcpuAffinites): Plug
leak, and hoist allocation outside loop.
2011-06-03 08:11:43 -06:00
Eric Blake
0a41733c13 lock: avoid leak on failure
Detected by Coverity.  Only possible on OOM situations.

* src/locking/lock_manager.c (virLockManagerPluginNew): Plug leak.
2011-06-03 08:11:43 -06:00
Eric Blake
f515bab78d storage: avoid memory leak on stat failure
Spotted by coverity.  Triggers on failed stat, although I'm not sure
how easy that condition is, so I'm not sure if this is a runtime
memory hog.  Regression introduced in commit 8077d64 (unreleased).

* src/util/storage_file.c (virStorageFileGetMetadataFromFD):
Reduce need for malloc, avoiding a leak.
2011-06-03 08:11:42 -06:00
Eric Blake
9892f7bca0 storage: avoid memory leak
Coverity detected that options was being set by strdup but never
freed.  But why even bother with an options variable?  The options
parameter never changes!  Leak present since commit 44948f5b (0.7.0).

This function could probably be rewritten to take better advantage
of virCommand, but that is more invasive.

* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemMount): Avoid wasted strdup, and
guarantee proper cleanup on all paths.
2011-06-03 08:11:42 -06:00
Eric Blake
bb8895290c command: avoid leak on failure
Detected by Coverity.  While it is possible on OOM condition, as
well as with bad code that passes binary == NULL, it is unlikely
to be encountered in the wild.

* src/util/command.c (virCommandNewArgList): Don't leak memory.
2011-06-03 08:11:42 -06:00
Daniel P. Berrange
6d68e0df72 Explicitly set VM state to paused after migration completes
In v3 migration, once migration is completed, the VM needs
to be left in a paused state until after Finish3 has been
executed on the target. Only then will the VM be killed
off. When using non-JSON QEMU monitor though, we don't
receive any 'STOP' event from QEMU, so we need to manually
set our state offline & thus release lock manager leases.
It doesn't hurt to run this on the JSON case too, just in
case the event gets lost somehow

* src/qemu/qemu_migration.c: Explicitly set VM state to
  paused when migration completes
2011-06-03 09:59:47 -04:00
Daniel P. Berrange
2027e184c5 Fix regressions BlockStats/Info APIs in QEMU driver
The change 18c2a59206 caused
some regressions in behaviour of virDomainBlockStats
and virDomainBlockInfo in the QEMU driver.

The virDomainBlockInfo API stopped working for inactive
guests if querying a block device.

The virDomainBlockStats API did not promptly report
an error if the guest was not running in some cases.

* src/qemu/qemu_driver.c: Fix inactive guest handling
  in BlockStats/Info APIs
2011-06-03 14:55:11 +01:00
Jim Fehlig
9a76e737fc Fix minor issues in libxenlight managed save
There were a few minor issues in commit 5b6c961e
- leak managed save path
- leak managed save fd
- functions that open an fd should also close it
2011-06-02 15:41:13 -06:00
Heath Petersen
39b59dbdb4 uml: correct command line networking parameters
I have been finding that some UML command line networking parameters are
being generated incorrectly.

For more information, see
https://bugzilla.redhat.com/show_bug.cgi?id=706295 .
2011-06-02 13:52:26 -06:00
Daniel P. Berrange
020342e68d Fix auditing of disk hotunplug operations
The qemuAuditDisk calls in disk hotunplug operations were being
passed 'ret >= 0', but the code which sets ret to 0 was not yet
executed, and the error path had already jumped to the 'cleanup'
label. This meant hotunplug failures were never audited, and
hotunplug success was audited as a failure

* src/qemu/qemu_hotplug.c: Fix auditing of hotunplug
2011-06-02 17:23:45 +01:00
Daniel P. Berrange
eb661ce3ee Avoid crash on NULL pointer in lock driver impls during hotplug
When virLockDriverAcquire is invoked during hotplug the state
parameter will be left as NULL.

* src/locking/lock_driver_nop.c,
  src/locking/lock_driver_sanlock.c: Don't reference NULL state
  parameter
2011-06-02 17:23:45 +01:00
Daniel P. Berrange
09240ef13b Fix return value in lock manager hotplug methods
Refactoring of the lock manager hotplug methods lost the
ret = 0 assignment for successful return path

* src/locking/domain_lock.c: Add missing ret = 0 assignments
2011-06-02 17:23:44 +01:00
Daniel P. Berrange
43917db3f9 Fix handling of VIR_EVENT_HANDLE_ERROR in QEMU monitor
Commit 4454a9efc7 introduced bad
behaviour on the VIR_EVENT_HANDLE_ERROR condition. This condition
is only hit when an invalid FD is used in poll() (typically due
to a double-close bug). The QEMU monitor code was treating this
condition as non-fatal, and thus libvirt would poll() in a fast
loop forever burning 100% CPU. VIR_EVENT_HANDLE_ERROR must be
handled in the same way as VIR_EVENT_HANDLE_HANGUP, killing the
QEMU instance.

* src/qemu/qemu_monitor.c: Treat VIR_EVENT_HANDLE_ERROR as EOF
2011-06-02 17:23:44 +01:00
Daniel P. Berrange
ebfb8c4243 Add call to sanlock_restrict() in QEMU lock driver
In between fork and exec, a connection to sanlock is acquired
and the socket file descriptor is intionally leaked to the
child process. sanlock watches this FD for POLL_HANGUP to
detect when QEMU has exited. We don't want a rogus/compromised
QEMU from issuing sanlock RPC calls on the leaked FD though,
since that could be used to DOS other guests. By calling
sanlock_restrict() on the socket before exec() we can lock
it down.

* configure.ac: Check for sanlock_restrict API
* src/locking/domain_lock.c: Restrict lock acquired in
  process startup phase
* src/locking/lock_driver.h: Add VIR_LOCK_MANAGER_ACQUIRE_RESTRICT
* src/locking/lock_driver_sanlock.c: Add call to sanlock_restrict
  when requested by VIR_LOCK_MANAGER_ACQUIRE_RESTRICT flag
2011-06-02 17:23:44 +01:00
Michal Privoznik
3ef7350c42 screenshot: Expose the new API in virsh
* tools/virsh.c: Add screenshot command
* tools/virsh.pod: Document new command
* src/libvirt.c: Fix off-be-one error
2011-06-02 14:57:00 +02:00
Daniel Veillard
4cc4aee680 libxl : fix the version for the managed save APIs 2011-06-02 20:39:40 +08:00
Markus Groß
5b6c961ef2 libxl: adds managed save and restore support
Based on the equivalent qemu driver code

* src/libxl/libxl_driver.c: refactor the Start save and restore
  routines of the driver and adds the new entry points for
  managed saves handling
2011-06-02 20:24:30 +08:00
Markus Groß
47370d5a0b libxl: get maximum memory of running domain
* src/libxl/libxl_driver.c: fix the libxlDomainGetInfo to return the
  maximum memory for running domain
2011-06-02 20:16:32 +08:00
Daniel P. Berrange
9f135031ff Add a plugin for the 'sanlock' project
Sanlock is a project that implements a disk-paxos locking
algorithm. This is suitable for cluster deployments with
shared storage.

* src/Makefile.am: Add dlopen plugin for sanlock
* src/locking/lock_driver_sanlock.c: Sanlock driver
* configure.ac: Check for sanlock
* libvirt.spec.in: Add a libvirt-lock-sanlock RPM
2011-06-02 10:54:01 +01:00
Daniel P. Berrange
30ffe7bceb Allow leases to be hotpluged with QEMU guests
* src/conf/domain_conf.c, src/conf/domain_conf.h: APIs for
  inserting/finding/removing virDomainLeaseDefPtr instances
* src/qemu/qemu_driver.c: Wire up hotplug/unplug for leases
* src/qemu/qemu_hotplug.h, src/qemu/qemu_hotplug.c: Support
  for hotplug and unplug of leases
2011-06-02 10:54:01 +01:00
Daniel P. Berrange
7474560bef Support passing QEMU lock state to dest during migration
Some lock managers associate state with leases, allowing a process
to temporarily release its leases, and re-acquire them later, safe
in the knowledge that no other process has acquired + released the
leases in between.

This is already used between suspend/resume operations, and must
also be used across migration. This passes the lockstate in the
migration cookie. If the lock manager uses lockstate, then it
becomes compulsory to use the migration v3 protocol to get the
cookie support.

* src/qemu/qemu_driver.c: Validate that migration v2 protocol is
  not used if lock manager needs state transfer
* src/qemu/qemu_migration.c: Transfer lock state in migration
  cookie XML
2011-06-02 10:54:01 +01:00
Daniel P. Berrange
12317957ec Integrate the QEMU driver with the lock manager infrastructure
The QEMU integrates with the lock manager instructure in a number
of key places

 * During startup, a lock is acquired in between the fork & exec
 * During startup, the libvirtd process acquires a lock before
   setting file labelling
 * During shutdown, the libvirtd process acquires a lock
   before restoring file labelling
 * During hotplug, unplug & media change the libvirtd process
   holds a lock while setting/restoring labels

The main content lock is only ever held by the QEMU child process,
or libvirtd during VM shutdown. The rest of the operations only
require libvirtd to hold the metadata locks, relying on the active
QEMU still holding the content lock.

* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h,
  src/qemu/libvirtd_qemu.aug, src/qemu/test_libvirtd_qemu.aug:
  Add config parameter for configuring lock managers
* src/qemu/qemu_driver.c: Add calls to the lock manager
2011-06-02 10:54:01 +01:00
Daniel P. Berrange
ad73a937ff Add higher level lock API for domain objects
To facilitate use of the locking plugins from hypervisor drivers,
introduce a higher level API for locking virDomainObjPtr instances.
In includes APIs targetted to VM startup, and hotplug/unplug

* src/Makefile.am: Add domain lock API
* src/locking/domain_lock.c, src/locking/domain_lock.h: High
  level API for domain locking
2011-06-02 10:54:01 +01:00
Daniel P. Berrange
db98851c24 Add a 'nop' lock driver implementation.
To allow hypervisor drivers to assume that a lock driver impl
will be guaranteed to exist, provide a 'nop' impl that is
compiled into the library

* src/Makefile.am: Add nop driver
* src/locking/lock_driver_nop.c, src/locking/lock_driver_nop.h:
  Nop lock driver implementation
* src/locking/lock_manager.c: Enable direct access of 'nop'
  driver, instead of dlopen()ing it.
2011-06-02 10:54:00 +01:00
Daniel P. Berrange
6a943419c5 Basic framework for lock manager plugins
Define the basic framework lock manager plugins. The
basic plugin API for 3rd parties to implemented is
defined in

  src/locking/lock_driver.h

This allows dlopen()able modules for alternative locking
schemes, however, we do not install the header. This
requires lock plugins to be in-tree allowing changing of
the lock manager plugin API in future.

The libvirt code for loading & calling into plugins
is in

  src/locking/lock_manager.{c,h}

* include/libvirt/virterror.h, src/util/virterror.c: Add
  VIR_FROM_LOCKING
* src/locking/lock_driver.h: API for lock driver plugins
  to implement
* src/locking/lock_manager.c, src/locking/lock_manager.h:
  Internal API for managing locking
* src/Makefile.am: Add locking code
2011-06-02 10:54:00 +01:00
Daniel P. Berrange
1ea83207c8 Support leases in guest XML and lock manager
A lock manager may operate in various modes. The direct mode of
operation is to obtain locks based on the resources associated
with devices in the XML. The indirect mode is where the app
creating the domain provides explicit leases for each resource
that needs to be locked. This XML extension allows for listing
resources in the XML

  <devices>
     ...
     <lease>
       <lockspace>somearea</lockspace>
       <key>thequickbrownfoxjumpsoverthelazydog</key>
       <target path='/some/lease/path' offset='23432'/>
     </lease>
     ...
  </devices>

The 'lockspace' is a unique identifier for the lockspace which
the lease is associated

The 'key' is a unique identifier for the resource associated
with the lease.

The 'target' is the file on disk where the leases are held.

* docs/schemas/domain.rng: Add lease schema
* src/conf/domain_conf.c, src/conf/domain_conf.h: parsing and
  formatting for leases
* tests/qemuxml2argvdata/qemuxml2argv-lease.args,
  tests/qemuxml2argvdata/qemuxml2argv-lease.xml,
  tests/qemuxml2xmltest.c: Test XML handling for leases
2011-06-02 10:54:00 +01:00
Daniel P. Berrange
285c2fdf0f Allow handshake with child process during startup
Allow the parent process to perform a bi-directional handshake
with the child process during fork/exec. The child process
will fork and do its initial setup. Immediately prior to the
exec(), it will stop & wait for a handshake from the parent
process. The parent process will spawn the child and wait
until the child reaches the handshake point. It will do
whatever extra setup work is required, before signalling the
child to continue.

The implementation of this is done using two pairs of blocking
pipes. The first pair is used to block the parent, until the
child writes a single byte. Then the second pair pair is used
to block the child, until the parent confirms with another
single byte.

* src/util/command.c, src/util/command.h,
  src/libvirt_private.syms: Add APIs to perform a handshake
2011-06-02 10:53:58 +01:00
Eric Blake
b598ac555c security: plug regression introduced in disk probe logic
Regression introduced in commit d6623003 (v0.8.8) - using the
wrong sizeof operand meant that security manager private data
was overlaying the allowDiskFormatProbing member of struct
_virSecurityManager.  This reopens disk probing, which was
supposed to be prevented by the solution to CVE-2010-2238.

* src/security/security_manager.c
(virSecurityManagerGetPrivateData): Use correct offset.
2011-06-01 17:05:24 -06:00
Jiri Denemark
c1a98d8825 Fix order of disks and controllers
Commit 2d6adabd53 replaced qsorting disk
and controller devices with inserting them at the right position. That
was to fix unnecessary reordering of devices. However, when parsing
domain XML devices are just taken in the order in which they appear in
the XML since. Use the correct insertion algorithm to honor device
target.
2011-06-01 19:11:58 +02:00
Matthias Bolte
9e7d479036 remote generator: Handle some virTypedParameterPtr using functions
This doesn't cover the getters that allow to query nparams yet.
2011-06-01 17:38:39 +02:00
Matthias Bolte
32abd5ee26 remote generator: Legacy support for hyper to long mappings
Remove some special case code that took care of mapping hyper to the
correct C types.

As the list of procedures that is allowed to map hyper to long is fixed
put it in the generator instead annotations in the .x files. This
results in simpler .x file parsing code.

Use macros for hyper to long assignments that perform overflow checks
when long is smaller than hyper. Map hyper to long long by default.

Suggested by Eric Blake.
2011-06-01 15:51:01 +02:00
Daniel P. Berrange
d191b801f3 Remove call to deprecated gnutls_certificate_type_set_priority
The gnutls_certificate_type_set_priority method is deprecated.
Since we already set the default gnutls priority, and do not
support OpenGPG credentials in any case, it was not serving
any useful purpose and can be removed

* src/remote/remote_driver.c: Remove src/remote/remote_driver.c
  call
2011-06-01 14:36:29 +01:00
Matthias Bolte
825f85acfc Use common parameter order for remote(De)SerializeTypedParameters
We commonly use "value, length" order, let's stick to this.
2011-06-01 13:06:37 +02:00
Matthias Bolte
d6caacd1e4 openvz: Add simple test for openvzReadNetworkConf
Convert openvzLocateConfFile to a replaceable function pointer to
allow testing the config file parsing without rewriting the whole
OpenVZ config parsing to a more testable structure.
2011-06-01 11:58:15 +02:00
Matthias Bolte
d173c12fe0 openvz: Set virtType to openvz in openvzLoadDomains
Otherwise virsh dumpxml will report <domain type='qemu'> instead
of the expected <domain type='openvz'>.
2011-06-01 10:36:39 +02:00
Osier Yang
a74575e374 util: Fix incorrect error in PCI functions
Substitute VIR_ERR_NO_SUPPORT with VIR_ERR_INTERNAL_ERROR. Error
like following is not what user want to see.

error : pciDeviceIsAssignable:1487 : this function is not supported
by the connection driver: Device 0000:07:10.0 is behind a switch
lacking ACS and cannot be assigned
2011-06-01 10:32:41 +08:00
Matthias Bolte
cf7d897f93 openvz: Restore original EOF handling in openvzGetProcessInfo
This function is also affected by getline conversion. But this
didn't result in a regression in general, because the difference
would only affect the behavior of the function when the line in
/proc/vz/vestat for the given vpsid wasn't found. Under normal
conditions this should not happen.
2011-05-31 20:26:05 +02:00
Matthias Bolte
4b15aad0d6 openvz: Handle getline failures in openvzReadConfigParam properly
The regression fix in 3aab7f2d6b altered the error handling.
getline returns -1 on failure to read a line (including EOF). The
original openvzReadConfigParam function using openvz_readline only
treated EOF as not-found. The current getline version treats all
getline failures as not-found.

This patch fixes this and distinguishes EOF from other getline
failures.
2011-05-31 19:38:08 +02:00
Cole Robinson
8077d64f96 storage: List directory volumes for dir/fs/netfs pools
Since directories can be used for <filesystem> passthrough, they are
basically storage volumes.

v2:
    Skip ., .., lost+found dirs

v3:
    Use gnulib last_component

v4:
    Use gnulib "dirname.h", not system <dirname.h>
    Don't skip lost+found
2011-05-31 12:47:58 -04:00
Michal Privoznik
155542a57f conf: Fix incorrect spice graphic XML format on compression options
If spice graphics has no <channel> elements, the output graphics XML
is messed up. To prevent this, we need to end the <graphics> element
just before adding any compression selecting elements.
2011-05-31 15:35:08 +02:00
Daniel P. Berrange
ef983dfe5a Fix sysinfo/virsh build problems on Win32
The virSysinfoIsEqual method was mistakenly inside a #ifndef WIN32
conditional.

The existing virSysinfoFormat is also stubbed out on Win32, even
though the code works without any trouble. This breaks XML output
on Win32, so the stub is removed.

virsh migrate mistakenly had some variables inside the conditional

* src/util/sysinfo.c: Build virSysinfoIsEqual on Win32 and remove
  Win32 stub for virSysinfoFormat
* tools/virsh.c: Fix variable declaration on Win32
2011-05-31 14:17:21 +01:00
Jean-Baptiste Rouault
0796395283 openvz: fix bridge devices parsing in openvzReadNetworkConf()
strchrnul() was called on the wrong string so it returned
the same result for each iteration.
2011-05-31 14:28:52 +02:00
Daniel P. Berrange
44924615ce Allow custom XML to be passed in during migration
Update the qemuDomainMigrateBegin method so that it accepts
an optional incoming XML document. This will be validated
for ABI compatibility against the current domain config,
and if this check passes, will be passed back out for use
by the qemuDomainMigratePrepare method on the target

* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h,
  src/qemu/qemu_migration.c: Allow custom XML to be passed
2011-05-31 12:14:57 +01:00
Daniel P. Berrange
08106e2044 Add an API for comparing the ABI of two guest configurations
To allow a client app to pass in custom XML during migration
of a guest it is neccessary to ensure the guest ABI remains
unchanged. The virDomainDefCheckABIStablity method accepts
two virDomainDefPtr structs and compares everything in them
that could impact the guest machine ABI

* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/libvirt_private.syms: Add virDomainDefCheckABIStablity
* src/conf/cpu_conf.c, src/conf/cpu_conf.h: Add virCPUDefIsEqual
* src/util/sysinfo.c, src/util/sysinfo.h: Add virSysinfoIsEqual
2011-05-31 12:14:55 +01:00
Daniel P. Berrange
0e4d4afb07 Remove unused 'target' field in virDomainHostdevDef
The virDomainHostdevDef struct contains a 'char *target'
field. This is set to 'NULL' when parsing XML and never
used / set anywhere else. Clearly it is bogus & unused

* src/conf/domain_conf.c, src/conf/domain_conf.h: Remove
  target from virDomainHostdevDef
2011-05-31 11:46:34 +01:00
Osier Yang
584ce634d7 lxc: Seperate domain config loading
This patch seperate the domain config loading just as qemu driver
does, first loading config of running or trasient domains, then
of persistent inactive domains. And only try to reconnect the
monitor of running domains, so that it won't always throws errors
saying can't connect to domain monitor.

And as "virDomainLoadConfig->virDomainAssignDef->virDomainObjAssignDef",
already do things like "vm->newDef = def", removed the codes
in "lxcReconnectVM" that does the same work.
2011-05-31 18:03:41 +08:00
Markus Groß
bf7f798314 Support maximum and current memory flags in libxl driver
Add support to set the maximum memory of the domain.
Also add support to change the memory of the current
state of the domain, which translates to a running
domain or the config of the domain.

Based on the code from the qemu driver.
2011-05-30 23:29:08 -06:00
Markus Groß
db0274c9d7 Add domainSave/Restore to libxl driver
v3:
* initialize xml pointer to avoid segfault
* throw error message if domain is paused as
  libxenlight itself will pause it

v2:
* header is now padded and has a version field
* the correct restore function from libxl is used
* only create the restore event once in libxlVmStart
2011-05-30 23:29:05 -06:00
Markus Groß
e69b192102 Add domainCoreDump to libxl driver
v2:
* incorporated Jim Fehlig's review
2011-05-30 23:26:56 -06:00
Markus Groß
648b521e0d Populate domid field of devices for libxenlight
This patch fixes the population of the
libxenlight data structures. Now the devices
should be removed correctly from the xenstore
if they are detached.
2011-05-30 18:11:42 -06:00
Daniel P. Berrange
80d2038d58 Issue full error messages when processing QEMU monitor I/O
Currently the QEMU monitor I/O handler code uses errno values
to report errors. This results in a sub-optimal error messages
on certain conditions, in particular when parsing JSON strings
malformed data simply results in 'EINVAL'.

This changes the code to use the standard libvirt error reporting
APIs. The virError is stored against the qemuMonitorPtr struct,
and when a monitor API is run, any existing stored error is copied
into that thread's error local

* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_text.c: Use
  virError APIs for all monitor I/O handling code
2011-05-29 20:51:08 +08:00
Daniel P. Berrange
4454a9efc7 Don't kill QEMU process when a monitor I/O parsing error occurs
Currently whenever there is any failure with parsing the monitor,
this is treated in the same was as end-of-file (ie QEMU quit).
The domain is terminated, if not already dead.

With this change, failures in parsing the monitor stream do not
result in the death of QEMU. The guest continues running unchanged,
but all further use of the monitor will be disabled.

The VMM_FAILURE event will be emitted, and the mgmt application
can decide when to kill/restart the guest to re-gain control

* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Run a
  different callback for monitor EOF vs error conditions.
* src/qemu/qemu_process.c: Emit VMM_FAILURE event when monitor
  fails
2011-05-29 20:37:29 +08:00
Daniel P. Berrange
a6135ec1e6 Introduce a new event emitted when a virtualization failure occurs
This introduces a new domain

  VIR_DOMAIN_EVENT_ID_CONTROL_ERROR

Which uses the existing generic callback

typedef void (*virConnectDomainEventGenericCallback)(virConnectPtr conn,
                                                     virDomainPtr dom,
                                                     void *opaque);

This event is intended to be emitted when there is a failure in
some part of the domain virtualization system. Whether the domain
continues to run/exist after the failure is an implementation
detail specific to the hypervisor.

The idea is that with some types of failure, hypervisors may
prefer to leave the domain running in a "degraded" mode of
operation. For example, if something goes wrong with the QEMU
monitor, it is possible to leave the guest OS running quite
happily. The mgmt app will simply loose the ability todo various
tasks. The mgmt app can then choose how/when to deal with the
failure that occured.
* daemon/remote.c: Dispatch of new event
* examples/domain-events/events-c/event-test.c: Demo catch
  of event
* include/libvirt/libvirt.h.in: Define event ID and callback
* src/conf/domain_event.c, src/conf/domain_event.h: Internal
  event handling
* src/remote/remote_driver.c: Receipt of new event from daemon
* src/remote/remote_protocol.x: Wire protocol for new event
* src/remote_protocol-structs: add new event for checks
2011-05-29 20:21:53 +08:00
Eric Blake
bb6cb66fde sched: provide new API shims for remaining drivers
Well, the remaining drivers that already had the get/set
scheduler parameter functionality to begin with.

For now, this blindly treats VIR_DOMAIN_SCHEDINFO_CURRENT as
the only supported operation for these 5 domains; it will
take domain-specific patches if more specific behavior is
preferred.

* src/esx/esx_driver.c (esxDomainGetSchedulerParameters)
(esxDomainSetSchedulerParameters): Move guts...
(esxDomainGetSchedulerParametersFlags)
(esxDomainSetSchedulerParametersFlags): ...to new functions.
* src/libxl/libxl_driver.c (libxlDomainGetSchedulerParameters)
(libxlDomainSetSchedulerParameters)
(libxlDomainGetSchedulerParametersFlags)
(libxlDomainSetSchedulerParametersFlags): Likewise.
* src/lxc/lxc_driver.c (lxcGetSchedulerParameters)
(lxcSetSchedulerParameters, lxcGetSchedulerParametersFlags)
(lxcSetSchedulerParametersFlags): Likewise.
* src/test/test_driver.c (testDomainGetSchedulerParams)
(testDomainSetSchedulerParams, testDomainGetSchedulerParamsFlags)
(testDomainSetSchedulerParamsFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainGetSchedulerParameters)
(xenUnifiedDomainSetSchedulerParameters)
(xenUnifiedDomainGetSchedulerParametersFlags)
(xenUnifiedDomainSetSchedulerParametersFlags): Likewise.
2011-05-29 18:51:33 +08:00
Eric Blake
baa371eca0 remote: introduce remoteGetSchedulerParametersFlags
* daemon/remote.c (remoteDispatchDomainGetSchedulerParameters):
New function.
* src/remote/remote_driver.c (remoteDomainGetSchedulerParameters):
Likewise.
* src/remote/remote_protocol.x
(remote_domain_get_scheduler_parameters_flags_args)
(remote_domain_get_scheduler_parameters_flags_ret): New types.
(remote_procedure): New RPC.
* src/remote_protocol-structs: Likewise.
2011-05-29 18:50:41 +08:00
Eric Blake
8432170f6f qemu: introduce qemuGetSchedulerParametersFlags
* src/qemu/qemu_driver.c (qemuGetSchedulerParameters): Move
guts...
(qemuGetSchedulerParametersFlags): ...to new callback, and honor
flags more accurately.
2011-05-29 18:40:06 +08:00
Eric Blake
bc4ee58972 sched: introduce virDomainGetSchedulerParametersFlags
If we can choose live or config when setting, then we need to
be able to choose which one we are querying.

Also, make the documentation clear that set must use a non-empty
subset (some of the hypervisors fail if params is NULL).

* include/libvirt/libvirt.h.in
(virDomainGetSchedulerParametersFlags): New prototype.
* src/libvirt.c (virDomainGetSchedulerParametersFlags): Implement
it.
* src/libvirt_public.syms: Export it.
* python/generator.py (skip_impl): Don't auto-generate.
* src/driver.h (virDrvDomainGetSchedulerParametersFlags): New
callback.
2011-05-29 18:38:10 +08:00
Eric Blake
8a47ed2981 remote: consolidate typed parameter handling
* src/remote/remote_protocol.x (remote_typed_param_value)
(remote_typed_param):  New types.
(remote_sched_param_value, remote_sched_param)
(remote_blkio_param_value, remote_blkio_param)
(remote_memory_param_value, remote_memory_param): Delete.
(remote_domain_get_scheduler_parameters_ret)
(remote_domain_set_scheduler_parameters_args)
(remote_domain_set_scheduler_parameters_flags_args)
(remote_domain_set_blkio_parameters_args)
(remote_domain_get_blkio_parameters_ret)
(remote_domain_set_memory_parameters_args)
(remote_domain_get_memory_parameters_ret): Update clients.
* src/remote_protocol-structs: Likewise.
* src/remote/remote_driver.c (remoteSerializeTypedParameters)
(remoteDeserializeTypedParameters): New functions.
(remoteDomainSetMemoryParameters)
(remoteDomainGetMemoryParameters, remoteDomainSetBlkioParameters)
(remoteDomainGetBlkioParameters)
(remoteDomainGetSchedulerParameters)
(remoteDomainSetSchedulerParameters)
(remoteDomainSetSchedulerParametersFlags): Update clients.
* daemon/remote.c (remoteSerializeTypedParameters)
(remoteDeserializeTypedParameters): New functions.
(remoteDispatchDomainGetSchedulerParameters)
(remoteDispatchDomainSetSchedulerParameters)
(remoteDispatchDomainSetSchedulerParametersFlags)
(remoteDispatchDomainSetMemoryParameters)
(remoteDispatchDomainGetMemoryParameters)
(remoteDispatchDomainSetBlkioParameters)
(remoteDispatchDomainGetBlkioParameters): Update clients.
2011-05-29 18:27:10 +08:00
Eric Blake
163e5f04ef maint: prefer newer API names internally
Rather mechanical in nature.

* src/driver.h: Use newer virTypedParameter API names.
* src/libvirt.c: Likewise.
* daemon/remote.c: Likewise.
* src/esx/esx_driver.c: Likewise.
* src/libxl/libxl_driver.c: Likewise.
* src/lxc/lxc_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/test/test_driver.c: Likewise.
* src/xen/xen_driver.c: Likewise.
* src/xen/xen_hypervisor.c: Likewise.
* src/xen/xen_hypervisor.h: Likewise.
* src/xen/xend_internal.c: Likewise.
* tools/virsh.c: Likewise.
2011-05-29 18:26:31 +08:00
Daniel Veillard
a9a95cb14a Fix a make check error
Apparently introdunced in commit 376e1d9420
the generator produces u_int flags not unsigned int flags.

* src/remote_protocol-structs: fix to the actual expected type and
  alignment
2011-05-29 18:21:24 +08:00
Richard Laager
4996c314b0 Fix virExecWithHook Prototype
This was necessary to get libvirt to build on Solaris 11 Express and
seems correct (as it makes this match the definition in util.c):
2011-05-29 10:09:00 +02:00
Stefan Berger
8cc166e76e nwfilter: reorder locks
This patch reorders the locks for the nwfilter updates and the access
the nwfilter objects. In the case that the IP address learning thread
was instantiating filters while an update happened, the previous order
lead to a deadlock.
2011-05-27 16:50:40 -04:00
Laine Stump
ecbe86c0c5 interface: reformat error logs
It was suggested during review of a different patch that the libvirt
interface driver API's should have "netcf:" in their log
messages. This patch eliminates that from all interface driver API
functions, and also eliminates the extra " - " in the case that netcf
returns no details in its error info (which *never* happens at
present, but could happen sometime in the future.
2011-05-27 14:40:42 -04:00
Michal Privoznik
88c5b97f7c interface: implement a test driver for network config transaction API. 2011-05-27 14:34:13 -04:00
Michal Privoznik
9c6000579b interface: Implement driver methods for network config transaction API
This is the functionality at the end of the libvirt part of the call
chain - for each function, the corresponding netcf API is called.
2011-05-27 14:33:59 -04:00
Michal Privoznik
376e1d9420 interface: implement remote protocol for network config transaction API 2011-05-27 14:29:14 -04:00
Michal Privoznik
e63d75bc1c interface: implement public APIs for libvirt transactional network changes 2011-05-27 14:28:45 -04:00
Michal Privoznik
b1f102edad interface: define internal driver API for network config transactions 2011-05-27 14:28:33 -04:00
Michal Privoznik
ba0b5934b3 interface: new public API for network config change transactions
This is the API agreed on in:

  https://www.redhat.com/archives/libvir-list/2011-May/msg00026.html

(with a slight name change to use "...begin" rather than
"...start"). This implements transactional changes to the host network
config. When a transaction is begun with ncf_change_begin(), all other
netcf APIs will continue to work as they always have, but a snapshot
of the existing config will be taken, allowing reversion (rollback,
using ncf_change_rollback()) to the exact state of config at the time
ncf_change_begin() was called. Alternately, if it's determined that
the new changes are acceptable, ncf_change_commit() can be called,
which will eliminate the snapshot and make the changes permanent.

As a failsafe measure, if neither ncf_change_commit() or
ncf_change_rollback() is called by the next time the system reboots,
the netcf-transaction initscript will be automatically called to
rollback the changes.
2011-05-27 14:28:23 -04:00
Matthias Bolte
89fcf6f3f0 openvz: Fix regression in openvzGetVPSUUID
Commit f044376530 replaced openvz_readline with getline and
changed EOF-handling in the openvzGetVPSUUID.

This patch restores original EOF-handling.

Reported by Jean-Baptiste Rouault.
2011-05-27 15:49:55 +02:00
Matthias Bolte
bf9aa21433 sexpr: Improve serialization error reporting 2011-05-27 15:31:33 +02:00
Matthias Bolte
a07d178447 Fix build with --with-driver-modules enabled
Export a bunch of missing symbols and link the remote driver to gnulib.
2011-05-27 09:51:28 +02:00
Hu Tao
4b997daaf5 qemu: implement the new flags for setting memory parameters
* src/qemu/qemu_driver.c: update qemuDomainSetMemoryParameters to
  look at the flag parameter and depending on it save the config
  or the live amount
2011-05-27 15:49:07 +08:00
Hu Tao
7639d1ef31 qemu: implement the new flags for getting memory parameters
* src/qemu/qemu_driver.c: update qemuDomainGetMemoryParameters to
  look at the flag parameter and depending on it read the config
  or the live amount
2011-05-27 15:48:55 +08:00
KAMEZAWA Hiroyuki
9c26d6f09e qemu : support persistent add/delete network interface
This patch allows to modify interfaces of domain(qemu)
* src/conf/domain_conf.c src/conf/domain_conf.h src/libvirt_private.syms:
  (virDomainNetInsert)     : Insert a network device to domain definition.
  (virDomainNetIndexByMac) : Returns an index of net device in array.
  (virDomainNetRemoveByMac): Remove a NIC of passed MAC address.
* src/qemu/qemu_driver.c
  (qemuDomainAttachDeviceConfig): add codes for NIC.
  (qemuDomainDetachDeviceConfig): add codes for NIC.
2011-05-27 15:01:47 +08:00
Matthias Bolte
8357d91b65 esx: Fix regression in absolute file name handling
Before commit 145d6cb05c (in August 2010) absolute file names
in VMX and domain XML configs were handled correctly. But this got
lost during the refactoring. The test cases didn't highlight this
problem because they have their own set of file name handling
functions. The actual ones require a real connection to an ESX
server. Also the test case functions always worked correctly.

Fix the regression and add a new in-the-wild VMX file that contains
such a problematic absolute path. Even though this test case won't
protect against new regressions.

Reported by lofic (IRC nick)
2011-05-26 23:32:44 +02:00
Matthias Bolte
4a3a029024 openvz: Add simple testcase for config file parsing function
This testcase passes before the regression is added in f0443765, fails
after that commit and passes again after the regression was fixed.
2011-05-26 22:43:40 +02:00
Hu Tao
83ea7c1b76 don't check flags in virDomainSetSchedulerParametersFlags
drivers implementing domainSetSchedulerParametersFlags should check
flags themselves.
2011-05-26 14:01:01 -06:00
Taisuke Yamada
3aab7f2d6b openvz: Fix regression in config file parsing
As reported by Diego Blanco in

  https://bugzilla.redhat.com/show_bug.cgi?id=702602

commit f0443765 which replaced openvz_readline to getline(3)
broke OpenVZ driver as it changed semantics of EOF-handling
when parsing OpenVZ configuration.

There're several other issues reported with current OpenVZ driver:

 #1: unclear error message when parsing "CPUS=" line
 #2: openvz driver goes into crashing loop
 #3: "NETIF=" line in configuration is not parsed correctly
 #4: aborts even when optional parameter is missing
 #5: there's a potential memory leak

This updated patch to fix #[145]. This patch does not fix #[23]
as I haven't verified these yet, but this at least got me to run
OpenVZ on libvirt once again.
2011-05-26 19:49:18 +02:00
Eric Blake
59953c3812 audit: fix minor off-by-one
Coverity spotted this off-by-one.  Thankfully, no one in libvirt
was ever calling virAuditSend with an argument of 3.

* src/util/virtaudit.c (virAuditSend): Use correct comparison.
2011-05-26 11:17:55 -06:00
Federico Simoncelli
18c2a59206 qemu: allow blkstat/blkinfo calls during migration
Originally most of libvirt domain-specific calls were blocking
during a migration.
A new mechanism to allow specific calls (blkstat/blkinfo) to be
executed in such condition has been implemented.
In the long term it'd be desirable to get a more general
solution to mark further APIs as migration safe, without needing
special case code.

 * src/qemu/qemu_migration.c: add some additional job signal
   flags for doing blkstat/blkinfo during a migration
 * src/qemu/qemu_domain.c: add a condition variable that can be
   used to efficiently wait for the migration code to clear the
   signal flag
 * src/qemu/qemu_driver.c: execute blkstat/blkinfo using the
   job signal flags during migration
2011-05-26 11:05:04 -06:00
Markus Groß
fffea7fed7 Add disk attach/detach support to libxl driver
Based on the device attach/detach code from the QEMU driver,
but using the new functions to create the structures associated.
* src/libxl/libxl_driver.c: implements domainAttachDevice,
  domainAttachDeviceFlags, domainDetachDevice, domainDetachDeviceFlags
  and domainUpdateDeviceFlags
2011-05-26 23:27:06 +08:00
Markus Groß
685753a360 Fix libxl vm def handling on domU cleanup
* src/libxl/libxl_driver.c: in libxlVmCleanup, free up the
  newDef definition if present overwise it would be leaked.
2011-05-26 23:16:31 +08:00
Markus Groß
f59b71ac57 Refactored libxl datastructure instantiation
Create 3 new function refactored from previous list ones and
exports them internally to the driver

* src/libxl/libxl_conf.c src/libxl/libxl_conf.h: create libxlMakeDisk,
  libxlMakeNic libxlMakeVfb out of the exsting static List functions
  and exports them
2011-05-26 23:09:01 +08:00
Markus Groß
23e5393c40 Fix modifying disk devices in qemu driver
When modifying the disk devices of a live domain and the domain
configuration, the function qemuDomainAttachDeviceConfig
first sets dev->data->disk to NULL. Later qemuDomainAttachDeviceLive
accesses dev->data.disk and causes a segfault.
* src/qemu/qemu_driver.c: fix qemuDomainModifyDeviceFlags() accordingly
2011-05-26 22:32:51 +08:00
Eric Blake
b3e6e45075 build: fix 'make dist' for ./configure --without-remote
Anything generated that must end up in the tarball must either
have unconditional rules for generation (remote_protocol.c) or
must live in libvirt.git for the case where the person running
'make dist' has disabled the configure options that control the
rebuild of the generated file (remote_protocol-structs).

* src/Makefile.am (remote_protocol-structs): Add a dependency and
document why it must live in git.
($(srcdir)/remote/%_protocol.c, $(srcdir)/remote/%_protocol.c):
Unconditionally generate.
2011-05-25 16:59:36 -06:00
Richard W.M. Jones
78eb8b60d5 json: Avoid passing large positive 64 bit integers to QMP.
http://lists.gnu.org/archive/html/qemu-devel/2011-05/threads.html#02162

Currently, qemu silently clips any JSON integer in the range
0x8000000000000000 - 0xffffffffffffffff (all numbers in this range
will be clipped to 0x7fffffffffffffff == LLONG_MAX).

To avoid this, pass these as signed 64 bit integers in the QMP
request.
2011-05-25 21:30:39 +01:00
Matthias Bolte
1ff2b6f6ee Fix sign mismatches between public API, driver API and XDR protocol
In most cases this affects flags parameters that are unsigned in the
public and driver API but signed in the XDR protocol. Switch the
XDR protocol to unsigned for those.

A counterexample is virNWFilterGetXMLDesc. Its flags parameter is signed
in the public API and XDR protocol, but unsigned in the driver API.
2011-05-25 19:18:14 +02:00
Matthias Bolte
30e9b1a186 remote generator: Fix XDR sign mismatch for virNodeGet(Cells)FreeMemory
virNodeGetFreeMemory used unsigned long long in the public API but
signed hyper in the XDR protocol. Convert the XDR protocol to use
unsigned hyper.

As explained by Eric before, this doesn't affect the on-the-wire protocol.
2011-05-25 19:18:09 +02:00
Matthias Bolte
c2de9f4a15 remote generator: Handle stream-using functions
Extend procedure annotation in the .x file for stream handling.

Adds a missing remoteStreamRelease call to remoteDomainScreenshot
error path.
2011-05-25 19:18:05 +02:00
Matthias Bolte
77582e7f3f remote generator: Make call-by-reference handling stricter
Several functions return values by reference parameters. This is realized
by passing the members of remote_CALL_ret by reference to the called
function.

The position of this parameters in the function signature follows some
patterns with some exceptions. This patterns and exceptions are hardcoded
in the generator.

Add an insert@<offset> annotation to the remote_CALL_ret struct members
for functions that return lists to remove some of the hardcoded patterns
and exceptions.
2011-05-25 19:18:00 +02:00
Matthias Bolte
fc86e6faa0 remote generator: Rename virNodeGetCellsFreeMemory parameters to common pattern
This allows to remove some special case code from the generator.
2011-05-25 19:14:29 +02:00
Matthias Bolte
a125f82ff4 remote generator: Handle virDomainCreateWithFlags
Add special case code for updating a given domain object instead of
returning a new one.
2011-05-25 19:12:50 +02:00
Matthias Bolte
cded0c80b0 time_t is not a long on FreeBSD, switch internal type to long long 2011-05-25 18:47:33 +02:00
Daniel P. Berrange
2593f9692d Fix the signature of virDomainMigrateFinish3 for error reporting
The current virDomainMigrateFinish3 method signature attempts to
distinguish two types of errors, by allowing return with ret== 0,
but ddomain == NULL, to indicate a failure to start the guest.
This is flawed, because when ret == 0, there is no way for the
virErrorPtr details to be sent back to the client.

Change the signature of virDomainMigrateFinish3 so it simply
returns a virDomainPtr, in the same way as virDomainMigrateFinish2
The disk locking code will protect against the only possible
failure mode this doesn't account for (loosing conenctivity to
libvirtd after Finish3 starts the CPUs, but before the client
sees the reply for Finish3).

* src/driver.h, src/libvirt.c, src/libvirt_internal.h: Change
  virDomainMigrateFinish3 to return a virDomainPtr instead of int
* src/remote/remote_driver.c, src/remote/remote_protocol.x,
  daemon/remote.c, src/qemu/qemu_driver.c, src/qemu/qemu_migration.c:
  Update for API change
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
5e31df9335 Fix preservation of errors across migration steps
When doing migration, if an error occurs in Perform, it must not
be overwritten during Finish/Confirm steps. If an error occurs
in Finish, it must not be overwritten in Confirm.

Previous commit a9d12c2444 added
code to qemudDomainMigrateFinish2 to preserve the error. This
is not the right place, because it is not applicable in non-p2p
migration. The src/libvirt.c virDomainMigrateV2/3 methods need
code to preserve errors for non-p2p migration, while the
doPeer2PeerMigrate2 and doPeer2PeerMigrate3 methods contain
code to preverse errors for p2p migration.

Remove the bogus error preservation from qemudDomainMigrateFinish2
and qemudDomainMigrateFinish3.

Fix virDomainMigrateV3 and doPeer2PeerMigrate3 so that they
preserve any error hit during the Finish3 step, before invoking
Confirm3.

Finally if qemuMigrationFinish fails to resume the CPUs, it must
preserve the error before tearing down the VM, so that VM cleanup
doesn't overwrite it.

* src/libvirt.c: Preserve error before invoking Confirm3
* src/qemu/qemu_driver.c: Remove bogus error preservation
  code in qemudDomainMigrateFinish2/qemudDomainMigrateFinish3
* src/qemu/qemu_migration.c: Preserve error before invoking Confirm3
  and after resume fails in qemuMigrationFinish.
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
03547eee92 Improve debug logging of migration APIs
* src/libvirt.c: Add further debug lines in helper APIs for
  migration
* src/qemu/qemu_migration.c: Add debug lines for all internal
  migration API parameters
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
1853bd9d6e Fix error propagation in finish method for v3 migration
Even when failing to start CPUs, the finish method was returning
a success result. Fix this so that the QEMU process is killed
off when finish fails under v3 protocol. Also rename the
killOnFinish boolean to 'v3proto' to make it clearer that this
is a tunable based on the migration protocol version

* src/qemu/qemu_driver.c: Update for API change
* src/qemu/qemu_migration.c, src/qemu/qemu_migration.h: Kill
  VM in qemuMigrationFinish if failing to start CPUs
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
b336710383 Fix SPICE seamless migration hostname
The SPICE seamless migration process requires data to be passed
back from the target host, to the source host via a cookie.
The cookie includes the target host's hostname, but this was not
stored, merely validated. This patch explicitly records the
remote hostname after parsing the cookie, and uses it when
initiating the SPICE migration

* qemu/qemu_migration.c: Fix SPICE seamless migration hostname
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
73b3e0b70b Fix resume on destination when doing non-live tunnelled migration
Before running perform in peer-2-peer migration, the current
guest state must be recorded, so that non-live migration can
currently unpause a running guest on completion.

* src/qemu/qemu_migration.c: Move check for offline guest
  to fix non-live migration
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
1355541662 Introduce two method migration APIs
There are two pieces of information which are desirable for
migration, which cannot be supplied by applications

 - The explicit QEMU migration URI, while using Peer2Peer
   migration
 - An override for the target VM XML

This introduces two new public APIs to support these extra
parameters. There is no need for extra wire protocool changes,
since this is supported by the v3 migration enhancements

* include/libvirt/libvirt.h.in,
  src/libvirt.c, src/libvirt_public.syms: Add virDomainMigrate2
  and virDomainMigrateToURI2
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
f9f2d4e147 Add a second URI parameter to virDomainMigratePerform3 method
The virDomainMigratePerform3 currently has a single URI parameter
whose meaning varies. It is either

 - A QEMU migration URI (normal migration)
 - A libvirtd connection URI (peer2peer migration)

Unfortunately when using peer2peer migration, without also
using tunnelled migration, it is possible that both URIs are
required.

This adds a second URI parameter to the virDomainMigratePerform3
method, to cope with this scenario. Each parameter how has a fixed
meaning.

NB, there is no way to actually take advantage of this yet,
since virDomainMigrate/virDomainMigrateToURI do not have any
way to provide the 2 separate URIs

* daemon/remote.c, src/remote/remote_driver.c,
  src/remote/remote_protocol.x, src/remote_protocol-structs: Add
  the second URI parameter to perform3 message
* src/driver.h, src/libvirt.c, src/libvirt_internal.h: Add
  the second URI parameter to Perform3 method
* src/libvirt_internal.h, src/qemu/qemu_migration.c,
  src/qemu/qemu_migration.h: Update to handle URIs correctly
2011-05-25 11:47:48 -04:00
Daniel P. Berrange
7ad4b6b9cc Extend v3 migration protocol to allow app supplied XML for target
This extends the v3 migration protocol such that the
virDomainMigrateBegin3 and virDomainMigratePerform3
methods accept an application supplied XML config for
the target VM.

If the 'xmlin' parameter is NULL, then Begin3 uses the
current guest XML as normal. A driver implementing the
Begin3 method should either reject all non-NULL 'xmlin'
parameters, or strictly validate that the app supplied
XML does not change guest ABI.

The Perform3 method also needed the xmlin parameter to
cope with the Peer2Peer migration sequence.

NB it is not yet possible to use this capability since
neither of the public virDomainMigrate/virDomainMigrateToURI
methods have a way to pass in XML.

* daemon/remote.c, src/remote/remote_driver.c,
  src/remote/remote_protocol.x, src/remote_protocol-structs:
  Add 'remote_string xmlin' parameter to begin3/perform3
  RPC messages
* src/libvirt.c, src/driver.h, src/libvirt_internal.h: Add
  'const char *xmlin' parameter to Begin3/Perform3 methods
* src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
  src/qemu/qemu_migration.h: Pass xmlin parameter around
  migration methods
2011-05-25 11:47:47 -04:00
Matthias Bolte
dea64db1d2 esx: Report an error when auth pointer is missing instead of declining
Otherwise an attempt to use virConnectOpen or virConnectOpenAuth without
auth pointer results in the driver declining the URI and libvirt falling
back to the remote driver for an esx:// URI.
2011-05-25 16:51:52 +02:00
Jim Fehlig
492e493a1e Fix initialization of current vcpus in libxl driver
The cur_vcpus member of struct libxl_domain_build_info was incorrectly
initialized to the number of vcpus, when it should have been interpreted
as a bitmap, where bit X corresponds to online/offline status of vcpuX.

To complicate matters, cur_vcpus is an int, so only 32 vcpus can be
set online.  Add a check to ensure vcpus does not exceed this limit.

V2: Eric Blake noted a compilation pitfal when '1 << 32' on an int.
    Account for vcpus == 32.
2011-05-24 14:13:04 -06:00
Eric Blake
4486f3a209 build: fix VIR_DEBUG on mingw
We don't use the gnulib vsnprintf replacement, which means that
on mingw, vsnprintf doesn't support %zn or %lln.

And as it turns out, VIR_GET_VAR_STR was a rather inefficient
reimplementation of virVasprintf logic.

* src/util/logging.c (VIR_GET_VAR_STR): Drop.
(virLogMessage): Inline a simpler version here.
* src/util/virterror.c (VIR_GET_VAR_STR, virRaiseErrorFull):
Likewise.
Reported by Matthias Bolte.
2011-05-24 12:34:43 -06:00
Michal Privoznik
764c282cdf qemu: Don't change ownership of file when appending to it
Saving domain to previously created file changes also its ownership.
This is certainly not what users want if some conditions are met:
it is a regular, local file and dynamic_ownership is off.
2011-05-24 17:41:34 +02:00
Laine Stump
51781b82f7 qemu: fix typo in name - should be VHOST_NET, not VNET_HOST
NB: the enum that uses the string vnet-host (now changed to vhost-net)
is used in XML, but fortunately that hasn't been in an official
release yet, so it can still be fixed.
2011-05-24 10:45:55 -04:00
Daniel P. Berrange
58765b58a3 Fix QEMU -vnc arg generation with raw IPv6 addresses
Since -vnc uses ':' to separate the address from the port, raw
IPv6 addresses need to be escaped like [addr]:port

* src/qemu/qemu_command.c: Escape raw IPv6 addresses with []
* tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.args,
  tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml: Tweak
  to test Ipv6 escaping
* docs/schemas/domain.rng: Allow Ipv6 addresses, or hostnames
  in <graphics> listen attributes
2011-05-24 10:33:53 -04:00
Daniel P. Berrange
65e1acad80 Fix peer2peer migration with transient VMs
The qemuMigrationConfirm method shouldn't deal with final VM
cleanup, since it can be called from the peer2peer migration,
which expects to still use the 'vm' object afterwards.

Push the cleanup code out of qemuMigrationConfirm, into its
caller, qemuDomainMigrateConfirm3

* src/qemu/qemu_driver.c: Add VM cleanup code to
  qemuDomainMigrateConfirm3
* src/qemu/qemu_migration.c, src/qemu/qemu_migration.h: Remove
  job handling cleanup from qemuMigrationConfirm
2011-05-24 05:41:23 -04:00
Daniel P. Berrange
f88af9dc16 Perform feature flag compat checking in QEMU migration cookies
To allow new mandatory migration cookie data to be introduced,
add support for checking supported feature flags when parsing
migration cookie.

* src/qemu/qemu_migration.c: Feature flag checking in migration
  cookie parsing
2011-05-24 05:40:50 -04:00
Jiri Denemark
5e09aea7b0 Replace all remaining setgid/setuid calls with virSetUIDGID
Two additional places need initgroups call to properly work in an
environment where the UID is allowed to open/create stuff through its
supplementary groups.
2011-05-24 12:09:53 +03:00
Jiri Denemark
4dd9c16161 util: Keep errno set to the root error after when returning from virSetUIDGID 2011-05-24 12:09:53 +03:00
Michal Privoznik
5f88d198bd storage: Add comment to picking return value of qemu-img
Commit d7b2679253 introduced
a return value picking of qemu-img on '-h', but without any comment.
2011-05-24 08:54:37 +02:00
Alon Levy
bb1c5423b9 spice: support streaming-video parameter
This adds a streaming-video=filter|all|off attribute. It is used to change
the behavior of video stream detection in spice, the default is filter (the
default for libvirt is not to specify it - the actual default is defined in
libspice-server.so).

Usage:

    <graphics type='spice' autoport='yes'>
      <streaming mode='off'/>
    </graphics>

Tested with the above and with tests/qemuxml2argvtest.

Signed-off-by: Alon Levy <alevy@redhat.com>
2011-05-23 20:53:59 -06:00
Stefan Berger
fcb0e8c227 nwfilter: enable filtering of gratuitous ARP packets
This patch enables filtering of gratuitous ARP packets using the following XML:

<rule action='accept' direction='in' priority='425'>
<arp gratuitous='true'/>
</rule>
2011-05-23 19:41:18 -04:00
Laine Stump
17266c5c68 qemu: don't require is_kvm for vhost-net support
This was discussed in:

  https://www.redhat.com/archives/libvir-list/2011-May/msg01370.html

The capabilities code only sets the flag to allow use of vhost-net if
kvm is detected (set if the help string contains "(qemu-kvm-" or
"(kvm-"), but actually vhost-net is available in some qemu builds that
don't have kvm in their name, so just checking for ",vhost=" is enough.
2011-05-23 15:59:31 -04:00
Doug Goldstein
a67407fa36 Use per-user TLS certificates when possible
When using TLS authentication and operating as the non-root user,
initially attempt to use that specific user's TLS certificates before
attempting to use the system wide TLS certificates.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2011-05-23 13:18:14 -06:00
Michal Privoznik
d7b2679253 storage: pick return value of qemu-img
qemu-img returns non-zero status on -h. Therefore we need to
provide virCommandRun() a non-NULL exit status pointer.
2011-05-23 13:47:06 +02:00
Matthias Bolte
f0a5be514d remote generator: Add special case for virConnectGetType 2011-05-20 18:12:50 +02:00
Richard W.M. Jones
bb12a63909 qemudDomainMemoryPeek: change ownership/selinux label on temporary file.
Otherwise qemu is unable to write to it, with the error:

libvir: QEMU error : internal error unable to execute QEMU command 'memsave': Could not open '/var/cache/libvirt/qemu/qemu.mem.RRNvLv'
2011-05-20 16:12:36 +01:00
Daniel P. Berrange
6b937b2430 Don't generate cookies with v2 migration protocol.
The v2 migration protocol had a limit on cookie length that was
too small to be useful for QEMU. Avoid generating cookies with
v2 protocol, so that old libvirtd can still reliably migrate a
guest to new libvirtd uses v2 protocol.

* src/qemu/qemu_driver.c: Avoid migration cookies with v2
  migration
2011-05-19 07:13:07 -04:00
Daniel P. Berrange
03f8832684 Fix QEMU migration cookie crash for guests with no graphics
When generating a cookie for a guest with no data, the
QEMU_MIGRATION_COOKIE_GRAPHICS flag was set even if no
graphics data was added. Avoid setting the flag unless
it was needed, also add a safety check for mig->graphics
being non-NULL

* src/qemu/qemu_migration.c: Avoid cookie crash for guest
  with no graphics
2011-05-19 07:13:00 -04:00
Daniel P. Berrange
2f3c682668 Ensure p2p and direct migration use the new v3 protocol if available
The internal virDomainMigratePeer2Peer and virDomainMigrateDirect
helper methods were not checking whether the target supports the
v3 migration protocol.

* src/libvirt.c: Use v3 migration protocol for p2p/direct
  migration if available.
2011-05-19 07:12:53 -04:00
Daniel P. Berrange
4bfe396e14 Blank out the 'listenAddr' parameter if empty string
Some bogus apps are generating a VNC/SPICE/RFB listen attribute
with no content. This then causes a failure with the graphics
migration cookie parsing. Blank out the 'listenAddr' parameter
after parsing domain XML if it is the empty string, so the host
default takes over

* src/qemu/qemu_migration.c: Blank out listenAddr parameter
  if empty
2011-05-19 07:12:45 -04:00
Eric Blake
8fcbc0c63c remote: remove special case for getting version
The on-the-wire protocol is identical; XDR guarantees that
both 'hyper' and 'unsigned hyper' are transmitted as 8 bytes.

* src/remote/remote_protocol.x (remote_get_version_ret)
(remote_get_lib_version_ret): Match public API.
* daemon/remote_generator.pl: Drop special case.
* src/remote_protocol-structs: Reflect updated type.
2011-05-18 15:25:03 -06:00
Eric Blake
7647422a8c build: silence clang false positive
Clang couldn't quite see that the same condition of
(flags & VIR_DOMAIN_MEM_CONFIG) is used twice, such that
the second block is guaranteed that def was assigned in
the first block.

* src/libxl/libxl_driver.c (libxlDomainSetMemoryFlags): Add a hint
for clang.
2011-05-18 12:47:46 -06:00
Matthias Bolte
4d2a189646 Improve invalid argument checks for the public API 2011-05-18 18:20:47 +02:00
Matthias Bolte
191e1ec65c Clarify that virDomainGet(Memory|Blkio)Parameters doesn't support subsets
Improve invalid argument checks in the size query case. The drivers already
relied on this unchecked behavior.

Relax the implementation of virDomainGet(Memory|Blkio)MemoryParameters
in the drivers and allow to pass more memory than necessary for all
parameters.
2011-05-18 18:20:47 +02:00
Matthias Bolte
8a3b74e770 Clarify that virDomainSet(Memory|Blkio)Parameters can take parameter subsets 2011-05-18 18:20:47 +02:00
Matthias Bolte
d870ec367d Clarify that virDomainSetSchedulerParameters(Flags) can take subsets
Add invalid argument checks for params and nparams to the public API
and remove them from the drivers (e.g. xend).

Add subset handling to libxl and test drivers.
2011-05-18 18:20:47 +02:00
Matthias Bolte
e430c0d0c6 Clarify the semantic of virDomainGetSchedulerParameters arguments
params and nparams are essential and cannot be NULL. Check this in
libvirt.c and remove redundant checks from the drivers (e.g. xend).

Instead of enforcing that nparams must point to exact same value as
returned by virDomainGetSchedulerType relax this to a lower bound
check. This is what some drivers (e.g. xen hypervisor and esx)
already did. Other drivers (e.g. xend) didn't check nparams at all
and assumed that there is enough space in params.

Unify the behavior in all drivers to a lower bound check and update
nparams to the number of valid values in params on success.
2011-05-18 18:20:47 +02:00
Matthias Bolte
7b2f20b10b Clarify semantic of nparams argument of virDomainGetSchedulerType
Some drivers assumed it can be NULL (e.g. qemu and lxc) and check it
before assigning to it, other drivers assumed it must be non-NULL
(e.g. test and esx) and just assigned to it.

Unify this to nparams being optional and document it.
2011-05-18 18:20:47 +02:00
Cole Robinson
ed97be6176 Fix messages using VIR_ERR_XML_ERROR
This error code has existed since the dawn of time, yet the messages it
generates are almost universally busted. Here's a small sampling:

src/conf/domain_conf.c:4889 : XML description for missing root element is not well formed or invalid
src/conf/domain_conf.c:4951 : XML description for unknown device type is not well formed or invalid
src/conf/domain_conf.c:5460 : XML description for maximum vcpus must be an integer is not well formed or invalid
src/conf/domain_conf.c:5468 : XML description for invalid maxvcpus %(count)lu is not well formed or invalid

Fix up the error code to instead be

XML error: <msg>

Adjust the few locations that were using the original correctly (or shouldn't
have been using the error code at all).

v2:
    Fix wording of error code without a passed argument
2011-05-18 11:18:09 -04:00
Dirk Herrendorefer
5252a06d65 Add support for 'passthru' mode for direct network interfaces
starting with kernel 2.6.38 macvtap supports a 'passthru' mode for
attaching virtual functions of a SRIOV capable network card directly to a VM.
This patch adds the capability to configure such a device.

Signed-off-by: Dirk Herrendoerfer <d.herrendoerfer@herrendoerfer.name>
2011-05-18 08:15:08 -06:00
Michal Privoznik
45b28f7c4f qemu: fix typo in spice migration code
This typo caused XPath returning improper value and thus not
working spice after migration.
2011-05-18 11:57:07 +02:00
Hu Tao
bb9f1bbf4a remote: introduce remoteSetSchedulerParametersFlags
support for virDomainSetSchedulerParametersFlags of remote driver.
2011-05-17 10:38:30 -06:00
Hu Tao
a9189e2c41 qemu: introduce qemuSetSchedulerParametersFlags
Support for virDomainSetSchedulerParametersFlags of qemu driver.
2011-05-17 10:17:53 -06:00
Hu Tao
d4b8a35755 introduce virDomainSetSchedulerParametersFlags
This new function allows aditional flags to be passed into from
the virsh command line.
2011-05-17 09:37:46 -06:00
Eric Blake
d4982b86d2 build: drop unused <sys/syslimits.h> header
<sys/syslimits.h> is not standardized, so portable programs should
not need to rely on it.  If there really is something that we need
where <sys/syslimits.h> provided the limit but <limits.h> did not,
then that would be a candidate for fixing in gnulib.  But this patch
did not turn up any compilation failures on Linux.

* src/internal.h (includes): Drop unused header.
* daemon/libvirtd.h (includes): Likewise.
* configure.ac (AC_CHECK_HEADERS): Likewise.
Based on a report by Matthias Bolte.
2011-05-17 09:34:11 -06:00
Daniel P. Berrange
00e74007cb Fix prototype of virRun for Win32 targets
* src/util/util.c: Fix virRun prototype
2011-05-17 16:23:22 +01:00
Eric Blake
b3918fabda build: tolerate unlimited group size
POSIX allows sysconf(_SC_GETPW_R_SIZE_MAX) to return -1 if there
is no fixed limit, and requires ERANGE errors to track real size.
Model our behavior after the example in POSIX itself:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpwuid_r.html

Also, on error for get*_r functions, errno is undefined, and the
real error was the return value.

* src/util/util.c (virGetUserEnt, virGetUserID, virGetGroupID)
(virSetUIDGID):  Cope with sysconf failure or too small buffer.
Reported by Matthias Bolte.
2011-05-17 09:17:46 -06:00
Eric Blake
00fa155578 openvz: fix logic bug in previous patch
We want to free names on failure, not on success.

* src/openvz/openvz_driver.c (openvzListDefinedDomains): Use
correct condition.
2011-05-17 09:12:16 -06:00
Cole Robinson
1ccc16c603 storage_backend: Convert virRunWithHook usage to virCommand
virRunWithHook is now unused, so we can drop it. Tested w/ raw + qcow2
volume creation and copying.

v2:
    Use opaque data to skip hook second time around
    Simply command building

v3:
    Drop explicit FindFileInPath
2011-05-17 10:16:38 -04:00
Cole Robinson
51622f21a2 storage_backend: Fix error reporting with regex helper
Some clients overwrite the error from the regex helper, or do half-baked
error reporting with the exitstatus.
2011-05-17 10:16:38 -04:00
Cole Robinson
be1965be66 storage: Covert regex helpers to virCommand
v2:
    Simplify command creation
    Add a missing virCommandFree
    Use virCommand auto-cleanup for async process
2011-05-17 10:16:38 -04:00
Cole Robinson
0c0ed675de openvz: Convert virExec usage to virCommand
v2:
    Use virCommand's autocleanup

v3:
    Don't free 'names' on success
2011-05-17 10:16:38 -04:00
Cole Robinson
1fcafb02e2 storage: iscsi: Convert virExec to virCommand
v2:
    Use virCommand auto-cleanup
2011-05-17 10:11:09 -04:00
Matthias Bolte
5b77f1d5dc Fix error reporting in stream creation code
virStreamNew needs to dispatch the error that virGetStream reports
on failure.

remoteCreateClientStream can fail due to virStreamNew or due to
VIR_ALLOC. Report OOM error for VIR_ALLOC failure to report errors
in all error cases.

Remove OOM error reporting from remoteCreateClientStream callers.
2011-05-17 14:54:54 +02:00
Matthias Bolte
55cb8f5baa remote generator, client: Add more special case handling
For virDomainDestroy and virDrvSupportsFeature.
2011-05-17 14:52:23 +02:00
Matthias Bolte
0882f7a200 remote generator, client: Handle functions that return an optional string 2011-05-17 14:48:08 +02:00
Matthias Bolte
483ed20ae6 esx: Simplify some esxVI_Boolean to bool 2011-05-17 13:20:49 +02:00
Matthias Bolte
93f31b073d esx: Convert autoAnswer from esxVI_Boolean to a simple bool
Just true/false is good enough for it. Also use it directly from the
parsed URI instead of caching it in esxPrivate.
2011-05-17 13:16:48 +02:00
Matthias Bolte
6bf31327c6 esx: Fix race condition in esxVI_EnsureSession
When the session has expired then multiple threads can race while
reestablishing it.

This race condition is not that critical as it requires a special usage
pattern to be triggered. It can only happen when an application doesn't
do API calls for quite some time (the session expires after 30 min
inactivity) and then multiple threads doing simultaneous API calls and
end up doing simultaneous calls to esxVI_EnsureSession.
2011-05-17 13:11:32 +02:00
Jiri Denemark
c256542e76 virsh: Correctly initialize libvirt
virsh didn't call virInitialize(), which (among other things)
initializes virLastErr thread local variable. As a result of that, virsh
could just segfault in virEventRegisterDefaultImpl() since that is the
first call that touches (resets) virLastErr.

I have no idea what lucky coincidence made this bug visible but I was
able to reproduce it in 100% cases but only in one specific environment
which included building in sandbox.
2011-05-17 12:37:30 +02:00
Matthias Bolte
a39376016a esx: Whitespace cleanup in the generator
Break long lines and change spacing of keyword arguments to match
Python style standards better.

No functional change included.
2011-05-17 09:44:37 +02:00
Matthias Bolte
a6946ea66e esx: Change some alignments in the input file
No functional change included.
2011-05-16 20:22:50 +02:00
Matthias Bolte
1f6fc82bf3 esx: Change generated method parameter autobinding
Instead of specifying the type of the managed object directly specify
the ServiceContent member name. This way the mapping dictionary can be
removed.
2011-05-16 20:21:10 +02:00
Eric Blake
1d8bcb45ca maint: mark more perl scripts executable
* src/remote/rpcgen_fix.pl: Add executable bit.
* tests/oomtrace.pl: Likewise.
2011-05-16 10:12:21 -06:00
Daniel P. Berrange
6e7c56f8c9 Add missing initialization to 'ret' in qemu migration
* src/qemu/qemu_migration.c: Add missing 'ret' initializer
  in qemuMigrationCookieXMLParseStr
2011-05-16 16:11:10 +01:00
Daniel P. Berrange
91e5c3dc7c Disable virCommandExec on Win32
Mingw execve() has a broken signature. Disable this
function until gnulib fixes the signature, since we
don't really need this on Win32 anyway.

* src/util/command.c: Disable virCommandExec on Win32
2011-05-16 15:20:48 +01:00
Daniel P. Berrange
7bf733584a Improve error message when XDR marshalling fails
When failing to marshall an XDR message, include the
full program/version/status/proc/type info, to allow
easier debugging & diagnosis of the problem.

* src/remote/remote_driver.c: Improve error when marshalling
  fails
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
1d916a60a7 Run tunnelled migration IO in separate thread
By running the doTunnelSendAll code in a separate thread, the
main thread can do qemuMigrationWaitForCompletion as with
normal migration. This in turn ensures that job signals work
correctly and that progress monitoring can be done

* src/qemu/qemu_migration.c: Run tunnelled migration in
  separate thread
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
5a6ca96a01 Don't overwrite error when stream send fails
virStreamSend already sets an error message, so don't
overwrite it

* src/qemu/qemu_migration.c: Remove bogus error report
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
2bf92bb829 Close all sockets before cancelling QEMU migration
Cancelling the QEMU migration may cause QEMU to flush pending
data on the migration socket. This may in turn block QEMU if
nothing reads from the other end of the socket. Closing the
socket before cancelling QEMU migration avoids this possible
deadlock.

* src/qemu/qemu_migration.c: Close sockets before cancelling
  migration on failure
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
74f332468d Ensure we always read a full buffer in tunnelled migration
The 'nbytes' variable was not re-initialized to the
buffer size on each iteration of the tunnelled migration
loop. While saferead() will ensure a full read, except
on EOF, it is clearer to use the real buffer size

* src/qemu/qemu_migration.c: Always read full buffer of data
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
dba5a60462 Make tunnelled migration honour resource restriction
The doTunnelMigrate method forgot to set the bandwidth
resource restriction

* src/qemu/qemu_migration.c: Set resource restriction
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
792a5a6159 Refactor migration completion loop to allow code reuse
The qemuMigrationWaitForCompletion method contains a loop which
repeatedly queries QEMU to check migration progress, and also
processes job signals (pause, setspeed, setbandwidth, cancel).

The tunnelled migration loop does not currently support this
functionality, but should. Refactor the code to allow it to
be used with tunnelled migration.
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
2d5caf7a25 Implement migration v3 protocol in QEMU driver
Implement the v3 migration protocol, which has two extra
steps, 'begin' on the source host and 'confirm' on the
source host. All other methods also gain both input and
output cookies to allow bi-directional data passing at
all stages.

The QEMU peer2peer migration method gains another impl
to provide the v3 migration. This finally allows migration
cookies to work with tunnelled migration, which is required
for Spice seamless migration & the lock manager transfer

* src/qemu/qemu_driver.c: Wire up migrate v3 APIs
* src/qemu/qemu_migration.c, src/qemu/qemu_migration.h: Add
  begin & confirm methods, and peer2peer impl of v3
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
636ee9267f Merge tunnel & non-tunnel migration impl into one
Merge the doNonTunnelMigrate2 and doTunnelMigrate2 methods
into one doPeer2PeerMigrate2 method, since they are substantially
the same. With the introduction of v3 migration, this will be
even more important, to avoid massive code duplication.

* src/qemu/qemu_migration.c: Merge tunnel & non-tunnel migration
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
6b0fa703a8 Fix VM teardown if prepare returns invalid URI in v2 migration
The v2 migration protocol was accidentally missing out the
finish step, when prepare succeeded, but returned an invalid
URI

* src/libvirt.c: Teardown VM if prepare returns invalid URI
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
13cb49f847 Refactor tunnelled migration methods
To facilitate the introduction of the v3 migration protocol,
the doTunnelMigrate method is refactored into two pieces. One
piece is intended to mirror the flow of virDomainMigrateVersion2,
while the other is the helper for setting up sockets and processing
the data.

Previously socket setup would be done before the 'prepare' step,
so errors could be dealt with immediately, avoiding need to shut
off the destination QEMU. In the new split, socket setup is done
after the 'prepare' step. This is not a serious problem, since
the control flow already requires calling 'finish' to tear down
the destination QEMU upon several errors.

* src/qemu/qemu_migration.c:
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
cc53b4c444 Wire up SPICE client relocation with QEMU migration
Use the graphics information from the QEMU migration cookie to
issue a 'client_migrate_info' monitor command to QEMU. This causes
the SPICE client to automatically reconnect to the target host
when migration completes

* src/qemu/qemu_migration.c: Set data for SPICE client relocation
  before starting migration on src
* 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
  new qemuMonitorGraphicsRelocate() command
2011-05-16 15:18:22 +01:00
Daniel P. Berrange
72de0d2819 Pass graphics setup from dst back to src via migration cookies
Extend the QEMU migration cookie structure to allow information
about the destination host graphics setup to be passed by to
the source host. This will enable seamless migration of any
connected graphics clients

* src/qemu/qemu_migration.c: Add graphics info to migration
  cookies
* daemon/libvirtd.c: Always initialize gnutls to enable
  x509 cert parsing in QEMU
2011-05-16 15:18:21 +01:00
Daniel P. Berrange
8654175c5b Introduce migration cookies to QEMU driver
The migration protocol has support for a 'cookie' parameter which
is an opaque array of bytes as far as libvirt is concerned. Drivers
may use this for passing around arbitrary extra data they might
need during migration. The QEMU driver needs to do a few things:

 - Pass hostname/uuid to allow strict protection against localhost
   migration attempts
 - Pass SPICE/VNC server port from the target back to the source to
   allow seamless relocation of client sessions
 - Pass lock driver state from source to destination

This patch introduces the basic glue for handling cookies
but only includes the host/guest UUID & name.

* src/libvirt_private.syms: Export virXMLParseStrHelper
* src/qemu/qemu_migration.c, src/qemu/qemu_migration.h: Parsing
  and formatting of migration cookies
* src/qemu/qemu_driver.c: Pass in cookie parameters where possible
* src/remote/remote_protocol.h, src/remote/remote_protocol.x: Change
  cookie max length to 16384 bytes
2011-05-16 15:18:20 +01:00
Daniel P. Berrange
9ab245585b Fix locking with qemuMigrationPrepareTunnel method
The qemuMigrationPrepareTunnel method should not unlock the
qemu driver, since that is the caller's job.

* src/qemu/qemu_migration.c: Fix qemuMigrationPrepareTunnel
  unlocking of QEMU driver
2011-05-16 15:17:15 +01:00
Daniel P. Berrange
d59e14a1a2 Remote driver implementation of new migration API
* src/remote/remote_protocol.x: Define wire protocol for migration
  protocol v3
* daemon/remote.c: Server side dispatch
* src/remote/remote_driver.c: Client side serialization
* src/remote/remote_protocol.c, src/remote/remote_protocol.h,
  daemon/remote_dispatch_args.h, daemon/remote_dispatch_prototypes.h,
  daemon/remote_dispatch_ret.h, daemon/remote_dispatch_table.h:
  Re-generate files
* src/remote_protocol-structs: Declare new ABIs
2011-05-16 15:09:25 +01:00
Daniel P. Berrange
65043d2dff Introduce yet another migration version in API.
Migration just seems to go from bad to worse. We already had to
introduce a second migration protocol when adding the QEMU driver,
since the one from Xen was insufficiently flexible to cope with
passing the data the QEMU driver required.

It turns out that this protocol still has some flaws that we
need to address. The current sequence is

 *  Src: DumpXML
          - Generate XML to pass to dst

 *  Dst: Prepare
          - Get ready to accept incoming VM
          - Generate optional cookie to pass to src

 *  Src: Perform
          - Start migration and wait for send completion
          - Kill off VM if successful, resume if failed

 *  Dst: Finish
          - Wait for recv completion and check status
          - Kill off VM if unsuccessful

The problems with this are:

 - Since the first step is a generic 'DumpXML' call, we can't
   add in other migration specific data. eg, we can't include
   any VM lease data from lock manager plugins
 - Since the first step is a generic 'DumpXML' call, we can't
   emit any 'migration begin' event on the source, or have
   any hook that runs right at the start of the process
 - Since there is no final step on the source, if the Finish
   method fails to receive all migration data & has to kill
   the VM, then there's no way to resume the original VM
   on the source

This patch attempts to introduce a version 3 that uses the
improved 5 step sequence

 *  Src: Begin
          - Generate XML to pass to dst
          - Generate optional cookie to pass to dst

 *  Dst: Prepare
          - Get ready to accept incoming VM
          - Generate optional cookie to pass to src

 *  Src: Perform
          - Start migration and wait for send completion
          - Generate optional cookie to pass to dst

 *  Dst: Finish
          - Wait for recv completion and check status
          - Kill off VM if failed, resume if success
          - Generate optional cookie to pass to src

 *  Src: Confirm
          - Kill off VM if success, resume if failed

The API is designed to allow both input and output cookies
in all methods where applicable. This lets us pass around
arbitrary extra driver specific data between src & dst during
migration. Combined with the extra 'Begin' method this lets
us pass lease information from source to dst at the start of
migration

Moving the killing of the source VM out of Perform and
into Confirm, means we can now recover if the dst host
can't successfully Finish receiving migration data.
2011-05-16 15:09:19 +01:00
Daniel P. Berrange
9b1ae97fdc Add many version number annotations to drivers
Add many version number annotations to the internal driver
tables, to allow hvsupport.html to display more accurate
information
2011-05-16 14:20:48 +01:00
Daniel P. Berrange
879d409e9e Convert all driver struct intializers to C99 style
Change all the driver struct initializers to use the
C99 style, leaving out unused fields. This will make
it possible to add new APIs without changing every
driver. eg change:

    qemudDomainResume, /* domainResume */
    qemudDomainShutdown, /* domainShutdown */
    NULL, /* domainReboot */
    qemudDomainDestroy, /* domainDestroy */

to

    .domainResume = qemudDomainResume,
    .domainShutdown = qemudDomainShutdown,
    .domainDestroy = qemudDomainDestroy,

And get rid of any existing C99 style initializersr which
set NULL, eg change

     .listPools          = vboxStorageListPools,
     .numOfDefinedPools  = NULL,
     .listDefinedPools   = NULL,
     .findPoolSources    = NULL,
     .poolLookupByName   = vboxStoragePoolLookupByName,

to

     .listPools          = vboxStorageListPools,
     .poolLookupByName   = vboxStoragePoolLookupByName,
2011-05-16 14:20:43 +01:00
Daniel P. Berrange
360df0199e Tweak driver naming for consistency with public API
Fix some driver names:

  s/virDrvCPUCompare/virDrvCompareCPU/
  s/virDrvCPUBaseline/virDrvBaselineCPU/
  s/virDrvQemuDomainMonitorCommand/virDrvDomainQemuMonitorCommand/
  s/virDrvSecretNumOfSecrets/virDrvNumOfSecrets/
  s/virDrvSecretListSecrets/virDrvListSecrets/

And some driver struct field names:

  s/getFreeMemory/nodeGetFreeMemory/
2011-05-16 14:20:35 +01:00
Jiri Denemark
9f1319618a qemu: Update domain state when reconnecting monitor
A qemu domain can get paused when libvirtd is stopped (e.g., because of
I/O error) so we should check its current state when reconnecting to it.
2011-05-16 13:36:08 +02:00
Jiri Denemark
b046c55d40 Implement domain state reason
Only in drivers which use virDomainObj, drivers that query hypervisor
for domain status need to be updated separately in case their hypervisor
supports this functionality.

The reason is also saved into domain state XML so if a domain is not
running (i.e., no state XML exists) the reason will be lost by libvirtd
restart. I think this is an acceptable limitation.
2011-05-16 13:36:08 +02:00
Jiri Denemark
26d94012f6 Implement basic virDomainGetState in all drivers
Reason is currently always set to 0 (i.e., *_UNKNOWN).
2011-05-16 11:33:53 +02:00
Jiri Denemark
9f181ebc14 Wire protocol format and remote driver for virDomainGetState 2011-05-16 10:04:19 +02:00
Jiri Denemark
46b95e6428 virDomainGetState public API implementation 2011-05-16 10:04:18 +02:00
Jiri Denemark
6feb1341e5 Internal driver API for virDomainGetState 2011-05-16 10:04:18 +02:00
Jiri Denemark
d65a924b34 virDomainGetState public API
This API is supposed to replace virDomainGetInfo when the only purpose
of calling it is getting current domain status.
2011-05-16 10:04:18 +02:00
Eric Blake
0f9e52da82 phyp: avoid a crash
This has been present since the introduction of phypAttachDevice
in commit 444fd07a.

* src/phyp/phyp_driver.c (phypAttachDevice): Don't dereference
NULL.
2011-05-14 09:24:27 -06:00
Eric Blake
34b999be42 stream: avoid use-after-free
virFDStreamClose used a mutex after it was freed, and failed
to destroy that mutex on its last use.

* src/fdstream.c (virFDStreamFree): Inline into sole caller...
(virFDStreamClose): ...to avoid use-after-free and leak.
Reported by Matthias Bolte.
2011-05-14 09:02:33 -06:00
Matthias Bolte
fbe3ab1a27 esx: Refactor common code in the generator
Move common code from Property and Parameter into new Member class.

Rename the other base class to Type.
2011-05-14 12:15:15 +02:00
Matthias Bolte
efd9265991 esx: Improve dynamic cast detection in the generator
Detect it based on usage as parameter, return type and member of other
object types.
2011-05-14 12:10:38 +02:00
Matthias Bolte
35cdab71e4 esx: Improve list usage detection in the generator
Detect it based on usage as parameter and return type too.
2011-05-14 12:00:46 +02:00
Matthias Bolte
59f1f5f151 esx: Remove 1000 lines of generated but unused code
Don't make all object and enum types (de)serializable by default.
Detect this from the input file instead.
2011-05-14 11:51:21 +02:00
Matthias Bolte
6c1d30a7f5 esx: Generate implicit _this macros
Several vSphere API methods are called on global objects like the
FileManager, the PerformanceManager or the SearchIndex. The generator
input file allows to mark such methods and the generator generates
such method in a way that automatically handles marked parameter. This
is done by some special macros. Those were manually written and this
patch moves them to the generator.
2011-05-14 11:45:08 +02:00
Matthias Bolte
0b85d10483 esx: Move the Event type from the VI generator to manually written code
Accept all types on deserialization in order to accept all Event subtypes.

This will be used for the upcoming domain event support.
2011-05-14 11:01:43 +02:00
Matthias Bolte
fe99c6b3c6 command: Fix compilation on FreeBSD
kill, SIGTERM and SIGKILL require additional header.
2011-05-14 07:00:27 +02:00
Matthias Bolte
0ec289a469 apparmor: Fix compilation by removing remains from virCommand conversion
Commit aaf20355b8 was incomplete here and
missed to remove some parts.
2011-05-14 06:51:32 +02:00
Cole Robinson
028c30885e remote: Convert SSH tunnel to virCommand 2011-05-13 15:48:16 -04:00
Cole Robinson
b3ecd78064 storage: Convert qemu-img -help parsing to virCommand 2011-05-13 14:19:08 -04:00
Cole Robinson
aaf20355b8 apparmor: Convert virExec usage to virCommand
Untested
2011-05-13 14:19:08 -04:00
Cole Robinson
8d0188fb45 util: Combine __virExec and virExecWithHook
All callers were expecting argv logging, so the split is unneeded.

v2:
    Reindent new virExecWithHook call
2011-05-13 14:19:08 -04:00
Cole Robinson
0f5599cd2a remote_driver: Convert virExecDaemonize usage to virCommand
And drop the now unused virExecDaemonize
2011-05-13 14:19:08 -04:00
Eric Blake
1c9c494fc1 remote: keep 'make check' happy
* src/remote_protocol-structs (remote_domain_screenshot_args): Use
spelling preferred by dwarves.
2011-05-13 11:31:06 -06:00
Eric Blake
a9bb4f65ec libxl: fix typos in previous patch
* src/libxl/libxl_driver.c (libxlDomainEventFlush, libxlShutdown)
(libxlStartup): Fix typos.
2011-05-13 11:31:05 -06:00
Cole Robinson
4e6e66728f remote: Use virDomainEventState helpers
One functionality change here is that we no longer force enable the event
timeout for every queued event, only enable it for the first event after
the queue has been flushed. This is how other drivers have already done it,
and I haven't encountered problems in practice.

v3:
    Adjust for new virDomainEventStateNew argument
2011-05-13 11:00:10 -04:00
Cole Robinson
7405aebe01 libxl: Convert to virDomainEventState 2011-05-13 10:48:32 -04:00
Cole Robinson
4d7297f87e test: Use virDomainEventState helpers
v3:
    Adjust for new virDomainEventStateNew argument
2011-05-13 10:48:32 -04:00
Cole Robinson
1ded8942c7 lxc: Use virDomainEventState helpers
v3:
    Adjust for new virDomainEventStateNew argument
2011-05-13 10:48:32 -04:00
Cole Robinson
42a3687f29 qemu: Use virDomainEventState helpers
v2:
    Drop libvirt_private.syms changes

v3:
    Adjust for new virDomainEventStateNew argument
2011-05-13 10:48:32 -04:00
Cole Robinson
227d67ca00 domain_event: Add common domain event queue/flush helpers
The same code for queueing, flushing, and deregistering events exists
in multiple drivers, which will soon use these common functions.

v2:
    Adjust libvirt_private.syms
    isDispatching bool fixes
    NONNULL tagging

v3:
    Add requireTimer parameter to virDomainEventStateNew
2011-05-13 10:48:32 -04:00
Cole Robinson
aaf2b70bae domain_event: Add virDomainEventState structure
This structure will be used to unify lots of duplicated event handling code
across the state drivers.

v2:
    Check for state == NULL in StateFree
    Add NONNULL tagging
    Use bool for isDispatching

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2011-05-13 10:48:32 -04:00
Cole Robinson
b9e51e5677 xml: Use virXMLParse* helpers everywhere
virt-aa-helper isn't even compile tested since I don't have the setup for
it.

v2:
    virt-aa-helper fixes from Eric
2011-05-13 10:32:53 -04:00
Cole Robinson
34639a3f6b domain: Require <init> for container guests
Use capabilities to allow a driver to register a default <init> if none
is specified in the XML. Openvz was already open-coding this to be /sbin/init

LXC currently falls over if no init is specified, so an explicit error is
an improvement IMO.

(Side note: I don't think we can set a default value for LXC. If we use
/sbin/init but the user doesn't specify a separate root FS for their guest,
the container will rerun the host's init which can be traumatic :). For
virt-install I'm thinking of defaulting to /sbin/init if a root FS has
been specified, otherwise require the user to manually specify <init>)
2011-05-13 10:32:53 -04:00
Cole Robinson
0571c3afde xml: Make sure virXpathNodeSet always sets an error
And update callers to actually respect the error
2011-05-13 10:32:52 -04:00
Michal Privoznik
11d5488791 vbox: Implement the driver methods
* src/vbox/vbox_tmpl.c: New vboxDomainScreenshot() function
2011-05-13 12:46:25 +02:00
Michal Privoznik
9936aecfd1 qemu: Implement the driver methods
* src/qemu/qemu_driver.c: new qemuDomainScreenshot() function
* 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:
  Monitor command
2011-05-13 12:45:42 +02:00
Michal Privoznik
6a1f5f568f virFDStream: Add option for delete file after it's opening
This is needed if we want to transfer a temporary file. If the
transfer is done with iohelper, we might run into a race condition,
where we unlink() file before iohelper is executed.

* src/fdstream.c, src/fdstream.h,
  src/util/iohelper.c: Add new option
* src/lxc/lxc_driver.c, src/qemu/qemu_driver.c,
  src/storage/storage_driver.c, src/uml/uml_driver.c,
  src/xen/xen_driver.c: Expand existing function calls
2011-05-13 12:44:49 +02:00
Michal Privoznik
2c6efac985 screenshot: Implementing the remote protocol
* src/remote/remote_protocol.x: Wire protocol definition
* daemon/remote.c: Daemon part
* src/remote/remote_driver.c: Client part
* src/remote_protocol-structs: Add structures
2011-05-13 12:44:23 +02:00
Michal Privoznik
1f9f12140f screenshot: Implementing the public API
* src/libvirt.c: new function virDomainScreenshot
2011-05-13 12:43:49 +02:00
Michal Privoznik
3c38664339 screenshot: Defining the internal API
* src/driver.h: Stub code for new API
* src/esx/esx_driver.c, src/libxl/libxl_driver.c,
  src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
  src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
  rc/remote/remote_driver.c, rc/test/test_driver.c,
  src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
  src/vmware/vmware_driver.c, src/xen/xen_driver.c,
  src/xen/xen_driver.h, src/xen/xen_hypervisor.c,
  src/xen/xen_inotify.c, src/xen/xend_internal.c,
  src/xen/xm_internal.c, src/xen/xs_internal.c,
  src/xenapi/xenapi_driver.c: Add dummy entries in driver
  table for new APIs
2011-05-13 12:35:58 +02:00
Michal Privoznik
6a1fcd9f20 screenshot: Defining the public API
Add public API for taking screenshots of current domain console.

* include/libvirt/libvirt.h.in: add virDomainScreenshot
* src/libvirt_public.syms: Export new symbol
2011-05-13 12:35:45 +02:00
Matthias Bolte
2a5251e2c4 remote generator: Add skipgen/autogen flags to .x files
Make procedure parsing more robust, by allowing arbitrary
amounts of whitespaces.

Also make some error messages more verbose.
2011-05-12 08:44:07 +02:00
Eric Blake
88d03d4ff1 nwfilter: drop unused flag argument
The public API and RPC over-the-wire format have no flags argument,
so neither should the internal callback API.  This simplifies the
RPC generator.

* src/driver.h (virDrvNWFilterDefineXML): Drop argument that does
not match public API.
* src/nwfilter/nwfilter_driver.c (nwfilterDefine): Likewise.
* src/libvirt.c (virNWFilterDefineXML): Likewise.
* daemon/remote_generator.pl: Drop special case.
2011-05-11 19:26:59 -06:00
Eric Blake
cb84580a25 maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.

* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:20:33 -06:00
Eric Blake
5c129f7438 build: wrap macro body in one-shot do-while loop
* src/libvirt.c (VIR_DOMAIN_DEBUG_1): Convert to single statement.
Suggested by Jiri Denemark.
2011-05-11 15:14:05 -06:00
Eric Blake
5bc168ede3 build: drop need for VIR_DOMAIN_DEBUG0()
This one's tricker than the VIR_DEBUG0() removal, but the end
result is still C99 compliant, and reasonable with enough comments.

* src/libvirt.c (VIR_ARG10, VIR_HAS_COMMA)
(VIR_DOMAIN_DEBUG_EXPAND, VIR_DOMAIN_DEBUG_PASTE): New macros.
(VIR_DOMAIN_DEBUG): Rewrite to handle one argument, moving
multi-argument guts to...
(VIR_DOMAIN_DEBUG_1): New macro.
(VIR_DOMAIN_DEBUG0): Rename to VIR_DOMAIN_DEBUG_0.
2011-05-11 15:08:53 -06:00
Eric Blake
bc6bfeaa17 build: avoid gcc preprocessor extensions
Use of ',##__VA_ARGS__' is a gcc extension not guaranteed by
C99; thankfully, we can avoid it by lumping the format argument
into the var-args set.

* src/util/logging.h (VIR_DEBUG_INT, VIR_INFO_INT, VIR_WARN_INT)
(VIR_ERROR_INT, VIR_DEBUG, VIR_INFO, VIR_WARN, VIR_ERROR): Stick
to C99 var-arg macro syntax.
* examples/domain-events/events-c/event-test.c (VIR_DEBUG):
Simplify.
2011-05-11 13:28:50 -06:00
Lai Jiangshan
b65f37a4a1 libvirt,logging: cleanup VIR_XXX0()
These VIR_XXXX0 APIs make us confused, use the non-0-suffix APIs instead.

How do these coversions works? The magic is using the gcc extension of ##.
When __VA_ARGS__ is empty, "##" will swallow the "," in "fmt," to
avoid compile error.

example: origin				after CPP
	high_level_api("%d", a_int)	low_level_api("%d", a_int)
	high_level_api("a  string")	low_level_api("a  string")

About 400 conversions.

8 special conversions:
VIR_XXXX0("") -> VIR_XXXX("msg") (avoid empty format) 2 conversions
VIR_XXXX0(string_literal_with_%) -> VIR_XXXX(%->%%) 0 conversions
VIR_XXXX0(non_string_literal) -> VIR_XXXX("%s", non_string_literal)
  (for security) 6 conversions

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2011-05-11 12:41:14 -06:00
Eric Blake
98cd17bd18 node_device: avoid null dereference on error
If we plow on after udev_device_get_syspath fails, we will hit a NULL
dereference.  Clang found one due to strdup later in udevSetParent,
but in fact we hit a NULL dereference sooner because of the use of
STREQ within virNodeDeviceFindBySysfsPath.

* src/conf/node_device_conf.h (virNodeDeviceFindBySysfsPath): Mark
path argument non-null.
* src/node_device/node_device_udev.c (udevSetParent): Avoid null
dereference.
2011-05-11 11:55:16 -06:00
Eric Blake
4c6ae9ae36 build: remove some dead assignments
No syntactic effect; this merely silences some clang warnings.

* src/libxl/libxl_driver.c (libxlDomainSetVcpusFlags): Drop
redundant ret=0 statement.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextDriveDel):
Likewise.
2011-05-11 10:43:13 -06:00
Daniel P. Berrange
cbf9f2f2c0 Allow destroying QEMU VM even if a job is active
Introduce a virProcessKill function that can be safely called
even when the job mutex is held. This allows virDomainDestroy
to kill any VM even if it is asleep in a monitor job. The PID
will die and the thread asleep on the monitor will then wake
up releasing the job mutex.

* src/qemu/qemu_driver.c: Kill process before using qemuProcessStop
  to ensure job is released
* src/qemu/qemu_process.c: Add virProcessKill for killing off
  QEMU processes
2011-05-11 09:35:15 +01:00
Daniel P. Berrange
9f5d3a912d Add support for YAJL version 2 API/ABI
Version 2.0.0 or yajl changed API. It is fairly trivial for us to
cope with both APIs in libvirt, so adapt.

* configure.ac: Probe for yajl2 API
* src/util/json.c: Conditional support for yajl2 API
2011-05-11 09:35:10 +01:00
Paolo Bonzini
761a742a8d libxl: support enabling the HPET
libxl accepts hpet configuration in its domain info struct.  Parse the
domain definition's <clock> element in order to set the value.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Apologies from Eric Blake, for mistakenly committing the broken
intermediate version.
2011-05-10 16:38:30 -06:00
Paolo Bonzini
0fd3fac537 libxl: support enabling the HPET
libxl accepts hpet configuration in its domain info struct.  Parse the
domain definition's <clock> element in order to set the value.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-05-10 16:28:09 -06:00
Paolo Bonzini
e547e44cb0 xen: parse and generate hpet item in sxpr
Recent versions of Xen disable the virtual HPET by default.  This is
usually more precise because tick policies are not implemented for
the HPET in Xen.  However, there may be several reasons to control
the HPET manually: 1) to test the emulation; 2) because distros may
provide the knob while leaving the default to "enabled" for compatibility
reasons.

This patch provides support for the hpet item in both sexpr and xm
formats, and translates it to a <timer> element.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2011-05-10 16:16:55 -06:00
Doug Goldstein
343c69dbad virsh: flexibility in CA cert and user cert/key
Allow the CA certificate to come from the user's home directory or from
the global location independently of the client certificate/key pair.

Mostly for the case when each user on a system has their own cert/key
pair but the system as a whole shares the same CA.

Signed-off-by: Doug Goldstein <cardoe@gentoo.org>
2011-05-10 14:45:09 -06:00
Matthias Bolte
bfb188dd44 remote generator: Unify unsigned int notation in .x files
Rename u_int and unsigned to unsigned int. This gets rid of some special
case code in the generator.
2011-05-10 20:47:24 +02:00
Matthias Bolte
9817604afc Rename internal DumpXML functions to GetXMLDesc
This matches the public API and helps to get rid of some special
case code in the remote generator.

Rename driver API functions and XDR protocol structs.

No functional change included outside of the remote generator.
2011-05-10 20:32:41 +02:00
Lai Jiangshan
fcf967f2ad qemu,inject-nmi: Implement the driver methods 2011-05-10 11:40:51 -06:00
Lai Jiangshan
b8c776eb63 inject-nmi: Implementing the remote protocol 2011-05-10 11:40:51 -06:00
Lai Jiangshan
9a1b5dc66f inject-nmi: Implementing the public API 2011-05-10 11:40:51 -06:00
Lai Jiangshan
b19bd85e15 inject-nmi: Defining the internal API 2011-05-10 11:40:51 -06:00
Lai Jiangshan
b08ad6cd87 inject-nmi: Defining the public API 2011-05-10 11:40:51 -06:00
Cole Robinson
0ed4aa448e lxc: container: Build init cmd before we close stdout
That way we can log the 'init' argv for debugging.
2011-05-10 13:15:50 -04:00
Cole Robinson
0719c3d64c lxc: container: Convert <init> exec to virCommand 2011-05-10 13:15:50 -04:00
Cole Robinson
f095398a47 command: Add virCommandExec helper
Actually execs the argv/env we've generated, replacing the current process.
Kind of has a limited usage, but allows us to use virCommand in LXC
driver to launch the 'init' process
2011-05-10 13:15:50 -04:00
Cole Robinson
924eb9a4b4 lxc: driver: Improve logging when launching emulator
Log the full command line and a timestamp like we do for QEMU
2011-05-10 13:15:50 -04:00
Cole Robinson
451cfd05a2 lxc: driver: Convert emulator launching to virCommand
v2:
    Shorten a few virCommand calls
    s/remain/retain/
2011-05-10 13:15:50 -04:00
Cole Robinson
35c1b35e25 command: Add virCommandEnvAddFormat
Similar to virCommandArgAddFormat. We will use this shortly.

v2:
    Convert virCommandEnvAddPair to use the new function
2011-05-10 13:15:50 -04:00
Matthias Bolte
fc0ab50abd Fix two uninitialized variable warnings
gcc only reports them when compiling with -O3.
2011-05-10 08:39:56 +02:00
Matthias Bolte
ebea59ad82 apparmor: Fix uninitalized variable warning in virt-aa-helper 2011-05-10 08:03:31 +02:00
Daniel P. Berrange
8b83cc4219 Remove bogus assert() from migration code
assert() is forbidden in libvirt code, and these two cases would
in fact never execute due to earlier error checks.

* src/libvirt.c: Remove assert() usage
2011-05-09 17:59:04 +01:00
Jiri Denemark
b9171eba2f json: Fix *GetBoolean functions
They were not used anywhere so far so nobody noticed they are broken.
2011-05-09 14:02:13 +02:00
Eric Blake
0f536dea9b build: rebuild generated files after rpcgen_fix.pl tweak
Noticed this while trying to run rpcgen on cygwin.

* src/Makefile.am ($(srcdir)/remote/%_protocol.h)
($(srcdir)/remote/%_protocol.c): Add a dependency.
2011-05-09 14:02:13 +02:00
Eric Blake
3e63a94cb9 build: fix VPATH builds
* src/Makefile.am (REMOTE_DRIVER_GENERATED): Generated files
should live in $(srcdir). Update rules to reflect this.
2011-05-09 14:02:13 +02:00
Daniel P. Berrange
3496b7f500 build: Remove all generated RPC files from GIT
Stop storing the generated files for the remote protocol client
and server in source control. The generated files will still be
included in the result of 'make dist' to avoid end-users needing
to generate the files

Signed-off-by: Eric Blake <eblake@redhat.com>

Unfortunately, this means that the strings marked for translation
in generated files are not picked up by gnulib's syntax-check,
I'm working on fixing that in gnulib.

* .gitignore, cfg.mk, po/POTFILES.in: Reflect deletion.
2011-05-06 16:22:33 -06:00
Daniel P. Berrange
fb1e8d9c44 build: refactor generated RPC files
Always generate the rpc files, and require rpcgen during bootstrap.

* daemon/Makefile.am: Removed generated files with
  maintainer-clean target
* src/Makefile.am: Removed generated files with
  maintainer-clean target. Always run 'rpcgen' if
  generated files are missing
2011-05-06 16:18:31 -06:00
Eric Blake
d3c5104dda build: rename generated files to .h, for automake's sake
In preparation for removing generated files, it is necessary
to tell automake that the generated files must be distributed
but not directly compiled (since they are included into the
body of a larger .c file that is compiled).  Hence, even though
these files are code and not headers in the strict sense of
the word, it is easier to rename them to .h for automake's sake.

* daemon/remote_client_bodies.c: Rename to .h.
* daemon/qemu_client_bodies.c: Likewise.
* src/remote/remote_client_bodies.c: Likewise.
* src/remote/qemu_client_bodies.c: Likewise.
* daemon/Makefile.am (remote_dispatch_bodies.c)
(qemu_dispatch_bodies.c): Rename to .h.
(remote.c, EXTRA_DIST): Reflect rename.
* daemon/remote.c: Likewise.
* daemon/remote_generator.pl: Likewise.
* src/Makefile.am (remote/remote_driver.c): Likewise.
* src/remote/remote_driver.c: Likewise.
* po/POTFILES.in: Likewise.
* cfg.mk (exclude_file_name_regexp--sc_require_config_h)
(exclude_file_name_regexp--sc_require_config_h_first)
(exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF):
Likewise.
2011-05-06 15:11:36 -06:00
Matthias Bolte
15b64ef0ed remote generator, client: Handle arguments with limited length
This adds length checks to all affected functions.
2011-05-06 20:27:29 +02:00
Matthias Bolte
b5041a49ec remote generator, client: Handle functions that return lists 2011-05-06 20:27:27 +02:00
Matthias Bolte
8921799aae remote: Refactor remote*Open and remote*Close functions
Add generic versions of the open and close functions and call them.
2011-05-06 20:27:26 +02:00
Matthias Bolte
58b6a5c49e remote generator, client: Handle functions with optional return values 2011-05-06 20:27:24 +02:00
Matthias Bolte
abd05a07ae remote generator, client: Handle functions with multiple return values 2011-05-06 20:27:22 +02:00
Matthias Bolte
a1c891ec1e remote generator, client: Handle functions with wrapped return values 2011-05-06 20:27:20 +02:00
Matthias Bolte
9de503f957 remote generator, client: Handle functions with simple return values 2011-05-06 20:27:18 +02:00
Matthias Bolte
f68bb4edb3 remote generator, client: Handle simple remote driver functions
Rename remoteSecretListSecrets to remoteListSecrets to match the normal
naming pattern.
2011-05-06 20:26:21 +02:00
Matthias Bolte
6384104bcc remote generator, daemon: Handle functions with multiple return values
Once again rename members in the XDR definitions to avoid special case
code in the generator.
2011-05-06 20:08:36 +02:00
Matthias Bolte
705519d8e9 remote: Rename 'nameslen' to the common 'maxnames'
Avoids special case handling in the remote generator.
2011-05-06 20:08:25 +02:00
Matthias Bolte
37cb0882b5 remote: Replace 'domain' with 'dom' in the XDR protocol
This simplifies the remote protocol code generator.

Also rename 'ret' to 'result' to resolve a naming conflict in the
generator.
2011-05-06 20:05:00 +02:00
Matthias Bolte
aff1db9fab remote generator, daemon: Output function bodies too
This patch just covers the simple functions without explicit return
values. There is more to be handled.

The generator collects the members of the XDR argument structs and uses
this information to generate the function bodies.

Exclude the generated files from offending syntax-checks.

Suggested by Richard W.M. Jones
2011-05-06 20:04:56 +02:00
Matthias Bolte
999f5b3ea6 remote generator: Replace tabs with spaces and rename file
No functional change included, just a whitespace change.
2011-05-06 20:04:55 +02:00
Markus Groß
0d9936f622 Balloon dom0 in libxl driver
Creating a domU on a freshly booted dom0 does not work,
because the libxl driver does not allocate memory for the domU.
After creating a domain with xl libvirt is able to create domains too.
This patch reserves enough memory for the domU first.
2011-05-06 11:20:33 -06:00
Doug Goldstein
db36449fd6 remote: check actual access to the cert
Instead of calling stat(), check that we'll actually be able to access
and read the file.

Signed-off-by: Doug Goldstein <cardoe@gentoo.org>
2011-05-06 10:38:14 -06:00
Eric Blake
f84fe150e1 maint: avoid comparisons to bool constants
HACKING already mentions that comparisons against literal 'true'
are unsafe; for consistency, also shorten comparisons against 'false'.

* src/conf/domain_conf.c (virDomainNetDefParseXML): Simplify.
* src/nwfilter/nwfilter_gentech_driver.c
(virNWFilterDomainFWUpdateCB): Likewise.
* tools/virsh.c (cmdVolDownload, vshCommandRun, vshPrintExtra):
Likewise.
2011-05-06 10:28:28 -06:00
Michal Privoznik
5d09c31495 Add warning message to XML definition files stored on disk
Users often edit XML file stored in configuration directory
thinking of modifying a domain/network/pool/etc. Thus it is wise
to let them know they are using the wrong way and give them hint.
2011-05-06 16:48:52 +02:00
Daniel P. Berrange
d37c6a3ae0 Fix security driver handling of FIFOs with QEMU
When setting up a FIFO for QEMU, it allows either a pair
of fifos used unidirectionally, or a single fifo used
bidirectionally. Look for the bidirectional fifo first
when labelling since that is more useful

* src/security/security_dac.c,
  src/security/security_selinux.c: Fix fifo handling
2011-05-06 12:56:32 +01:00
Daniel P. Berrange
f79cddad55 Make taint warnings also go into the domain logfile
As well as taint warnings going to the main libvirt log,
add taint warnings to the per-domain logfile

  Domain id=3 is tainted: high-privileges
  Domain id=3 is tainted: disk-probing
  Domain id=3 is tainted: shell-scripts
  Domain id=3 is tainted: custom-monitor

* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Enhance
  qemuDomainTaint to also log to the domain logfile
* src/qemu/qemu_driver.c: Pass -1 for logFD to taint methods to
  auto-append to logfile
* src/qemu/qemu_process.c: Pass open logFD at startup for taint
  methods
2011-05-06 12:02:02 +01:00
Daniel P. Berrange
1f1db0b52f Add a qemuDomainAppendLog method for writing to the domain logfile
The qemuDomainAppendLog method allows writing a formatted string
to the end of the domain logfile, optionally opening it if needed.

* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Add
  qemuDomainAppendLog
2011-05-06 12:02:02 +01:00
Daniel P. Berrange
ce1b1f4186 Move qemuProcessLogReadFD and qemuProcessLogFD methods
Move the qemuProcessLogReadFD and qemuProcessLogFD methods
into qemu_domain.c, renaming them to qemuDomainCreateLog
and qemuDomainOpenLog.

* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Add
  qemuDomainCreateLog and qemuDomainOpenLog.
* src/qemu/qemu_process.c: Remove qemuProcessLogFD
  and qemuProcessLogReadFD
2011-05-06 12:02:02 +01:00
Daniel P. Berrange
718ac9b52f Log taint warnings in QEMU driver
Wire up logging of VM tainting to the QEMU driver

 - If running QEMU as root user/group or without capabilities
   being cleared
 - If passing custom QEMU command line args
 - If issuing custom QEMU monitor commands
 - If using a network interface config with an associated
   shell script
 - If using a disk config relying on format probing

The warnings, per-VM appear in the main libvirtd logs

  11:56:17.571: 10832: warning : qemuDomainObjTaint:712 : Domain id=1 name='l2' uuid=c7a3edbd-edaf-9455-926a-d65c16db1802 is tainted: high-privileges
  11:56:17.571: 10832: warning : qemuDomainObjTaint:712 : Domain id=1 name='l2' uuid=c7a3edbd-edaf-9455-926a-d65c16db1802 is tainted: disk-probing

The taint flags are reset when the VM is stopped.

* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Helper APIs
  for logging taint warnings
* src/qemu/qemu_driver.c: Log tainting with custom QEMU monitor
  commands and disk/net hotplug with unsupported configs
* src/qemu/qemu_process.c: Log tainting at startup based on
  unsupported configs
2011-05-06 12:02:02 +01:00
Daniel P. Berrange
7998465005 Add field to virDomainObjPtr to track "tainting"
Some configuration setups for guests are allowed, but strongly
discouraged and unsupportable in production systems. Introduce
a concept of 'tainting' to virDomainObjPtr to allow such setups
to be identified. Drivers can then log warnings at suitable
times

* src/conf/domain_conf.c, src/conf/domain_conf.h: Declare taint
  flags and add parsing/formatting of domain status XML
2011-05-06 12:01:57 +01:00
Doug Goldstein
1945d74cc3 virsh: improve TLS certificate error messages
Print the name of the CA cert, certificate, and key file that resulted
in the failure so that the user has an idea what to troubleshoot.

Signed-off-by: Doug Goldstein <cardoe@gentoo.org>
2011-05-05 17:16:58 -06:00
Eric Blake
f09acccfd7 buf: add virBufferVasprintf
Match the fact that we have virAsprintf and virVasprintf.

* src/util/buf.h (virBufferVasprintf): New prototype.
* src/util/buf.c (virBufferAsprintf): Move guts...
(virBufferVasprintf): ...to new function.
* src/libvirt_private.syms (buf.h): Export it.
* bootstrap.conf (gnulib_modules): Add stdarg, for va_copy.
2011-05-05 13:48:19 -06:00
Eric Blake
68ea80cfdd maint: rename virBufferVSprintf to virBufferAsprintf
We already have virAsprintf, so picking a similar name helps for
seeing a similar purpose.  Furthermore, the prefix V before printf
generally implies 'va_list', even though this variant was '...', and
the old name got in the way of adding a new va_list version.

global rename performed with:

$ git grep -l virBufferVSprintf \
  | xargs -L1 sed -i 's/virBufferVSprintf/virBufferAsprintf/g'

then revert the changes in ChangeLog-old.
2011-05-05 13:47:40 -06:00
Daniel P. Berrange
f7fc885dec Fix qemuMigrationToFile nonull annotation
The qemuMigrationToFile method was accidentally annotated for
the 'compressor' parameter to be non-null, instead of the
'path' parameter. Thus GCC with -O2, unhelpfully deleted the
entire 'if (compressor == NULL)' block of code during
optimization. Thus NULL was passed to virCommandNew() with
predictably bad results.

* src/qemu/qemu_migration.h: Fix non-null annotation to be
  against path instead of compressor
2011-05-05 12:53:23 +01:00
Daniel P. Berrange
7c31e1ef0f Make QEMU migration use cached qemu capabilities data
* src/qemu/qemu_migration.c, src/qemu/qemu_migration.h: Remove
  qemuCaps parameters & use cached data
* src/qemu/qemu_driver.c: Don't create & pass qemuCaps to
  migration methods
2011-05-05 11:33:15 +01:00
Daniel P. Berrange
a623bff450 Make QEMU hotplug use cached qemu capabilities data
* src/qemu/qemu_hotplug.h, src/qemu/qemu_hotplug.c: Remove
  qemuCaps parameters from all methods
* src/qemu/qemu_driver.c: Don't create & pass qemuCaps to
  hotplug methods
2011-05-05 11:33:10 +01:00
Daniel P. Berrange
43c01d3838 Persist qemu capabilities in the domain status file
To cope with the QEMU binary being changed while a VM is running,
it is neccessary to persist the original qemu capabilities at the
time the VM is booted.

* src/qemu/qemu_capabilities.c, src/qemu/qemu_capabilities.h: Add
  an enum for a string rep of every capability
* src/qemu/qemu_domain.c, src/qemu/qemu_domain.h: Support for
  storing capabilities in the domain status XML
* src/qemu/qemu_process.c: Populate & free QEMU capabilities at
  domain startup
2011-05-05 11:33:03 +01:00
Eric Blake
4644f0b253 storage: avoid null deref and leak on failure
Detected by clang.  NULL deref added in commit 343a27a (Mar 11),
but leak of voldef present since commit 2cd9b2d (Apr 09).

* src/storage/storage_driver.c (storageVolumeCreateXML): Don't
leak voldef or dereference null volobj.
2011-05-04 15:01:13 -06:00
Matthias Bolte
6eb3a1f4f7 esx: Disable performance counter queries in esxDomainGetInfo
The queried values aren't used yet.
2011-05-04 20:41:09 +02:00
Matthias Bolte
62a6b7cc9b esx: Avoid null dereference on error in esxDomainGetInfo
Add missing early exits and convert error logging to proper API level
error reporting.

Centralize cleanup code for the PerfQuerySpec object.

Reported by Eric Blake, detected by clang.
2011-05-04 20:25:28 +02:00
Matthias Bolte
d0a8f99c75 esx: Remove dead store in esxUtil_ParseDatastorePath
The ++ on preliminaryFileName was a left over from a previous version
of this function that explicitly returned the filename and did a strdup
on preliminaryFileName afterwards.

As the filename isn't returned explicitly anymore remove the preliminary
variable for it and reuse the tmp variable instead.

Reported by Eric Blake, detected by clang.
2011-05-04 18:33:14 +02:00
Eric Blake
29e131dec2 qemu: update qemuCgroupControllerActive signature
Clang warned about a dead assignment.  In the process, I noticed
that we are only using the function for a bool value.  I audited
all other callers in qemu_{migration,cgroup,driver,hotplug), and
all were making the call in a bool context.

Also, do bounds checking on the argument.

* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Delete dead
assignment.
(qemuCgroupControllerActive): Change return type to bool.
* src/qemu/qemu_cgroup.h (qemuCgroupControllerActive): Likewise.
2011-05-04 09:35:47 -06:00
Eric Blake
44aa49aefe util: remove dead assignment
Clang complained about this, and it was easy enough to fix.

* src/util/util.c (virFileOpenAs): Drop dead assignment.
2011-05-04 09:25:07 -06:00
Eric Blake
32388f12d5 lxc: report correct error
Clang noticed a dead assignment, which turned out to be the use
of the wrong variable.  rc starts life as -1, and is only ever
assigned to 0 just before a successful cleanup.

* src/lxc/lxc_driver.c (lxcSetupInterfaces): Don't call
virReportSystemError(-1).
2011-05-04 09:24:09 -06:00
Eric Blake
710f8811f5 libxl: avoid compiler warning
Detected by gcc:

libxl/libxl_driver.c: In function 'libxlDomainDestroy':
libxl/libxl_drier.c:1351:30: error: variable 'priv' set but not used [-Werror=unused-but-set-variable]

* src/libxl/libxl_driver.c (libxlDomainDestroy): Delete unused
variable.
2011-05-04 09:21:05 -06:00
Eric Blake
5f929dd3aa qemu: remove dead assignment
Detected by clang.

* src/qemu/qemu_migration.c (qemuMigrationToFile): Nothing later
uses is_reg.
2011-05-04 09:14:13 -06:00
Eric Blake
f72393fa97 storage: use virCommand to avoid compiler warning
clang didn't like the last increment to nargs.  But why even
track nargs ourselves, when virCommand does it for us?

* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIConnection): Switch to virCommand to avoid
a dead-store warning on nargs.
2011-05-04 08:54:20 -06:00
Eric Blake
ead2b43357 cgroup: avoid leaking a file
Clang detected a dead store to rc.  It turns out that in fixing this,
I also found a FILE* leak.

This is a subtle change in behavior, although unlikely to hit.  The
pidfile is a kernel file, so we've probably got more serious problems
under foot if we fail to parse one.  However, the previous behavior
was that even if one pid file failed to parse, we tried others,
whereas now we give up on the first failure.  Either way, though,
the function returns -1, so the caller will know that something is
going wrong, and that not all pids were necessarily reaped.  Besides,
there were other instances already in the code where failure in the
inner loop aborted the outer loop.

* src/util/cgroup.c (virCgroupKillInternal): Abort rather than
resuming loop on fscanf failure, and cleanup file on error.
2011-05-04 08:38:27 -06:00
Eric Blake
d8f7528157 qemu: silence clang false positives
Clang 2.8 wasn't quite able to follow that persistentDef was
assigned earlier if (flags & VIR_DOMAIN_MEM_CONFIG) is true.
Silence this false positive, to make clang analysis easier to use.

* src/qemu/qemu_driver.c (qemudDomainSetMemoryFlags): Add an
annotation to silence clang's claim of a NULL dereference.
2011-05-03 13:19:48 -06:00
Eric Blake
1164e1a2da pci: fix null pointer dereference
Clang detected a null-pointer dereference regression, introduced
in commit 4e8969eb.  Without this patch, a device with
unbind_from_stub set to false would eventually try to call
virFileExists on uncomputed drvdir.

* src/util/pci.c (pciUnbindDeviceFromStub): Ensure drvdir is set
before use.
2011-05-03 10:59:57 -06:00
Eric Blake
4d080ee403 qemu: avoid null pointer dereference
This code has had problems historically.  As originally
written, in commit 6bcf2501 (Jun 08), it could call unlink
on a random string, nuking an unrelated file.

Then commit 182a80b9 (Sep 09), the code was rewritten to
allocate tmp, with both a use-after-free bug and a chance to
call unlink(NULL).

Commit e206946 (Mar 11) fixed the use-after-free, but not the
NULL dereference.  Thanks to clang for catching this!

* src/qemu/qemu_driver.c (qemudDomainMemoryPeek): Don't call
unlink on NULL.
2011-05-03 10:59:55 -06:00
Eric Blake
6e177fa1b6 Revert "lxc: Do not try to reconnect inactive domain when do lxcStartup"
This reverts commit 0e7f7f8566.

From the mailing list:

> So, AFAICT, this patch means we will never reconnect to any LXC
> VMs now.
>
> The correct solution, is to refactor LXC driver startup to work
> the same way as the QEMU driver startup.
>
>   - Load all the live state XML files (to pick up running VMs)
>   - Reconnect to all VMs
>   - Load all the persistent config XML files (to pick up any additional
>     inactive guets)

But that solution is invasive enough to be post-0.9.1.
2011-05-03 10:07:48 -06:00
Michal Privoznik
a2eab0033c Fix disability to run on systems with no PCI bus
The patch which moved libpciaccess initialization to one place caused
regression - we were not able to run on system with no PCI bus, like
s390(x).
2011-05-03 13:46:22 +02:00
Osier Yang
0e7f7f8566 lxc: Do not try to reconnect inactive domain when do lxcStartup
Otherwise if there are inactive lxc domains, lxcStartup will
try to reconnect to sockets of these domains, which results in
errors in libvirtd log.
2011-05-03 14:48:03 +08:00
Christophe Fergeau
b15a8a1bdf qemu: fix uninitialized variable warning
This commit fixes
qemu/qemu_driver.c: In function 'qemuDomainModifyDeviceFlags':
qemu/qemu_driver.c:4041:8: warning: 'ret' may be used uninitialized in this
function [-Wuninitialized]
qemu/qemu_driver.c:4013:9: note: 'ret' was declared here

The variable is set to -1 so that the error paths are taken when the code
to set it didn't get a chance to run. Without initializing it, we could
return some an undefined value from this function.

While I was at it, I made a trivial whitespace change in the same function
to improve readability.
2011-05-02 09:23:47 -06:00
Matthias Bolte
0e7c7b8b32 nwfilter: Fix memory leak in the ebtables subdriver
Call shutdown functions for all subcomponents in nwfilterDriverShutdown.

Make sure that this shutdown functions can safely be called multiple times
and independent from the actual subcomponents state.
2011-04-30 17:37:54 +02:00
Matthias Bolte
feecc9f395 qemu: Fix qemuDomainModifyDeviceFlags leaking the caps bitmap 2011-04-30 17:37:34 +02:00
Matthias Bolte
9d50b323a9 Fix memory leak in __virExec
Commit e0d014f237 made binary potentially allocated on the heap.
It was freed in the parent in the error path, but not in the success path
that doesn't goto the cleanup label.

Found by 'make -C tests valgrind'.
2011-04-30 17:37:29 +02:00
Eric Blake
701bee0193 hash: fix memory leak regression
Commit 1671d1d introduced a memory leak in virHashFree, and
wholesale table corruption in virHashRemoveSet (elements not
requested to be freed are lost).

* src/util/hash.c (virHashFree): Free bucket array.
(virHashRemoveSet): Don't lose elements.
* tests/hashtest.c (testHashCheckForEachCount): New method.
(testHashCheckCount): Expose the bug.
2011-04-29 14:26:40 -06:00
KAMEZAWA Hiroyuki
f37c29c8aa libvirt/qemu - support persistent update of disks
Support update of disks by MODIFY_CONFIG

This patch includes changes for qemu's disk to support
virDomainUpdateDeviceFlags() with VIR_DOMAIN_DEVICE_MODIFY_CONFIG.

This patch adds support for CDROM/foppy disk types.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

* src/qemu/qemu_driver.c
(qemuDomainUpdateDeviceConfig): support cdrom/floppy.
2011-04-28 14:59:06 -06:00
Jim Fehlig
578391e1bc Xen: Do not generate net ifname if domain is inactive
V2: Use virAsprintf instead of snprintf/strdup

The xend driver will generate a virDomainNetDef ifname if one is not
specified in xend sexpr, even if domain is inactive.  The result is
network interface XML containing 'vif-1.Y' on dev attribute of target
element, e.g.

  <interface type='bridge'>
    <target dev='vif-1.0'/>
    ...

This patch changes the behavior to only generate the ifname if not
specified in xend sexpr *and* domain is not inactive (id != -1).
2011-04-28 14:54:06 -06:00
Yufang Zhang
a88916665d xen: check if device is assigned to guest before reattaching
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=664059

Reattaching pci device back to host without destroying guest or
detaching device from guest would cause host to crash. This patch adds
a check before doing device reattach. If the device is being assigned
to guest, libvirt refuses to reattach device to host. The patch only
works for Xen, for it just checks xenstore to get pci device
information.

Signed-off-by: Yufang Zhang <yuzhang@redhat.com>
2011-04-28 14:45:31 -06:00
Laine Stump
f7bd72fa26 network: fix return value of hostsFileWrite
The lone caller to hostsFileWrite (and the callers for at least 3
levels up the return stack) assume that the return value will be < 0
on failure. However, hostsFileWrite returns 0 on success, and a
positive errno on failure. This patch changes hostsFileWrite to return
-errno on failure.
2011-04-28 10:44:57 -04:00
Eric Blake
a372c405b4 maint: fix comment typos
* src/esx/esx_driver.c: Fix spelling of 'relative'.
* src/util/util.c: Likewise.
2011-04-28 08:19:51 -06:00
Osier Yang
32398e1282 util: Initialize hooks at daemon shutdown if no hooks defined
We support to initialize the hooks at daemon reload if there is no
hooks script is defined, we should also support initialize the hooks
at daemon shutdown if no hooks is defined.

To address bz: https://bugzilla.redhat.com/show_bug.cgi?id=688859
2011-04-28 14:48:26 +08:00
KAMEZAWA Hiroyuki
ab9102c232 libvirt/qemu - support persistent attach/detach disks
Support changes of disks by MODIFY_CONFIG for qemu.

This patch includes patches for qemu's disk to support
virDomainAt(De)tachDeviceFlags with VIR_DOMAIN_DEVICE_MODIFY_CONFIG.

Other devices can be added incrementally.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

* /src/conf/domain_conf.c
(virDomainDiskIndexByName): returns array index of disk in vmdef.
(virDomainDiskRemoveByName): removes a disk which has the name in vmdef.
* src/qemu/qemu_driver.c
(qemuDomainAttachDeviceConfig): add support for Disks.
(qemuDomainDetachDeviceConfig): add support for Disks.
2011-04-27 21:46:35 -06:00
KAMEZAWA Hiroyuki
da1eba6bc8 libvirt/qemu - support persistent modification of devices
This patch adds functions for modify domain's persistent definition.
To do error recovery in easy way, we use a copy of vmdef and update it.

The whole sequence will be:

  make a copy of domain definition.

  if (flags & MODIFY_CONFIG)
      update copied domain definition
  if (flags & MODIF_LIVE)
      do hotplug.
  if (no error)
      save copied one to the file and update cached definition.
  else
      discard copied definition.

This patch is mixuture of Eric Blake's work and mine.
From: Eric Blake <eblake@redhat.com>
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

(virDomainObjCopyPersistentDef): make a copy of persistent vm definition
(qemuDomainAttach/Detach/UpdateDeviceConfig) : callbacks. now empty
(qemuDomainModifyDeviceFlags): add support for MODIFY_CONFIG and MODIFY_CURRENT
2011-04-27 21:33:58 -06:00
Jiri Denemark
1671d1dc78 util: Simplify hash implementation
So far first entries for each hash key are stored directly in the hash
table while other entries mapped to the same key are linked through
pointers. As a result of that, the code is cluttered with special
handling for the first items.

This patch makes all entries (even the first ones) linked through
pointers, which significantly simplifies the code and makes it more
maintainable.
2011-04-27 15:32:30 +02:00
Jiri Denemark
91e12a5094 tests: More unit tests for internal hash APIs
This adds several tests for remaining hash APIs (custom
hasher/comparator functions are not covered yet, though).

All tests pass both before and after the "Simplify hash implementation".
2011-04-27 15:32:30 +02:00
Wen Congyang
968fd0111a release PCI address only when we have ensured it successfully
Steps to reproduce this bug:
1. # cat net.xml # 00:03.0 has been used
    <interface type='network'>
      <mac address='52:54:00:04:72:f3'/>
      <source network='default'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>

2. # virsh attach-device vm1 net.xml
   error: Failed to attach device from net.xml
   error: internal error unable to reserve PCI address 0:0:3

3. # virsh attach-device vm1 net.xml
   error: Failed to attach device from net.xml
   error: internal error unable to execute QEMU command 'device_add': Device 'rtl8139' could not be initialized

The reason of this bug is that: we can not reserve PCI address 0:0:3 because it has
been used, but we release PCI address when we reserve it failed.
2011-04-27 20:12:14 +08:00
Wen Congyang
6fee3da262 free buf->content when vsnprintf() failed
When buf->error is 1, we do not return buf->content in the function
virBufferContentAndReset(). So we should free buf->content when
vsnprintf() failed.
2011-04-27 20:12:13 +08:00
Matthias Bolte
4a9019afbb esx: Fix dynamic dispatch for CastFromAnyType functions
This was broken by the refactoring in ac1e6586ec. It resulted in a
segfault for 'virsh vol-dumpxml' and related volume functions.

Before the refactoring all users of the ESX_VI__TEMPLATE__DISPATCH
macro dispatched on the item type, as the item is the input to all those
functions.

Commit ac1e6586ec made the dynamically dispatched CastFromAnyType
functions use this macro too, but this functions dispatched on the
actual type of the AnyType object. The item is the output of the
CastFromAnyType functions.

This difference was missed in the refactoring, making CastFromAnyType
functions dereferencing the item pointer that is NULL at the time of
the dispatch.
2011-04-27 09:33:02 +02:00
Matthias Bolte
3ba5d77f3c Move call to virReportOOMError into virFileBuildPath
Suggested by Daniel P. Berrange
2011-04-27 09:18:53 +02:00
Eric Blake
59a5981dd3 build: use gnulib passfd for simpler SCM_RIGHTS code
* .gnulib: Update to latest for passfd fixes.
* bootstrap.conf (gnulib_modules): Add passfd.
* src/util/util.c (virFileOpenAs): Simplify.
2011-04-26 10:36:56 -06:00
Jiri Denemark
1c84237852 qemu: Add flags checking in DomainCoreDump 2011-04-26 13:37:26 +02:00
Mark Wu
d9b46a0d04 Make crash and live flags mutually exclusive in virDomainCoreDump
They don't make any sense when used together.
2011-04-26 13:37:21 +02:00
Guido Günther
bf5e3f6598 Make sure DNSMASQ_STATE_DIR exists
otherwise the directory returned by networkDnsmasqLeaseFileName will not
be created if ipdef->nhosts == 0 in networkBuildDnsmasqArgv.
2011-04-25 23:41:57 +02:00
Matthias Bolte
bf130d2c85 Fix small memory leaks in config parsing related functions
Found by 'make -C tests valgrind'.

xen_xm.c: Dummy allocation via virDomainChrDefNew is directly
overwritten and lost. Free 'script' in success path too.

vmx.c: Free virtualDev_string in success path too.

domain_conf.c: Free compression in success path too.
2011-04-25 19:08:53 +02:00
Matthias Bolte
14a961ca73 Add virDomainEventRebootNew
This will be used in the ESX driver event handling.
2011-04-25 18:55:01 +02:00
Eric Blake
90d761eeb2 build: make VIR_FREE do some type checking
We can exploit the fact that gcc warns about int-to-pointer conversion
in ternary cond?(void*):(int) in order to prevent future mistakes of
calling VIR_FREE on a scalar lvalue.  For example, between commits
158ba873 and 802e2df, we would have had this warning:

cc1: warnings being treated as errors
remote.c: In function 'remoteDispatchListNetworks':
remote.c:3684:70: error: pointer/integer type mismatch in conditional expression

There are still a number of places that malloc into a const char*;
while it would probably be worth scrubbing them to use char*
instead, that is a separate patch, so we have to cast away const
in VIR_FREE for now.

* src/util/memory.h (VIR_FREE): Make gcc warn about integers.
Iteratively developed from a patch by Christophe Fergeau.
2011-04-25 10:20:18 -06:00
Eric Blake
99de59900a threads: add one-time initialization support
mingw lacks the counterpart to PTHREAD_MUTEX_INITIALIZER, so the
best we can do is portably expose once-only runtime initialization.

* src/util/threads.h (virOnceControlPtr): New opaque type.
(virOnceFunc): New callback type.
(virOnce): New prototype.
* src/util/threads-pthread.h (virOnceControl): Declare.
(VIR_ONCE_CONTROL_INITIALIZER): Define.
* src/util/threads-win32.h (virOnceControl)
(VIR_ONCE_CONTROL_INITIALIZER): Likewise.
* src/util/threads-pthread.c (virOnce): Implement in pthreads.
* src/util/threads-win32.c (virOnce): Implement in WIN32.
* src/libvirt_private.syms: Export it.
2011-04-25 08:53:09 -06:00
Matthias Bolte
061956ccc7 esx: Add a wrapper for shared CURL handles
To be used to share a CURL handle between multiple threads in the
upcoming domain event support.
2011-04-24 11:33:47 +02:00
Matthias Bolte
d21342af19 esx: Move CURL handling code to it's own type 2011-04-24 11:22:23 +02:00
KAMEZAWA Hiroyuki
9b8543b6ad libvirt/qemu - clean up UpdateDevice for consolidation.
This patch strips reusable part of qemuDomainUpdateDeviceFlags()
and consolidate it to qemuDomainModifyDeviceFlags().
No functional changes.

* src/qemu/qemu_driver.c
(qemuDomainChangeDiskMediaLive) : pulled out code for updating disks.
(qemuDomainUpdateDeviceLive) : core of UpdateDevice, extracted from
UpdateDeviceFlags()
(qemuDomainModifyDeviceFlags): add support for updating device in live domain.
(qemuDomainUpdateDeviceFlags): reworked as a wrapper function of
qemuDomainModifyDeviceFlags()

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-04-21 15:49:57 -06:00
KAMEZAWA Hiroyuki
19ad136f60 libvirt/qemu - clean up At(De)tachDeviceFlags() for consolidation.
clean up At(De)tachDeviceFlags() for consolidation.

qemuDomainAttachDeviceFlags()/qemuDomainDetachFlags()/
qemuDomainUpdateDeviceFlags() has similar logics and copied codes.

This patch series tries to unify them to use shared code when it can.
At first, clean up At(De)tachDeviceFlags() and devide it into functions.

By this, this patch pulls out shared components between functions.
Based on patch series by Eric Blake, I added some modification as
switch-case with QEMU_DEVICE_ATTACH, QEMU_DEVICE_DETACH, QEMU_DEVICE_UPDATE

* src/qemu/qemu_driver.c
(qemuDomainAt(De)tachDeviceFlags) : pulled out to qemuDomainModifyDeviceFlags()
(qemuDomainModifyDeviceFlags) : implements generic code for modifying domain.
(qemuDomainAt(De)tachDeviceFlagsLive) : code for at(de)taching devices to
domain in line. no changes in logic from old code.
(qemuDomainAt(De)tachDeviceDiskLive) : for at(de)taching Disks.
(qemuDomainAt(De)tachDeviceControllerLive) : for at(de)taching Controllers

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-04-21 14:19:21 -06:00
KAMEZAWA Hiroyuki
2160116ff8 libvirt/qemu - Centralize device modification in the more flexible APIs
Centralize device modification in the more flexible APIs, to allow future
honoring of additional flags.  Explicitly reject the
VIR_DOMAIN_DEVICE_MODIFY_FORCE flag on attach/detach.

Based on Eric Blake<eblake@redhat.com>'s work.

* src/qemu/qemu_driver.c
(qemudDomainAttachDevice)(qemudDomainAttachDeviceFlags): Swap bodies,rename...
(qemudDomainDetachDevice, qemudDomainDetachDeviceFlags): Likewise.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-04-21 13:12:04 -06:00
Michal Privoznik
eb954ede72 Add support for s390(x) cpu options parsing
Up to now we missed parser for cpuinfo on x390(x) machines. Those machines
have only 1 thread, core, socket. What is missing is information about
CPU frequency.
2011-04-21 10:50:17 -06:00
Daniel P. Berrange
29fca78541 Fix QEMU tunnelled migration FD handling
The two ends of the pipe used for feeding QEMU tunnelled
migration data were interchanged, so QEMU got given the
"write" end instead of the "read" end.

The qemuMigrationPrepareTunnel method was also immediately
closing the "write" end of the pipe, so the stream failed
to actually write anything.

* src/qemu/qemu_migration.c: Swap tunnelled migration
  pipe FDs & don't close pipe given to stream
2011-04-21 17:27:53 +01:00
Jiri Denemark
068add8ea9 Remove artificial minimum limit for guest memory
Remove the artificial minimum of 4096 KB for guest memory. It's drivers'
job to set the limit if needed.
2011-04-21 12:06:41 +02:00
Eduardo Otubo
41461ff7f7 PHYP: Adding reboot domain function
Adding reboot <domain> function for pHyp driver.
2011-04-21 08:25:33 +02:00
Wen Congyang
2cb1d6f220 fix tunnelled migration's regression
If the migrateFrom is "stdio" not "stdin", qemuBuildCommandLine()
will convert it to exec:cat or fd:n.
2011-04-20 21:30:00 +08:00
Stefan Berger
973b681bdf nwfilter: no support for direct type of interface
Ebtables filtering doesn't work on macvtap device. Remove support for direct type of interface.
2011-04-19 16:23:59 -04:00
Wen Congyang
d2fd997ea6 qemu: fix the check of virDomainObjUnref()'s return value
If vm is unlocked in virDomainObjUnref(), the return value is 0, not less
than 0.
2011-04-19 21:46:09 +08:00
Markus Groß
68c5b6fb2b Add cputune support to libxl driver
Here is a new version of this patch:
https://www.redhat.com/archives/libvir-list/2011-April/msg00337.html

v2:
  - store the cputune info for the whole runtime of the domain
  - remove cputune info when domain is destroyed

The nodeGetInfo code had to be moved into a helper
function to reuse it without a virConnectPtr.
2011-04-18 12:13:11 -06:00
Matthias Bolte
78ef49eae3 Update and sort msg_gen_function list and mark unmarked messages
Inspired by Eric Blake
2011-04-18 19:05:15 +02:00
Eric Blake
a35af32c1e phyp: another simplification
Rather than copying and pasting lots of code, factor it into a
single helper function.

This commit adds a warning if tighter integer parsing would fail
due to any stray bytes after the number, but should not change
any behavior other than the bug fix for phypNumDomainsGeneric
looking only at numeric lines.

* src/phyp/phyp_driver.c (phypExecInt): New function.
(phypGetVIOSPartitionID, phypNumDomainsGeneric, phypGetLparID)
(phypGetLparMem, phypGetLparCPUGeneric, phypGetRemoteSlot)
(phypGetVIOSNextSlotNumber, phypAttachDevice)
(phypGetStoragePoolSize, phypStoragePoolNumOfVolumes)
(phypNumOfStoragePools, phypInterfaceDestroy)
(phypInterfaceDefineXML, phypInterfaceLookupByName)
(phypInterfaceIsActive, phypNumOfInterfaces): Use it.
(phypNumDomainsGeneric): Correctly find numeric line.
2011-04-18 10:53:26 -06:00
Daniel P. Berrange
ce3ae1b084 build: fix qemu build failure in previous patch
This last minute addition caused a build failure

cc1: warnings being treated as errors
qemu/qemu_process.c: In function 'qemuProcessHandleWatchdog':
qemu/qemu_process.c:436:34: error: ignoring return value of 'virDomainObjUnref', declared with attribute warn_unused_result [-Wunused-result]
make[3]: *** [libvirt_driver_qemu_la-qemu_process.lo] Error 1
2011-04-18 09:27:13 -06:00
Wen Congyang
b060d2e5d4 enhance processWatchdogEvent()
This patch does the following two things:
1. hold an extra reference while handling watchdog event
   If the domain is not persistent, and qemu quits unexpectedly before
   calling processWatchdogEvent(), vm will be freed and the function
   processWatchdogEvent() will be dangerous.

2. unlock qemu driver and vm before returning from processWatchdogEvent()
   When the function processWatchdogEvent() failed, we only free wdEvent,
   but forget to unlock qemu driver and vm, free dumpfile.
2011-04-18 09:38:45 +08:00
Wen Congyang
847efb32de qemu: avoid qemu_driver being unlocked twice when virThreadPoolNew() failed
We do not lock qemu_driver when calling virThreadPoolNew(). If it failed,
we will unlock qemu_driver. It is dangerous.

We may use this pool during auto starting domains. So we must create it before
calling qemuAutostartDomains(). Otherwise, libvirtd will crash.
2011-04-18 09:38:45 +08:00
Richard Laager
cf7124946a Fix two out-of-date comments in LVM backend 2011-04-17 08:37:31 +02:00
Matthias Bolte
12459d1ea7 xen: Replace statsErrorFunc with a macro
Also mark error messages in block_stats.c for translation, add the
new macro to the msg_gen functions in cfg.mk and add block_stats.c
to po/POTFILES.in
2011-04-17 07:53:26 +02:00
Matthias Bolte
60d769a13a Remove virConnectPtr from virRaiseErrorFull
And from all related macros and functions.
2011-04-17 07:22:23 +02:00
Wen Congyang
ffbdf3e144 build: include esx_vi.generated.* into dist file
commit d4601696 introduces two more generated files: esx_vi.generated.h
and esx_vi.generated.h. But we do not include them into dist file.
It will break building if using dist file to build.
2011-04-16 07:09:51 +02:00
Eric Blake
0bd34a9dec phyp: avoid memory leaks in command values
* src/phyp/phyp_driver.c (phypExecBuffer): New function. Use it
throughout file for less code, and for plugging a few leaks.
2011-04-15 15:32:19 -06:00
Eric Blake
a1b46e714a phyp: use consistent return string handling
Use the name 'ret' for all phypExec results, to make it easier
to wrap phypExec.  Don't allow a possibly NULL ret through printf.

* src/phyp/phyp_driver.c (phypBuildVolume, phypDestroyStoragePool)
(phypBuildStoragePool, phypBuildLpar): Avoid NULL dereference.
(phypInterfaceDestroy): Avoid redundant free.
(phypVolumeLookupByPath, phypVolumeGetPath): Use consistent
naming.
2011-04-15 15:26:27 -06:00
Eric Blake
e00c892f0b phyp: prefer memcpy over memmove when legal
* src/phyp/phyp_driver.c (phypUUIDTable_AddLpar)
(phypGetLparUUID, phypGetStoragePoolUUID, phypVolumeGetXMLDesc)
(phypGetStoragePoolXMLDesc): Use faster method.
2011-04-15 15:26:27 -06:00
Eric Blake
f61785225d phyp: use consistent style for labels
* src/phyp/phyp_driver.c: Match label style of rest of project.
(phypExec, phypUUIDTable_Pull): Drop an extra label.
2011-04-15 15:26:26 -06:00
Eric Blake
444306d591 phyp: more return handling cleanup
* src/phyp/phyp_driver.c (phypInterfaceDestroy)
(phypInterfaceDefineXML, phypInterfaceLookupByName)
(phypInterfaceIsActive, phypListInterfaces, phypNumOfInterfaces):
Clean up return handling of recent additions.
2011-04-15 15:26:26 -06:00
Eric Blake
8f03c6e869 phyp: avoid memory leak on failure
* src/phyp/phyp_driver.c (phypUUIDTable_Init): Avoid memory leak
on error.
2011-04-15 15:26:26 -06:00
Eric Blake
ef6147c40e phyp: avoid a logic bug
Ever since commit ebc46f, the destroy function built two command
variants but only used one.  I went with the variant that matches
the idiom used in the counterpart of phypBuildStoragePool.

* src/phyp/phyp_driver.c (phypDestroyStoragePool): Avoid
clobbering cmd.  Fix error message typo.
2011-04-15 15:26:26 -06:00
Eric Blake
dbe3bad987 maint: use lighter-weight function for straight appends
It costs quite a few processor cycles to go through printf parsing
just to determine that we only meant to append.

* src/xen/xend_internal.c (xend_op_ext): Consolidate multiple
printfs into one.
* src/qemu/qemu_command.c (qemuBuildWatchdogDevStr)
(qemuBuildUSBInputDevStr, qemuBuildSoundDevStr)
(qemuBuildSoundCodecStr, qemuBuildVideoDevStr): Likewise.
(qemuBuildCpuArgStr, qemuBuildCommandLine): Prefer virBufferAdd
over virBufferVsprintf for trivial appends.
* src/phyp/phyp_driver.c (phypExec, phypUUIDTable_Push)
(phypUUIDTable_Pull): Likewise.
* src/conf/nwfilter_conf.c (macProtocolIDFormatter)
(arpOpcodeFormatter, formatIPProtocolID, printStringItems)
(virNWFilterPrintStateMatchFlags, virNWIPAddressFormat)
(virNWFilterDefFormat): Likewise.
* src/security/virt-aa-helper.c (main): Likewise.
* src/util/sexpr.c (sexpr2string): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprChr): Likewise.
* src/xenxs/xen_xm.c (xenFormatXMDisk): Likewise.
2011-04-15 15:26:26 -06:00
Matthias Bolte
1afaafe307 esx: Fix gcc 4.6 warning about initialized but unused variables
This warnings come from partly generated code. Therefore, the best
solution is to mark them as potentially being unused using the
ATTRIBUTE_UNUSED macro. This is suggested by the gcc documentation.

Reported by Christophe Fergeau
2011-04-15 12:31:38 -06:00
Eric Blake
e692352689 maint: silence cppi warnings
* src/nodeinfo.c (linuxNodeInfoCPUPopulate): Fix indentation of
last patch.
2011-04-14 13:33:24 -06:00
Laine Stump
020ad8d1a2 network: truncate bridges' dummy tap device names to IFNAMSIZ (15) chars
This patch addresses:

   https://bugzilla.redhat.com/show_bug.cgi?id=694382

In order to give each libvirt-created bridge a fixed MAC address,
commit 5754dbd56d, added code to create
a dummy tap device with guaranteed lowest MAC address and attach it to
the bridge. This tap device was given the name "${bridgename}-nic".
However, an interface device name must be IFNAMSIZ (15) characters or
less, so a valid ${bridgename} such as "verylongname123" (15
characters) would lead to an invalid tap device name
("verylongname123-nic" - 19 characters), and that in turn led to a
failure to bring up the network.

The solution is to shorten the part of the original name used to
generate the tap device name. However, simply truncating it is
insufficient, because the last few characters of an interface name are
often a number used to indicate one of a list of several similar
devices (for example, "verylongname123", "verylongname124", etc) and
simple truncation would lead to duplicate names (eg "verlongnam-nic"
and "verylongnam-nic"). So instead we take the first 8 characters of
$bridgename ("verylong" in the example), add on the final 3 bytes
("123"), then add "-nic" (so "verylong123-nic").  Not pretty, but it
is much more likely to generate a unique name, and is reproducible
(unlike, say, a random number).
2011-04-14 15:24:17 -04:00
Stefan Berger
d21f9d5a64 ppc: Enable starting of Qemu VMs on ppc host
Due to differences in /proc/cpuinfo the parsing of the cpu data is
different between architectures. On PPC /proc/cpuinfo looks like this:

[original formatting with tabs]

processor    : 0
cpu          : PPC970MP, altivec supported
clock        : 2297.700000MHz
revision     : 1.1 (pvr 0044 0101)

processor    : 1
cpu          : PPC970MP, altivec supported
clock        : 2297.700000MHz
revision     : 1.1 (pvr 0044 0101)

[..]

timebase     : 14318000
platform     : pSeries
model        : IBM,8844-AC1
machine      : CHRP IBM,8844-AC1

The patch adapts the parsing of the data found in /proc/cpuinfo.

/sys/devices/system/cpu/cpuX/topology/physical_package_id also
always returns -1. Check for it on ppc and make it '0' if found negative.
2011-04-14 14:50:22 -04:00
Stefan Berger
cf2145d546 Migrate VMs between different-endianess hosts
This patch enables the migration of Qemu VMs between hosts of different endianess. I tested this by migrating a i686 VM between a x86 and ppc64 host.

I am converting the 'int's in the VM's state header to uint32_t assuming this doesn't break compatibility with existing deployments other than Linux.
2011-04-14 14:48:03 -04:00
Christophe Fergeau
c59f3d8de4 Fix gcc 4.6 warnings in vbox_tmpl.c 2011-04-14 19:23:30 +02:00
Christophe Fergeau
454e50beee Fix gcc 4.6 warnings
gcc 4.6 warns when a variable is initialized but isn't used afterwards:

vmware/vmware_driver.c:449:18: warning: variable 'vmxPath' set but not used [-Wunused-but-set-variable]

This patch fixes these warnings. There are still 2 offending files:

- vbox_tmpl.c: the variable is used inside an #ifdef and is assigned several
  times outside of #ifdef. Fixing the warning would have required wrapping
  all the assignment inside #ifdef which hurts readability.

vbox/vbox_tmpl.c: In function 'vboxAttachDrives':
vbox/vbox_tmpl.c:3918:22: warning: variable 'accessMode' set but not used [-Wunused-but-set-variable]

- esx_vi_types.generated.c: the name implies it's generated code and I
  didn't want to dive into the code generator

esx/esx_vi_types.generated.c: In function 'esxVI_FileQueryFlags_Free':
esx/esx_vi_types.generated.c:1203:3: warning: variable 'item' set but not used [-Wunused-but-set-variable]
2011-04-14 19:09:12 +02:00
Michal Novotny
2ac455c4d2 Introduce virDomainChrDefNew()
Make: passed
Make check: passed
Make syntax-check: passed

this is the commit to introduce the function to create new character
device definition for the domain as advised by Cole Robinson
<crobinso@redhat.com>.

The function is used on the relevant places and also new tests has
been added.

Signed-off-by: Michal Novotny <minovotn@redhat.com>
2011-04-14 10:29:39 -06:00
Michal Privoznik
abb1570eac Spice: support audio, images and stream compression
This extends the SPICE XML to allow variable compression settings for audio,
images and streaming:
    <graphics type='spice' port='5901' tlsPort='-1' autoport='yes'>
        <image compression='auto_glz'/>
        <jpeg compression='auto'/>
        <zlib compression='auto'/>
        <playback compression='on'/>
    </graphics>

All new elements are optional.
2011-04-14 10:23:59 -06:00
Hu Tao
eed9d69e3c free cpumask of vcpupinDef
cpumask doesn't get freed when vcpupinDef being freed, this leaks
memory.
2011-04-14 09:47:10 -06:00
Matthias Bolte
e63dfb8198 esx: Make the parsed URI part of the private connection data
This will be used to make esxVI_Context clonable.

Also move cleanup code for esxPrivate to esxFreePrivate().
2011-04-14 17:39:05 +02:00
Matthias Bolte
991f97d827 esx: Mark error message in macros for translation 2011-04-14 17:35:11 +02:00
Matthias Bolte
d460169610 esx: Extend VI generator to cover managed object types
Generate lookup functions for managed object types.
2011-04-14 17:14:21 +02:00
Matthias Bolte
ac1e6586ec esx: Cleanup and refactor CastFromAnyType macros
Add CastFromAnyType functions for the String type.
2011-04-14 17:03:42 +02:00
Matthias Bolte
a8ad5a40c6 esx: Cleanup VI generator code 2011-04-14 16:56:50 +02:00
Michal Privoznik
2444c411ca network: Fix NULL dereference during error recovery
This fixes: https://bugzilla.redhat.com/show_bug.cgi?id=696660

While starting a network, if brSetForwardDelay() fails, we go to err1
where we want to access macTapIfName variable which was just
VIR_FREE'd a few lines above. Instead, keep macTapIfName until we are
certain of success.
2011-04-14 10:56:17 -04:00
Daniel P. Berrange
97263cb115 Add missing checks for QEMU domain state in tunables APIs
The methods qemuDomain{Get,Set}{Memory,Blkio,Scheduler}Parameters
all forgot to do a check on virDomainIsActive(), resulting in bogus
error messages from later parts of their impl

* src/qemu/qemu_driver.c: Add missing checks on virDomainIsActive()
2011-04-14 14:32:34 +01:00
Matthias Bolte
28e938a9ec phyp: Fix too small buffer allocation in phypAttachDevice
sizeof(domain->name) is the wrong thing. Instead of using strdup here
rewrite escape_specialcharacters to allocate the buffer itself.

Add a contains_specialcharacters to be used in phypOpen, as phypOpen is
not interested in the escaped version.
2011-04-14 13:58:22 +02:00
Matthias Bolte
e13e1f4f5d phyp: Don't overwrite error from virDomainDeviceDefParse by OOM error 2011-04-14 13:08:30 +02:00
Matthias Bolte
e69aa73339 phyp: Don't try to use a string from a failed virAsprintf 2011-04-14 13:06:37 +02:00
Matthias Bolte
d765a6f071 phyp: Reduce code duplication in error and success paths
Also fix memory leaks along the way in phypCreateServerSCSIAdapter and
phypAttachDevice.
2011-04-14 13:01:37 +02:00
Matthias Bolte
444fd07a0a phyp: Remove stack allocating a 4kb volume key and fix related memory leaks
Don't pre-allocate 4kb per key, make phypVolumeGetKey allocate the memory.

Make phypBuildVolume return the volume key instead of using pre-allocated
memory to store it.

Also fix a memory leak in phypVolumeLookupByName when phypVolumeGetKey
fails. Fix another memory leak in phypVolumeLookupByPath in the success
path. Fix phypVolumeGetXMLDesc leaking voldef.key.
2011-04-14 12:54:36 +02:00
Daniel P. Berrange
4bfab4a0d3 Remove C99 variable declare in PHYP network driver
Move the virInterfacePtr declaration to the top of the
function to avoid jump uninitialized variable warnings

* src/phyp/phyp_driver.c: Fix var declaration
2011-04-13 19:15:22 +01:00
Eduardo Otubo
67eecd1610 PHYP: Adding network interface
This is the implementation of the previous patch now using virInterface*
API. Ended up this patch got much more simpler, smaller and easier to
review. Here is some details:

  * MAC size and interface name are fixed due to specifications on HMC,
    both are created automatically and CAN'T be specified from user. They
    have the following format:

     * MAC: 122980003002
     * Interface name: U9124.720.067BE8B-V3-C0

  * I did replaced all the |grep|sed following the comments Eric Blake
    did on the last patch.

  * According to my last email, It's not possible to create a network
    interface without assigning it to a specific lpar. Then, I am using
    this very minimalistic XML file for testing:

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

    In this file I am using "name" as the lpar name which I am going to
    assign the new network interface. I couldn't find a better way to
    refer to it. Comments are welcome.

  * Regarding the fact I am sleeping one second waiting for the HMC to
    complete creation of the interface, I don't have means to check
    if the whole process is done. All I do is execute a command, wait
    until is complete (which is not enough in this case) check
    the return and the exit status. The process of actually creating
    a networking interface seems to take a little longer than just the
    return of the ssh control.
2011-04-13 11:18:22 -06:00
Hu Tao
30c551ab4e qemu: fix a dead-lock problem
In qemuDomainObjBeginJobWithDriver, when virCondWaitUntil timeouts,
the function tries to call qemuDriverLock with virDomainObj locked,
this causes the dead-lock problem. This patch fixes this.
2011-04-13 09:43:16 +08:00
Jiri Denemark
5c53160a2f util: Fix crash when removing entries during hash iteration
Commit 9677cd33ee made it possible to
remove current entry when iterating through all hash entries. However,
it didn't properly handle a special case of removing first entry
assigned to a given key which contains several entries in its collision
list.
2011-04-12 19:18:08 +02:00
Michal Privoznik
50e4b9195d Fix possible infinite loop in remote driver
When we take out completed calls from queue we might end up
in circular pointer. We don't want pointer to previous item
point to element taken out.
2011-04-12 09:18:40 -06:00
Eric Blake
99fa30804b maint: fix grammar errors
Jim Meyering recently improved gnulib to catch various grammar
errors during 'make syntax-check'.

* .gnulib: Update to latest, for syntax-check improvements.
* include/libvirt/libvirt.h.in (virConnectAuthCallbackPtr): Use
cannot rather than two words.
* src/driver.c: Likewise.
* src/driver.h (VIR_SECRET_GET_VALUE_INTERNAL_CALL): Likewise.
* src/remote/remote_driver.c (initialize_gnutls): Likewise.
* src/util/pci.c (pciBindDeviceToStub): Likewise.
* src/storage/storage_backend.c (virStorageBackendCreateQemuImg):
Likewise.
(virStorageBackendUpdateVolTargetInfoFD): Avoid doubled word.
* docs/formatdomain.html.in: Likewise.
* src/qemu/qemu_process.c (qemuProcessStart): Likewise.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_can_not)
(exclude_file_name_regexp--sc_prohibit_doubled_word): Exclude
existing translation problems.
2011-04-12 09:06:14 -06:00
Matthias Bolte
6519b76000 xen: Remove PATH_MAX sized stack allocation from block stats code 2011-04-10 13:35:04 +02:00
Taku Izumi
c1795c5204 maxmem: implement virDomainSetMaxMemory API of the qemu driver
This patch implements the code to support virDomainSetMaxMemory API,
and to support VIR_DOMAIN_MEM_MAXIMUM flag in qemudDomainSetMemoryFlags function.
As a result, we can change the maximum memory size of inactive QEMU guests.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-08 17:40:29 -06:00
Taku Izumi
e3b4ca21b2 maxmem: introduces VIR_DOMAIN_MEM_MAXIMUM flag
This patch introduces VIR_DOMAIN_MEM_MAXIMUM flag.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-08 16:38:00 -06:00
Jean-Baptiste Rouault
ae25096692 docs: remove "returns" word from beginning of lines
Move "returns" keyword from beginning of API doc lines
when it does not describe return values.
Maybe the API doc extractor could be changed to look for
"returns: " to avoid such confusion.
2011-04-08 16:27:06 -06:00
Eric Blake
5bc22e129b docs: tweak virsh restore warning
* tools/virsh.pod: Fix grammar, and clarify wording.
* src/qemu/qemu_driver.c (qemudDomainObjStart): Drop redundant
condition.
2011-04-08 07:58:07 -06:00
Wen Congyang
2999bb06f3 do not build libvirt_iohelper when building without libvirtd
The libexec program libvirt_iohelper is only for libvirtd. If we build rpm
without libvirtd, we will receive the following messages:

Checking for unpackaged file(s): /usr/lib/rpm/check-files /home/wency/rpmbuild/BUILDROOT/libvirt-0.9.0-1.el6.x86_64
error: Installed (but unpackaged) file(s) found:
   /usr/libexec/libvirt_iohelper
2011-04-08 21:52:46 +08:00
Stefan Berger
6ab24feb44 nwfilters: support for TCP flags evaluation
This patch adds support for the evaluation of TCP flags in nwfilters.

It adds documentation to the web page and extends the tests as well.
Also, the nwfilter schema is extended.

The following are some example for rules using the tcp flags:

<rule action='accept' direction='in'>
    <tcp state='NONE' flags='SYN/ALL' dsptportstart='80'/>
</rule>
<rule action='drop' direction='in'>
    <tcp state='NONE' flags='SYN/ALL'/>
</rule>
2011-04-07 20:13:38 -04:00
Taku Izumi
95298e2380 setmem: add VIR_DOMAIN_MEM_CURRENT support to qemu
This patch adds virDomainSetMemoryFlags(,,VIR_DOMAIN_MEM_CURRENT) support
code to qemu driver.

Also, change virDomainObjIsActive to return bool, given its usage.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-07 17:13:56 -06:00
Taku Izumi
0f2e50be5f setmem: introduce VIR_DOMAIN_MEM_CURRENT flag
This patch introduces VIR_DOMAIN_MEM_CURRENT flag and
modifies virDomainSetMemoryFlags function to support it.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-07 17:13:56 -06:00
Jim Fehlig
f7e9b44812 build: Install libxenlight log dir
Add $localstatedir/log/libvirt/libxl when building libxenlight driver
2011-04-07 16:39:04 -06:00
Eric Blake
8ae5df5d93 virsh: fix mingw startup
* .gnulib: Update to latest, for pipe2.
* bootstrap.conf (gnulib_modules): Add pipe2.
* src/util/event_poll.c (virEventPollInit): Use it, to avoid
problematic virSetCloseExec on mingw.
2011-04-07 15:13:24 -06:00
Markus Groß
a7a4414b75 Add domainSet/GetSchedulerParameters to libxl driver
Libxenlight currently only supports the credit scheduler.
Therefore setting or getting a parameter of other
schedulers raise an error (for now).
2011-04-07 10:23:19 -06:00
Osier Yang
a73bbfc8be qemu: Remove the managed state file only if restoring succeeded
1) Both "qemuDomainStartWithFlags" and "qemuAutostartDomain" try to
restore the domain from managedsave'ed image if it exists (by
invoking "qemuDomainObjRestore"), but it unlinks the image even
if restoring fails, which causes data loss. (This problem exists
for "virsh managedsave dom; virsh start dom").

The fix for is to unlink the managed state file only if restoring
succeeded.

2) For "virsh save dom; virsh restore dom;", it can cause data
corruption if one reuse the saved state file for restoring. Add
doc to tell user about it.

3) In "qemuDomainObjStart", if "managed_save" is NULL, we shouldn't
fallback to start the domain, skipping it to cleanup as a incidental
fix. Discovered by Eric.
2011-04-07 16:58:26 +08:00
Wen Congyang
a4efb2e335 reattach pci devices when qemuPrepareHostdevPCIDevices() failed
Reattach all pci devices that we detached when qemuPrepareHostdevPCIDevices()
failed.
2011-04-07 13:09:46 +08:00
Wen Congyang
4e8969ebcf reattach pci device when pciBindDeviceToStub() failed
We should bind pci device to original driver when pciBindDeviceToStub() failed.
If the pci device is not bound to any driver before calling pciBindDeviceToStub(),
we should only unbind it from pci-stub. If it is bound to pci-stub, we should not
unbind it from pci-stub.
2011-04-07 13:09:46 +08:00
Wen Congyang
9121b1930f rename pciUnBindDeviceFromStub() to pciUnbindDeviceFromStub() and float it up
This patch do the following things:
1. rename the function as 'Unbind' is better than 'UnBind'.
2. pciUnbindDeviceFromStub() will be used in the function pciBindDeviceToStub() in
   next patch. Float it up, instead of having to have a forward declaration
2011-04-07 13:09:46 +08:00
Wen Congyang
115498597a remove devices from driver->activePciHostdevs when qemuPrepareHostdevPCIDevices() failed
We should not mark pci devices as active when qemuPrepareHostdevPCIDevices()
failed.
2011-04-07 13:09:45 +08:00
Wen Congyang
d5981f1caf pci: avoid invalid free, init path to NULL
This bug was introduce by commit 57162db8, and it will cause libvirtd crashed.
2011-04-07 13:09:39 +08:00
Eric Blake
f6447e8a54 build: avoid compiler warning on cygwin
In file included from util/threads.c:31:
util/threads-pthread.c: In function 'virThreadSelfID':
util/threads-pthread.c:214: warning: cast from function call of type 'pthread_t' to non-matching type 'int' [-Wbad-function-cast]

* src/util/threads-pthread.c (virThreadSelfID) [!SYS_gettid]:
Add intermediate cast to silence gcc.
2011-04-06 17:07:23 -06:00
Markus Groß
bf7f62519a Add domainIsUpdated to libxl driver 2011-04-06 15:31:04 -06:00
Serge Hallyn
2879582847 Change locking for udev monitor and callbacks
We're seeing bugs apparently resulting from thread unsafety of
libpciaccess, such as
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/726099
To prevent those, as suggested by danpb on irc, move the
nodeDeviceLock(driverState) higher into the callers.  In
particular:

  udevDeviceMonitorStartup should hold the lock while calling
  udevEnumerateDevices(), and udevEventHandleCallback should hold it
  over its entire execution.

It's not clear to me whether it is ok to hold the
nodeDeviceLock while taking the virNodeDeviceObjLock(dev) on a
device.  If not, then the lock will need to be dropped around
the calling of udevSetupSystemDev(), and udevAddOneDevice()
may not actually be safe to call from higher layers with the
driverstate lock held.

libvirt 0.8.8 with this patch on it seems to work fine for me.
Assuming it looks ok and I haven't done anything obviously dumb,
I'll ask the bug submitters to try this patch.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2011-04-06 10:20:47 -06:00
Jiri Denemark
87e78b2bc0 qemu: Support for overriding NPROC limit
This patch adds max_processes option to qemu.conf which can be used to
override system default limit on number of processes that are allowed to
be running for qemu user.
2011-04-06 12:08:59 +02:00
Osier Yang
7b2cac1238 qemu: Always reserves slot 0x02 for primary VGA.
To address https://bugzilla.redhat.com/show_bug.cgi?id=692355

This fix is to reserve slot 0x02 for primary VGA even if there
is no "video" specified in domain XML to avoid the problem.
2011-04-06 14:22:54 +08:00
Eric Blake
3eb869a04b libxl: avoid compiler warning
cc1: warnings being treated as errors
libxl/libxl_driver.c: In function 'libxlDomainSetVcpusFlags':
libxl/libxl_driver.c:1570:14: error: cast from function call of type 'double' to non-matching type 'unsigned int' [-Wbad-function-cast]
libxl/libxl_driver.c:1578:15: error: cast from function call of type 'double' to non-matching type 'unsigned int' [-Wbad-function-cast]

This was the only use of floor() and ceil(), and floating-point
is overkill for power-of-two manipulations.

* src/libxl/libxl_driver.c (libxlDomainSetVcpusFlags): Avoid -lm
for trivial computations.
2011-04-05 11:09:12 -06:00
Daniel P. Berrange
5b099250e3 Avoid compiler warnings about int -> void * casts
GCC is a little confused about the cast of beginthread/beginthreadex
from unsigned long -> void *. Go via an intermediate variable avoids
the bogus warning, and makes the code a little cleaner

* src/util/threads-win32.c: Avoid compiler warning in cast
2011-04-05 17:43:33 +01:00
Daniel P. Berrange
fdcd06ef71 Improve SCSI volume key generation
The SCSI volumes get a better 'key' field based on the fully
qualified volume path. All SCSI volumes have a unique serial
available in hardware which can be obtained by sending a
suitable SCSI command. Call out to udev's 'scsi_id' command
to fetch this value

* src/storage/storage_backend_scsi.c: Improve volume key
  field value stability and uniqueness
2011-04-05 16:04:22 +01:00
Jiri Denemark
ef264e82ee qemu: Ignore unusable binaries
When initializing qemu guest capabilities, we should ignore qemu
binaries that we are not able to extract version/help info from since
they will be unusable for creating domains anyway. Ignoring them is also
much better than letting initialization of qemu driver fail.
2011-04-05 14:02:55 +02:00
Jiri Denemark
69afdf14b8 qemu: Rewrite LOOKUP_PTYS macro into a function
The macro is huge and gives us nothing but headache when maintaining it.
2011-04-05 14:02:55 +02:00
Daniel P. Berrange
a4e37ff1a3 Enable use of -Wold-style-definition compiler flag
A couple of functions were declared using the old style foo()
for no-parameters, instead of foo(void)

* src/xen/xen_hypervisor.c, tests/testutils.c: Replace () with (void)
  in some function declarations
* m4/virt-compile-warnings.m4: Enable -Wold-style-definition
2011-04-05 11:40:04 +01:00
Daniel P. Berrange
329e9dc629 Enable use of -Wmissing-noreturn
* src/internal.h: Define a ATTRIBUTE_NO_RETURN annotation
* src/lxc/lxc_container.c: Annotate lxcContainerDummyChild
  with ATTRIBUTE_NO_RETURN
* tests/eventtest.c: Mark async thread as ATTRIBUTE_NO_RETURN
* m4/virt-compile-warnings.m4: Enable -Wmissing-noreturn
2011-04-05 11:39:58 +01:00
Daniel P. Berrange
222402417d Remove possible uninitialized variable in openvz driver
* src/openvz/openvz_driver.c: Initialize saveptr variable
2011-04-05 10:54:59 +01:00
Matthias Bolte
9e3550dc4e Use virBufferPtr for sexpr2string instead of manual buffer handling
Removes 4kb stack allocation in the XenD subdriver.
2011-04-05 09:14:59 +02:00