]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agoRename virRequest{Username,Password} to virAuthGet{Username,Password}
Daniel P. Berrange [Mon, 19 Mar 2012 16:23:47 +0000 (16:23 +0000)]
Rename virRequest{Username,Password} to virAuthGet{Username,Password}

Ensure that the functions in virauth.h have names matching the file
prefix, by renaming  virRequest{Username,Password} to
virAuthGet{Username,Password}

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoRename src/util/authhelper.[ch] to src/util/virauth.[ch]
Daniel P. Berrange [Mon, 19 Mar 2012 16:21:12 +0000 (16:21 +0000)]
Rename src/util/authhelper.[ch] to src/util/virauth.[ch]

To follow latest naming conventions, rename src/util/authhelper.[ch]
to src/util/virauth.[ch].

* src/util/authhelper.[ch]: Rename to src/util/virauth.[ch]
* src/esx/esx_driver.c, src/hyperv/hyperv_driver.c,
  src/phyp/phyp_driver.c, src/xenapi/xenapi_driver.c: Update
  for renamed include files

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoAdd a virKeyfilePtr object for parsing '.ini' files
Daniel P. Berrange [Fri, 16 Mar 2012 16:29:49 +0000 (16:29 +0000)]
Add a virKeyfilePtr object for parsing '.ini' files

The '.ini' file format is a useful alternative to the existing
config file style, when you need to have config files which
are hashes of hashes. The 'virKeyFilePtr' object provides a
way to parse these file types.

* src/Makefile.am, src/util/virkeyfile.c,
  src/util/virkeyfile.h: Add .ini file parser
* tests/Makefile.am, tests/virkeyfiletest.c: Test
  basic parsing capabilities

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoConvert drivers over to use virURIPtr for query params
Daniel P. Berrange [Tue, 20 Mar 2012 14:11:10 +0000 (14:11 +0000)]
Convert drivers over to use virURIPtr for query params

Convert drivers currently using the qparams APIs, to instead
use the virURIPtr query parameters directly.

* src/esx/esx_util.c, src/hyperv/hyperv_util.c,
  src/remote/remote_driver.c, src/xenapi/xenapi_utils.c: Remove
  use of qparams
* src/util/qparams.h, src/util/qparams.c: Delete
* src/Makefile.am, src/libvirt_private.syms: Remove qparams

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoStore parsed query parameters directly in the virURIPtr struct
Daniel P. Berrange [Tue, 20 Mar 2012 13:59:32 +0000 (13:59 +0000)]
Store parsed query parameters directly in the virURIPtr struct

Avoid the need for each driver to parse query parameters itself
by storing them directly in the virURIPtr struct. The parsing
code is a copy of that from src/util/qparams.c  The latter will
be removed in a later patch

* src/util/viruri.h: Add query params to virURIPtr
* src/util/viruri.c: Parse query parameters when creating virURIPtr
* tests/viruritest.c: Expand test to cover params

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoUse a libvirt custom struct for virURIPtr
Daniel P. Berrange [Tue, 20 Mar 2012 13:33:41 +0000 (13:33 +0000)]
Use a libvirt custom struct for virURIPtr

Instead of just typedef'ing the xmlURIPtr struct for virURIPtr,
use a custom libvirt struct. This allows us to fix various
problems with libxml2. This initially just fixes the query vs
query_raw handling problems.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoCentralize error reporting for URI parsing/formatting problems
Daniel P. Berrange [Tue, 20 Mar 2012 12:16:54 +0000 (12:16 +0000)]
Centralize error reporting for URI parsing/formatting problems

Move error reporting out of the callers, into virURIParse
and virURIFormat, to get consistency.

* include/libvirt/virterror.h, src/util/virterror.c: Add VIR_FROM_URI
* src/util/viruri.c, src/util/viruri.h: Add error reporting
* src/esx/esx_driver.c, src/libvirt.c, src/libxl/libxl_driver.c,
  src/lxc/lxc_driver.c, src/openvz/openvz_driver.c,
  src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
  src/remote/remote_driver.c, src/uml/uml_driver.c,
  src/vbox/vbox_tmpl.c, src/vmx/vmx.c, src/xen/xen_driver.c,
  src/xen/xend_internal.c, tests/viruritest.c: Remove error
  reporting

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agos/xmlURIPtr/virURIPtr/ in virURIFormat impl
Daniel P. Berrange [Tue, 20 Mar 2012 13:37:55 +0000 (13:37 +0000)]
s/xmlURIPtr/virURIPtr/ in virURIFormat impl

The parameter in the virURIFormat impl mistakenly used the
xmlURIPtr type, instead of virURIPtr. Since they will soon
cease to be identical, this needs fixing

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoUse virURIFree instead of xmlFreeURI
Daniel P. Berrange [Tue, 20 Mar 2012 11:59:42 +0000 (11:59 +0000)]
Use virURIFree instead of xmlFreeURI

Since we defined a custom virURIPtr type, we should use a
virURIFree method instead of assuming it will always be
a typedef for xmlURIPtr

* src/util/viruri.c, src/util/viruri.h, src/libvirt_private.syms:
  Add a virURIFree method
* src/datatypes.c, src/esx/esx_driver.c, src/libvirt.c,
  src/qemu/qemu_migration.c, src/vmx/vmx.c, src/xen/xend_internal.c,
  tests/viruritest.c: s/xmlFreeURI/virURIFree/

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoAdd test case for virURIPtr classs
Daniel P. Berrange [Tue, 20 Mar 2012 11:55:11 +0000 (11:55 +0000)]
Add test case for virURIPtr classs

To ensure we properly escape & unescape IPv6 numeric addresses,
add a test case

* tests/Makefile.am, tests/viruritest.c: URI parsing test

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoLeave all child processes running when stopping systemd service
Daniel P. Berrange [Thu, 22 Mar 2012 14:01:12 +0000 (14:01 +0000)]
Leave all child processes running when stopping systemd service

Currently the libvirt.service unit file for systemd does not
specify any kill mode. So systemd kills off every process
inside its cgroup. ie all dnsmasq processes, all virtual
machines. This obviously not what we want. Set KillMode=process
so that it only kills the top level process of libvirtd

* daemon/libvirtd.service.in: Add KillMode=process

Reported-By: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
13 years agoClarify virsh freecell manpage entry
Dave Allan [Thu, 22 Mar 2012 20:49:07 +0000 (16:49 -0400)]
Clarify virsh freecell manpage entry

13 years agodocs: fix typo
Zhou Peng [Fri, 23 Mar 2012 02:40:09 +0000 (10:40 +0800)]
docs: fix typo

Bogus <code/>, and incorrect use of it's instead of its.

13 years agoClarify what documentation is being referenced
Dave Allan [Thu, 22 Mar 2012 02:07:51 +0000 (22:07 -0400)]
Clarify what documentation is being referenced

virsh.pod had several instances in which it referred to "the
documentation" which was a little puzzling to me since it is
documentation.  Reading the document from end to end makes it clear
that it means a specific URI which was noted previously in the text,
but I had never noticed those URIs in several years of referring to
the man page.  This patch adds those URIs to several additional places
in the text.

13 years agopython: add virDomainGetCPUStats python binding API
Guannan Ren [Tue, 20 Mar 2012 04:34:06 +0000 (12:34 +0800)]
python: add virDomainGetCPUStats python binding API

    dom.getCPUStats(True, 0)
      [{'cpu_time': 24699446159L, 'system_time': 10870000000L, 'user_time': 950000000L}]
    dom.getCPUStats(False, 0)
      [{'cpu_time': 8535292289L}, {'cpu_time': 1005395355L}, {'cpu_time': 9351766377L}, {'cpu_time': 5813545649L}]

    *generator.py Add a new naming rule
    *libvirt-override-api.xml The API function description
    *libvirt-override.c Implement it.

13 years agopython: Avoid memory leaks on libvirt_virNodeGetCPUStats
Alex Jia [Wed, 21 Mar 2012 16:25:22 +0000 (00:25 +0800)]
python: Avoid memory leaks on libvirt_virNodeGetCPUStats

Detected by valgrind. Leaks are introduced in commit 4955602.

* python/libvirt-override.c (libvirt_virNodeGetCPUStats): fix memory leaks
and improve codes return value.

For details, please see the following link:
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770943

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agobuild: drop a painfully long gnulib test
Eric Blake [Tue, 20 Mar 2012 23:04:38 +0000 (17:04 -0600)]
build: drop a painfully long gnulib test

On machines with massive amounts of CPUs, the gnulib 'test-lock'
could take minutes, or even appear to deadlock, because of poor
scaling of timing interactions between multiple cores.

See https://bugzilla.redhat.com/show_bug.cgi?id=797284.
For precedence, note that iwhd has done the same:
https://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00311.html

We can re-enable things if gnulib ever analyzes and improves the
situation.

* bootstrap.conf (gnulib_tool_option_extras): Avoid lock-tests.

13 years agoqemu: Avoid dangling migration-out job when client dies
Jiri Denemark [Mon, 19 Mar 2012 15:48:43 +0000 (16:48 +0100)]
qemu: Avoid dangling migration-out job when client dies

When a client which started non-p2p migration dies in a bad time, the
source libvirtd never clears the migration job and almost nothing can be
done with the domain without restarting the daemon. This patch makes use
of connection close callbacks and ensures that migration job is properly
discarded when the client disconnects.

13 years agoqemu: Make autodestroy utilize connection close callbacks
Jiri Denemark [Mon, 19 Mar 2012 13:31:41 +0000 (14:31 +0100)]
qemu: Make autodestroy utilize connection close callbacks

13 years agoqemu: Add connection close callbacks
Jiri Denemark [Mon, 19 Mar 2012 13:28:10 +0000 (14:28 +0100)]
qemu: Add connection close callbacks

Add support for registering arbitrary callback to be called for a domain
when a connection gets closed.

13 years agoqemu: Avoid dangling migration-in job on shutoff domains
Jiri Denemark [Fri, 16 Mar 2012 06:56:19 +0000 (07:56 +0100)]
qemu: Avoid dangling migration-in job on shutoff domains

Destination daemon should not rely on the client or source daemon
(depending on the type of migration) to call Finish when migration
fails, because the client may crash before it can do so. The domain
prepared for incoming migration is set to be destroyed (and migration
job cleaned up) when connection with the client closes but this is not
enough. If the associated qemu process crashes after Prepare step and
the domain is cleaned up before the connection gets closed, autodestroy
is not called for the domain and migration jobs remains set. In case the
domain is defined on destination host (i.e., it is not completely
removed once destroyed) we keep the job set for ever. To fix this, we
register a cleanup callback which is responsible to clean migration-in
job when a domain dies anywhere between Prepare and Finish steps. Note
that we can't blindly clean any job when spotting EOF on monitor since
normally an API is running at that time.

13 years agoqemu: Add support for domain cleanup callbacks
Jiri Denemark [Fri, 16 Mar 2012 06:52:26 +0000 (07:52 +0100)]
qemu: Add support for domain cleanup callbacks

Add support for registering cleanup callbacks to be run when a domain
transitions to shutoff state.

13 years agoqemu: Use unlimited speed when migrating to file
Jiri Denemark [Tue, 20 Mar 2012 15:56:29 +0000 (16:56 +0100)]
qemu: Use unlimited speed when migrating to file

This reverts commit 61f2b6ba5fdef0613d6351b99913b5ef468144ce and most of
commit d8916dc8e2f612ab3ce46f32c4bfeb0bd73f6007, which effectively
brings back commit ef1065cf5acad13767c054758cbe7f4e8af5d241 written by
Jim Fehlig:

The qemu migration speed default is 32MiB/s as defined in migration.c

/* Migration speed throttling */
static int64_t max_throttle = (32 << 20);

There's no need to throttle migration when targeting a file, so set
migration speed to unlimited prior to migration, and restore to libvirt
default value after migration.

Default units is MB for migrate_set_speed monitor command, so
(INT64_MAX / (1024 * 1024)) is used for unlimited migration speed.

This was reverted because migration to file could not be canceled and
even monitored since qemu was not processing any monitor commands until
the migration finished. This is now different as we make sure the
file descriptor we pass to qemu is able to properly report EAGAIN.
Recent qemu changes might have helped as well.

I tested managedsave with this patch in and indeed, it is 10x faster
while I can still monitor its progress.

13 years agopython: Avoid memory leaks on libvirt_virNodeGetMemoryStats
Alex Jia [Wed, 21 Mar 2012 15:30:03 +0000 (23:30 +0800)]
python: Avoid memory leaks on libvirt_virNodeGetMemoryStats

Detected by valgrind. Leaks are introduced in commit 17c7795.

* python/libvirt-override.c (libvirt_virNodeGetMemoryStats): fix memory leaks
and improve codes return value.

For details, please see the following link:
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=770944

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agopython: always include config.h first
Eric Blake [Tue, 20 Mar 2012 22:44:39 +0000 (16:44 -0600)]
python: always include config.h first

On RHEL 5.7, I got this compilation failure:

In file included from /usr/include/python2.4/pyport.h:98,
                 from /usr/include/python2.4/Python.h:55,
                 from libvirt.c:3:
../gnulib/lib/time.h:468: error: expected ';', ',' or ')' before '__timer'

Turns out that our '#define restrict __restrict' from config.h wasn't
being picked up.  Gnulib _requires_ that all .c files include <config.h>
first, otherwise the gnulib header overrides tend to misbehave.

Problem introduced by patch c700613b8.

* python/generator.py (buildStubs): Include <config.h> first.

13 years agoMinor docs fix
Martin Kletzander [Mon, 19 Mar 2012 21:52:29 +0000 (22:52 +0100)]
Minor docs fix

End tag for "host" element was missing in example configuration

13 years agoconf: forbid use of multicast mac addresses
Laine Stump [Mon, 19 Mar 2012 16:49:17 +0000 (12:49 -0400)]
conf: forbid use of multicast mac addresses

A few times libvirt users manually setting mac addresses have
complained of a networking failure that ends up being due to a multicast
mac address being used for a guest interface. This patch prevents that
by logging an error and failing if a multicast mac address is
encountered in each of the three following cases:

1) domain xml <interface> mac address.
2) network xml bridge mac address.
3) network xml dhcp/host mac address.

There are several other places where a mac address can be input that
aren't controlled in this manner because failure to do so has no
consequences (e.g., if the address will be used to search through
existing interfaces for a match).

The RNG has been updated to add multiMacAddr and uniMacAddr along with
the existing macAddr, and macAddr was switched to uniMacAddr where
appropriate.

13 years agoconf: return immediately on error in dhcp host element
Laine Stump [Mon, 19 Mar 2012 03:57:50 +0000 (23:57 -0400)]
conf: return immediately on error in dhcp host element

If an error was encountered parsing a dhcp host entry mac address or
name, parsing would continue and log a less descriptive error that
might make it more difficult to notice the true nature of the problem.

This patch returns immediately on logging the first error.

13 years agoutil: fail attempts to use same mac address for guest and tap
Laine Stump [Mon, 5 Mar 2012 00:21:16 +0000 (19:21 -0500)]
util: fail attempts to use same mac address for guest and tap

This patch is in response to:

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

If a guest's tap device is created using the same MAC address the
guest uses for its own network card (which connects to the tap
device), the Linux kernel will log the following message and traffic
will not pass:

 kernel: vnet9: received packet with own address as source address

This patch disallows MAC addresses with a first byte of 0xFE, but only in
the case that the MAC address is used for a guest interface that's
connected by way of a standard tap device. (In other words, the
validation is done at runtime at the same place the MAC address is
modified for the tap device, rather than when mac address is parsed,
the idea being that it is then we know for sure the address will be
problematic.)

13 years agoCpu mapping cleanup
Martin Kletzander [Mon, 19 Mar 2012 12:29:05 +0000 (13:29 +0100)]
Cpu mapping cleanup

Using inheritance, this patch cleans up the cpu_map.xml file and also
sorts all CPU features according to the feature and registry
values. Model features are sorted the same way as foeatures in the
specification.
Also few models that are related were organized together and parts of
the XML are marked with comments

13 years agosnapshot: make quiesce a bit safer
Eric Blake [Fri, 16 Mar 2012 20:43:58 +0000 (14:43 -0600)]
snapshot: make quiesce a bit safer

If a guest is paused, we were silently ignoring the quiesce flag,
which results in unclean snapshots, contrary to the intent of the
flag.  Since we can't quiesce without guest agent support, we should
instead fail if the guest is not running.

Meanwhile, if we attempt a quiesce command, but the guest agent
doesn't respond, and we time out, we may have left the command
pending on the guest's queue, and when the guest resumes parsing
commands, it will freeze even though our command is no longer
around to issue a thaw.  To be safe, we must _always_ pair every
quiesce call with a counterpart thaw, even if the quiesce call
failed due to a timeout, so that if a guest wakes up and starts
processing a command backlog, it will not get stuck in a frozen
state.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive):
Always issue thaw after a quiesce, even if quiesce failed.
(qemuDomainSnapshotFSThaw): Add a parameter.

13 years agovirConfGetValue: Fixed NULL pointer check
Martin Kletzander [Mon, 19 Mar 2012 10:05:30 +0000 (11:05 +0100)]
virConfGetValue: Fixed NULL pointer check

This patch fixes a NULL pointer check that was causing SegFault on
some specific configurations. It also reverts commit 59d0c9801c1ab
that was checking for this value in one place.

13 years agovirsh: trim aliases from -h output
Eric Blake [Fri, 16 Mar 2012 19:23:00 +0000 (13:23 -0600)]
virsh: trim aliases from -h output

Commit af3f9aab taught 'virsh help' to ignore command aliases,
but forgot 'virsh -h'.

* tools/virsh.c (vshUsage): Handle aliases.

13 years agoFix handling of blkio deviceWeight empty string
Daniel P. Berrange [Fri, 16 Mar 2012 11:05:31 +0000 (11:05 +0000)]
Fix handling of blkio deviceWeight empty string

A common coding pattern for changing blkio parameters is

  1. virDomainGetBlkioParameters

  2. change one or more params

  3. virDomainSetBlkioParameters

For this to work, it must be possible to roundtrip through
the methods without error. Unfortunately virDomainGetBlkioParameters
will return "" for the deviceWeight parameter for guests by default,
which virDomainSetBlkioParameters will then reject as invalid.

This fixes the handling of "" to be a no-op, and also improves the
error message to tell you what was invalid

13 years agoremote: Fix migration leaks
Osier Yang [Fri, 16 Mar 2012 11:37:05 +0000 (19:37 +0800)]
remote: Fix migration leaks

How to reproduce:

% valgrind -v --leak-check=full virsh migrate mig \
  qemu+ssh://$dest/system --unsafe

== 8 bytes in 1 blocks are definitely lost in loss record 1 of 28
==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==    by 0x3EB7115FB8: xdr_reference (in /lib64/libc-2.12.so)
==    by 0x3EB7115F10: xdr_pointer (in /lib64/libc-2.12.so)
==    by 0x4D1EA84: xdr_remote_string (remote_protocol.c:40)
==    by 0x4D1EAD8: xdr_remote_domain_migrate_prepare3_ret (remote_protocol.c:4772)
==    by 0x4D2FFD2: virNetMessageDecodePayload (virnetmessage.c:382)
==    by 0x4D2789C: virNetClientProgramCall (virnetclientprogram.c:382)
==    by 0x4D0707D: callWithFD (remote_driver.c:4549)
==    by 0x4D070FB: call (remote_driver.c:4570)
==    by 0x4D12AEE: remoteDomainMigratePrepare3 (remote_driver.c:4138)
==    by 0x4CF7BE9: virDomainMigrateVersion3 (libvirt.c:4815)
==    by 0x4CF9432: virDomainMigrate2 (libvirt.c:5454)
==
== LEAK SUMMARY:
==    definitely lost: 8 bytes in 1 blocks
==    indirectly lost: 0 bytes in 0 blocks
==      possibly lost: 0 bytes in 0 blocks
==    still reachable: 126,995 bytes in 1,343 blocks
==         suppressed: 0 bytes in 0 blocks

This patch also fixes the leaks in remoteDomainMigratePrepare and
remoteDomainMigratePrepare2.

13 years agolibvirt: fix comment typo
Alex Jia [Fri, 16 Mar 2012 09:49:11 +0000 (17:49 +0800)]
libvirt: fix comment typo

* src/libvirt.c (virStorageVolResize): correct comment typo according to
  virStorageVolResizeFlags enum definition.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoAdd support for forcing a private network namespace for LXC guests
Daniel P. Berrange [Wed, 18 Jan 2012 11:38:49 +0000 (11:38 +0000)]
Add support for forcing a private network namespace for LXC guests

If no <interface> elements are included in an LXC guest XML
description, then the LXC guest will just see the host's
network interfaces. It is desirable to be able to hide the
host interfaces, without having to define any guest interfaces.

This patch introduces a new feature flag <privnet/> to allow
forcing of a private network namespace for LXC. In the future
I also anticipate that we will add <privuser/> to force a
private user ID namespace.

* src/conf/domain_conf.c, src/conf/domain_conf.h: Add support
  for <privnet/> feature. Auto-set <privnet> if any <interface>
  devices are defined
* src/lxc/lxc_container.c: Honour request for private network
  namespace

13 years agolib: Don't access configuration if none is present
Peter Krempa [Thu, 15 Mar 2012 16:10:22 +0000 (17:10 +0100)]
lib: Don't access configuration if none is present

Commit e457d5ef2015e6106094b85f8bbd1582002edc4d adds ability to pass the
default URI using the client configuration file. If the file is not
present, it still accesses the NULL config object causing a segfault.

Caught running "make check".

13 years agoqemuDomainDetachPciDiskDevice: Free allocated cgroup
Michal Privoznik [Thu, 15 Mar 2012 10:47:13 +0000 (11:47 +0100)]
qemuDomainDetachPciDiskDevice: Free allocated cgroup

This function potentially allocates new virCgroup but never
frees it.

13 years agoEmit graphics events when a SPICE client connects/disconnects
Laine Stump [Wed, 14 Mar 2012 05:41:35 +0000 (01:41 -0400)]
Emit graphics events when a SPICE client connects/disconnects

Wire up the domain graphics event notifications for SPICE. Adapted
from a RHEL-only patch written by Dan Berrange that used custom
__com.redhat_SPICE events - equivalent events are now available in
upstream QEMU (including a SPICE_CONNECTED event, which was missing in
the __COM.redhat_SPICE version).

* src/qemu/qemu_monitor_json.c: Wire up SPICE graphics events

13 years agonumad: Fix typo and warning
Osier Yang [Thu, 15 Mar 2012 11:40:33 +0000 (19:40 +0800)]
numad: Fix typo and warning

src/libvirt_private.syms:
  s/virDomainCpuPlacement/virDomainCpuPlacementMode/
src/qemu/qemu_process.c
  def->mem.cur_balloon expects "llu"
--
pushed under build-breaker rule

13 years agoAdd container_uuid env variable to LXC guests
Daniel P. Berrange [Wed, 14 Mar 2012 12:52:58 +0000 (12:52 +0000)]
Add container_uuid env variable to LXC guests

Systemd has declared that all container virtualization technologies
should set 'container_uuid' to identify themselves.

http://cgit.freedesktop.org/systemd/systemd/commit/?id=09b967eaa51a39dabb7f238927f67bd682466dbc

13 years agoAllow overriding default URI in config file
Daniel P. Berrange [Wed, 14 Mar 2012 12:30:52 +0000 (12:30 +0000)]
Allow overriding default URI in config file

Currently if the URI passed to virConnectOpen* is NULL, then we

 - Look for LIBVIRT_DEFAULT_URI env var
 - Probe for drivers

This changes it so that

 - Look for LIBVIRT_DEFAULT_URI env var
 - Look for 'uri_default' in $HOME/.libvirt/libvirt.conf
 - Probe for drivers

13 years agovirsh: A bit smarter attach-disk
Osier Yang [Thu, 15 Mar 2012 10:16:52 +0000 (18:16 +0800)]
virsh: A bit smarter attach-disk

Detects the file type of source path if no "--sourcetype" and
"driver" is specified, instead of always set the disk type as
"block".

13 years agovirsh: fix invalid free
Alex Jia [Thu, 15 Mar 2012 05:57:50 +0000 (13:57 +0800)]
virsh: fix invalid free

* tools/virsh.c (cmdDetachDisk): fix invalid free due to using
  uninitialised value.

* How to reproduce?
# virsh detach-disk a b
error: failed to get domain 'a'
*** glibc detected *** virsh: double free or corruption (out): 0x00007fff410ed1a0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x39cf0750c6]
/usr/lib/libvirt.so.0(virFree+0x39)[0x7f045938a239]
virsh[0x41c768]
virsh[0x415075]
virsh[0x425d64]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x39cf01ecdd]
virsh[0x40a419]
======= Memory map: ========
00400000-0044e000 r-xp 00000000 08:0e 760441                             /usr/bin/virsh
0064e000-00650000 rw-p 0004e000 08:0e 760441                             /usr/bin/virsh
......
39d7229000-39d722b000 r--p 00029000 08:0e 2183477                        /lib64/libk5crypto.so.3.1
39d722b000-39d722c000 rw-p 0002b000 08:0e 2183477                        /lib64/lAborted (core dumped)

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoqemu: Support numad
Osier Yang [Thu, 8 Mar 2012 13:36:26 +0000 (21:36 +0800)]
qemu: Support numad

numad is an user-level daemon that monitors NUMA topology and
processes resource consumption to facilitate good NUMA resource
alignment of applications/virtual machines to improve performance
and minimize cost of remote memory latencies. It provides a
pre-placement advisory interface, so significant processes can
be pre-bound to nodes with sufficient available resources.

More details: http://fedoraproject.org/wiki/Features/numad

"numad -w ncpus:memory_amount" is the advisory interface numad
provides currently.

This patch add the support by introducing a new XML attribute
for <vcpu>. e.g.

  <vcpu placement="auto">4</vcpu>
  <vcpu placement="static" cpuset="1-10^6">4</vcpu>

The returned advisory nodeset from numad will be printed
in domain's dumped XML. e.g.
  <vcpu placement="auto" cpuset="1-10^6">4</vcpu>

If placement is "auto", the number of vcpus and the current
memory amount specified in domain XML will be used for numad
command line (numad uses MB for memory amount):
  numad -w $num_of_vcpus:$current_memory_amount / 1024

The advisory nodeset returned from numad will be used to set
domain process CPU affinity then. (e.g. qemuProcessInitCpuAffinity).

If the user specifies both CPU affinity policy (e.g.
(<vcpu cpuset="1-10,^7,^8">4</vcpu>) and placement == "auto"
the specified CPU affinity will be overridden.

Only QEMU/KVM drivers support it now.

See docs update in patch for more details.

13 years agoqemu: Use scsi-block for lun passthrough instead of scsi-disk
Osier Yang [Mon, 12 Mar 2012 14:19:56 +0000 (22:19 +0800)]
qemu: Use scsi-block for lun passthrough instead of scsi-disk

And don't allow to hotplug a usb disk with "device == lun". This
is the missed pieces in previous virtio-scsi patchset:

http://www.redhat.com/archives/libvir-list/2012-February/msg01052.html

13 years agoqemu: Reverse condition in qemuDomainCheckDiskPresence
Michal Privoznik [Wed, 14 Mar 2012 10:08:52 +0000 (11:08 +0100)]
qemu: Reverse condition in qemuDomainCheckDiskPresence

With current code, we pass true iff domain is cold booting. However,
if disk is inaccessible and startupPolicy for that disk is set to
'requisite' we have to fail iff cold booting.

13 years agocpu: Add cpu definition for Intel Sandy Bridge cpu type
Peter Krempa [Wed, 8 Feb 2012 11:43:07 +0000 (12:43 +0100)]
cpu: Add cpu definition for Intel Sandy Bridge cpu type

This patch adds support for the new tsc-deadline feature flag
and a new model to the supported model list describing the
Intel Sandy Bridge platform.

13 years agoAdded support for AMD Bulldozer CPU
Martin Kletzander [Tue, 13 Mar 2012 11:35:41 +0000 (12:35 +0100)]
Added support for AMD Bulldozer CPU

AMD Bulldozer (or Opteron_G4 as called in QEMU) was added to the list
of cpu models, flags were taken from upstream qemu cpu specifications
and should be sorted by bit values (or first occurence in the feature
specification part of cpu_map.xml).

Based on QEMU upstream commit 885bb0369a4f0abe2c0185178f3cb347cb02cdf1.

13 years agographics: Cleanup port policy
Michal Privoznik [Mon, 12 Mar 2012 15:50:39 +0000 (16:50 +0100)]
graphics: Cleanup port policy

Even though we say in documentation setting (tls-)port to -1 is legacy
compat style for enabling autoport, we're roughly doing this for VNC.
However, in case of SPICE auto enable autoport iff both port & tlsPort
are equal -1 as documentation says autoport plays with both.

13 years agoqemu: fix segfault when detaching non-existent network device
Guannan Ren [Mon, 12 Mar 2012 15:50:02 +0000 (23:50 +0800)]
qemu: fix segfault when detaching non-existent network device

In qemuDomainDetachNetDevice, detach was being used before it had been
validated. If no matching device was found, this resulted in a
dereference of a NULL pointer.

This behavior was a regression introduced in commit
cf90342be0022520e25cfa258cef1034b229a100, so it has not been a part of
any official libvirt release.

13 years agoqemu: Fix (managed)save and snapshots with host mode CPU
Jiri Denemark [Fri, 9 Mar 2012 15:42:46 +0000 (16:42 +0100)]
qemu: Fix (managed)save and snapshots with host mode CPU

When host-model and host-passthrouh CPU modes were introduced, qemu
driver was properly modify to update guest CPU definition during
migration so that we use the right CPU at the destination. However,
similar treatment is needed for (managed)save and snapshots since they
need to save the exact CPU so that a domain can be properly restored.
To avoid repetition of such situation, all places that need live XML
share the code which generates it.

As a side effect, this patch fixes error reporting from
qemuDomainSnapshotWriteMetadata().

13 years agodocs: fix usage example on setting log levels
Eric Blake [Mon, 12 Mar 2012 21:34:55 +0000 (15:34 -0600)]
docs: fix usage example on setting log levels

Reported by Michael S. Tsirkin.

* docs/logging.html.in (log_examples): Use correct libvirtd.conf
syntax.

13 years agocpustats: report user and sys times
Eric Blake [Fri, 9 Mar 2012 15:20:20 +0000 (08:20 -0700)]
cpustats: report user and sys times

Thanks to cgroups, providing user vs. system time of the overall
guest is easy to add to our existing API.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_CPU_STATS_USERTIME)
(VIR_DOMAIN_CPU_STATS_SYSTEMTIME): New constants.
* src/util/virtypedparam.h (virTypedParameterArrayValidate)
(virTypedParameterAssign): Enforce checking the result.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Fix offender.
(qemuDomainGetTotalcpuStats): Implement new parameters.
* tools/virsh.c (cmdCPUStats): Tweak output accordingly.

13 years agocpustats: collect VM user and sys times
Eric Blake [Fri, 9 Mar 2012 00:35:59 +0000 (17:35 -0700)]
cpustats: collect VM user and sys times

As documented in linux.git/Documentation/cgroups/cpuacct.txt,
cpuacct.stat returns user and system time in ticks (the same
unit used in times(2)).  It would be a bit nicer if it were like
getrusage(2) and reported timeval contents, or like cpuacct.usage
and in nanoseconds, but we can't be picky.

* src/util/cgroup.h (virCgroupGetCpuacctStat): New function.
* src/util/cgroup.c (virCgroupGetCpuacctStat): Implement it.
(virCgroupGetValueStr): Allow for multi-line files.
* src/libvirt_private.syms (cgroup.h): Export it.

13 years agoqemu: support disk filenames with comma
Eric Blake [Fri, 9 Mar 2012 19:13:30 +0000 (16:13 -0300)]
qemu: support disk filenames with comma

If there is a disk file with a comma in the name, QEmu expects a double
comma instead of a single one (e.g., the file "virtual,disk.img" needs
to be specified as "virtual,,disk.img" in QEmu's command line). This
patch fixes libvirt to work with that feature. Fix RHBZ #801036.

Based on an initial patch by Crístian Viana.

* src/util/buf.h (virBufferEscape): Alter signature.
* src/util/buf.c (virBufferEscape): Add parameter.
(virBufferEscapeSexpr): Fix caller.
* src/qemu/qemu_command.c (qemuBuildRBDString): Likewise.  Also
escape commas in file names.
(qemuBuildDriveStr): Escape commas in file names.
* docs/schemas/basictypes.rng (absFilePath): Relax RNG to allow
commas in input file names.
* tests/qemuxml2argvdata/*-disk-drive-network-sheepdog.*: Update
test.

Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoFix a few typo in translated strings
Daniel Veillard [Mon, 12 Mar 2012 09:41:26 +0000 (17:41 +0800)]
Fix a few typo in translated strings

this was raised by our hindi localization team
chandan kumar <chandankumar.093047@gmail.com>

13 years agoRemoved more AMD-specific features from cpu64-rhel* models
Martin Kletzander [Fri, 9 Mar 2012 13:31:47 +0000 (14:31 +0100)]
Removed more AMD-specific features from cpu64-rhel* models

We found few more AMD-specific features in cpu64-rhel* models that
made it impossible to start qemu guest on Intel host (with this
setting) even though qemu itself starts correctly with them.
This impacts one test, thus the fix in tests/cputestdata/.

13 years agoconf: eliminate redundant VIR_ALLOC of 1st element of network DNS hosts.
Laine Stump [Thu, 11 Aug 2011 03:34:07 +0000 (23:34 -0400)]
conf: eliminate redundant VIR_ALLOC of 1st element of network DNS hosts.

virNetworkDNSHostsDefParseXML was calling VIR_ALLOC(def->hosts) if
def->hosts was NULL. This is a waste of time, though, since
VIR_REALLOC_N is called a few lines further down, prior to any use of
def->hosts. (initializing def->nhosts to 0 is also redundant, because
the newly allocated memory will always be cleared to all 0's anyway).

13 years agoqemuxml2argvtest: Pass some additional flags to graphics-spice-agentmouse
Michal Privoznik [Fri, 9 Mar 2012 09:10:53 +0000 (10:10 +0100)]
qemuxml2argvtest: Pass some additional flags to graphics-spice-agentmouse

One of the recent commits introduced support for
spice agent-mouse. However, test for this feature
require some tweaking: pass QEMU_CAPS_CHARDEV_SPICEVMC |
QEMU_CAPS_NODEFCONFIG and add "-vga cirrus".

13 years agoqemuBuildCommandLine: Don't add tlsPort if none set
Michal Privoznik [Thu, 8 Mar 2012 13:27:14 +0000 (14:27 +0100)]
qemuBuildCommandLine: Don't add tlsPort if none set

If user hasn't supplied any tlsPort we default to setting it
to zero in our internal structure. However, when building command
line we test it against -1 which is obviously wrong.

13 years agoqemu: spice agent-mouse support
Peng Zhou [Fri, 9 Mar 2012 07:26:24 +0000 (15:26 +0800)]
qemu: spice agent-mouse support

spice agent-mouse support

Usage:
  <graphics type='spice'>
    <mouse mode='client'|'server'/>
  <graphics/>

Signed-off-by: Osier Yang <jyang@redhat.com>
13 years agovirsh: Use option alias for outmoded "--persistent"
Osier Yang [Thu, 8 Mar 2012 11:38:57 +0000 (19:38 +0800)]
virsh: Use option alias for outmoded "--persistent"

Since VIR_DOMAIN_AFFECT_{LIVE,CONFIG,CURRENT} was created,
all new virsh commands use "--config" to represents the
persistent changing. This patch add "--config" option
for the old commands which still use "--persistent",
and "--persistent" is now alias of "--config".

tools/virsh.c: (use "--config", and "--persistent" is
    alias of "--config" now).
    cmdDomIfSetLink, cmdDomIfGetLink, cmdAttachDevice,
    cmdDetachDevice, cmdUpdateDevice, cmdAttachInterface,
    cmdDetachInterface, cmdAttachDisk, cmdDetachDisk

toos/virsh.pod: Update docs of the changed commands, and
    add some missed docs for "--config" (detach-interface,
    detach-disk, and detach-device).

13 years agoremove daemon/probes.h from .gitignore
Laine Stump [Thu, 8 Mar 2012 20:44:38 +0000 (15:44 -0500)]
remove daemon/probes.h from .gitignore

The file daemon/probes.h used to be generated as part of a build, but
is no longer used. However, a stale copy of it lying around could
cause a build to fail. Removing it from .gitignore will make it more
likely someone will notice that they have it lying around.

13 years agoutil: consolidate duplicated error messages in pci.c
Laine Stump [Thu, 8 Mar 2012 20:41:53 +0000 (15:41 -0500)]
util: consolidate duplicated error messages in pci.c

This is nearly identical to an earlier patch for virnetlink.c.

There are special stub versions of all public functions in this file
that are compiled when the platform isn't linux. Each of these
functions had an almost identical message, differing only in the
function name included in the message. Since log messages already
contain the function name, we can just define a const char* with the
common part of the string, and use that same string for all the log
messages.

If nothing else, this at least makes for less strings that need
translating...

13 years agoqemu: eliminate memory leak in qemuDomainUpdateDeviceConfig
Laine Stump [Thu, 8 Mar 2012 06:46:36 +0000 (01:46 -0500)]
qemu: eliminate memory leak in qemuDomainUpdateDeviceConfig

This function was freeing a virDomainNetDef with
VIR_FREE(). virDomainNetDef is a complex structure with many pointers
to other dynamically allocated data; to properly free it
virDomainNetDefFree() must be called instead, otherwise several
strings (and potentially other things) will be leaked.

13 years agoqemu: support persistent hotplug of <hostdev> devices
Laine Stump [Wed, 7 Mar 2012 21:05:34 +0000 (16:05 -0500)]
qemu: support persistent hotplug of <hostdev> devices

For some reason, although live hotplug of <hostdev> devices is
supported, persistent hotplug is not. This patch adds the proper
VIR_DOMAIN_DEVICE_HOSTDEV cases to the switches in
qemuDomainAttachDeviceConfig and qemuDomainDetachDeviceConfig.

13 years agoutil: standardize return from functions calling virNetlinkCommand
Laine Stump [Wed, 7 Mar 2012 17:44:56 +0000 (12:44 -0500)]
util: standardize return from functions calling virNetlinkCommand

There are several functions that call virNetlinkCommand, and they all
follow a common pattern, with three exit labels: err_exit (or
cleanup), malformed_resp, and buffer_too_small. All three of these
labels do their own cleanup and have their own return. However, the
malformed_resp label usually frees the same items as the
cleanup/err_exit label, and the buffer_too_small label just doesn't
free recvbuf (because it's known to always be NULL at the time we goto
buffer_too_small.

In order to simplify and standardize the code, I've made the following
changes to all of these functions:

1) err_exit is replaced with the more libvirt-ish "cleanup", which
   makes sense because in all cases this code is also executed in the
   case of success, so labelling it err_exit may be confusing.

2) rc is initialized to -1, and set to 0 just before the cleanup
   label. Any code that currently sets rc = -1 is made to instead goto
   cleanup.

3) malformed_resp and buffer_too_small just log their error and goto
   cleanup. This gives us a single return path, and a single place to
   free up resources.

4) In one instance, rather then logging an error immediately, a char*
   msg was pointed to an error string, then goto cleanup (and cleanup
   would log an error if msg != NULL). It takes no more lines of code
   to just log the message as we encounter it.

This patch should have 0 functional effects.

13 years agoutil: eliminate device object leaks related to virDomain*Remove*()
Laine Stump [Tue, 6 Mar 2012 23:06:14 +0000 (18:06 -0500)]
util: eliminate device object leaks related to virDomain*Remove*()

There are several functions in domain_conf.c that remove a device
object from the domain's list of that object type, but don't free the
object or return it to the caller to free. In many cases this isn't a
problem because the caller already had a pointer to the object and
frees it afterward, but in several cases the removed object was just
left floating around with no references to it.

In particular, the function qemuDomainDetachDeviceConfig() calls
functions to locate and remove net (virDomainNetRemoveByMac), disk
(virDomainDiskRemoveByName()), and lease (virDomainLeaseRemove())
devices, but neither it nor its caller qemuDomainModifyDeviceConfig()
ever obtain a pointer to the device being removed, much less free it.

This patch modifies the following "remove" functions to return a
pointer to the device object being removed from the domain device
arrays, to give the caller the option of freeing the device object
using that pointer if needed. In places where the object was
previously leaked, it is now freed:

  virDomainDiskRemove
  virDomainDiskRemoveByName
  virDomainNetRemove
  virDomainNetRemoveByMac
  virDomainHostdevRemove
  virDomainLeaseRemove
  virDomainLeaseRemoveAt

The functions that had been leaking:

  libxlDomainDetachConfig - leaked a virDomainDiskDef
  qemuDomainDetachDeviceConfig - could leak a virDomainDiskDef,
                            a virDomainNetDef, or a
                            virDomainLeaseDef
  qemuDomainDetachLease   - leaked a virDomainLeaseDef

13 years agoqemu: don't 'remove' hostdev objects from domain if operation fails
Laine Stump [Wed, 7 Mar 2012 01:43:22 +0000 (20:43 -0500)]
qemu: don't 'remove' hostdev objects from domain if operation fails

There were certain paths through the hostdev detach code that could
lead to the lower level function failing (and not removing the object
from the domain's hostdevs list), but the higher level function
free'ing the hostdev object anyway. This would leave a stale
hostdevdef pointer in the list, which would surely cause a problem
eventually.

This patch relocates virDomainHostdevRemove from the lower level
functions qemuDomainDetachThisHostDevice and
qemuDomainDetachHostPciDevice, to their caller
qemuDomainDetachThisHostDevice, placing it just before the call to
virDomainHostdevDefFree. This makes it easy to verify that either both
operations are done, or neither.

NB: The "dangling pointer" part of this problem was introduced in
commit 13d5a6, so it is not present in libvirt versions prior to
0.9.9. Earlier versions would return failure in certain cases even
though the the device object was removed/deleted, but the removal and
deletion operations would always both happen or neither.

13 years agoutil: make virDomainLeaseDefFree global
Laine Stump [Wed, 7 Mar 2012 02:06:30 +0000 (21:06 -0500)]
util: make virDomainLeaseDefFree global

It will be used in a different file in an upcoming patch.

13 years agoutil: consolidate duplicated error messages in virnetlink.c
Laine Stump [Tue, 6 Mar 2012 17:21:21 +0000 (12:21 -0500)]
util: consolidate duplicated error messages in virnetlink.c

There are special stub versions of all public functions in this file
that are compiled when either libnl isn't available or the platform
isn't linux. Each of these functions had two almost identical message,
differing only in the function name included in the message. Since log
messages already contain the function name, we can just define a const
char* with the common part of the string, and use that same string for
all the log messages.

Also, rather than doing #if defined ... #else ... #endif *inside the
error log macro invocation*, this patch does #if defined ... just
once, using it to decide which single string to define. This turns the
error log in each function from 6 lines, to 1 line.

13 years agoutil: log error on OOM in virNetDevOpenvswitchAddPort
Laine Stump [Thu, 8 Mar 2012 18:48:52 +0000 (13:48 -0500)]
util: log error on OOM in virNetDevOpenvswitchAddPort

OOM conditions silently returned failure.

13 years agoAttach vm-id to Open vSwitch interfaces.
Ansis Atteka [Wed, 7 Mar 2012 07:15:36 +0000 (23:15 -0800)]
Attach vm-id to Open vSwitch interfaces.

This patch will allow OpenFlow controllers to identify which interface
belongs to a particular VM by using the Domain UUID.

ovs-vsctl get Interface vnet0 external_ids
{attached-mac="52:54:00:8C:55:2C", iface-id="83ce45d6-3639-096e-ab3c-21f66a05f7fa", iface-status=active, vm-id="142a90a7-0acc-ab92-511c-586f12da8851"}

V2 changes:
Replaced vm-uuid with vm-id. There was a discussion in Open vSwitch
mailinglist that we should stick with the same DB key postfixes for the
sake of consistency (e.g iface-id, vm-id ...).

13 years agoutil: whitespace change to virNetDevOpenvswitchAddPort
Laine Stump [Thu, 8 Mar 2012 18:31:06 +0000 (13:31 -0500)]
util: whitespace change to virNetDevOpenvswitchAddPort

The indentation on the final lines of the function was off by four
spaces, making me wonder for a second if there was something
missing. (There wasn't.)

13 years agoutil: add stub pciConfigAddressToSysfsFile for non-linux platforms
Laine Stump [Thu, 8 Mar 2012 19:19:36 +0000 (14:19 -0500)]
util: add stub pciConfigAddressToSysfsFile for non-linux platforms

Absence of this stub function caused a build failure on mingw32.

13 years agorpc: generalize solution for VPATH builds
Eric Blake [Tue, 6 Mar 2012 20:49:53 +0000 (13:49 -0700)]
rpc: generalize solution for VPATH builds

Commit 5d4b0c4c80 tried to fix certain classes of VPATH builds,
but was too limited.  In particular, Guannan Ren reported:

>    For example: The libvirt source code resides in /home/testuser,
>                 I make dist in /tmp/buildvpath, the XDR routine .c file will
>                 include full path of the header file like:
>
>                 #include "/home/testuser/src/rpc/virnetprotocol.h"
>                 #include "internal.h"
>                 #include <arpa/inet.h>
>
>    If we distribute the tarball to another machine to compile,
>    it will report error as follows:
>
>    rpc/virnetprotocol.c:7:59: fatal error:
>    /home/testuser/src/rpc/virnetprotocol.h: No such file or directory

* src/rpc/genprotocol.pl: Fix more include lines.

13 years agoxml: Clean up schemas to use shared data types instead of local
Peter Krempa [Tue, 6 Mar 2012 14:08:02 +0000 (15:08 +0100)]
xml: Clean up schemas to use shared data types instead of local

The schema files contained duplicate data types that can be shared from
the basictypes.rng file.

13 years agoutil: Don't overflow on errno in virFileAccessibleAs
Michal Privoznik [Thu, 8 Mar 2012 10:27:57 +0000 (11:27 +0100)]
util: Don't overflow on errno in virFileAccessibleAs

If we need to virFork() to check assess() under different
UID+GID we need to translate returned status via WEXITSTATUS().
Otherwise, we may return values greater than 255 which is
obviously wrong.

13 years agosanlock: Use STREQ_NULLABLE instead of STREQ on strings that may be null
Peter Krempa [Wed, 7 Mar 2012 14:04:33 +0000 (15:04 +0100)]
sanlock: Use STREQ_NULLABLE instead of STREQ on strings that may be null

The function sanlock_inquire can return NULL in the state string if the
message consists only of a header. The return value is arbitrary and
sent by the server. We should proceed carefully while touching such
pointers.

13 years agosanlock: Fix condition left crippled while debugging
Peter Krempa [Wed, 7 Mar 2012 14:31:54 +0000 (15:31 +0100)]
sanlock: Fix condition left crippled while debugging

13 years agoqemu: Don't parse device twice in attach/detach
Michal Privoznik [Thu, 1 Mar 2012 18:47:34 +0000 (19:47 +0100)]
qemu: Don't parse device twice in attach/detach

Some members are generated during XML parse (e.g. MAC address of
an interface); However, with current implementation, if we
are plugging a device both to persistent and live config,
we parse given XML twice: first time for live, second for config.
This is wrong then as the second time we are not guaranteed
to generate same values as we did for the first time.
To prevent that we need to create a copy of DeviceDefPtr;
This is done through format/parse process instead of writing
functions for deep copy as it is easier to maintain:
adding new field to any virDomain*DefPtr doesn't require change
of copying function.

13 years agoqemu: Fix startupPolicy for snapshot-revert
Michal Privoznik [Wed, 7 Mar 2012 18:15:01 +0000 (19:15 +0100)]
qemu: Fix startupPolicy for snapshot-revert

Currently, startupPolicy='requisite' was determining cold boot
by migrateFrom != NULL. That means, if domain was started up
with migrateFrom set we didn't require disk source path and allowed
it to be dropped. However, on snapshot-revert domain wasn't migrated
but according to documentation, requisite should drop disk source
as well.

13 years agovirsh: improve memory unit parsing
Eric Blake [Tue, 6 Mar 2012 00:06:57 +0000 (17:06 -0700)]
virsh: improve memory unit parsing

The last vestige of the inaccurate 'kilobytes' when we meant 1024 is
now gone.  And virsh is now useful for setting memory in units other
than KiB.

* tools/virsh.c (cmdSetmem, cmdSetmaxmem): Use new helper routine,
allow passing bogus arguments on to hypervisor to test driver
sanity checking, and fix leak on parse error.
(vshMemtuneGetSize): New helper.
(cmdMemtune): Use it.
* tools/virsh.pod (setmem, setmaxmem, memtune): Document this.

13 years agovirsh: improve storage unit parsing
Eric Blake [Thu, 8 Mar 2012 01:10:30 +0000 (18:10 -0700)]
virsh: improve storage unit parsing

Now can now do:

virsh vol-resize $vol 10M
virsh blockresize $dom $vol 10M

to get both interfaces to resize to 10MiB.  The remaining wart
is that vol-resize defaults to bytes, but blockresize defaults
to KiB, but we can't break existing scripts; oh well, it's no
worse than the same wart of the underlying virDomainBlockResize.

The API for virStorageVolResize states that capacity must always
be positive, and that the presence of shrink and delta flags is
what implies a negative change.

* tools/virsh.c (vshCommandOptScaledInt): New function.
(cmdVolResize): Don't pass negative size.
(cmdVolSize): Rename...
(vshVolSize): ...and use new helper routine.
(cmdBlockResize): Use new helper routine, and support new bytes
flag.
* tools/virsh.pod (NOTES): Document suffixes.
(blockresize, vol-create-as, vol-resize): Point to notes.

13 years agovirsh: add command aliases, and rename nodedev-detach
Eric Blake [Fri, 2 Mar 2012 19:01:06 +0000 (12:01 -0700)]
virsh: add command aliases, and rename nodedev-detach

Just because our public API has a typo doesn't mean that virsh
has to keep the typo.

* tools/virsh.c (VSH_CMD_FLAG_ALIAS): New flag.
(nodedevCmds): Use it.
(cmdHelp): Omit alias commands.
(cmdNodeDeviceDettach): Rename...
(cmdNodeDeviceDetach): ...to this.
* tools/virsh.pod (nodedev-detach): Document it.

13 years agovirsh: use option aliases
Eric Blake [Fri, 2 Mar 2012 18:18:00 +0000 (11:18 -0700)]
virsh: use option aliases

Command line interfaces should use dash, not underscore, as many
keyboard layouts allow that to be typed with fewer shift key presses.

Also, the US spelling of --tunneled gets more google hits than the
UK spelling of --tunnelled.

* tools/virsh.c (opts_migrate): Allow US variant.
(opts_blkdeviotune): Prefer - over _.
* tools/virsh.pod (blkdeviotune): Fix spelling.

13 years agovirsh: add option aliases
Eric Blake [Fri, 2 Mar 2012 18:01:15 +0000 (11:01 -0700)]
virsh: add option aliases

In the past, we have created some virsh options with less-than-stellar
names.  For back-compat reasons, those names must continue to parse,
but we don't want to document them in help output.  This introduces
a new option type, an alias, which points to a canonical option name
later in the option list.

I'm actually quite impressed that our code has already been factored
to do all option parsing through common entry points, such that I
got this added in relatively few lines of code!

* tools/virsh.c (VSH_OT_ALIAS): New option type.
(opts_echo): Hook up an alias, for easy testing.
(vshCmddefOptParse, vshCmddefHelp, vshCmddefGetOption): Allow for
aliases.
* tools/virsh.pod (NOTES): Document promise of back-compat.
* tests/virshtest.c (mymain): Test new feature.

13 years agoxml: allow scaled memory on input
Eric Blake [Mon, 5 Mar 2012 21:52:07 +0000 (14:52 -0700)]
xml: allow scaled memory on input

Output is still in kibibytes, but input can now be in different
scales for ease of typing.

* src/conf/domain_conf.c (virDomainParseMemory): New helper.
(virDomainDefParseXML): Use it when parsing.
* docs/schemas/domaincommon.rng: Expand XML; rename memoryKBElement
to memoryElement and update callers.
* docs/formatdomain.html.in (elementsMemoryAllocation): Document
scaling.
* tests/qemuxml2argvdata/qemuxml2argv-memtune.xml: Adjust test.
* tests/qemuxml2xmltest.c: Likewise.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-memtune.xml: New file.

13 years agoxml: use better types for memory values
Eric Blake [Fri, 2 Mar 2012 20:27:39 +0000 (13:27 -0700)]
xml: use better types for memory values

Using 'unsigned long' for memory values is risky on 32-bit platforms,
as a PAE guest can have more than 4GiB memory.  Our API is
(unfortunately) locked at 'unsigned long' and a scale of 1024, but
the rest of our system should consistently use 64-bit values,
especially since the previous patch centralized overflow checking.

* src/conf/domain_conf.h (_virDomainDef): Always use 64-bit values
for memory.  Change hugepage_backed to a bool.
* src/conf/domain_conf.c (virDomainDefParseXML)
(virDomainDefCheckABIStability, virDomainDefFormatInternal): Fix
clients.
* src/vmx/vmx.c (virVMXFormatConfig): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxpr, xenFormatSxpr): Likewise.
* src/xenxs/xen_xm.c (xenXMConfigGetULongLong): New function.
(xenXMConfigGetULong, xenXMConfigSetInt): Avoid truncation.
(xenParseXM, xenFormatXM): Fix clients.
* src/phyp/phyp_driver.c (phypBuildLpar): Likewise.
* src/openvz/openvz_driver.c (openvzDomainSetMemoryInternal):
Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDefineXML): Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_process.c (qemuProcessStart): Likewise.
* src/qemu/qemu_monitor.h (qemuMonitorGetBalloonInfo): Likewise.
* src/qemu/qemu_monitor_text.h (qemuMonitorTextGetBalloonInfo):
Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetBalloonInfo):
Likewise.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONGetBalloonInfo):
Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetBalloonInfo):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetInfo)
(qemuDomainGetXMLDesc): Likewise.
* src/uml/uml_conf.c (umlBuildCommandLine): Likewise.

13 years agoxml: use long long internally, to centralize overflow checks
Eric Blake [Sat, 3 Mar 2012 00:47:16 +0000 (17:47 -0700)]
xml: use long long internally, to centralize overflow checks

On 64-bit platforms, unsigned long and unsigned long long are
identical, so we don't have to worry about overflow checks.
On 32-bit platforms, anywhere we narrow unsigned long long back
to unsigned long, we have to worry about overflow; it's easier
to do this in one place by having most of the code use the same
or wider types, and only doing the narrowing at the last minute.
Therefore, the memory set commands remain unsigned long, and
the memory get command now centralizes the overflow check into
libvirt.c, so that drivers don't have to repeat the work.

This also fixes a bug where xen returned the wrong value on
failure (most APIs return -1 on failure, but getMaxMemory
must return 0 on failure).

* src/driver.h (virDrvDomainGetMaxMemory): Use long long.
* src/libvirt.c (virDomainGetMaxMemory): Raise overflow.
* src/test/test_driver.c (testGetMaxMemory): Fix driver.
* src/rpc/gendispatch.pl (name_to_ProcName): Likewise.
* src/xen/xen_hypervisor.c (xenHypervisorGetMaxMemory): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainGetMaxMemory): Likewise.
* src/xen/xend_internal.c (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xend_internal.h (xenDaemonDomainGetMaxMemory):
Likewise.
* src/xen/xm_internal.c (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xm_internal.h (xenXMDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.c (xenStoreDomainGetMaxMemory): Likewise.
* src/xen/xs_internal.h (xenStoreDomainGetMaxMemory): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainGetMaxMemory):
Likewise.
* src/esx/esx_driver.c (esxDomainGetMaxMemory): Likewise.
* src/libxl/libxl_driver.c (libxlDomainGetMaxMemory): Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetMaxMemory): Likewise.
* src/lxc/lxc_driver.c (lxcDomainGetMaxMemory): Likewise.
* src/uml/uml_driver.c (umlDomainGetMaxMemory): Likewise.

13 years agoxml: drop unenforced minimum memory limit from RNG
Eric Blake [Thu, 23 Feb 2012 04:18:39 +0000 (21:18 -0700)]
xml: drop unenforced minimum memory limit from RNG

The test domain allows <memory>0</memory>, but the RNG was stating
that memory had to be at least 4096000 bytes.  Hypervisors should
enforce their own limits, rather than complicating the RNG.

Meanwhile, some copy and paste had introduced some fishy constructs
in various unit tests.

* docs/schemas/domaincommon.rng (memoryKB, memoryKBElement): Drop
limit that isn't enforced in code.
* src/conf/domain_conf.c (virDomainDefParseXML): Require current
<= maximum.
* tests/qemuxml2argvdata/*.xml: Fix offenders.

13 years agostorage: support more scaling suffixes
Eric Blake [Mon, 5 Mar 2012 21:06:33 +0000 (14:06 -0700)]
storage: support more scaling suffixes

Disk manufacturers are fond of quoting sizes in powers of 10,
rather than powers of 2 (after all, 2.1 GB sounds larger than
2.0 GiB, even though the exact opposite is true).  So, we might
as well follow coreutils' lead in supporting three types of
suffix: single letter ${u} (which we already had) and ${u}iB
for the power of 2, and ${u}B for power of 10.

Additionally, it is impossible to create a file with more than
2**63 bytes, since off_t is signed (if you have enough storage
to even create one 8EiB file, I'm jealous).  This now reports
failure up front rather than down the road when the kernel
finally refuses an impossible size.

* docs/schemas/basictypes.rng (unit): Add suffixes.
* src/conf/storage_conf.c (virStorageSize): Use new function.
* docs/formatstorage.html.in: Document it.
* tests/storagevolxml2xmlin/vol-file-backing.xml: Test it.
* tests/storagevolxml2xmlin/vol-file.xml: Likewise.

13 years agoxml: output memory unit for clarity
Eric Blake [Thu, 23 Feb 2012 00:48:38 +0000 (17:48 -0700)]
xml: output memory unit for clarity

Make it obvious to 'dumpxml' readers what unit we are using,
since our default of KiB for memory (1024) differs from qemu's
default of MiB; and differs from our use of bytes for storage.

Tests were updated via:

$ find tests/*data tests/*out -name '*.xml' | \
  xargs sed -i 's/<\(memory\|currentMemory\|hard_limit\|soft_limit\|min_guarantee\|swap_hard_limit\)>/<\1 unit='"'KiB'>/"
$ find tests/*data tests/*out -name '*.xml' | \
  xargs sed -i 's/<\(capacity\|allocation\|available\)>/<\1 unit='"'bytes'>/"

followed by a few fixes for the stragglers.

Note that with this patch, the RNG for <memory> still forbids
validation of anything except unit='KiB', since the code silently
ignores the attribute; a later patch will expand <memory> to allow
scaled input in the code and update the RNG to match.

* docs/schemas/basictypes.rng (unit): Add 'bytes'.
(scaledInteger): New define.
* docs/schemas/storagevol.rng (sizing): Use it.
* docs/schemas/storagepool.rng (sizing): Likewise.
* docs/schemas/domaincommon.rng (memoryKBElement): New define; use
for memory elements.
* src/conf/storage_conf.c (virStoragePoolDefFormat)
(virStorageVolDefFormat): Likewise.
* src/conf/domain_conf.h (_virDomainDef): Document unit used
internally.
* src/conf/storage_conf.h (_virStoragePoolDef, _virStorageVolDef):
Likewise.
* tests/*data/*.xml: Update all tests.
* tests/*out/*.xml: Likewise.
* tests/define-dev-segfault: Likewise.
* tests/openvzutilstest.c (testReadNetworkConf): Likewise.
* tests/qemuargv2xmltest.c (blankProblemElements): Likewise.

13 years agoxml: share 'unit' in RNG
Eric Blake [Wed, 29 Feb 2012 04:16:28 +0000 (21:16 -0700)]
xml: share 'unit' in RNG

The code supported unit='E' for "exabyte", but the RNG did not;
conversely, the RNG supported "z" and "y" but the code did not
(I'm jealous if you have that much storage, particularly since
it won't fit in 64-bit off_t).  Also, the code supported
<allocation unit='...'>, but not the RNG.

In an effort to make 'unit' more worthwhile in future patches,
it's easier to share it between files.

In making this factorization, note that absFilePath is more
permissive than 'path', so storage pools and storage volumes
will now validate with a wider set of file names than before.
I don't think this should be a problem in practice.

* docs/schemas/storagepool.rng: Include basic types, rather than
repeating things here.
* docs/schemas/storagevol.rng: Likewise.
* docs/schemas/basictypes.rng: Add 'unsignedLong', 'unit', and fix
to match storage code.

13 years agoutil: new function for scaling numbers
Eric Blake [Mon, 5 Mar 2012 16:28:59 +0000 (09:28 -0700)]
util: new function for scaling numbers

Scaling an integer based on a suffix is something we plan on reusing
in several contexts: XML parsing, virsh CLI parsing, and possibly
elsewhere.  Make it easy to reuse, as well as adding in support for
powers of 1000.

* src/util/util.h (virScaleInteger): New function.
* src/util/util.c (virScaleInteger): Implement it.
* src/libvirt_private.syms (util.h): Export it.

13 years agoapi: add overflow error
Eric Blake [Fri, 2 Mar 2012 23:58:05 +0000 (16:58 -0700)]
api: add overflow error

Overflow can be user-induced, so it deserves more than being called
an internal error.  Note that in general, 32-bit platforms have
far more places to trigger this error (anywhere the public API
used 'unsigned long' but the other side of the connection is a
64-bit server); but some are possible on 64-bit platforms (where
the public API computes the product of two numbers).

* include/libvirt/virterror.h (VIR_ERR_OVERFLOW): New error.
* src/util/virterror.c (virErrorMsg): Translate it.
* src/libvirt.c (virDomainSetVcpusFlags, virDomainGetVcpuPinInfo)
(virDomainGetVcpus, virDomainGetCPUStats): Use it.
* daemon/remote.c (HYPER_TO_TYPE): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockResize): Likewise.

13 years agodocs: use correct terminology for 1024 bytes
Eric Blake [Fri, 2 Mar 2012 15:23:07 +0000 (08:23 -0700)]
docs: use correct terminology for 1024 bytes

Yes, I like kilobytes better than kibibytes (when I say kilobytes,
I generally mean 1024).  But since the term is ambiguous, it can't
hurt to say what we mean, by using both the correct name and
calling out the numeric equivalent.

* src/libvirt.c (virDomainGetMaxMemory, virDomainSetMaxMemory)
(virDomainSetMemory, virDomainSetMemoryFlags)
(virNodeGetFreeMemory): Tweak wording.
* docs/formatdomain.html.in: Likewise.
* docs/formatstorage.html.in: Likewise.

13 years agoutil: fix build mingw (and all non-linux) build failure
Laine Stump [Wed, 7 Mar 2012 18:16:53 +0000 (13:16 -0500)]
util: fix build mingw (and all non-linux) build failure

ATTRIBUTE_UNUSED was accidentally forgotten on one arg of a stub
function for functionality that's not present on non-linux
platforms. This causes a non-linux build with
--enable-compile-warnings=error to fail.