]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
12 years agobandwidth: Create network bandwidth (un)plug functions
Michal Privoznik [Fri, 16 Nov 2012 13:29:01 +0000 (14:29 +0100)]
bandwidth: Create network bandwidth (un)plug functions

Network should be notified if we plug in or unplug an
interface, so it can perform some action, e.g. set/unset
network part of QoS. However, we are doing this in very
early stage, so iface->ifname isn't filled in yet. So
whenever we want to report an error, we must use a different
identifier, e.g. the MAC address.

12 years agobandwidth: Create rate update function
Michal Privoznik [Fri, 16 Nov 2012 11:52:44 +0000 (12:52 +0100)]
bandwidth: Create rate update function

This will be used whenever a NIC with guaranteed throughput is to
be plugged into a bridge. It will adjust the average throughput of
non guaranteed NICs (classid 1:2) to meet new requirements.

12 years agobandwidth: Create (un)plug functions
Michal Privoznik [Fri, 16 Nov 2012 11:37:51 +0000 (12:37 +0100)]
bandwidth: Create (un)plug functions

These set bridge part of QoS when bringing domain's interface up.
Long story short, if there's a 'floor' set, a new QoS class is created.
ClassID MUST be unique within the bridge and should be kept for
unplug phase.

12 years agobandwidth: Create hierarchical shaping classes
Michal Privoznik [Fri, 16 Nov 2012 10:36:02 +0000 (11:36 +0100)]
bandwidth: Create hierarchical shaping classes

These classes can borrow unused bandwidth. Basically,
only egress qdsics can have classes, therefore we can
do this kind of traffic shaping only on host's outgoing,
that is domain's incoming traffic.

12 years agobandwidth: add new 'floor' attribute
Michal Privoznik [Fri, 16 Nov 2012 09:37:15 +0000 (10:37 +0100)]
bandwidth: add new 'floor' attribute

This is however supported only on domain interfaces with
type='network'. Moreover, target network needs to have at least
inbound QoS set. This is required by hierarchical traffic shaping.

From now on, the required attribute for <inbound/> is either 'average'
(old) or 'floor' (new). This new attribute can be used just for
interfaces type of network (<interface type='network'/>) currently.

12 years agobandwidth: Attach sfq to leaf node
Michal Privoznik [Mon, 19 Nov 2012 11:16:07 +0000 (12:16 +0100)]
bandwidth: Attach sfq to leaf node

Stochastic Fairness Queuing (SFQ) is queuing discipline
(qdisc) which doesn't really shape any traffic but 'just'
re-arrange packets in sending buffer so no stream starve.
The goal is to ensure fairness. There is basically only one
configuration parameter (perturb) which is set to advised
value of 10.

12 years agoparallels: handle network adapters of type 'routed'
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:49 +0000 (14:59 +0400)]
parallels: handle network adapters of type 'routed'

Network adapters of type 'routed' is a special case. Other adapters
have 'network' parameter in prlctl's output instead.

Routed network adapters should be connected to 'routed' network
from libvirt's view.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add routed pseudo network
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:48 +0000 (14:59 +0400)]
parallels: add routed pseudo network

Historically if traffic from the adapter is routed to LAN without
NAT, it isn't connected to any virtual networks, but has a 'type'
instead. Sinse libvirt has special virtual network type for such case,
let's add pseudo network 'routed' to fit libvirt's API well.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: parse virtual network properties
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:47 +0000 (14:59 +0400)]
parallels: parse virtual network properties

Fill bridge name and mac for bridged network and
DHCP server parameter for host-only network.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add network driver
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:45 +0000 (14:59 +0400)]
parallels: add network driver

Parallels Cloud Server uses virtual networks model for network
configuration. It uses own tools for virtual network management.
So add network driver, which will be responsible for listing
virtual networks and performing different operations on them
(in consequent patched).

This patch only allows listing virtual network names, without
any parameters like DHCP server settings.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: move parallelsParseError to parallels_utils.h
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:44 +0000 (14:59 +0400)]
parallels: move parallelsParseError to parallels_utils.h

This macro will be used in another file in the next
patch, so move it to common header file.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add support of network interfaces to parallelsDomainDefineXML
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:43 +0000 (14:59 +0400)]
parallels: add support of network interfaces to parallelsDomainDefineXML

Allow changing network interfaces in domain configuration.

ifname is used as iterface identifier: if there is interface
with some ifname in old config and there are no interfaces with
such name in the new config - issue prlctl command to delete
the network interface. And vice versa - if interface with
some ifname exists only in new config - issue prlctl command
to create it.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: parse information about network interfaces
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:42 +0000 (14:59 +0400)]
parallels: parse information about network interfaces

Parse network interfaces info from prlctl output.

Parallels Cloud Server uses virtual networks model for
network configuration: You can add network adapter to
VM and connect it to some predefined virtual network.

Fill type, mac, network name and linkstate fields of
virDomainNetDef structure.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoqemu: snapshot: Remove memory image if external checkpoint fails
Peter Krempa [Tue, 11 Dec 2012 11:02:16 +0000 (12:02 +0100)]
qemu: snapshot: Remove memory image if external checkpoint fails

When the disk snapshot part of an external system checkpoint fails the
memory image is retained. This patch adds code to remove the image in
such case.

12 years agoqemu: snapshot: Don't leak XML definition if restarting of CPUs fails
Peter Krempa [Tue, 11 Dec 2012 10:59:58 +0000 (11:59 +0100)]
qemu: snapshot: Don't leak XML definition if restarting of CPUs fails

In case the snapshot code isn't able to restart CPUs after an external
checkpoint we would leak a copy of the domains XML definition. This
patch fixes the cleanup path.

12 years agoqemu: fix uninitialized variable warning in doPeer2PeerMigrate
Ján Tomko [Tue, 11 Dec 2012 11:50:53 +0000 (12:50 +0100)]
qemu: fix uninitialized variable warning in doPeer2PeerMigrate

False positive, but it breaks the build with gcc-4.6.3.

qemu/qemu_migration.c:2931:37: error: 'offline' may be used
uninitialized in this function [-Werror=uninitialized]
qemu/qemu_migration.c:2887:10: note: 'offline' was declared here

12 years agoconf: Remove duplicate declaration of virNetworkDNSDefPtr
Jiri Denemark [Tue, 11 Dec 2012 12:27:53 +0000 (13:27 +0100)]
conf: Remove duplicate declaration of virNetworkDNSDefPtr

12 years agoexamples: Fix balloon event callback
Jiri Denemark [Tue, 11 Dec 2012 11:07:34 +0000 (12:07 +0100)]
examples: Fix balloon event callback

12 years agonetwork: put dnsmasq parameters in conf-file instead of command line
Gene Czarcinski [Thu, 6 Dec 2012 17:20:39 +0000 (12:20 -0500)]
network: put dnsmasq parameters in conf-file instead of command line

This patch changes how parameters are passed to dnsmasq.  Instead of
being on the command line, the parameters are put into a file (one
parameter per line) and a commandline --conf-file= specifies the
location of the file.  The file is located in the same directory as
the leases file.

Putting the dnsmasq parameters into a configuration file
allows them to be examined and more easily understood than
examining the command lines displayed by "ps ax".  This is
especially true when a number of networks have been started.

When the use of dnsmasq was originally done, the required command line
was simple, but it has gotten more complicated over time and will
likely become even more complicated in the future.

Note: The test conf files have all been renamed .conf instead of
.argv, and tests/networkxml2xmlargvdata was moved to
tests/networkxml2xmlconfdata.

12 years agonetwork: add support for DHCPv6
Gene Czarcinski [Thu, 6 Dec 2012 17:20:38 +0000 (12:20 -0500)]
network: add support for DHCPv6

The DHCPv6 support includes IPV6 dhcp-range and dhcp-host for one
IPv6 subnetwork on one interface.  This support will only work
if dnsmasq version >= 2.64; otherwise an error occurs if
dhcp-range or dhcp-host is specified for an IPv6 address.

Essentially, this change provides the same DHCP support for IPv6
that has been available for IPv4.

With dnsmasq >= 2.64, support for the RA service is also now provided
by dnsmasq (radvd is no longer used/started). (Although at least one
version of dnsmasq prior to 2.64 "supported" IPv6 Router
Advertisement, there were bugs (fixed in 2.64) that rendered it
unusable.)

Documentation and the network schema has been updated
to reflect the new support.

12 years agoconf: split <forward> parser/clear into separate functions
Laine Stump [Sun, 11 Nov 2012 22:57:16 +0000 (17:57 -0500)]
conf: split <forward> parser/clear into separate functions

virNetworkDefUpdateForward requires separate functions to parse and
clear a virNetworkForwardDef by itself, but they were previously just
inlined in the virNetworkDef parse and free functions. This patch
makes them into separate functions.

12 years agoconf: put data for network <forward> element into its own struct
Laine Stump [Thu, 8 Nov 2012 02:16:17 +0000 (21:16 -0500)]
conf: put data for network <forward> element into its own struct

The attributes of a <network> element's <forward> element were
previously stored directly in the virNetworkDef object, but
virNetworkUpdateForward() needs to operate on a <forward> in
isolation, so this patchs pulls out all those attributes into a
separate virNetworkForwardDef struct (and shortens their names
appropriately). This new object is contained in the virNetworkDef, not
pointed to by it, so there is no extra memory management.

This patch makes no functional changes, it only changes, e.g.,
"nForwardIfs" to "forward.nifs".

12 years agoconf: make virNetworkIpDefClear consistent with other functions
Laine Stump [Sun, 11 Nov 2012 15:27:55 +0000 (10:27 -0500)]
conf: make virNetworkIpDefClear consistent with other functions

The other clear functions in network_conf.c that clear out arrays of
sub-objects do so by using the n[itemname]s value as a counter going
down to 0. Make this one consistent. There's no functional value, just
makes the style more consistent with the rest of the file.

12 years agoconf: rename some labels and functions in network_conf
Laine Stump [Sun, 11 Nov 2012 23:55:12 +0000 (18:55 -0500)]
conf: rename some labels and functions in network_conf

This makes some function names and arg lists for consistent with other
parse functions in network_conf.c. While modifying
virNetworkIPParseXML(), also change its "error" label to "cleanup",
since the code at that label is executed on success as well as
failure.

12 years agonetwork: backend functions for updating network dns host/srv/txt
Laine Stump [Mon, 12 Nov 2012 21:18:02 +0000 (16:18 -0500)]
network: backend functions for updating network dns host/srv/txt

These three functions are very similar - none allow a MODIFY
operation; you can only add or delete.

The biggest difference between them (other than the data itself) is in
the criteria for determining a match, and whether or not multiple
matches are possible:

1) for HOST records, it's considered a match if the IP address or any
of the hostnames of an existing record matches.

2) for SRV records, it's a match if all of
domain+service+protocol+target *which have been specified* are
matched.

3) for TXT records, there is only a single field to match - name
(value can be the same for multiple records, and isn't considered a
search term), so by definition there can be no ambiguous matches.

In all three cases, if any matches are found, ADD will fail; if
multiple matches are found, it means the search term was ambiguous,
and a DELETE will fail.

The upper level code in bridge_driver.c is already implemented for
these functions - appropriate conf files will be re-written, and
dnsmasq will be SIGHUPed or restarted as appropriate.

12 years agoconf: clear and parse functions for dns host/srv/txt records
Laine Stump [Mon, 12 Nov 2012 00:00:22 +0000 (19:00 -0500)]
conf: clear and parse functions for dns host/srv/txt records

Since there is only a single virNetworkDNSDef for any virNetworkDef,
and it's trivial to determine whether or not it contains any real
data, it's much simpler (and fits more uniformly with the parse
function calling sequence of the parsers for many other objects that
are subordinates of virNetworkDef) if virNetworkDef *contains* an
virNetworkDNSDef rather than pointing to one.

Since it is now just a part of another object rather than its own
object, it no longer makes sense to have a *Free() function, so that
is changed to a *Clear() function.

More importantly though, ParseXML and Clear functions are needed for
the individual items contained in a virNetworkDNSDef (srv, txt, and
host records), but none of them have a *Clear(), and only two of the
three had *ParseXML() functions (both of which used a non-uniform
arglist). Those problems are cleared up by this patch - it splits the
higher-level Clear function into separate functions for each of the
three, creates a parse for txt records, and cleans up the srv and host
parsers, so we now have all the utility functions necessary to
implement virNetworkDefUpdateDNS(Host|Srv|Txt).

12 years agoconf: rename network dns host/srv/txt arrays
Laine Stump [Sun, 11 Nov 2012 23:59:28 +0000 (18:59 -0500)]
conf: rename network dns host/srv/txt arrays

This shortens the name of the structs for srv and txt, and their
instances in virNetworkDNSDef, to be more compact and uniform with the
naming of the dns host array. It also changes the type of ntxts, etc
from unsigned int to size_t, so that they can be used directly as args
to VIR_*_ELEMENT.

12 years agoconf: use VIR_(INSERT|DELETE)_ELEMENT in virNetworkUpdate backend
Laine Stump [Mon, 8 Oct 2012 17:42:21 +0000 (13:42 -0400)]
conf: use VIR_(INSERT|DELETE)_ELEMENT in virNetworkUpdate backend

The already-written backend functions for virNetworkUpdate that add
and delete items into lists within the a network were already debugged
to work properly, but future such functions will use
VIR_(INSERT|DELETE)_ELEMENT instead, so these are changed for
uniformity.

12 years agoutil: add VIR_(APPEND|INSERT|DELETE)_ELEMENT
Laine Stump [Mon, 8 Oct 2012 17:33:35 +0000 (13:33 -0400)]
util: add VIR_(APPEND|INSERT|DELETE)_ELEMENT

I noticed when writing the backend functions for virNetworkUpdate that
I was repeating the same sequence of memmove, VIR_REALLOC, nXXX-- (and
messed up the args to memmove at least once), and had seen the same
sequence in a lot of other places, so I decided to write a few
utility functions/macros - see the .h file for full documentation.

The intent is to reduce the number of lines of code, but more
importantly to eliminate the need to check the element size and
element count arithmetic every time we need to do this (I *always*
make at least one mistake.)

VIR_INSERT_ELEMENT: insert one element at an arbitrary index within an
  array of objects. The size of each object is determined
  automatically by the macro using sizeof(*array). The new element's
  contents are copied into the inserted space, then the original copy
  of contents are 0'ed out (if everything else was
  successful). Compile-time assignment and size compatibility between
  the array and the new element is guaranteed (see explanation below
  [*])

VIR_INSERT_ELEMENT_COPY: identical to VIR_INSERT_ELEMENT, except that
  the original contents of newelem are not cleared to 0 (i.e. a copy
  is made).

VIR_APPEND_ELEMENT: This is just a special case of VIR_INSERT_ELEMENT
  that "inserts" one past the current last element.

VIR_APPEND_ELEMENT_COPY: identical to VIR_APPEND_ELEMENT, except that
  the original contents of newelem are not cleared to 0 (i.e. a copy
  is made).

VIR_DELETE_ELEMENT: delete one element at an arbitrary index within an
  array of objects. It's assumed that the element being deleted is
  already saved elsewhere (or cleared, if that's what is appropriate).

All five of these macros have an _INPLACE variant, which skips the
memory re-allocation of the array, assuming that the caller has
already done it (when inserting) or will do it later (when deleting).

Note that VIR_DELETE_ELEMENT* can return a failure, but only if an
invalid index is given (index + amount to delete is > current array
size), so in most cases you can safely ignore the return (that's why
the helper function virDeleteElementsN isn't declared with
ATTRIBUTE_RETURN_CHECK). A warning is logged if this ever happens,
since it is surely a coding error.

[*] One initial problem with the INSERT and APPEND macros was that,
due to both the array pointer and newelem pointer being cast to void*
when passing to virInsertElementsN(), any chance of type-checking was
lost. If we were going to move in newelem with a memmove anyway, we
would be no worse off for this. However, most current open-coded
insert/append operations use direct struct assignment to move the new
element into place (or just populate the new element directly) - thus
use of the new macros would open a possibility for new usage errors
that didn't exist before (e.g. accidentally sending &newelemptr rather
than newelemptr - I actually did this quite a lot in my test
conversions of existing code).

But thanks to Eric Blake's clever thinking, I was able to modify the
INSERT and APPEND macros so that they *do* check for both assignment
and size compatibility of *ptr (an element in the array) and newelem
(the element being copied into the new position of the array). This is
done via clever use of the C89-guaranteed fact that the sizeof()
operator must have *no* side effects (so an assignment inside sizeof()
is checked for validity, but not actually evaluated), and the fact
that virInsertElementsN has a "# of new elements" argument that we
want to always be 1.

12 years agoqemu: Restart CPUs with valid async job type when doing external snapshots
Peter Krempa [Fri, 7 Dec 2012 10:50:52 +0000 (11:50 +0100)]
qemu: Restart CPUs with valid async job type when doing external snapshots

When restarting CPUs after an external snapshot, the restarting function
was called without the appropriate async job type. This caused that a
new sync job wasn't created and allowed races in the monitor.

12 years agoparallels: add support of removing disks
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:13 +0000 (17:43 +0400)]
parallels: add support of removing disks

If some hard disk is not found in new domain configuration, it
should be removed.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: apply config after VM creation
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:12 +0000 (17:43 +0400)]
parallels: apply config after VM creation

New VM will have default values for all parameters, like
cpu number, we have to change its configuration as provided
by xml definition, given to parallelsDomainDefineXML.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add support of disks creation
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:11 +0000 (17:43 +0400)]
parallels: add support of disks creation

Implement creation of new disks - if a new disk found
in configuration, find a volume by disk path and
actually create a disk image by issuing prlctl command.
If it's successfully finished - remove the file with volume
definition.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add function parallelsGetDiskBusName
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:10 +0000 (17:43 +0400)]
parallels: add function parallelsGetDiskBusName

Add function for convertion bus from libvirt's numeric constant
to a name, used in a parallels command-line tools.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: split parallelsStorageVolumeDelete function
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:09 +0000 (17:43 +0400)]
parallels: split parallelsStorageVolumeDelete function

Move part, which deletes existing volume, to a new function
parallelsStorageVolumeDefRemove so that we can use it later
in parallels_driver.c

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: fill volumes capacity parameter
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:08 +0000 (17:43 +0400)]
parallels: fill volumes capacity parameter

Read disk images size from xml description and fill
virStorageVolDef.capacity and allocation (let's consider
that allocation is the same as capacity, calculating real
allcoation will be implemented later).

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add info about volumes
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:07 +0000 (17:43 +0400)]
parallels: add info about volumes

Disk images in Parallels Cloud Server stored in directories. Each
one has files with data and xml description of an image stored in
file DiskDescriptior.xml.

Since we have to support 'detached' images, which are not used by
any VM, the better way to collect info about volumes is searching for
directories with a file DiskDescriptior.xml in each VM directory.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: fix leaks in parallelsFindVolumes
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:06 +0000 (17:43 +0400)]
parallels: fix leaks in parallelsFindVolumes

We always have to close opened dir and free 'path'.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: create storage pools by VM list
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:05 +0000 (17:43 +0400)]
parallels: create storage pools by VM list

There are no storage pools in Parallels Cloud Server -
All VM data stored in a single directory: config, snapshots,
memory dump together with disk images.

Let's look through list of VMs and create a storage pool for
each directory, containing VMs.

So if you have 3 vms: /var/parallels/vm-1.pvm,
/var/parallels/vm-2.pvm and /root/test.pvm - 2 storage pools
appear: -var-parallels and -root. xml descriptions of the pools
will be saved in /etc/libvirt/parallels-storage, so UUIDs will
not change netween connections to libvirt.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: remove unused code from storage driver
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:04 +0000 (17:43 +0400)]
parallels: remove unused code from storage driver

We don't support unprivileged users anymore, so remove code, which
selects configuration directory depending on user.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: split parallelsStorageOpen function
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:03 +0000 (17:43 +0400)]
parallels: split parallelsStorageOpen function

Move code for loading inforation about pools to a separate
function - parallelsLoadPools.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: handle disk devices in parallelsDomainDefineXML
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:02 +0000 (17:43 +0400)]
parallels: handle disk devices in parallelsDomainDefineXML

Allow changing some parameters of the hard disks: bus,
image and drive address.

Creating new disk devices and removing existing ones
require changes in the storage driver, so it will be
implemented later.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add info about hard disk devices
Dmitry Guryanov [Tue, 4 Dec 2012 13:43:01 +0000 (17:43 +0400)]
parallels: add info about hard disk devices

Parse information about hard disks and fill disks array
in virDomainDef structure.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoAdd support for offline migration
liguang [Wed, 21 Nov 2012 08:28:49 +0000 (16:28 +0800)]
Add support for offline migration

Offline migration transfers inactive definition of a domain (which may
or may not be active). After successful completion, the domain remains
in its current state on source host and is defined but inactive on
destination host. It's a bit more clever than virDomainGetXMLDesc() on
source host followed by virDomainDefineXML() on destination host, as
offline migration will run pre-migration hook to update the domain XML
on destination host. Currently, copying non-shared storage is not
supported during offline migration.

Offline migration can be requested with a new migration flag called
VIR_MIGRATE_OFFLINE (which has to be combined with
VIR_MIGRATE_PERSIST_DEST flag).

12 years agoqemu: eliminate bogus error log when changing netdev's bridge
Laine Stump [Mon, 10 Dec 2012 16:21:39 +0000 (11:21 -0500)]
qemu: eliminate bogus error log when changing netdev's bridge

This fixes a problem that showed up during testing of:

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

Due to a logic error in the function that gets the name of the bridge
an interface connects to, any time a bridge was specified directly
(type='bridge') rather than indirectly (type='network'), An error
would be logged (although the operation would then complete
successfully):

   Network type 6 is not supported

The final virReportError() in the function
qemuDomainNetGetBridgeName() was apparently avoided in the past with a
"goto cleanup" at the end of each case, but the case of bridge somehow
no longer has that final goto cleanup.

The proper solution is anyway to not rely on goto's, but put the error
log inside an else {} clause, so that it's executed only if the type
is neither bridge nor network (in reality, this function should only
ever be called for those two types, that's why this is an internal
error).

While making this change, the error message was also tuned to be more
correct (since it's not really the type of the network, but the type
of the interface, and it *is* otherwise supported, it's just that the
interface type in question doesn't *have* a bridge device associated
with it, or at least we don't know how to get it).

12 years agoS390: Assign default model "virtio" for network interfaces
Viktor Mihajlovski [Mon, 10 Dec 2012 10:00:05 +0000 (11:00 +0100)]
S390: Assign default model "virtio" for network interfaces

If a network interface model is not specified, libvirt will run
into an unchecked NULL pointer coredump. On the other hand if
the empty model is ignored, a PCI bus address would be generated,
which is not supported by S390.
Since the only valid network type model for S390 is virtio,
we use this as the default value, which is the same for QEMU.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agoRevert "dnsmasq: Fix parsing of the version number"
Michal Privoznik [Mon, 10 Dec 2012 13:00:02 +0000 (14:00 +0100)]
Revert "dnsmasq: Fix parsing of the version number"

This reverts commit 5114431396fd125b6ebe4d1a20a981111f948ee7
which was pushed accidentally.

12 years agoqemu: capabilities: fix machine name/canonical swappage
Cole Robinson [Fri, 7 Dec 2012 16:30:34 +0000 (11:30 -0500)]
qemu: capabilities: fix machine name/canonical swappage

Things are supposed to look like:

<machine canonical='pc-0.12'>pc</machine>

But are currently swapped. This can cause many VMs to revert to having
machine type='pc' which will affect save/restore across qemu upgrades.

12 years agovirsh: Fix usage of header termios.h
Peter Krempa [Thu, 6 Dec 2012 18:41:53 +0000 (19:41 +0100)]
virsh: Fix usage of header termios.h

The termios struct exported by the termios.h header is used as an
argument for vshMakeStdinRaw(). The header isn't used anywhere in
tools/virsh-domain.c.

This patch adds the header to the header declaring vshMakeStdinRaw() and
removes other places in virsh.

12 years agovirsh: allow metadata preallocation when creating volumes
Ján Tomko [Wed, 5 Dec 2012 10:48:08 +0000 (11:48 +0100)]
virsh: allow metadata preallocation when creating volumes

Add --prealloc-metadata flag to these commands:
vol-clone
vol-create
vol-create-as
vol-create-from

12 years agostorage: allow metadata preallocation when creating qcow2 images
Ján Tomko [Wed, 5 Dec 2012 10:48:07 +0000 (11:48 +0100)]
storage: allow metadata preallocation when creating qcow2 images

Add VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA flag to virStorageVolCreateXML
and virStorageVolCreateXMLFrom. This flag requests metadata
preallocation when creating/cloning qcow2 images, resulting in creating
a sparse file with qcow2 metadata. It has only slightly larger disk usage
compared to new image with no allocation, but offers higher performance.

12 years agoqemu: Allow the user to specify vendor and product for disk
Osier Yang [Thu, 6 Dec 2012 10:23:02 +0000 (18:23 +0800)]
qemu: Allow the user to specify vendor and product for disk

QEMU supports setting vendor and product strings for disk since
1.2.0 (only scsi-disk, scsi-hd, scsi-cd support it), this patch
exposes it with new XML elements <vendor> and <product> of disk
device.

12 years agoConvert libxl driver to Xen 4.2
Jim Fehlig [Mon, 26 Nov 2012 16:28:56 +0000 (09:28 -0700)]
Convert libxl driver to Xen 4.2

Based on a patch originally authored by Daniel De Graaf

  http://lists.xen.org/archives/html/xen-devel/2012-05/msg00565.html

This patch converts the Xen libxl driver to support only Xen >= 4.2.
Support for Xen 4.1 libxl is dropped since that version of libxl is
designated 'technology preview' only and is incompatible with Xen 4.2
libxl.  Additionally, the default toolstack in Xen 4.1 is still xend,
for which libvirt has a stable, functional driver.

12 years agoInhibit daemon shutdown during driver initialization
Guido Günther [Wed, 5 Dec 2012 19:21:14 +0000 (20:21 +0100)]
Inhibit daemon shutdown during driver initialization

As of 1a50ba2cb07d8bb2aa724062889deb9efd7ad9e9 qemu capabilities probing
takes longer since we timeout waiting for the monitor socket. When
probing qemu for different architectures this can add up so the daemon
auto shutdown timeout is reached and the client doesn't have a chance
to connect. To avoid that inhibit daemon shutdown during driver
initialization (which includes capabilities probing).

This fixes

http://honk.sigxcpu.org:8001/job/libvirt-tck-debian-wheezy-qemu-session/227/

12 years agoutil: Don't fail virGetGroupIDByName when group not found
Christophe Fergeau [Wed, 5 Dec 2012 10:21:10 +0000 (11:21 +0100)]
util: Don't fail virGetGroupIDByName when group not found

virGetGroupIDByName is documented as returning 1 if the groupname
cannot be found. getgrnam_r is documented as returning:
« 0 or ENOENT or ESRCH or EBADF or EPERM or ...  The given name
or gid was not found. »
 and that:
« The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
It  does  not  call  "not  found"  an error, hence does not specify what
value errno might have in this situation.  But that makes it impossible to
recognize errors.  One might argue that according to POSIX errno should be
left unchanged if an entry is not found.  Experiments on various UNIX-like
systems shows that lots of different values occur in this situation: 0,
ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others. »

virGetGroupIDByName returns an error when the return value of getgrnam_r
is non-0. However on my RHEL system, getgrnam_r returns ENOENT when the
requested user cannot be found, which then causes virGetGroupID not
to behave as documented (it returns an error instead of falling back
to parsing the passed-in value as an gid).

This commit makes virGetGroupIDByName only report an error when errno
is set to one of the values in the posix description of getgrnam_r
(which are the same as the ones described in the manpage on my system).

12 years agoutil: Don't fail virGetUserIDByName when user not found
Christophe Fergeau [Wed, 5 Dec 2012 10:21:10 +0000 (11:21 +0100)]
util: Don't fail virGetUserIDByName when user not found

virGetUserIDByName is documented as returning 1 if the username
cannot be found. getpwnam_r is documented as returning:
« 0 or ENOENT or ESRCH or EBADF or EPERM or ...  The given name
or uid was not found. »
 and that:
« The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
It  does  not  call  "not  found"  an error, hence does not specify what
value errno might have in this situation.  But that makes it impossible to
recognize errors.  One might argue that according to POSIX errno should be
left unchanged if an entry is not found.  Experiments on various UNIX-like
systems shows that lots of different values occur in this situation: 0,
ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others. »

virGetUserIDByName returns an error when the return value of getpwnam_r
is non-0. However on my RHEL system, getpwnam_r returns ENOENT when the
requested user cannot be found, which then causes virGetUserID not
to behave as documented (it returns an error instead of falling back
to parsing the passed-in value as an uid).

This commit makes virGetUserIDByName only report an error when errno
is set to one of the values in the posix description of getpwnam_r
(which are the same as the ones described in the manpage on my system).

12 years agodnsmasq: Fix parsing of the version number
Michal Privoznik [Thu, 6 Dec 2012 12:48:11 +0000 (13:48 +0100)]
dnsmasq: Fix parsing of the version number

If debugging is enabled, the debug messages are sent to stderr.
Moreover, if a command has catching of stderr set, the messages
gets mixed with stdout output (assuming both outputs are stored
in the same variable). The resulting string then doesn't
necessarily have to start with desired prefix then. This bug
exposes itself when parsing dnsmasq output:

2012-12-06 11:18:11.445+0000: 18491: error :
dnsmasqCapsSetFromBuffer:664 : internal error cannot parse
/usr/sbin/dnsmasq version number in '2012-12-06
11:11:02.232+0000: 18492: debug : virFileClose:72 : Closed fd 22'

We can clearly see that the output of dnsmasq --version doesn't
start with expected "Dnsmasq version " string but a libvirt debug
output.

12 years agodnsmasq: Fix parsing of the version number
Michal Privoznik [Thu, 6 Dec 2012 11:25:50 +0000 (12:25 +0100)]
dnsmasq: Fix parsing of the version number

If the debugging is enabled, the virCommand subsystem catches debug
messages in the command output as well. In that case, we can't assume
the string corresponding to command's stdout will start with specific
prefix. But the prefix can be moved deeper in the string. This bug
shows itself when parsing dnsmasq output:

2012-12-06 11:18:11.445+0000: 18491: error :
dnsmasqCapsSetFromBuffer:664 : internal error cannot parse
/usr/sbin/dnsmasq version number in '2012-12-06 11:11:02.232+0000:
18492: debug : virFileClose:72 : Closed fd 22'

We can clearly see that the output of dnsmasq --version
doesn't start with expected "Dnsmasq version " string but a libvirt
debug output.

12 years agonetwork: prevent a few invalid configuration combinations
Laine Stump [Wed, 5 Dec 2012 19:10:24 +0000 (14:10 -0500)]
network: prevent a few invalid configuration combinations

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=767057

It was possible to define a network with <forward mode='bridge'> that
had both a bridge device and a forward device defined. These two are
mutually exclusive by definition (if you are using a bridge device,
then this is a host bridge, and if you have a forward dev defined,
this is using macvtap). It was also possible to put <ip>, <dns>, and
<domain> elements in this definition, although those aren't supported
by the current driver (although it's conceivable that some other
driver might support that).

The items that are invalid by definition, are now checked in the XML
parser (since they will definitely *always* be wrong), and the others
are checked in networkValidate() in the network driver (since, as
mentioned, it's possible that some other network driver, or even this
one, could some day support setting those).

12 years agonetwork: allow guest to guest IPv6 without gateway definition
Gene Czarcinski [Mon, 3 Dec 2012 16:13:36 +0000 (11:13 -0500)]
network: allow guest to guest IPv6 without gateway definition

This patch adds the capability for virtual guests to do IPv6
communication via a virtual network interface with no IPv6 (gateway)
addresses specified.  This capability has always been enabled by
default for IPv4, but disabled for IPv6 for security concerns, and
because it requires the ip6tables command to be operational (which
isn't the case on a system with the ipv6 module completely disabled).

This patch adds a new attribute "ipv6" at the toplevel of a <network>
object.  If ipv6='yes', the extra ip6tables rules required to permite
inter-guest communications are added when the network is started. If
it is 'no', or not present, those rules will not be added; thus the
default behavior doesn't change, so there should be no compatibility
issues with any existing installations.

Note that virtual guests cannot communication with the virtualization
host via this interface, because the following kernel tunable has
been set:

   net.ipv6.conf.<bridge_interface_name>.disable_ipv6 = 1

This assures that the bridge interface will not have an IPv6
link-local (fe80::) address.

To control this behavior so that it is not enabled by default, the parameter
ipv6='yes' on the <network> statement has been added.

Documentation related to this patch has been updated.
The network schema has also been updated.

12 years agostorage: Error out earlier if the volume target path already exists
Osier Yang [Wed, 5 Dec 2012 04:44:11 +0000 (12:44 +0800)]
storage: Error out earlier if the volume target path already exists

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

It's odd to fall through to buildVol, and the existed file is
removed when buildVol fails. This checks if the volume target
path already exists in createVol. The reason for not using
error like "Volume already exists" is that there isn't volume
maintained by libvirt for the path until a operation like
pool-refresh, using error like that will just cause confusion.

12 years agoremote: Avoid the thread race condition
Daniel P. Berrange [Wed, 5 Dec 2012 14:48:43 +0000 (22:48 +0800)]
remote: Avoid the thread race condition

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

Since the virConnect object is not locked wholely when doing
virConenctDispose, a thread can get the lock and thus might
cause the race.

Detected by valgrind:

==23687== Invalid read of size 4
==23687==    at 0x38BAA091EC: pthread_mutex_lock (pthread_mutex_lock.c:61)
==23687==    by 0x3FBA919E36: remoteClientCloseFunc (remote_driver.c:337)
==23687==    by 0x3FBA936BF2: virNetClientCloseLocked (virnetclient.c:688)
==23687==    by 0x3FBA9390D8: virNetClientIncomingEvent (virnetclient.c:1859)
==23687==    by 0x3FBA851AAE: virEventPollRunOnce (event_poll.c:485)
==23687==    by 0x3FBA850846: virEventRunDefaultImpl (event.c:247)
==23687==    by 0x40CD61: vshEventLoop (virsh.c:2128)
==23687==    by 0x3FBA8626F8: virThreadHelper (threads-pthread.c:161)
==23687==    by 0x38BAA077F0: start_thread (pthread_create.c:301)
==23687==    by 0x33F68E570C: clone (clone.S:115)
==23687==  Address 0x4ca94e0 is 144 bytes inside a block of size 312 free'd
==23687==    at 0x4A0595D: free (vg_replace_malloc.c:366)
==23687==    by 0x3FBA8588B8: virFree (memory.c:309)
==23687==    by 0x3FBA86AAFC: virObjectUnref (virobject.c:145)
==23687==    by 0x3FBA8EA767: virConnectClose (libvirt.c:1458)
==23687==    by 0x40C8B8: vshDeinit (virsh.c:2584)
==23687==    by 0x41071E: main (virsh.c:3022)

The above race is caused by the eventLoop thread tries to handle
the net client event by calling the callback set by:
    virNetClientSetCloseCallback(priv->client,
                                 remoteClientCloseFunc,
                                 conn, NULL);

I.E. remoteClientCloseFunc, which lock/unlock the virConnect object.

This patch is to fix the bug by setting the callback to NULL when
doRemoteClose.

12 years agopci: Fix building of 32bit PCI command array
Peter Krempa [Wed, 5 Dec 2012 10:58:39 +0000 (11:58 +0100)]
pci: Fix building of 32bit PCI command array

The pciWrite32 function assembled the array of data to be written to the
fd with a bad offset on the last byte. This issue was probably caused by
a typo (14, 24).

12 years agoutil: Do not keep PCI device config file open
Jiri Denemark [Tue, 4 Dec 2012 21:50:58 +0000 (22:50 +0100)]
util: Do not keep PCI device config file open

Directly open and close PCI config file in the APIs that need it rather
than keeping the file open for the whole life of PCI device structure.

12 years agoqemu: Fix memory (and FD) leak on PCI device detach
Jiri Denemark [Tue, 4 Dec 2012 08:18:44 +0000 (09:18 +0100)]
qemu: Fix memory (and FD) leak on PCI device detach

Unmanaged PCI devices were only leaked if pciDeviceListAdd failed but
managed devices were always leaked. And leaking PCI device is likely to
leave PCI config file descriptor open. This patch fixes
qemuReattachPciDevice to either free the PCI device or add it to the
inactivePciHostdevs list.

12 years agoutil: Slightly refactor PCI list functions
Jiri Denemark [Tue, 4 Dec 2012 07:30:46 +0000 (08:30 +0100)]
util: Slightly refactor PCI list functions

In order to be able to steal PCI device by its index in the list.

12 years agoqemu: Don't free PCI device if adding it to activePciHostdevs fails
Jiri Denemark [Fri, 30 Nov 2012 15:52:03 +0000 (16:52 +0100)]
qemu: Don't free PCI device if adding it to activePciHostdevs fails

The device is still referenced from pcidevs and freeing it would leave
an invalid pointer there.

12 years agoqemu: Fix error code when attaching existing device
Jiri Denemark [Tue, 4 Dec 2012 09:20:30 +0000 (10:20 +0100)]
qemu: Fix error code when attaching existing device

An attempt to attach device that is already attached to a domain results
in the following error:

virsh # attach-device rhel6 pci2 --persistent
error: Failed to attach device from pci2
error: invalid argument: device is already in the domain configuration

The "invalid argument" error code looks wrong, we usually use "operation
invalid" when the action cannot be done in current state.

12 years agospec: require dbus-daemon when using libvirtd in Fedora
Eric Blake [Wed, 5 Dec 2012 03:43:05 +0000 (20:43 -0700)]
spec: require dbus-daemon when using libvirtd in Fedora

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

In older Fedora, the spec file for libivrt depended on avahi, which
included avahi-daemon, which in turn depended on dbus.  But now that
avahi libs and avahi-daemon are (correctly) in separate pacakges,
and since we REALLY don't want a mandatory dependency on avahi-daemon,
and considering that our init scripts require the messagebus service
from dbus, we need to explicitly require dbus ourselves.

* libvirt.spec.in (Requires): Add dbus for libvirt-daemon.

12 years agosystemd: require dbus service
Eric Blake [Wed, 5 Dec 2012 03:43:04 +0000 (20:43 -0700)]
systemd: require dbus service

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

The initscript and upstart services depend on dbus starting
before libvirtd.  When we first wrote the systemd script, we
tried to do the same, but we depended on dbus.target (which
does not exist) in comparison to network.target (which does
exist), so we removed that in commit 4c7973e.  But we still
need dbus up and running first, especially now that we want
to support shutdown inhibition via dbus (whereas we originally
needed dbus only for firewall control).

http://www.freedesktop.org/software/systemd/man/systemd.target.html
explains how a target (such as network.target) is just a collection
of common services bundled together, and why we want network.target
but dbus.service.

* daemon/libvirtd.service.in (Unit): Depend on dbus starting
first.

12 years agoqemu: Simplify the code
Osier Yang [Tue, 4 Dec 2012 17:29:15 +0000 (01:29 +0800)]
qemu: Simplify the code

"disk" is initialized to "dev->data.disk" in the beginning of the
function.

12 years agostorage: Remove the redundant white lines
Osier Yang [Wed, 5 Dec 2012 04:16:28 +0000 (12:16 +0800)]
storage: Remove the redundant white lines

Pushed under trivial rule.

12 years agoqemu: improve error for failed JSON commands
Eric Blake [Tue, 4 Dec 2012 20:24:40 +0000 (13:24 -0700)]
qemu: improve error for failed JSON commands

Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice.  Suggested by Osier Yang.

* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.

12 years agoqemu: nicer error message if live disk snapshot unsupported
Eric Blake [Mon, 3 Dec 2012 21:25:30 +0000 (14:25 -0700)]
qemu: nicer error message if live disk snapshot unsupported

Without this patch, attempts to create a disk snapshot when qemu
is too old results in a cryptic message:

virsh # snapshot-create 23 --disk-only
error: operation failed: Failed to take snapshot: unknown command: 'snapshot_blkdev'

Now it reports:

virsh # snapshot-create 23 --disk-only
error: unsupported configuration: live disk snapshot not supported with this QEMU binary

All versions of qemu that support live disk snapshot also support
QMP (basically upstream qemu 1.1 and later, and backports to RHEL 6.2).

* src/qemu/qemu_capabilities.h (QEMU_CAPS_DISK_SNAPSHOT): New
capability.
* src/qemu/qemu_capabilities.c (qemuCaps): Track it.
(qemuCapsProbeQMPCommands): Set it.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive): Use
it.
* src/qemu/qemu_monitor.c (qemuMonitorDiskSnapshot): Simplify.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskSnapshot):
Likewise.
* src/qemu/qemu_monitor_text.h (qemuMonitorTextDiskSnapshot):
Delete.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextDiskSnapshot):
Likewise.

12 years agorpc: fix build failure with older dbus
Eric Blake [Tue, 4 Dec 2012 22:45:11 +0000 (15:45 -0700)]
rpc: fix build failure with older dbus

RHEL 6.3 uses dbus-devel-1.2.24, which lacked support for the
DBUS_TYPE_UNIX_FD define (contrast with Fedora 18 using 1.6.8).
But since it is an older dbus, it also lacks support for shutdown
inhibitions as provided by newer systemd.

Compilation failure introduced in commit 31330926.

* src/rpc/virnetserver.c (virNetServerAddShutdownInhibition):
Compile out if dbus is too old.

12 years agoFix memory leak introduced by commit 501bfad1
Jim Fehlig [Tue, 4 Dec 2012 17:39:07 +0000 (10:39 -0700)]
Fix memory leak introduced by commit 501bfad1

501bfad1 missed freeing priv->saveDir when opening the Xen unified
driver failed.

12 years agoimplement managedsave in libvirt xen legacy driver
Bamvor Jian Zhang [Tue, 4 Dec 2012 10:00:02 +0000 (18:00 +0800)]
implement managedsave in libvirt xen legacy driver

Implement the domainManagedSave, domainHasManagedSaveImage, and
domainManagedSaveRemove functions in the libvirt legacy xen driver.

domainHasManagedSaveImage check the managedsave image from filesystem
everytime. This is different from qemu and libxl driver. In qemu or
libxl driver, there is a hasManagesSave flag in virDomainObjPtr which
is not used in xen legacy driver. This flag could not add into xen
driver ptr either, because the driver ptr will be released at the end of
every libvirt api call. Meanwhile, AFAIK, xen store all the flags in
xen not in libvirt xen driver. There is no need to add this flag in xen.

Signed-off-by: Bamvor Jian Zhang <bjzhang@suse.com>
12 years agoFix the indention
Osier Yang [Tue, 4 Dec 2012 15:37:41 +0000 (23:37 +0800)]
Fix the indention

Introduced by commit 1465876a, pushed under build-breaker &&
trivial rule.

12 years agoDo not export symbol virStateActive anymore
Osier Yang [Tue, 4 Dec 2012 15:34:48 +0000 (23:34 +0800)]
Do not export symbol virStateActive anymore

Commit 79b8a56995 removes virStateActive, however it forgot to
remove the symbol together. Pushed under build-breaker rule.

12 years agoBind connection close callback APIs to python binding
Daniel P. Berrange [Mon, 30 Jul 2012 16:30:42 +0000 (17:30 +0100)]
Bind connection close callback APIs to python binding

Add code in the python binding to cope with the new APIs
virConnectRegisterCloseCallback and
virConnectUnregisterCloseCallback. Also demonstrate their
use in the python domain events demo

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoShut down session libvirtd cleanly on host shutdown/user logout
Alexander Larsson [Wed, 31 Oct 2012 19:03:57 +0000 (19:03 +0000)]
Shut down session libvirtd cleanly on host shutdown/user logout

When the session dies or when the system is going to be shut down
we issue a virStateStop() call to instruct drivers to prepare to
be stopped. This will remove any previously acquire inhibitions.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoInhibit desktop shutdown while any virtual machines are running
Daniel P. Berrange [Wed, 31 Oct 2012 19:03:56 +0000 (19:03 +0000)]
Inhibit desktop shutdown while any virtual machines are running

Use the freedesktop inhibition DBus service to prevent host
shutdown or session logout while any VMs are running.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoReplace polling for active VMs with signalling by drivers
Daniel P. Berrange [Wed, 31 Oct 2012 19:03:55 +0000 (19:03 +0000)]
Replace polling for active VMs with signalling by drivers

Currently to deal with auto-shutdown libvirtd must periodically
poll all stateful drivers. Thus sucks because it requires
acquiring both the driver lock and locks on every single virtual
machine. Instead pass in a "inhibit" callback to virStateInitialize
which drivers can invoke whenever they want to inhibit shutdown
due to existance of active VMs.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoOnly let VM drivers block libvirtd timed shutdown
Daniel P. Berrange [Tue, 4 Dec 2012 12:12:51 +0000 (12:12 +0000)]
Only let VM drivers block libvirtd timed shutdown

The only important state that should prevent libvirtd shutdown
is from running VMs. Networks, host devices, network filters
and storage pools are all long lived resources that have no
significant in-memory state. They should not block shutdown.

12 years agoMake QEMU perform managed save of all VMs on stop of libvirtd
Daniel P. Berrange [Wed, 31 Oct 2012 19:03:53 +0000 (19:03 +0000)]
Make QEMU perform managed save of all VMs on stop of libvirtd

When the virStateStop() method is invoked, perform a managed
save of all VMs currently running

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agobuild: fix incremental autogen.sh when no AUTHORS is present
Eric Blake [Mon, 3 Dec 2012 20:12:09 +0000 (13:12 -0700)]
build: fix incremental autogen.sh when no AUTHORS is present

Commit 71d1256 tried to fix a problem where rebasing an old
branch on top of newer libvirt.git resulted in automake failing
because of a missing AUTHORS file.  However, while the fix
worked for an incremental 'make', it did not work for someone
that directly reran './autogen.sh'.  Reported by Laine Stump.

* autogen.sh (autoreconf): Check for same conditions as cfg.mk.
* cfg.mk (_update_required): Add comments.

12 years agoAdd iSCSI backend storage driver for ESX
Ata E Husain Bohra [Sat, 10 Nov 2012 07:18:08 +0000 (23:18 -0800)]
Add iSCSI backend storage driver for ESX

The patch adds the backend driver to support iSCSI format storage pools
and volumes for ESX host. The mapping of ESX iSCSI specifics to Libvirt
is as follows:

1. ESX static iSCSI target <------> Libvirt Storage Pools
2. ESX iSCSI LUNs          <------> Libvirt Storage Volumes.

The above understanding is based on http://libvirt.org/storage.html.

The operation supported on iSCSI pools includes:

1. List storage pools & volumes.
2. Get XML descriptor operaion on pools & volumes.
3. Lookup operation on pools & volumes by name, UUID and path (if applicable).

iSCSI pools does not support operations such as: Create / remove pools
and volumes.

12 years agoqemu: support live update of an interface's filter
Laine Stump [Mon, 12 Nov 2012 16:21:10 +0000 (11:21 -0500)]
qemu: support live update of an interface's filter

Since we can't (currently) rely on the ability to provide blanket
support for all possible network changes by calling the toplevel
netdev hostside disconnect/connect functions (due to qemu only
supporting a lockstep between initialization of host side and guest
side of devices), in order to support live change of an interface's
nwfilter we need to make a special purpose function to only call the
nwfilter teardown and setup functions if the filter for an interface
(or its parameters) changes. The pattern is nearly identical to that
used to change the bridge that an interface is connected to.

This patch was inspired by a request from Guido Winkelmann
<guido@sagersystems.de>, who tested an earlier version.

12 years agonwfilter: utility function virNWFilterVarValueEqual
Stefan Berger [Thu, 29 Nov 2012 17:49:32 +0000 (12:49 -0500)]
nwfilter: utility function virNWFilterVarValueEqual

To detect if an interface's nwfilter has changed, we need to also
compare the filterparams, which is a hashtable of virNWFilterVarValue.
virHashEqual can do this nicely, but requires a pointer to a function
that will compare two of the items being stored in the hashes.

12 years agoconf: fix virDomainNetGetActualDirect*() and BridgeName()
Laine Stump [Mon, 3 Dec 2012 17:24:46 +0000 (12:24 -0500)]
conf: fix virDomainNetGetActualDirect*() and BridgeName()

This resolves:

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

These three functions:

  virDomainNetGetActualBridgeName
  virDomainNetGetActualDirectDev
  virDomainNetGetActualDirectMode

return attributes that are in a union whose contents are interpreted
differently depending on the actual->type and so they should only
return non-0 when actual->type is 'bridge' (in the first case) or
'direct' (in the other two cases, but I had neglected to do that, so
...DirectDev() was returning bridge.brname (which happens to share the
same spot in the union with direct.linkdev) if actual->type was
'bridge', and ...BridgeName was returning direct.linkdev when
actual->type was 'direct'.

How does this involve Bug 881480 (which was about the inability to
switch between two networks that both have "<forward mode='bridge'/>
<bridge name='xxx'/>"? Whenever the return value of
virDomainNetGetActualDirectDev() for the new and old network
definitions doesn't match, qemuDomainChangeNet() requires a "complete
reconnect" of the device, which qemu currently doesn't
support. ...DirectDev() *should* have been returning NULL for old and
new, but was instead returning the old and new bridge names, which
differ.

(The other two functions weren't causing any behavioral problems in
virDomainChangeNet(), but their problem and fix was identical, so I
included them in this same patch).

12 years agovirsh: Report errors if arguments of the schedinfo command are incorrect
Peter Krempa [Mon, 3 Dec 2012 13:17:52 +0000 (14:17 +0100)]
virsh: Report errors if arguments of the schedinfo command are incorrect

Libvirt's helper API's when called directly don't raise the error so
that virsh remembers it. Subsequent calls to libvirt API's might reset
the error.

In case of schedinfo virDomainFree() in the cleanup section resets the
error when virTypedParameterAssignFromStr() fails.

This patch adds function vshSaveLibvirtError() that can be called after
calling libvirt helper APIs to ensure the error is remembered.

12 years agomaint: Misc whitespace cleanups
Peter Krempa [Mon, 3 Dec 2012 13:17:29 +0000 (14:17 +0100)]
maint: Misc whitespace cleanups

12 years agoconf: prevent crash with no uuid in cephx auth secret
Ján Tomko [Mon, 3 Dec 2012 12:35:05 +0000 (13:35 +0100)]
conf: prevent crash with no uuid in cephx auth secret

Fix the null pointer access when UUID is not specified.
Introduce a bool 'uuidUsable' to virStoragePoolAuthCephx that indicates
if uuid was specified or not and use it instead of the pointless
comparison of the static UUID array to NULL.
Add an error message if both uuid and usage are specified.

Fixes:
Error: FORWARD_NULL (CWE-476):
libvirt-0.10.2/src/conf/storage_conf.c:461: var_deref_model: Passing
    null pointer "uuid" to function "virUUIDParse(char const *, unsigned
    char *)", which dereferences it. (The dereference is assumed on the
    basis of the 'nonnull' parameter attribute.)
Error: NO_EFFECT (CWE-398):
    libvirt-0.10.2/src/conf/storage_conf.c:979: array_null: Comparing an
    array to null is not useful: "src->auth.cephx.secret.uuid != NULL".

12 years agoFix the coding style
Osier Yang [Mon, 3 Dec 2012 08:41:45 +0000 (16:41 +0800)]
Fix the coding style

Fix the "if ... else" coding style, and indentions problem.

12 years agoFix indentions
Osier Yang [Mon, 3 Dec 2012 01:57:00 +0000 (09:57 +0800)]
Fix indentions

12 years agovirsh: don't crash if shutdown --mode not provided
Eric Blake [Fri, 30 Nov 2012 21:48:24 +0000 (14:48 -0700)]
virsh: don't crash if shutdown --mode not provided

virStringSplit requires a non-NULL input, but commit cef78ed forgot
to follow the rule.

* tools/virsh-domain.c (cmdReboot, cmdShutdown): Avoid NULL deref.

12 years agologging: more API needing to log flags
Eric Blake [Fri, 30 Nov 2012 20:19:20 +0000 (13:19 -0700)]
logging: more API needing to log flags

Commit a21f5112 fixed one API, but missed two others that also
failed to log their 'flags' argument.

* src/libvirt.c (virNodeSuspendForDuration, virDomainGetHostname):
Log flags parameter.

12 years agos/flags=%u/flags=%x/ in earlier commit
Daniel P. Berrange [Fri, 30 Nov 2012 20:01:57 +0000 (20:01 +0000)]
s/flags=%u/flags=%x/ in earlier commit

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAllow duration=0 for virsh nodesuspend
Daniel P. Berrange [Fri, 30 Nov 2012 18:43:40 +0000 (18:43 +0000)]
Allow duration=0 for virsh nodesuspend

The virNodeSuspend API allows for a duration of 0, to mean no
timed wakup. virsh needlessly forbids this though

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAllow comma separated list of shutdown/reboot modes with virsh
Daniel P. Berrange [Fri, 30 Nov 2012 15:30:05 +0000 (15:30 +0000)]
Allow comma separated list of shutdown/reboot modes with virsh

The shutdown and reboot commands in virsh allow a comma
separated list of mode values

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>