]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
14 years agoSupport Xen sysctl v8, domctl v7
Jim Fehlig [Thu, 17 Mar 2011 20:16:47 +0000 (14:16 -0600)]
Support Xen sysctl v8, domctl v7

xen-unstable c/s 21118:28e5409e3fb3 bumped sysctl version to 8.
xen-unstable c/s 21212:de94884a669c introduced CPU pools feature,
adding another member to xen_domctl_getdomaininfo struct.  Add a
corresponding domctl v7 struct in xen hypervisor sub-driver and
detect sysctl v8 during initialization.

14 years agoremote: Add missing virCondDestroy calls
Matthias Bolte [Thu, 17 Mar 2011 16:51:33 +0000 (17:51 +0100)]
remote: Add missing virCondDestroy calls

The virCond of the remote_thread_call struct was leaked in some
places. This results in leaking the underlying mutex. Which in turn
leaks a handle on Windows.

Reported by Aliaksandr Chabatar and Ihar Smertsin.

14 years agobuild: improve rpm generation for distro backports
Eric Blake [Wed, 16 Mar 2011 17:50:44 +0000 (11:50 -0600)]
build: improve rpm generation for distro backports

When building for an older distro, it's convenient to just
tell rpmbuild to define dist (for example, to .el6_0), rather
than also remembering to define rhel to 6.

* libvirt.spec.in: Guess %{rhel} based on %{dist}.
Based on an idea by Jiri Denemark.

14 years agomacvtap: log an error if on failure to connect to netlink socket
Laine Stump [Tue, 15 Mar 2011 20:22:25 +0000 (16:22 -0400)]
macvtap: log an error if on failure to connect to netlink socket

A bug in libnl (see https://bugzilla.redhat.com/show_bug.cgi?id=677724
and https://bugzilla.redhat.com/show_bug.cgi?id=677725) makes it very
easy to create a failure to connect to the netlink socket when trying
to open a macvtap network device ("type='direct'" in domain interface
XML). When that error occurred (during a call to libnl's nl_connect()
from libvirt's nlComm(), there was no log message, leading virsh (for
example) to report "unknown error".

There were two other cases in nlComm where an error in a libnl
function might return with failure but no error reported. In all three
cases, this patch logs a message which will hopefully be more useful.

Note that more detailed information about the failure might be
available from libnl's nl_geterror() function, but it calls
strerror(), which is not threadsafe, so we can't use it.

14 years agostorage: Fix a problem which will cause libvirtd crashed
Osier Yang [Wed, 16 Mar 2011 08:28:07 +0000 (16:28 +0800)]
storage: Fix a problem which will cause libvirtd crashed

If pool xml has no definition for "port", then "Segmentation fault"
happens when jumping to "cleanup:" to do "VIR_FREE(port)", as "port"
was not initialized in this situation.

* src/conf/storage_conf.c

14 years agoqemu: support migration to fd
Eric Blake [Wed, 2 Mar 2011 04:37:30 +0000 (21:37 -0700)]
qemu: support migration to fd

* src/qemu/qemu_monitor.h (qemuMonitorMigrateToFd): New
prototype.
* src/qemu/qemu_monitor.c (qemuMonitorMigrateToFd): New function.

14 years agoqemu: improve efficiency of dd during snapshots
Eric Blake [Wed, 22 Dec 2010 20:48:05 +0000 (13:48 -0700)]
qemu: improve efficiency of dd during snapshots

POSIX states about dd:

If the bs=expr operand is specified and no conversions other than
sync, noerror, or notrunc are requested, the data returned from each
input block shall be written as a separate output block; if the read
returns less than a full block and the sync conversion is not
specified, the resulting output block shall be the same size as the
input block. If the bs=expr operand is not specified, or a conversion
other than sync, noerror, or notrunc is requested, the input shall be
processed and collected into full-sized output blocks until the end of
the input is reached.

Since we aren't using conv=sync, there is no zero-padding, but our
use of bs= means that a short read results in a short write.  If
instead we use ibs= and obs=, then short reads are collected and dd
only has to do a single write, which can make dd more efficient.

* src/qemu/qemu_monitor.c (qemuMonitorMigrateToFile):
Avoid 'dd bs=', since it can cause short writes.

14 years agovirsh: allow empty string arguments
Eric Blake [Mon, 14 Mar 2011 16:44:37 +0000 (10:44 -0600)]
virsh: allow empty string arguments

"virsh connect ''" should try to connect to the default connection,
but the previous patch made it issue a warning about an invalid URI.

* tools/virsh.c (VSH_OFLAG_EMPTY_OK): New option flag.
(vshCommandOptString): Per the declaration, value is required to
be non-NULL.  Honor new flag.
(opts_connect): Allow empty string connection.

14 years agoqemu: Fallback to HMP when cpu_set QMP command is not found
Wen Congyang [Tue, 15 Mar 2011 08:53:06 +0000 (16:53 +0800)]
qemu: Fallback to HMP when cpu_set QMP command is not found

14 years agoChange message for VIR_FROM_RPC error domain
Daniel P. Berrange [Tue, 8 Mar 2011 18:10:02 +0000 (18:10 +0000)]
Change message for VIR_FROM_RPC error domain

The VIR_FROM_RPC error domain is used generically for any RPC
problem, not simply XML-RPC problems.

* src/util/virterror.c: s/XML-RPC/RPC/

14 years agoAdd compat function for geteuid()
Daniel P. Berrange [Fri, 11 Mar 2011 15:49:39 +0000 (15:49 +0000)]
Add compat function for geteuid()

* configure.ac: Check for geteuid()
* src/util/util.h: Compat for geteuid()

14 years agoFix misc bugs in virCommandPtr
Daniel P. Berrange [Tue, 8 Mar 2011 18:06:09 +0000 (18:06 +0000)]
Fix misc bugs in virCommandPtr

The virCommandNewArgs() method would free the virCommandPtr
if it failed to add the args. This meant errors reported in
virCommandAddArgSet() were lost. Simply removing the check
for errors from the constructor means they can be reported
correctly later

The virCommandAddEnvPassCommon() method failed to check for
errors before reallocating the cmd->env array, causing a
potential SEGV if cmd was NULL

The virCommandAddArgSet() method needs to validate that at
least 1 element in 'val's parameter is non-NULL, otherwise
code like

    cmd = virCommandNew(binary)
    virCommandAddAtg(cmd, "foo")

Would end up trying todo  execve("foo"), if binary was
NULL.

14 years agoAdd virSetBlocking() to allow O_NONBLOCK to be toggle on or off
Daniel P. Berrange [Tue, 8 Mar 2011 18:04:06 +0000 (18:04 +0000)]
Add virSetBlocking() to allow O_NONBLOCK to be toggle on or off

The virSetNonBlock() API only allows enabling non-blocking
operations. It doesn't allow turning blocking back on. Add
a new API to allow arbitrary toggling.

* src/libvirt_private.syms, src/util/util.h
  src/util/util.c: Add virSetBlocking

14 years agoqemu: use more appropriate error
Eric Blake [Tue, 15 Mar 2011 14:49:04 +0000 (08:49 -0600)]
qemu: use more appropriate error

Fixes bug in commit acacced

* src/qemu/qemu_command.c (qemuBuildCommandLine):
s/INVALID_ARG/CONFIG_UNSUPPORTED/.
Reported by Daniel P. Berrange.

14 years agodocs: update windows page for initial libvirt 0.8.8 installer
Justin Clift [Tue, 15 Mar 2011 10:31:33 +0000 (21:31 +1100)]
docs: update windows page for initial libvirt 0.8.8 installer

14 years agolibvirt: fix a simple bug in virDomainSetMemoryFlags()
Taku Izumi [Tue, 15 Mar 2011 07:49:31 +0000 (16:49 +0900)]
libvirt: fix a simple bug in virDomainSetMemoryFlags()

This patch fix a simple bug in virDomainSetMemoryFlags function.
The patch sent before lacks the consideration of the case
where the driver doesn't support virDomainSetMemoryFlags API.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
14 years agoMake LXC container startup/shutdown/I/O more robust
Daniel P. Berrange [Tue, 22 Feb 2011 17:35:06 +0000 (17:35 +0000)]
Make LXC container startup/shutdown/I/O more robust

The current LXC I/O controller looks for HUP to detect
when a guest has quit. This isn't reliable as during
initial bootup it is possible that 'init' will close
the console and let mingetty re-open it. The shutdown
of containers was also flakey because it only killed
the libvirt I/O controller and expected container
processes to gracefully follow.

Change the I/O controller such that when it see HUP
or an I/O error, it uses kill($PID, 0) to see if the
process has really quit.

Change the container shutdown sequence to use the
virCgroupKillPainfully function to ensure every
really goes away

This change makes the use of the 'cpu', 'devices'
and 'memory' cgroups controllers compulsory with
LXC

* docs/drvlxc.html.in: Document that certain cgroups
  controllers are now mandatory
* src/lxc/lxc_controller.c: Check if PID is still
  alive before quitting on I/O error/HUP
* src/lxc/lxc_driver.c: Use virCgroupKillPainfully

14 years agoAllow to dynamically set the size of the debug buffer
Daniel Veillard [Tue, 8 Mar 2011 10:31:20 +0000 (18:31 +0800)]
Allow to dynamically set the size of the debug buffer

This is the part allowing to dynamically resize the debug log
buffer from it's default 64kB size. The buffer is now dynamically
allocated.
It adds a new API virLogSetBufferSize() which resizes the buffer
If passed a zero size, the buffer is deallocated and we do the small
optimization of not formatting messages which are not output anymore.
On the daemon side, it just adds a new option log_buffer_size to
libvirtd.conf and call virLogSetBufferSize() if needed
* src/util/logging.h src/util/logging.c src/libvirt_private.syms:
  make buffer dynamic and add virLogSetBufferSize() internal API
* daemon/libvirtd.conf: document the new log_buffer_size option
* daemon/libvirtd.c: read and use the new log_buffer_size option

14 years agoqemu: consolidate duplicated monitor migration code
Eric Blake [Fri, 4 Mar 2011 18:51:48 +0000 (11:51 -0700)]
qemu: consolidate duplicated monitor migration code

* src/qemu/qemu_monitor_text.h (qemuMonitorTextMigrate): Declare
in place of individual monitor commands.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONMigrate): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextMigrateToHost)
(qemuMonitorTextMigrateToCommand, qemuMonitorTextMigrateToFile)
(qemuMonitorTextMigrateToUnix): Delete.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMigrateToHost)
(qemuMonitorJSONMigrateToCommand, qemuMonitorJSONMigrateToFile)
(qemuMonitorJSONMigrateToUnix): Delete.
* src/qemu/qemu_monitor.c (qemuMonitorMigrateToHost)
(qemuMonitorMigrateToCommand, qemuMonitorMigrateToFile)
(qemuMonitorMigrateToUnix): Consolidate shared code.

14 years agoqemu: use lighter-weight fd:n on incoming tunneled migration
Eric Blake [Thu, 23 Dec 2010 18:24:42 +0000 (11:24 -0700)]
qemu: use lighter-weight fd:n on incoming tunneled migration

Outgoing migration still uses a Unix socket and or exec netcat until
the next patch.

* src/qemu/qemu_migration.c (qemuMigrationPrepareTunnel):
Replace Unix socket with simpler pipe.
Suggested by Paolo Bonzini.

14 years agomaint: make spacing in .sh files easier
Eric Blake [Mon, 14 Mar 2011 14:36:26 +0000 (08:36 -0600)]
maint: make spacing in .sh files easier

Commit 7f193757 renamed libvirt-guests.init from .in to .sh, which
made it slip past sc_TAB_in_indentation.  I nearly reintroduced a
tab, so I'm pushing this to prevent that from happening.

* cfg.mk (sc_TAB_in_indentation): Update rule to include .sh files.
* .dir-locals.el: List spacing preference for .sh files.

14 years agoqemu: Check the unsigned integer overflow
Osier Yang [Tue, 15 Mar 2011 03:50:09 +0000 (11:50 +0800)]
qemu: Check the unsigned integer overflow

As perhaps other hypervisor drivers use different capacity units,
do the checking in qemu driver instead of in conf/domain_conf.c.

14 years agoFix performance problem of virStorageVolCreateXMLFrom()
Minoru Usui [Tue, 8 Mar 2011 11:06:51 +0000 (20:06 +0900)]
Fix performance problem of virStorageVolCreateXMLFrom()

This patch changes zerobuf variable from array to VIR_ALLOC_N().

Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
14 years agolibvirt-guests: avoid globbing when splitting $URIS
Eric Blake [Fri, 11 Mar 2011 21:06:09 +0000 (14:06 -0700)]
libvirt-guests: avoid globbing when splitting $URIS

* tools/libvirt-guests.init.sh (start, stop, gueststatus): Avoid
shell globbing, since valid URIs can contain '?'.

14 years agolibvirt-guest.init: quoting variables
Philipp Hahn [Wed, 9 Mar 2011 08:54:57 +0000 (09:54 +0100)]
libvirt-guest.init: quoting variables

At least protect the $uri variable against further expansion by properly
quoting it. While doing that, also quote all other variables to protect
against shell meta characters.

Signed-off-by: Philipp Hahn <hahn@univention.de>
14 years agodocs/formatdomain.html.in: Fix spelling PIC->PCI
Philipp Hahn [Mon, 14 Mar 2011 07:52:14 +0000 (08:52 +0100)]
docs/formatdomain.html.in: Fix spelling PIC->PCI

Not "Programmable Interrupt Controller" but "Peripheral Component
Interconnect".

Signed-off-by: Philipp Hahn <hahn@univention.de>
14 years agoaudit: eliminate potential null pointer deref when auditing macvtap devices
Laine Stump [Mon, 14 Mar 2011 15:15:19 +0000 (11:15 -0400)]
audit: eliminate potential null pointer deref when auditing macvtap devices

The newly added call to qemuAuditNetDevice in qemuPhysIfaceConnect was
assuming that res_ifname (the name of the macvtap device) was always
valid, but this isn't the case. If openMacvtapTap fails, it always
returns NULL, which would result in a segv.

Since the audit log only needs a record of devices that are actually
sent to qemu, and a failure to open the macvtap device means that no
device will be sent to qemu, we can solve this problem by only doing
the audit if openMacvtapTap is successful (in which case res_ifname is
guaranteed valid).

14 years agovirsh: Insert error messages to avoid a quiet abortion of commands
Michal Privoznik [Mon, 14 Mar 2011 12:34:57 +0000 (13:34 +0100)]
virsh: Insert error messages to avoid a quiet abortion of commands

in case of incorrect option parsing.

14 years agonetwork driver: don't send default route to clients on isolated networks
Laine Stump [Sun, 13 Mar 2011 08:42:58 +0000 (04:42 -0400)]
network driver: don't send default route to clients on isolated networks

Normally dnsmasq will send a default route (the address of the host in
the network definition) to any client requesting an address via
DHCP. On an isolated network this makes no sense, as we have iptables
to prevent any traffic going out via that interface, so anything sent
that way would be dropped anyway.

This extra/unusable default route becomes problematic if you have
setup a guest with multiple network interfaces, with one connected to
an isolated network and another that provides connectivity to the
outside (example - one interface directly connecting to a physical
interface via macvtap, with a second connected to an isolated network
so that the host and guest can communicate (macvtap doesn't support
guest<->host communication without an external switch that supports
vepa, or reflecting all traffic back)). In this case, if the guest
chooses the default route of the isolated network, the guest will not
be able to get network traffic beyond the host.

To prevent dnsmasq from sending a default route, you can tell it to
send 0 bytes of data for the default route option (option number 3)
with --dhcp-option=3 (normally the data to send for the option would
follow the option number; no extra data means "don't send this option").

I have checked on RHEL5 (a good representative of the oldest supported
libvirt platforms) and its version of dnsmasq (2.45) does support
--dhcp-option, so this shouldn't create any compatibility problems.

14 years agopython: Use hardcoded python path in libvirt.py
Jiri Denemark [Fri, 11 Mar 2011 12:44:20 +0000 (13:44 +0100)]
python: Use hardcoded python path in libvirt.py

This partially reverts (and fixes that part in a different way) commit
e4384459c93e3e786aa483c7f077d1d22148f689, which replaced
``/usr/bin/python'' with ``/usr/bin/env python'' in all examples or
scripts used during build to generate other files.

However, python bindings module is compiled and linked against a
specific python discovered or explicitly provided in configure phase.
Thus libvirt.py, which is generated and installed into the system,
should use the same python binary for which the module has been built.

The hunk in Makefile.am replaces $(srcdir) with $(PYTHON), which might
seem wrong but it is not. generator.py didn't use any of its command
line arguments so passing $(srcdir) to it was redundant.

14 years agovirsh: Allow starting domains by UUID
Jiri Denemark [Fri, 11 Mar 2011 11:07:12 +0000 (12:07 +0100)]
virsh: Allow starting domains by UUID

14 years agovirsh: Free stream when shutdown console
Osier Yang [Mon, 14 Mar 2011 07:11:03 +0000 (15:11 +0800)]
virsh: Free stream when shutdown console

Otherwise connection of hypervisor driver will be leaked when
one shutdown the guest in console. e.g.

[root@localhost]# init 0
......
init: Re-executing /sbin/init
Halting system...
Power down.

error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

14 years agoAdd missing checks for read only connections
Guido Günther [Mon, 14 Mar 2011 02:56:28 +0000 (10:56 +0800)]
Add missing checks for read only connections

As pointed on CVE-2011-1146, some API forgot to check the read-only
status of the connection for entry point which modify the state
of the system or may lead to a remote execution using user data.
The entry points concerned are:
  - virConnectDomainXMLToNative
  - virNodeDeviceDettach
  - virNodeDeviceReAttach
  - virNodeDeviceReset
  - virDomainRevertToSnapshot
  - virDomainSnapshotDelete

* src/libvirt.c: fix the above set of entry points to error on read-only
                 connections

14 years agonetwork driver: Use a separate dhcp leases file for each network
Laine Stump [Fri, 11 Mar 2011 18:20:48 +0000 (13:20 -0500)]
network driver: Use a separate dhcp leases file for each network

By default, all dnsmasq processes share the same leases file. libvirt
also uses the --dhcp-lease-max option to control the maximum number of
leases allowed. The problem is that libvirt puts in a number equal to
the number of addresses in the range for the one network handled by a
single instance of dnsmasq, but dnsmasq checks the total number of
leases in the file (which could potentially contain many more).

The solution is to tell each instance of dnsmasq to create and use its
own leases file. (/var/lib/libvirt/network/<net-name>.leases).

This file is created by dnsmasq when it starts, but not deleted when
it exists. This is fine when the network is just being stopped, but if
the leases file was left around when a network was undefined, we could
end up with an ever-increasing number of dead files - instead, we
explicitly unlink the leases file when a network is undefined.

Note that Ubuntu carries a patch against an older version of libvirt for this:

hhttps://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/713071
ttp://bazaar.launchpad.net/~serge-hallyn/ubuntu/maverick/libvirt/bugall/revision/109

I was certain I'd also seen discussion of this on libvir-list or
libvirt-users, but couldn't find it.

14 years agonetwork driver: Fix indentation from previous commit
Laine Stump [Fri, 11 Mar 2011 17:07:09 +0000 (12:07 -0500)]
network driver: Fix indentation from previous commit

The previous commit put a large portion of networkBuildDnsmasqArgv
inside an if { } block. This readjusts the indentation.

14 years agonetwork driver: Start dnsmasq even if no dhcp ranges/hosts are specified.
Laine Stump [Fri, 11 Mar 2011 16:47:58 +0000 (11:47 -0500)]
network driver: Start dnsmasq even if no dhcp ranges/hosts are specified.

This fixes a regression introduced in commit ad48df, and reported on
the libvirt-users list:

  https://www.redhat.com/archives/libvirt-users/2011-March/msg00018.html

The problem in that commit was that we began searching a list of ip
address definitions (rather than just having one) to look for a dhcp
range or static host; when we didn't find any, our pointer (ipdef) was
left at NULL, and when ipdef was NULL, we returned without starting up
dnsmasq.

Previously dnsmasq was started even without any dhcp ranges or static
entries, because it's still useful for DNS services.

Another problem I noticed while investigating was that, if there are
IPv6 addresses, but no IPv4 addresses of any kind, we would jump out
at an ever higher level in the call chain.

This patch does the following:

1) networkBuildDnsmasqArgv() = all uses of ipdef are protected from
   NULL dereference. (this patch doesn't change indentation, to make
   review easier. The next patch will change just the
   indentation). ipdef is intended to point to the first IPv4 address
   with DHCP info (or the first IPv4 address if none of them have any
   dhcp info).

2) networkStartDhcpDaemon() = if the loop looking for an ipdef with
   DHCP info comes up empty, we then grab the first IPv4 def from the
   list. Also, instead of returning if there are no IPv4 defs, we just
   return if there are no IP defs at all (either v4 or v6). This way a
   network that is IPv6-only will still get dnsmasq listening for DNS
   queries.

3) in networkStartNetworkDaemon() - we will startup dhcp not just if there
   are any IPv4 addresses, but also if there are any IPv6 addresses.

14 years agoDon't use INT64_MAX in libvirt.h because it requires stdint.h
Matthias Bolte [Wed, 9 Mar 2011 09:42:49 +0000 (10:42 +0100)]
Don't use INT64_MAX in libvirt.h because it requires stdint.h

VIR_DOMAIN_MEMORY_PARAM_UNLIMITED uses INT64_MAX but stdint.h
was not and should not be included. Therefore, libvirt.h was
not self-contained.

Instead of including stdint.h specify the value directly.

14 years agolibvirt-guest.init: handle domain name with spaces
Philipp Hahn [Tue, 1 Mar 2011 17:57:01 +0000 (18:57 +0100)]
libvirt-guest.init: handle domain name with spaces

awk splits the line on consecutive spaces, which breaks getting the name
of a domain whose name contains spaces. Use sed instead to strip the
"Name:" prefix from the line

Signed-off-by: Philipp Hahn <hahn@univention.de>
14 years agodomain.rng vs. formatdomain.html#elementsUSB
Philipp Hahn [Tue, 1 Mar 2011 10:23:20 +0000 (11:23 +0100)]
domain.rng vs. formatdomain.html#elementsUSB

The Relax-NG schema for domains regarding <hostdev> doesn't match what's
implemented in src/conf/domain_conf.c#virDomainHostdevDefFormat(): The
implementation only requires @type, but the schema currently either
required none or all three attributes (@mode, @type, and @managed) to be
defined together, because they are declared in the same
<optional)-section. (@managed is currently even undocumented on
<http://libvirt.org/formatdomain.html#elementsUSB>).

Thus the following minimal <hostdev>-example fails to validate:
<domain type='test'>
        <name>N</name>
        <memory>4096</memory>
        <bootloader>/bin/false</bootloader>
        <os>
                <type arch='x86_64' machine='xenpv'>linux</type>
        </os>
        <devices>
                <hostdev type='pci'>
                        <source>
                                <address bus='0x06' slot='0x00' function='0x0'/>
                        </source>
                </hostdev>
        </devices>
</domain>

The schema is changed to match the current implementation:
1. @mode is optional (which defaults to 'subsystem')
2. @type is required
3. @managed is optional (which defaults to 'no')

The documentation is updated to mention @managed.

Signed-off-by: Philipp Hahn <hahn@univention.de>
14 years agoqemu: fix -global argument usage
Eric Blake [Fri, 11 Mar 2011 16:59:32 +0000 (09:59 -0700)]
qemu: fix -global argument usage

* src/qemu/qemu_command.c (qemuBuildCommandLine): Pass two
separate arguments, and fix indentation.

14 years agodocs: fix missing </p>
Eric Blake [Fri, 11 Mar 2011 17:08:24 +0000 (10:08 -0700)]
docs: fix missing </p>

* docs/formatdomain.html.in: Fix typo in last patch.
Reported by Matthias Bolte.

14 years agoIgnore backing file errors in FS storage pool
Philipp Hahn [Tue, 1 Mar 2011 15:48:20 +0000 (16:48 +0100)]
Ignore backing file errors in FS storage pool

Currently a single storage volume with a broken backing file will disable the
whole storage pool. This can happen when the backing file is on some
unavailable network storage or if the backing volume is deleted, while the
storage volumes using it remain.
Since the storage pool can not be re-activated, re-creating the missing
or deleting the now useless volumes using libvirt only is not possible.

Fixing this is a little bit tricky:
1. virStorageBackendProbeTarget() only detects the missing backing file,
   if the backing file format is not explicitly specified. If the
   backing file is created using
   kvm-img create -f qcow2 -o backing_fmt=qcow2,backing_file=... ...
   no error is detected at this stage.
   The new return code -3 signals that the backing file could not be
   opened.
2. The backingStore.format must be >= 0, since values < 0 would break
   virStorageVolTargetDefFormat() when dumping the XML data such as
       <format type='...'/>
   Because of this the format is faked as VIR_STORAGE_FILE_RAW.
3. virStorageBackendUpdateVolTargetInfo() always opens the backing file
   and thus always detects a missing backing file.
   Since it "only" updates the capacity, allocation, owner, group, mode
   and SELinux label, just ignore errors at this stage, print an error
   message and continue.
4. Using vol-dump on a broken volume still doesn't work, but at least
   vol-destroy and pool-refresh do work now.

To reproduce:
  dir=$(mktemp -d)
  virsh pool-create-as tmp dir '' '' '' '' "$dir"
  virsh vol-create-as --format qcow2 tmp back 1G
  virsh vol-create-as --format qcow2 --backing-vol-format qcow2 --backing-vol back tmp cow 1G
  virsh vol-delete --pool tmp back
  virsh pool-refresh tmp
After the last step, the pool will be gone (because it was not persistent). As
long as the now broken image stays in the directory, you will not be able to
re-create or re-start the pool.

Signed-off-by: Philipp Hahn <hahn@univention.de>
14 years agodocumenting the 802.1Qbg parameters of a 'direct' interface
Gerhard Stenzel [Fri, 11 Mar 2011 09:47:57 +0000 (10:47 +0100)]
documenting the 802.1Qbg parameters of a 'direct' interface

This patchs adds documentation about the 802.1Qbg related parameters
of the virtualport element in a 'direct' interface definition.

Signed-off-by: Gerhard Stenzel <gerhard.stenzel@de.ibm.com>
14 years agoremote-protocol: implement new BlkioParameters API
Gui Jianfeng [Tue, 22 Feb 2011 05:34:28 +0000 (13:34 +0800)]
remote-protocol: implement new BlkioParameters API

Remote protocol implementation of virDomainSetBlkioParameters and virDomainGetBlkioParameters.

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
14 years agovirsh: Adding blkiotune command to virsh tool
Gui Jianfeng [Tue, 22 Feb 2011 05:33:24 +0000 (13:33 +0800)]
virsh: Adding blkiotune command to virsh tool

Adding blkiotune command to virsh tool

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
14 years agoqemu: implement new BlkioParameters API
Gui Jianfeng [Tue, 22 Feb 2011 05:32:38 +0000 (13:32 +0800)]
qemu: implement new BlkioParameters API

Implement domainSetBlkioParameters and domainGetBlkioParameters for QEmu

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
14 years agolibvirt: implements virDomain{Get,Set}BlkioParameters
Gui Jianfeng [Tue, 22 Feb 2011 05:31:57 +0000 (13:31 +0800)]
libvirt: implements virDomain{Get,Set}BlkioParameters

Implements virDomainSetBlkioParameters and virDomainGetBlkioParameters and initialization

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
14 years agolibvirt: add virDomain{Get,Set}BlkioParameters
Gui Jianfeng [Tue, 22 Feb 2011 05:30:33 +0000 (13:30 +0800)]
libvirt: add virDomain{Get,Set}BlkioParameters

Add virDomainSetBlkioParameters virDomainGetBlkioParameters

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
14 years agosetmem: add the new options to "virsh setmem" command
Taku Izumi [Wed, 2 Mar 2011 08:13:39 +0000 (17:13 +0900)]
setmem: add the new options to "virsh setmem" command

This patch adds the new options (--live and --config)  to "virsh setmem" command.
The behavior of above options is the same as that of "virsh setvcpus" and so on.
That is, when the --config option is specified, a modification is effective for
the persistent domain. Moreover we can modify the memory size of inactive domains
as well as that of active domains.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
14 years agosetmem: implement the remote protocol to address the new API
Taku Izumi [Wed, 2 Mar 2011 08:13:24 +0000 (17:13 +0900)]
setmem: implement the remote protocol to address the new API

This patch implements the remote protocol to address the new API.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
14 years agosetmem: implement the code to address the new API in the qemu driver
Taku Izumi [Wed, 2 Mar 2011 08:13:09 +0000 (17:13 +0900)]
setmem: implement the code to address the new API in the qemu driver

This patch implements the code to address the new API
in the qemu driver.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
14 years agosetmem: introduce a new libvirt API (virDomainSetMemoryFlags)
Taku Izumi [Wed, 2 Mar 2011 08:07:48 +0000 (17:07 +0900)]
setmem: introduce a new libvirt API (virDomainSetMemoryFlags)

This patch introduces a new libvirt API (virDomainSetMemoryFlags) and
a flag (virDomainMemoryModFlags).

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
14 years agoMake sure we reset the umask on the error path
Guido Günther [Wed, 9 Mar 2011 13:19:56 +0000 (14:19 +0100)]
Make sure we reset the umask on the error path

14 years agoaudit: audit use of /dev/net/tun, /dev/tapN, /dev/vhost-net
Eric Blake [Tue, 8 Mar 2011 18:00:59 +0000 (11:00 -0700)]
audit: audit use of /dev/net/tun, /dev/tapN, /dev/vhost-net

Opening raw network devices with the intent of passing those fds to
qemu is worth an audit point.  This makes a multi-part audit: first,
we audit the device(s) that libvirt opens on behalf of the MAC address
of a to-be-created interface (which can independently succeed or
fail), then we audit whether qemu actually started the network device
with the same MAC (so searching backwards for successful audits with
the same MAC will show which fd(s) qemu is actually using).  Note that
it is possible for the fd to be successfully opened but no attempt
made to pass the fd to qemu (for example, because intermediate
nwfilter operations failed) - no interface start audit will occur in
that case; so the audit for a successful opened fd does not imply
rights given to qemu unless there is a followup audit about the
attempt to start a new interface.

Likewise, when a network device is hot-unplugged, there is only one
audit message about the MAC being discontinued; again, searching back
to the earlier device open audits will show which fds that qemu quits
using (and yes, I checked via /proc/<qemu-pid>/fd that qemu _does_
close out the fds associated with an interface on hot-unplug).  The
code would require much more refactoring to be able to definitively
state which device(s) were discontinued at that point, since we
currently don't record anywhere in the XML whether /dev/vhost-net was
opened for a given interface.

* src/qemu/qemu_audit.h (qemuAuditNetDevice): New prototype.
* src/qemu/qemu_audit.c (qemuAuditNetDevice): New function.
* src/qemu/qemu_command.h (qemuNetworkIfaceConnect)
(qemuPhysIfaceConnect, qemuOpenVhostNet): Adjust prototype.
* src/qemu/qemu_command.c (qemuNetworkIfaceConnect)
(qemuPhysIfaceConnect, qemuOpenVhostNet): Add audit points and
adjust parameters.
(qemuBuildCommandLine): Adjust caller.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.

14 years agoqemu: don't request cgroup ACL access for /dev/net/tun
Eric Blake [Wed, 9 Mar 2011 22:05:00 +0000 (15:05 -0700)]
qemu: don't request cgroup ACL access for /dev/net/tun

Since libvirt always passes /dev/net/tun to qemu via fd, we should
never trigger the cases where qemu tries to directly open the
device.  Therefore, it is safer to deny the cgroup device ACL.

* src/qemu/qemu_cgroup.c (defaultDeviceACL): Remove /dev/net/tun.
* src/qemu/qemu.conf (cgroup_device_acl): Reflect this change.

14 years agoqemu: support vhost in attach-interface
Eric Blake [Wed, 9 Mar 2011 04:43:33 +0000 (21:43 -0700)]
qemu: support vhost in attach-interface

* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Honor vhost
designations, similar to qemu_command code paths.
* src/qemu/qemu_command.h (qemuOpenVhostNet): New prototype.
* src/qemu/qemu_command.c (qemuOpenVhostNet): Export.

14 years agoqemu: Stop guest CPUs before creating a snapshot
Jiri Denemark [Thu, 24 Feb 2011 15:46:44 +0000 (16:46 +0100)]
qemu: Stop guest CPUs before creating a snapshot

14 years agoqemu: Refactor qemuDomainSnapshotCreateXML
Jiri Denemark [Fri, 25 Feb 2011 09:29:57 +0000 (10:29 +0100)]
qemu: Refactor qemuDomainSnapshotCreateXML

14 years agoqemu: Escape snapshot name passed to {save,load,del}vm
Jiri Denemark [Wed, 9 Mar 2011 20:47:06 +0000 (21:47 +0100)]
qemu: Escape snapshot name passed to {save,load,del}vm

14 years agoqemu: Fallback to HMP for snapshot commands
Jiri Denemark [Wed, 23 Feb 2011 11:12:11 +0000 (12:12 +0100)]
qemu: Fallback to HMP for snapshot commands

qemu driver in libvirt gained support for creating domain snapshots
almost a year ago in libvirt 0.8.0. Since then we enabled QMP support
for qemu >= 0.13.0 but QMP equivalents of {save,load,del}vm commands are
not implemented in current qemu (0.14.0) so the domain snapshot support
is not very useful.

This patch detects when the appropriate QMP command is not implemented
and tries to use human-monitor-command (aka HMP passthrough) to run
it's HMP equivalent.

14 years agoqemu: Rename qemuMonitorCommandWithHandler as qemuMonitorText*
Jiri Denemark [Thu, 10 Mar 2011 08:37:08 +0000 (09:37 +0100)]
qemu: Rename qemuMonitorCommandWithHandler as qemuMonitorText*

To make it more obvious that it is only used for text monitor. The
naming also matches the style of qemuMonitorTextCommandWithFd.

14 years agoqemu: Rename qemuMonitorCommand{,WithFd} as qemuMonitorHMP*
Jiri Denemark [Thu, 10 Mar 2011 08:33:01 +0000 (09:33 +0100)]
qemu: Rename qemuMonitorCommand{,WithFd} as qemuMonitorHMP*

So that it's obvious that they are supposed to be used with HMP commands.

14 years agoqemu: Setup infrastructure for HMP passthrough
Jiri Denemark [Wed, 9 Mar 2011 20:24:04 +0000 (21:24 +0100)]
qemu: Setup infrastructure for HMP passthrough

JSON monitor command implementation can now just directly call text
monitor implementation and it will be automatically encapsulated into
QMP's human-monitor-command.

14 years agoqemu: Fix warnings in event handlers
Jiri Denemark [Tue, 8 Mar 2011 13:42:05 +0000 (14:42 +0100)]
qemu: Fix warnings in event handlers

Some qemu monitor event handlers were issuing inadequate warning when
virDomainSaveStatus() failed. They copied the message from I/O error
handler without customizing it to provide better information on why
virDomainSaveStatus() was called.

14 years agostorage: Update qemu-img flag checking
Osier Yang [Thu, 10 Mar 2011 07:02:28 +0000 (15:02 +0800)]
storage: Update qemu-img flag checking

For newer qemu-img, the help string for "backing file format" is
"[-F backing_fmt]".

Fix the wrong logic error by commit e997c268.

* src/storage/storage_backend.c

14 years agoqemu: Replace deprecated option of qemu-img
Osier Yang [Thu, 10 Mar 2011 02:05:14 +0000 (10:05 +0800)]
qemu: Replace deprecated option of qemu-img

qemu-img silently disable "-e", so we can't use it for volume
encryption anymore, change it into "-o encryption=on" if qemu
supports "-o" option.

14 years agoaudit: also audit cgroup ACL permissions
Eric Blake [Wed, 9 Mar 2011 03:06:26 +0000 (20:06 -0700)]
audit: also audit cgroup ACL permissions

* src/qemu/qemu_audit.h (qemuAuditCgroupMajor)
(qemuAuditCgroupPath): Add parameter.
* src/qemu/qemu_audit.c (qemuAuditCgroupMajor)
(qemuAuditCgroupPath): Add 'acl=rwm' to cgroup audit entries.
* src/qemu/qemu_cgroup.c: Update clients.
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Likewise.

14 years agocgroup: allow fine-tuning of device ACL permissions
Eric Blake [Wed, 9 Mar 2011 03:13:18 +0000 (20:13 -0700)]
cgroup: allow fine-tuning of device ACL permissions

Adding audit points showed that we were granting too much privilege
to qemu; it should not need any mknod rights to recreate any
devices.  On the other hand, lxc should have all device privileges.
The solution is adding a flag parameter.

This also lets us restrict write access to read-only disks.

* src/util/cgroup.h (virCgroup*Device*): Adjust prototypes.
* src/util/cgroup.c (virCgroupAllowDevice)
(virCgroupAllowDeviceMajor, virCgroupAllowDevicePath)
(virCgroupDenyDevice, virCgroupDenyDeviceMajor)
(virCgroupDenyDevicePath): Add parameter.
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Update clients.
* src/lxc/lxc_controller.c (lxcSetContainerResources): Likewise.
* src/qemu/qemu_cgroup.c: Likewise.
(qemuSetupDiskPathAllow): Also, honor read-only disks.

14 years agoaudit: rename remaining qemu audit functions
Eric Blake [Tue, 8 Mar 2011 21:28:51 +0000 (14:28 -0700)]
audit: rename remaining qemu audit functions

Also add ATTRIBUTE_NONNULL markers.

* src/qemu/qemu_audit.h: The pattern qemuDomainXXXAudit is
inconsistent; prefer qemuAuditXXX instead.
* src/qemu/qemu_audit.c: Reflect the renames.
* src/qemu/qemu_driver.c: Likewise.
* src/qemu/qemu_hotplug.c: Likewise.
* src/qemu/qemu_migration.c: Likewise.
* src/qemu/qemu_process.c: Likewise.

14 years agoaudit: also audit cgroup controller path
Eric Blake [Mon, 7 Mar 2011 23:41:40 +0000 (16:41 -0700)]
audit: also audit cgroup controller path

Although the cgroup device ACL controller path can be worked out
by researching the code, it is more efficient to include that
information directly in the audit message.

* src/util/cgroup.h (virCgroupPathOfController): New prototype.
* src/util/cgroup.c (virCgroupPathOfController): Export.
* src/libvirt_private.syms: Likewise.
* src/qemu/qemu_audit.c (qemuAuditCgroup): Use it.

14 years agoaudit: split cgroup audit types to allow more information
Eric Blake [Mon, 7 Mar 2011 23:17:26 +0000 (16:17 -0700)]
audit: split cgroup audit types to allow more information

Device names can be manipulated, so it is better to also log
the major/minor device number corresponding to the cgroup ACL
changes that libvirt made.  This required some refactoring
of the relatively new qemu cgroup audit code.

Also, qemuSetupChardevCgroup was only auditing on failure, not success.

* src/qemu/qemu_audit.h (qemuDomainCgroupAudit): Delete.
(qemuAuditCgroup, qemuAuditCgroupMajor, qemuAuditCgroupPath): New
prototypes.
* src/qemu/qemu_audit.c (qemuDomainCgroupAudit): Rename...
(qemuAuditCgroup): ...and drop a parameter.
(qemuAuditCgroupMajor, qemuAuditCgroupPath): New functions, to
allow listing device major/minor in audit.
(qemuAuditGetRdev): New helper function.
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Adjust callers.
* src/qemu/qemu_cgroup.c (qemuSetupDiskPathAllow)
(qemuSetupHostUsbDeviceCgroup, qemuSetupCgroup)
(qemuTeardownDiskPathDeny): Likewise.
(qemuSetupChardevCgroup): Likewise, fixing missing audit.

14 years agoaudit: tweak audit messages to match conventions
Eric Blake [Sat, 26 Feb 2011 00:28:21 +0000 (17:28 -0700)]
audit: tweak audit messages to match conventions

* src/qemu/qemu_audit.c (qemuDomainHostdevAudit): Avoid use of
"type", which has a pre-defined meaning.
(qemuDomainCgroupAudit): Likewise, as well as "item".

14 years agodocs: silence warnings about generated API docs
Eric Blake [Wed, 9 Mar 2011 03:42:19 +0000 (20:42 -0700)]
docs: silence warnings about generated API docs

I noticed these while testing 'make dist'.

Parsing ./../src/util/event.c
Function comment for virEventRegisterDefaultImpl lacks description of return value
Function comment for virEventRunDefaultImpl lacks description of return value
Parsing ./../src/util/virterror.c
Missing comment for function virSetErrorLogPriorityFunc

* src/util/event.c (virEventRegisterDefaultImpl)
(virEventRunDefaultImpl): Document return types.
* src/util/virterror.c (virSetErrorLogPriorityFunc): Provide docs.

14 years agodocs: document <driver name='vhost'/> for interfaces
Eric Blake [Tue, 8 Mar 2011 23:35:17 +0000 (16:35 -0700)]
docs: document <driver name='vhost'/> for interfaces

* docs/formatdomain.html.in: Document virtio backend selection.

14 years agoMake sure the rundir is accessible by the user
Guido Günther [Wed, 9 Mar 2011 13:15:48 +0000 (14:15 +0100)]
Make sure the rundir is accessible by the user

otherwise the user might not have enough permissions to access the
socket if root's umask is 077.

http://bugs.debian.org/614210

14 years agoDon't overwrite virRun error messages
Cole Robinson [Tue, 8 Mar 2011 18:46:29 +0000 (13:46 -0500)]
Don't overwrite virRun error messages

virRun gives pretty useful error output, let's not overwrite it unless there
is a good reason. Some places were providing more information about what
the commands were _attempting_ to do, however that's usually less useful from
a debugging POV than what actually happened.

14 years agolibvirtd: Remove indirect linking
Guido Günther [Tue, 8 Mar 2011 20:44:14 +0000 (21:44 +0100)]
libvirtd: Remove indirect linking

as described at
http://wiki.debian.org/ToolChain/DSOLinking
https://fedoraproject.org/wiki/UnderstandingDSOLinkChange

otherwise the build fails on current Debian unstable with:

CCLD   libvirtd
/usr/bin/ld: ../src/.libs/libvirt_driver_lxc.a(libvirt_driver_lxc_la-lxc_container.o): undefined reference to symbol 'capng_apply'
/usr/bin/ld: note: 'capng_apply' is defined in DSO //usr/lib/libcap-ng.so.0 so try adding it to the linker command line

CCLD   libvirtd
/usr/bin/ld: ../src/.libs/libvirt_driver_storage.a(libvirt_driver_storage_la-storage_backend.o): undefined reference to symbol 'fgetfilecon'
/usr/bin/ld: note: 'fgetfilecon' is defined in DSO //lib/libselinux.so.1 so try adding it to the linker command line
//lib/libselinux.so.1: could not read symbols: Invalid operation

and similar errors.

14 years agoFix a wrong error message thrown to user
Hu Tao [Wed, 9 Mar 2011 12:09:25 +0000 (20:09 +0800)]
Fix a wrong error message thrown to user

* src/qemu/qemu_driver.c: qemuDomainUpdateDeviceFlags() is not disk
  specific as the message suggests

14 years agobuild: avoid compiler warning on cygwin
Eric Blake [Wed, 9 Mar 2011 04:47:49 +0000 (21:47 -0700)]
build: avoid compiler warning on cygwin

On cygwin:

  CC       libvirt_driver_security_la-security_dac.lo
security/security_dac.c: In function 'virSecurityDACSetProcessLabel':
security/security_dac.c:618: warning: format '%d' expects type 'int', but argument 7 has type 'uid_t' [-Wformat]

We've done this before (see src/util/util.c).

* src/security/security_dac.c (virSecurityDACSetProcessLabel): On
cygwin, uid_t is a 32-bit long.

14 years agobuild: fix build on cygwin
Eric Blake [Wed, 9 Mar 2011 04:43:26 +0000 (21:43 -0700)]
build: fix build on cygwin

On cygwin:

  CC        libvirt_util_la-cgroup.lo
util/cgroup.c: In function 'virCgroupKillRecursiveInternal':
util/cgroup.c:1458: warning: implicit declaration of function 'virCgroupNew' [-Wimplicit-function-declaration]

* src/util/cgroup.c (virCgroupKill): Don't build on platforms
where virCgroupNew is unsupported.

14 years agobuild: fix building error when building without libvirtd
Wen Congyang [Wed, 9 Mar 2011 03:18:36 +0000 (11:18 +0800)]
build: fix building error when building without libvirtd

When building libvirt without libvirtd, I receive the following errors:
make[1]: Leaving directory `/home/wency/source/test/libvirt/src'
 (cd daemon && make  top_distdir=../libvirt-0.8.8 distdir=../libvirt-0.8.8/daemon \
     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)
make[1]: Entering directory `/home/wency/source/test/libvirt/daemon'
make[1]: *** No rule to make target `libvirtd.8.in', needed by `distdir'.  Stop.

This bug was caused by commit 6db98a2d.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
14 years agodocs: correct range of default NAT subnet
Eric Blake [Tue, 8 Mar 2011 23:15:47 +0000 (16:15 -0700)]
docs: correct range of default NAT subnet

* docs/formatdomain.html.in: Fix typo.

14 years agovirsh: Remove indirect link against libxml2
Guido Günther [Tue, 8 Mar 2011 18:24:28 +0000 (19:24 +0100)]
virsh: Remove indirect link against libxml2

as described at
http://wiki.debian.org/ToolChain/DSOLinking
https://fedoraproject.org/wiki/UnderstandingDSOLinkChange

otherwise the build fails on current Debian unstable with:

CCLD   virsh
/usr/bin/ld: virsh-virsh.o: undefined reference to symbol 'xmlSaveTree@@LIBXML2_2.6.8'
/usr/bin/ld: note: 'xmlSaveTree@@LIBXML2_2.6.8' is defined in DSO //usr/lib/libxml2.so.2 so try adding it to the linker command line
//usr/lib/libxml2.so.2: could not read symbols: Invalid operation

14 years agovirsh: Change option parsing functions to return tri-state information
Michal Privoznik [Tue, 8 Mar 2011 16:29:31 +0000 (17:29 +0100)]
virsh: Change option parsing functions to return tri-state information

This is needed to detect situations when optional argument was
specified with non-integer value: '--int-opt foo'. To keep functions
uniform vshCommandOptString function was also changed, because it
returns tri-state value as well. Given result pointer is updated only
in case of success. If parsing fails, result is not updated at all.

14 years agovirsh: change vshCommandOptString return type and fix const-correctness
Michal Privoznik [Tue, 8 Mar 2011 16:29:30 +0000 (17:29 +0100)]
virsh: change vshCommandOptString return type and fix const-correctness

This function should return pointer to const, because we don't want
to change command option value. Therefore we can ensure const-correctness.

14 years agodocs/formatdomain: Add release info for disk <driver> attributes
Cole Robinson [Tue, 8 Mar 2011 18:02:43 +0000 (13:02 -0500)]
docs/formatdomain: Add release info for disk <driver> attributes

14 years agoFix build on cygwin
Daniel Veillard [Tue, 8 Mar 2011 08:01:25 +0000 (16:01 +0800)]
Fix build on cygwin

Apparently some signals found on Unix are not exposed, this led
to a compilation failure
* src/util/logging.c: make code related to each signal dependant
  upon the definition of that signal

14 years agosupport to detach USB disk
Wen Congyang [Mon, 7 Mar 2011 03:36:48 +0000 (11:36 +0800)]
support to detach USB disk

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
14 years agorename qemuDomainDetachSCSIDiskDevice to qemuDomainDetachDiskDevice
Wen Congyang [Mon, 7 Mar 2011 03:31:48 +0000 (11:31 +0800)]
rename qemuDomainDetachSCSIDiskDevice to qemuDomainDetachDiskDevice

The way to detach a USB disk is the same as that to detach a SCSI
disk. Rename this function and we can use it to detach a USB disk.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
14 years agoqemu_hotplug: Reword error if spice password change not available
Cole Robinson [Mon, 7 Mar 2011 18:09:35 +0000 (13:09 -0500)]
qemu_hotplug: Reword error if spice password change not available

Currently it sounds like spice is completely unsupported, which is
confusing.

14 years agounlock eventLoop before calling callback function
Wen Congyang [Mon, 7 Mar 2011 06:06:49 +0000 (14:06 +0800)]
unlock eventLoop before calling callback function

When I use newest libvirt to save a domain, libvirtd will be deadlock.
Here is the output of gdb:
(gdb) thread 3
[Switching to thread 3 (Thread 0x7f972a1fc710 (LWP 30265))]#0  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
(gdb) bt
    at qemu/qemu_driver.c:2074
    ret=0x7f972a1fbbe0) at remote.c:2273
(gdb) thread 7
[Switching to thread 7 (Thread 0x7f9730bcd710 (LWP 30261))]#0  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
(gdb) bt
(gdb) p *(virMutexPtr)0x6fdd60
$2 = {lock = {__data = {__lock = 2, __count = 0, __owner = 30261, __nusers = 1, __kind = 0, __spins = 0, __list = {__prev = 0x0, __next = 0x0}},
    __size = "\002\000\000\000\000\000\000\000\065v\000\000\001", '\000' <repeats 26 times>, __align = 2}}
(gdb) p *(virMutexPtr)0x1a63ac0
$3 = {lock = {__data = {__lock = 2, __count = 0, __owner = 30265, __nusers = 1, __kind = 0, __spins = 0, __list = {__prev = 0x0, __next = 0x0}},
    __size = "\002\000\000\000\000\000\000\000\071v\000\000\001", '\000' <repeats 26 times>, __align = 2}}
(gdb) info threads
  7 Thread 0x7f9730bcd710 (LWP 30261)  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
  6 Thread 0x7f972bfff710 (LWP 30262)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  5 Thread 0x7f972b5fe710 (LWP 30263)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  4 Thread 0x7f972abfd710 (LWP 30264)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
* 3 Thread 0x7f972a1fc710 (LWP 30265)  0x000000351fe0e034 in __lll_lock_wait () from /lib64/libpthread.so.0
  2 Thread 0x7f97297fb710 (LWP 30266)  0x000000351fe0b43c in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
  1 Thread 0x7f9737aac800 (LWP 30260)  0x000000351fe0803d in pthread_join () from /lib64/libpthread.so.0

The reason is that we will try to lock some object in callback function, and we may call event API with locking the same object.
In the function virEventDispatchHandles(), we unlock eventLoop before calling callback function. I think we should
do the same thing in the function virEventCleanupTimeouts() and virEventCleanupHandles().

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
14 years agoExpose event loop implementation as a public API
Daniel P. Berrange [Wed, 2 Mar 2011 16:59:54 +0000 (16:59 +0000)]
Expose event loop implementation as a public API

Not all applications have an existing event loop they need
to integrate with. Forcing them to implement the libvirt
event loop integration APIs is an undue burden. This just
exposes our simple poll() based implementation for apps
to use. So instead of calling

   virEventRegister(....callbacks...)

The app would call

   virEventRegisterDefaultImpl()

And then have a thread somewhere calling

    static bool quit = false;
    ....
    while (!quit)
      virEventRunDefaultImpl()

* daemon/libvirtd.c, tools/console.c,
  tools/virsh.c: Convert to public event loop APIs
* include/libvirt/libvirt.h.in, src/libvirt_private.syms: Add
  virEventRegisterDefaultImpl and virEventRunDefaultImpl
* src/util/event.c: Implement virEventRegisterDefaultImpl
  and virEventRunDefaultImpl using poll() event loop
* src/util/event_poll.c: Add full error reporting
* src/util/virterror.c, include/libvirt/virterror.h: Add
  VIR_FROM_EVENTS

14 years agoMove event code out of the daemon/ into src/util/
Daniel P. Berrange [Thu, 24 Feb 2011 17:58:04 +0000 (17:58 +0000)]
Move event code out of the daemon/ into src/util/

The event loop implementation is used by more than just the
daemon, so move it into the shared area.

* daemon/event.c, src/util/event_poll.c: Renamed
* daemon/event.h, src/util/event_poll.h: Renamed
* tools/Makefile.am, tools/console.c, tools/virsh.c: Update
  to use new virEventPoll APIs
* daemon/mdns.c, daemon/mdns.c, daemon/Makefile.am: Update
  to use new virEventPoll APIs

14 years agoConvert daemon/virsh over to use primary event APIs, rather than impl
Daniel P. Berrange [Wed, 2 Mar 2011 15:08:31 +0000 (15:08 +0000)]
Convert daemon/virsh over to use primary event APIs, rather than impl

The daemon code calls virEventAddHandleImpl directly instead
of calling the wrapper virEventAddHandle.

* tools/console.c, daemon/libvirtd.c, daemon/mdns.c: Convert to
  use primary event APIs

14 years agoCleaning up some of the logging code
Daniel Veillard [Mon, 7 Mar 2011 13:23:53 +0000 (21:23 +0800)]
Cleaning up some of the logging code

* src/util/logging.c: fix virLogDumpAllFD() to avoid snprintf, simplify
  the code and provide more useful signal descriptions. Also remove an
  unused variable.

14 years agoqemu: Support vram for video of qxl type
Osier Yang [Sun, 6 Mar 2011 14:00:27 +0000 (22:00 +0800)]
qemu: Support vram for video of qxl type

For qemu names the primary vga as "qxl-vga":

  1) if vram is specified for 2nd qxl device:

    -vga qxl -global qxl-vga.vram_size=$SIZE \
    -device qxl,id=video1,vram_size=$SIZE,...

  2) if vram is not specified for 2nd qxl device, (use the default
     set by global):

    -vga qxl -global qxl-vga.vram_size=$SIZE \
    -device qxl,id=video1,...

For qemu names all qxl devices as "qxl":

  1) if vram is specified for 2nd qxl device:

    -vga qxl -global qxl.vram_size=$SIZE \
    -device qxl,id=video1,vram_size=$SIZE ...

  2) if vram is not specified for 2nd qxl device:

    -vga qxl -global qxl-vga.vram_size=$SIZE \
    -device qxl,id=video1,...

"-global" is the only way to define vram_size for the primary qxl
device, regardless of how qemu names it, (It's not good a good
way, as original idea of "-global" is to set a global default for
a driver property, but to specify vram for first qxl device, we
have to use it).

For other qxl devices, as they are represented by "-device", could
specify it directly and seperately for each, and it overrides the
default set by "-global" if specified.

v1 - v2:
  * modify "virDomainVideoDefaultRAM" so that it returns 16M as the
    default vram_size for qxl device.

  * vram_size * 1024 (qemu accepts bytes for vram_size).

  * apply default vram_size for qxl device for which vram_size is
    not specified.

  * modify "graphics-spice" tests (more sensiable vram_size)

  * Add an argument of virDomainDefPtr type for qemuBuildVideoDevStr,
    to use virDomainVideoDefaultRAM in qemuBuildVideoDevStr).

v2 - v3:
  * Modify default video memory size for qxl device from 16M to 24M

  * Update codes to be consistent with changes on qemu_capabilities.*

14 years agofixes for several memory leaks
Phil Petty [Fri, 4 Mar 2011 16:52:12 +0000 (09:52 -0700)]
fixes for several memory leaks

Signed-off-by: Eric Blake <eblake@redhat.com>
14 years agoDump the debug buffer to libvirtd.log on fatal signal
Daniel Veillard [Thu, 3 Mar 2011 09:41:44 +0000 (17:41 +0800)]
Dump the debug buffer to libvirtd.log on fatal signal

In case of imminent crash or upon request (signal USR2),
dump the logging buffer to the libvirtd.log file for
post-mortem analysis
* daemon/libvirtd.c: create a sig_fatal() handler connected to
  SIGFPE SIGSEGV SIGILL SIGABRT SIGBUS and SIGUSR2, just dumping
  the log buffer using virLogEmergencyDumpAll

14 years agoAdd an an internal API for emergency dump of debug buffer
Daniel Veillard [Thu, 3 Mar 2011 08:32:18 +0000 (16:32 +0800)]
Add an an internal API for emergency dump of debug buffer

virLogEmergencyDumpAll() allows to dump the content of the
debug buffer from within a signal handler. It saves to all
log file or stderr if none is found
* src/util/logging.h src/util/logging.c: add the new API
  and cleanup the old virLogDump code
* src/libvirt_private.syms: exports it as a private symbol

14 years agoFix a counter bug in the log buffer
Daniel Veillard [Thu, 3 Mar 2011 07:45:52 +0000 (15:45 +0800)]
Fix a counter bug in the log buffer

* src/util/logging.c: the start pointer need to wrap around too