]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
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.

13 years agorpc: allow truncated return for virDomainGetCPUStats
Eric Blake [Wed, 7 Mar 2012 04:36:53 +0000 (21:36 -0700)]
rpc: allow truncated return for virDomainGetCPUStats

The RPC code assumed that the array returned by the driver would be
fully populated; that is, ncpus on entry resulted in ncpus * return
value on exit.  However, while we don't support holes in the middle
of ncpus, we do want to permit the case of ncpus on entry being
longer than the array returned by the driver (that is, it should be
safe for the caller to pass ncpus=128 on entry, and the driver will
stop populating the array when it hits max_id).

Additionally, a successful return implies that the caller will then
use virTypedParamArrayClear on the entire array; for this to not
free uninitialized memory, the driver must ensure that all skipped
entries are explicitly zeroed (the RPC driver did this, but not
the qemu driver).

There are now three cases:
server 0.9.10 and client 0.9.10 or newer: No impact - there were no
hypervisor drivers that supported cpu stats

server 0.9.11 or newer and client 0.9.10: if the client calls with
ncpus beyond the max, then the rpc call will fail on the client side
and disconnect the client, but the server is no worse for the wear

server 0.9.11 or newer and client 0.9.11: the server can return a
truncated array and the client will do just fine

I reproduced the problem by using a host with 2 CPUs, and doing:
virsh cpu-stats $dom --start 1 --count 2

* daemon/remote.c (remoteDispatchDomainGetCPUStats): Allow driver
to omit tail of array.
* src/remote/remote_driver.c (remoteDomainGetCPUStats):
Accommodate driver that omits tail of array.
* src/libvirt.c (virDomainGetCPUStats): Document this.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Clear all
unpopulated entries.

13 years agoconf: fix error log with "address address"
Laine Stump [Wed, 7 Mar 2012 13:58:49 +0000 (08:58 -0500)]
conf: fix error log with "address address"

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

13 years agoEnsure max_id is initialized in linuxParseCPUmap()
Daniel P. Berrange [Wed, 7 Mar 2012 11:41:34 +0000 (11:41 +0000)]
Ensure max_id is initialized in linuxParseCPUmap()

13 years agocpu-stats command shows cpu statistics information of a domain.
KAMEZAWA Hiroyuki [Fri, 2 Mar 2012 02:54:24 +0000 (10:54 +0800)]
cpu-stats command shows cpu statistics information of a domain.

CPU0:
cpu_time   88.231593093 seconds
CPU1:
cpu_time   123.613341883 seconds
Total:
cpu_time   211.844934976 seconds

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoqemu driver for virDomainGetCPUstats using cpuacct cgroup.
KAMEZAWA Hiroyuki [Fri, 2 Mar 2012 02:54:23 +0000 (10:54 +0800)]
qemu driver for virDomainGetCPUstats using cpuacct cgroup.

* For now, only "cpu_time" is supported.
* cpuacct cgroup is used for providing percpu cputime information.

* src/qemu/qemu.conf     - take care of cpuacct cgroup.
* src/qemu/qemu_conf.c   - take care of cpuacct cgroup.
* src/qemu/qemu_driver.c - added an interface
* src/util/cgroup.c/h    - added interface for getting percpu cputime

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
13 years agoadd nodeGetCPUmap() for getting available CPU IDs in a cpumap.
KAMEZAWA Hiroyuki [Fri, 2 Mar 2012 02:54:22 +0000 (10:54 +0800)]
add nodeGetCPUmap() for getting available CPU IDs in a cpumap.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
13 years agodocs: Fix typo
Osier Yang [Wed, 7 Mar 2012 04:01:33 +0000 (12:01 +0800)]
docs: Fix typo

It used "&lt" for ">", reported by Kyla Zhang <weizhan@redhat.com>

13 years agoBuild error on OSX in src/util/virnetlink.c
Duncan Rance [Tue, 6 Mar 2012 16:15:41 +0000 (16:15 +0000)]
Build error on OSX in src/util/virnetlink.c

I'm building on OSX with no libnl. I had to do this to get src/util/virnetlink.c to compile:

13 years agoqemu: install port profile and mac address on netdev hostdevs
Roopa Prabhu [Tue, 6 Mar 2012 01:12:44 +0000 (17:12 -0800)]
qemu: install port profile and mac address on netdev hostdevs

These changes are applied only if the hostdev has a parent net device
(i.e. if it was defined as "<interface type='hostdev'>" rather than
just "<hostdev>").  If the parent netdevice has virtual port
information, the original virtualport associate functions are called
(these set and restore both mac and port profile on an
interface). Otherwise, only mac address is set on the device.

Note that This is only supported for SR-IOV Virtual Functions (not for
standard PCI or USB netdevs), and virtualport association is only
supported for 802.1Qbh. For all other types of cards and types of
virtualport, a "Config Unsupported" error is returned and the
operation fails.

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
13 years agoutil: Changes to support portprofiles for hostdevs
Roopa Prabhu [Tue, 6 Mar 2012 01:12:39 +0000 (17:12 -0800)]
util: Changes to support portprofiles for hostdevs

This patch includes the following changes to virnetdevmacvlan.c and
virnetdevvportprofile.c:

 - removes some netlink functions which are now available in
   virnetdev.c

 - Adds a vf argument to all port profile functions.

For 802.1Qbh devices, the port profile calls can use a vf argument if
passed by the caller. If the vf argument is -1 it will try to derive the vf
if the device passed is a virtual function.

For 802.1Qbg devices, This patch introduces a null check for the device
argument because during port profile assignment on a hostdev, this argument
can be null.

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
13 years agoutil: support functions for mac/portprofile associations on hostdev
Roopa Prabhu [Tue, 6 Mar 2012 01:12:34 +0000 (17:12 -0800)]
util: support functions for mac/portprofile associations on hostdev

This patch adds the following:

- functions to set and get vf configs
- Functions to replace and store vf configs (Only mac address is handled today.
  But the functions can be easily extended for vlans and other vf configs)
- function to dump link dev info (This is moved from virnetdevvportprofile.c)

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
13 years agoutil: two new pci util functions
Roopa Prabhu [Tue, 6 Mar 2012 01:12:23 +0000 (17:12 -0800)]
util: two new pci util functions

pciDeviceGetVirtualFunctionInfo returns pf netdevice name and virtual
function index for a given vf. This is just a wrapper around existing functions
to return vf's pf and vf_index with one api call

pciConfigAddressToSysfsfile returns the sysfile pci device link
from a 'struct pci_config_address'

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
13 years agoqemu: support type=hostdev network device live hotplug attach/detach
Laine Stump [Mon, 27 Feb 2012 19:20:17 +0000 (14:20 -0500)]
qemu: support type=hostdev network device live hotplug attach/detach

qemuDomainAttachNetDevice

  - re-ordered some things at start of function because
    networkAllocateActualDevice should always be run and a slot
    in def->nets always allocated, but host_net_add isn't needed
    if the actual type is hostdev.

  - if actual type is hostdev, defer to
    qemuDomainAttachHostDevice (which will reach up to the NetDef
    for things like MAC address when necessary). After return
    from qemuDomainAttachHostDevice, slip directly to cleanup,
    since the rest of the function is specific to emulated net
    devices.

  - put assignment of new NetDef into expanded def->nets down
    below cleanup: (but only on success) since it is also needed
    for emulated and hostdev net devices.

qemuDomainDetachHostDevice

  - after locating the exact device to detach, check if it's a
    network device and, if so, use toplevel
    qemuDomainDetachNetDevice instead so that the def->nets list
    is properly updated, and 'actual device' properly returned to
    network pool if appropriate. Otherwise, for normal hostdevs,
    call the lower level qemuDomainDetachThisDevice.

qemuDomainDetachNetDevice

  - This is where it gets a bit tricky. After locating the device
    on the def->nets list, if the network device type == hostdev,
    call the *lower level* qemuDomainDetachThisDevice (which will
    reach back up to the parent net device for MAC address /
    virtualport when appropriate, then clear the device out of
    def->hostdevs) before skipping past all the emulated
    net-device-specific code to cleanup:, where the network
    device is removed from def->nets, and the network device
    object is freed.

In short, any time a hostdev-type network device is detached, we must
go through the toplevel virDomaineDetachNetDevice function first and
last, to make sure 1) the def->nnets list is properly managed, and 2)
any device allocated with networkAllocateActualDevice is properly
freed. At the same time, in the middle we need to go through the
lower-level vidDomainDetach*This*HostDevice to be sure that 1) the
def->hostdevs list is properly managed, 2) the PCI device is properly
detached from the guest and reattached to the host (if appropriate),
and 3) any higher level teardown is called at the appropriate time, by
reaching back up to the NetDef config (part (3) will be covered in a
separate patch).

13 years agoqemu: use virDomainNetRemove instead of inline code
Laine Stump [Mon, 27 Feb 2012 17:22:22 +0000 (12:22 -0500)]
qemu: use virDomainNetRemove instead of inline code

The code being replaced is exactly identical to the newly global
function, right down to the comment.

13 years agoconf: change virDomainNetRemove from static to global
Laine Stump [Mon, 27 Feb 2012 17:13:41 +0000 (12:13 -0500)]
conf: change virDomainNetRemove from static to global

This exact code is duplicated in qemuDomainDetachNetDevice().

13 years agoqemu: support type='hostdev' network devices at domain start
Laine Stump [Thu, 23 Feb 2012 15:45:35 +0000 (10:45 -0500)]
qemu: support type='hostdev' network devices at domain start

This patch makes sure that each network device ("interface") of
type='hostdev' appears on both the hostdevs list and the nets list of
the virDomainDef, and it modifies the qemu driver startup code so that
these devices will be presented to qemu on the commandline as hostdevs
rather than as network devices.

It does not add support for hotplug of these type of devices, or code
to honor the <mac address> or <virtualport> given in the config (both
of those will be done in separate patches).

Once each device is placed on both lists, much of what this patch does
is modify places in the code that traverse all the device lists so
that these hybrid devices are only acted on once - either along with
the other hostdevs, or along with the other network interfaces. (In
many cases, only one of the lists is traversed / a specific operation
is performed on only one type of device. In those instances, the code
can remain unchanged.)

There is one special case - when building the commandline, interfaces
are allowed to proceed all the way through
networkAllocateActualDevice() before deciding to skip the rest of
netdev-specific processing - this is so that (once we have support for
networks with pools of hostdev devices) we can get the actual device
allocated, then rely on the loop processing all hostdevs to generate
the correct commandline.

(NB: <interface type='hostdev'> is only supported for PCI network
devices that are SR-IOV Virtual Functions (VF). Standard PCI[e] and
USB devices, and even the Physical Functions (PF) of SR-IOV devices
can only be assigned to a guest using the more basic <hostdev> device
entry. This limitation is mostly due to the fact that non-SR-IOV
ethernet devices tend to lose mac address configuration whenever the
card is reset, which happens when a card is assigned to a guest;
SR-IOV VFs fortunately don't suffer the same problem.)

13 years agoconf: parse/format type='hostdev' network interfaces
Laine Stump [Wed, 15 Feb 2012 17:37:15 +0000 (12:37 -0500)]
conf: parse/format type='hostdev' network interfaces

This is the new interface type that sets up an SR-IOV PCI network
device to be assigned to the guest with PCI passthrough after
initializing some network device-specific things from the config
(e.g. MAC address, virtualport profile parameters). Here is an example
of the syntax:

  <interface type='hostdev' managed='yes'>
    <source>
      <address type='pci' domain='0' bus='0' slot='4' function='3'/>
    </source>
    <mac address='00:11:22:33:44:55'/>
    <address type='pci' domain='0' bus='0' slot='7' function='0'/>
  </interface>

This would assign the PCI card from bus 0 slot 4 function 3 on the
host, to bus 0 slot 7 function 0 on the guest, but would first set the
MAC address of the card to 00:11:22:33:44:55.

NB: The parser and formatter don't care if the PCI card being
specified is a standard single function network adapter, or a virtual
function (VF) of an SR-IOV capable network adapter, but the upcoming
code that implements the back end of this config will work *only* with
SR-IOV VFs. This is because modifying the mac address of a standard
network adapter prior to assigning it to a guest is pointless - part
of the device reset that occurs during that process will reset the MAC
address to the value programmed into the card's firmware.

Although it's not supported by any of libvirt's hypervisor drivers,
usb network hostdevs are also supported in the parser and formatter
for completeness and consistency. <source> syntax is identical to that
for plain <hostdev> devices, except that the <address> element should
have "type='usb'" added if bus/device are specified:

  <interface type='hostdev'>
    <source>
      <address type='usb' bus='0' device='4'/>
    </source>
    <mac address='00:11:22:33:44:55'/>
  </interface>

If the vendor/product form of usb specification is used, type='usb'
is implied:

  <interface type='hostdev'>
    <source>
      <vendor id='0x0012'/>
      <product id='0x24dd'/>
    </source>
    <mac address='00:11:22:33:44:55'/>
  </interface>

Again, the upcoming patch to fill in the backend of this functionality
will log an error and fail with "Unsupported Config" if you actually
try to assign a USB network adapter to a guest using <interface
type='hostdev'> - just use a standard <hostdev> entry in that case
(and also for single-port PCI adapters).

13 years agoqemu: refactor hotplug detach of hostdevs
Laine Stump [Mon, 27 Feb 2012 11:53:19 +0000 (06:53 -0500)]
qemu: refactor hotplug detach of hostdevs

This refactoring is necessary to support hotplug detach of
type=hostdev network devices, but needs to be in a separate patch to
make potential debugging of regressions more practical.

Rather than the lowest level functions searching for a matching
device, the search is now done in the toplevel function, and an
intermediate-level function (qemuDomainDetachThisHostDevice()), which
expects that the device's entry is already found, is called (this
intermediate function will be called by qemuDomainDetachNetDevice() in
order to support detach of type=hostdev net devices)

This patch should result in 0 differences in functionality.

13 years agoqemu: re-order functions in qemu_hotplug.c
Laine Stump [Mon, 27 Feb 2012 12:03:12 +0000 (07:03 -0500)]
qemu: re-order functions in qemu_hotplug.c

Code movement only, no functional change. This is necessary to prevent
a forward reference in an upcoming patch.

13 years agoconf: hostdev utility functions
Laine Stump [Mon, 27 Feb 2012 06:46:47 +0000 (01:46 -0500)]
conf: hostdev utility functions

Three new functions useful in other files:

virDomainHostdevInsert:

Add a new hostdev at the end of the array. This would more sensibly be
called virDomainHostdevAppend, but the existing functions for other
types of devices are called Insert.

virDomainHostdevRemove:

Eliminates one entry from the hostdevs array, but doesn't free it;
patterned after the code at the end of the two
qemuDomainDetachHostXXXDevice functions (and also other pre-existing
virDomainXXXRemove functions for other device types).

virDomainHostdevFind:

This function is patterned from the search loops at the top of
qemuDomainDetachHostPciDevice and qemuDomainDetachHostUsbDevice, and
will be used to re-factor those (and other detach-related) functions.

13 years agoconf: put subsys part of virDomainHostdevDef into its own struct
Laine Stump [Mon, 27 Feb 2012 06:42:22 +0000 (01:42 -0500)]
conf: put subsys part of virDomainHostdevDef into its own struct

To shorten some new code that accesses the many fields within the
subsys struct of a hostdev, create a separate toplevel, typedefed
virDomainHostdevSubsys struct so that we can define temporary pointers
to the subsys part.

13 years agoconf: give each hostdevdef a parent pointer
Laine Stump [Fri, 3 Feb 2012 16:13:08 +0000 (11:13 -0500)]
conf: give each hostdevdef a parent pointer

The parent can be any type of device. It defaults to type=none, and a
NULL pointer. The intent is that if a hostdevdef is contained in the
def for a higher level device (e.g. virDomainNetDef), hostdev->parent
will point to the higher level device, and type will be set to that
type of device. This way, during attach and detach of the device,
parent can be checked, and appropriate callouts made to do higher
level device initialization (e.g. setting MAC address).

Also, although these hostdevs with parents will be added to a domain's
hostdevs list, they will be treated slightly differently when
traversing the list, e.g. virDomainHostdefDefFree for a hostdev that
has a parent doesn't need to be called (and will be a NOP); it will
simply be removed from the list (since the parent device object is in
its own type-specific list, and will be freed from there).

13 years agoconf: HostdevDef parse/format helper functions
Laine Stump [Sun, 19 Feb 2012 21:04:44 +0000 (16:04 -0500)]
conf: HostdevDef parse/format helper functions

In an upcoming patch, virDomainNetDef will acquire a
virDomainHostdevDef, and the <interface> XML will take on some of the
elements of a <hostdev>. To avoid duplicating the code for parsing and
formatting the <source> element (which will be nearly identical in
these two cases), this patch factors those parts out of the
HostdevDef's parse and format functions, and puts them into separate
helper functions that are now called by the HostdevDef
parser/formatter, and will soon be called by the NetDef
parser/formatter.

One change in behavior - previously virDomainHostdevDefParseXML() had
diverged from current common coding practice by logging an error and
failing if it found any subelements of <hostdev> other than those it
understood (standard libvirt practice is to ignore/discard unknown
elements and attributes during parse). The new helper function ignores
unknown elements, and thus so does the new
virDomainHostdevDefParseXML.

13 years agoconf: make hostdev info a separate object
Laine Stump [Tue, 31 Jan 2012 09:16:54 +0000 (04:16 -0500)]
conf: make hostdev info a separate object

In order to allow for a virDomainHostdevDef that uses the
virDomainDeviceInfo of a "higher level" device (such as a
virDomainNetDef), this patch changes the virDomainDeviceInfo in the
HostdevDef into a virDomainDeviceInfoPtr. Rather than adding checks
all over the code to check for a null info, we just guarantee that it
is always valid. The new function virDomainHostdevDefAlloc() allocates
a virDomainDeviceInfo and plugs it in, and virDomainHostdevDefFree()
makes sure it is freed.

There were 4 places allocating virDomainHostdevDefs, all of them
parsers of one sort or another, and those have all had their
VIR_ALLOC(hostdev) changed to virDomainHostdevDefAlloc(). Other than
that, and the new functions, all the rest of the changes are just
mechanical removals of "&" or changing "." to "->".

13 years agoconf: add device pointer to args of virDomainDeviceInfoIterate callback
Laine Stump [Wed, 22 Feb 2012 21:06:10 +0000 (16:06 -0500)]
conf: add device pointer to args of virDomainDeviceInfoIterate callback

There will be cases where the iterator callback will need to know the
type of the device whose info is being operated on, and possibly even
need to use some of the device's config. This patch adds a
virDomainDeviceDefPtr to the args of every callback, and fills it in
appropriately as the devices are iterated through.

13 years agoqemu: rename virDomainDeviceInfoPtr variables to avoid confusion
Laine Stump [Thu, 23 Feb 2012 17:59:21 +0000 (12:59 -0500)]
qemu: rename virDomainDeviceInfoPtr variables to avoid confusion

The virDomainDeviceInfoPtrs in qemuCollectPCIAddress and
qemuComparePCIDevice are named "dev" and "dev1", but those functions
will be changed (in order to match a change in the args sent to
virDomainDeviceInfoIterate() callback args) to contain a
virDomainDeviceDefPtr device.

This patch renames "dev" to "info" (and "dev[n]" to "info[n]") to
avoid later confusion.

13 years agoconf: reorder static functions in domain_conf.c
Laine Stump [Sat, 18 Feb 2012 03:32:21 +0000 (22:32 -0500)]
conf: reorder static functions in domain_conf.c

No code change, movement only.  This is necessary to eliminate forward
references.

13 years agoconf: relocate virDomainDeviceDef and virDomainHostdevDef
Laine Stump [Thu, 16 Feb 2012 21:41:47 +0000 (16:41 -0500)]
conf: relocate virDomainDeviceDef and virDomainHostdevDef

This patch is only code movement + adding some forward definitions of
typedefs.

virDomainHostdevDef (not just a pointer to it, but an actual object)
will be needed in virDomainNetDef and virDomainActualNetDef, so it
must be relocated earlier in the file.

Likewise, virDomainDeviceDef will be needed in virDomainHostdevDef, so
it must be moved up even earlier. This, in turn, creates a forward
reference problem, but fortunately only with pointers to other device
types, so their typedefs can be moved up in the file, eliminating the
problem.

13 years agoconf: add missing device types to virDomainDevice(Type|Def)
Laine Stump [Wed, 22 Feb 2012 20:54:35 +0000 (15:54 -0500)]
conf: add missing device types to virDomainDevice(Type|Def)

Not all device types were represented in virDomainDeviceType, so some
types of devices couldn't be represented in a virDomainDeviceDef
(which requires a different type of pointer in the union for each
different kind of device).

Since serial, parallel, channel, and console devices are all
virDomainChrDef, and the virDomainDeviceType is never used to produce
a string from the type (and only used in the other direction
internally to code, never to produce XML), I only added one "CHR"
type, which is associated with "virDomainChrDefPtr chr" in the union.

13 years agoFix build after commit e3ba4025
Jim Fehlig [Mon, 5 Mar 2012 19:08:54 +0000 (12:08 -0700)]
Fix build after commit e3ba4025

Commit e3ba4025 introduced a few build errors with HAVE_LIBNL undefined.

13 years agoutil: eliminate crash in virNetDevMacVLanCreateWithVPortProfile
Laine Stump [Mon, 5 Mar 2012 19:53:48 +0000 (14:53 -0500)]
util: eliminate crash in virNetDevMacVLanCreateWithVPortProfile

Commit 723d5c (added after the release of 0.9.10) adds a
NetlinkEventClient for each interface sent to
virNetDevMacVLanCreateWithVPortProfile. This should only be done if
the interface actually *has* a virtPortProfile, otherwise the event
handler would be a NOP. The bigger problem is that part of the setup
to create the NetlinkEventClient is to do a memcpy of virtPortProfile
- if it's NULL, this triggers a segv.

This patch just qualifies the code that adds the client - if
virtPortProfile is NULL, it's skipped.

13 years agoblockResize: add flag for bytes
Eric Blake [Sat, 3 Mar 2012 14:43:22 +0000 (07:43 -0700)]
blockResize: add flag for bytes

Qemu supports sizing by bytes; we shouldn't force the user to
round up if they really wanted an unaligned total size.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_RESIZE_BYTES):
New flag.
* src/libvirt.c (virDomainBlockResize): Document it.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockResize): Take
size in bytes.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextBlockResize):
Likewise.  Pass bytes, not megabytes, to monitor.
* src/qemu/qemu_driver.c (qemuDomainBlockResize): Implement new
flag.

13 years agoqemu: Shared or readonly disks are always safe wrt migration
Jiri Denemark [Mon, 5 Mar 2012 11:10:21 +0000 (12:10 +0100)]
qemu: Shared or readonly disks are always safe wrt migration

No matter what cache mode is used, readonly disks are always safe wrt
migration. Shared disks are required to be readonly or to disable
host-side cache, which makes them safe as well.

13 years agolibvirt-guests: Add parallel startup and shutdown of guests
Peter Krempa [Tue, 28 Feb 2012 15:09:42 +0000 (16:09 +0100)]
libvirt-guests: Add parallel startup and shutdown of guests

With this patch, it's possible to shut down guests in parallel. Parallel
startup was possible before, but this functionality was not documented
properly.

To enable parallel startup set the START_DELAY to 0.

Parallel shutdown has a configurable parameter PARALLEL_SHUTDOWN that
defines the number of machines being shut down in parallel. Enabling
this feature changes the semantics of SHUTDOWN_TIMEOUT parameter that is
applied as a cumulative timeout to shutdown all guests on a URI.

13 years agorpc: Fix client crash on connection close
Jiri Denemark [Fri, 2 Mar 2012 18:57:27 +0000 (19:57 +0100)]
rpc: Fix client crash on connection close

A multi-threaded client with event loop may crash if one of its threads
closes a connection while event loop is in the middle of sending
keep-alive message (either request or response). The right place for it
is inside virNetClientIOEventLoop() between poll() and
virNetClientLock(). We should only close a connection directly if no-one
is using it and defer the closing to the last user otherwise. So far we
only did so if the close was initiated by keep-alive timeout.

13 years agobuild: Fix build with dtrace + apparmor
Jiri Denemark [Thu, 1 Mar 2012 15:02:31 +0000 (16:02 +0100)]
build: Fix build with dtrace + apparmor

Building virt-aa-helper with dtrace probes enabled, ldd complained about
undefined references:

./.libs/libvirt_util.a(libvirt_util_la-event_poll.o):(.note.stapsdt+0x24):
undefined reference to `libvirt_event_poll_purge_timeout_semaphore'
...