]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agoEnable chains with names having a known prefix
Stefan Berger [Fri, 18 Nov 2011 16:58:18 +0000 (11:58 -0500)]
Enable chains with names having a known prefix

This patch enables chains that have a known prefix in their name.
Known prefixes are: 'ipv4', 'ipv6', 'arp', 'rarp'. All prefixes
are also protocols that can be evaluated on the ebtables level.

Following the prefix they will be automatically connected to an interface's
'root' chain and jumped into following the protocol they evaluate, i.e.,
a table 'arp-xyz' will be accessed from the root table using

ebtables -t nat -A <iface root table> -p arp -j I-<ifname>-arp-xyz

thus generating a 'root' chain like this one here:

Bridge chain: libvirt-O-vnet0, entries: 5, policy: ACCEPT
-p IPv4 -j O-vnet0-ipv4
-p ARP -j O-vnet0-arp
-p 0x8035 -j O-vnet0-rarp
-p ARP -j O-vnet0-arp-xyz
-j DROP

where the chain 'arp-xyz' is accessed for filtering of ARP packets.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoExtend the filter XML to support priorities of chains
Stefan Berger [Fri, 18 Nov 2011 16:58:17 +0000 (11:58 -0500)]
Extend the filter XML to support priorities of chains

This patch extends the filter XML to support priorities of chains
in the XML. An example would be:

<filter name='allow-arpxyz' chain='arp-xyz' priority='200'>
[...]
</filter>

The permitted values for priorities are [-1000, 1000].
By setting the priority of a chain the order in which it is accessed
from the interface root chain can be influenced.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoUse the actual names of chains in data structure
Stefan Berger [Fri, 18 Nov 2011 16:58:17 +0000 (11:58 -0500)]
Use the actual names of chains in data structure

Use the name of the chain rather than its type index (enum).
This pushes the later enablement of chains with user-given names
into the XML parser. For now we still only allow those names that
are well known ('root', 'arp', 'rarp', 'ipv4' and 'ipv6').

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoUse scripting for cleaning and renaming of chains
Stefan Berger [Fri, 18 Nov 2011 16:58:17 +0000 (11:58 -0500)]
Use scripting for cleaning and renaming of chains

Use scripts for the renaming and cleaning up of chains. This allows us to get
rid of some of the code that is only capable of renaming and removing chains
whose names are hardcoded.

A shell function 'collect_chains' is introduced that is given the name
of an ebtables chain and then recursively determines the names of all
chains that are accessed from this chain and its sub-chains using 'jumps'.

The resulting list of chain names is then used to delete all the found
chains by first flushing and then deleting them.

The same function is also used for renaming temporary filters to their final
names.

I tested this with the bash and dash as script interpreters.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoMake filter creation in root table more flexible
Stefan Berger [Fri, 18 Nov 2011 16:58:17 +0000 (11:58 -0500)]
Make filter creation in root table more flexible

Use the previously introduced chain priorities to sort the chains for access
from an interface's 'root' table and have them created in the proper order.
This gets rid of a lot of code that was previously creating the chains in a
more hardcoded way.

To determine what protocol a filter is used for evaluation do prefix-
matching, i.e., the filter 'arp' is used to filter for the 'arp' protocol,
'ipv4' for the 'ipv4' protocol and 'arp-xyz' will also be used to filter
for the 'arp' protocol following the prefix 'arp' in its name.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoIntroduce an internal priority for chains
Stefan Berger [Fri, 18 Nov 2011 16:58:17 +0000 (11:58 -0500)]
Introduce an internal priority for chains

For better handling of the sorting of chains introduce an internally used
priority. Use a lookup table to store the priorities. For now their actual
values do not matter just that the values cause the chains to be properly
sorted through changes in the following patches. However, the values are
chosen as negative so that once they are sorted along with filtering rules
(whose priority may only be positive for now) they will always be instantiated
before them (lower values cause instantiation before higher values). This
is done to maintain backwards compatibility.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoAdd function to get hash table's key/value pairs
Stefan Berger [Fri, 18 Nov 2011 16:58:17 +0000 (11:58 -0500)]
Add function to get hash table's key/value pairs

Add a function to the virHashTable for getting an array of the hash table's
key-value pairs and have the keys (optionally) sorted.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
13 years agoAdd support for systemd init service
Daniel P. Berrange [Thu, 7 Jul 2011 13:45:07 +0000 (14:45 +0100)]
Add support for systemd init service

This patch adds support for a systemd init service for libvirtd
and libvirt-guests. The libvirtd.service is *not* written to use
socket activation, since we want libvirtd to start on boot so it
can do guest auto-start.

The libvirt-guests.service is pretty lame, just exec'ing the
original init script for now. Ideally we would factor out the
functionality, into some shared tool.

Instead of

  ./configure --with-init-script=redhat

You can now do

  ./configure --with-init-script=systemd

Or better still:

  ./configure --with-init-script=systemd+redhat

We can also now support install of the upstart init script

* configure.ac: Add systemd, and systemd+redhat options to
  --with-init-script option
* daemon/Makefile.am: Install systemd services
* daemon/libvirtd.sysconf: Add note about unused env variable
  with systemd
* daemon/libvirtd.service.in: libvirtd systemd service unit
* libvirt.spec.in: Add scripts to installing systemd services
  and migrating from legacy init scripts
* tools/Makefile.am: Install systemd services
* tools/libvirt-guests.init.sh: Rename to tools/libvirt-guests.init.in
* tools/libvirt-guests.service.in: systemd service unit

13 years agoAdd support for interfaces with type=direct to LXC
Daniel P. Berrange [Thu, 10 Nov 2011 11:09:13 +0000 (11:09 +0000)]
Add support for interfaces with type=direct to LXC

Support creation of macvlan devices for LXC containers. Do not
allow setting of bandwidth controls or vport profiles due to the
complication that there is no host side visible device to work
with.

* src/lxc/lxc_driver.c: Support type=direct interfaces

13 years agoAllow creation of plain macvlan devices
Daniel P. Berrange [Thu, 10 Nov 2011 10:29:09 +0000 (10:29 +0000)]
Allow creation of plain macvlan devices

Update virNetDevMacVLanCreateWithVPortProfile to allow creation
of plain macvlan devices, as well as macvtap devices. The former
is useful for LXC containers

* src/qemu/qemu_command.c: Explicitly request a macvtap device
* src/util/virnetdevmacvlan.c, src/util/virnetdevmacvlan.h: Add
  new flag to allow switching between macvlan and macvtap
  creation

13 years agoRefactor LXC network setup to allow future enhancements
Daniel P. Berrange [Thu, 10 Nov 2011 09:19:25 +0000 (09:19 +0000)]
Refactor LXC network setup to allow future enhancements

The current lxcSetupInterfaces() method directly performs setup
of the bridge devices. Since it will shortly need to also create
macvlan devices, move the bridge related code into a separate
method

* src/lxc/lxc_driver.c: Split lxcSetupInterfaces() to create a
  new lxcSetupInterfaceBridge()

13 years agoAdd missing 'const' annotations for internal domain conf helpers
Daniel P. Berrange [Thu, 10 Nov 2011 11:18:57 +0000 (11:18 +0000)]
Add missing 'const' annotations for internal domain conf helpers

The virDomainNetGetActualBridgeName and virDomainNetGetActualDirectDev
methods both return strings that point to data in the virDomainDefPtr
struct, and should therefore not be freed. The return values should
thus be 'const char *' not 'char *'.

* src/conf/domain_conf.c, src/conf/domain_conf.h: Mark const
* src/network/bridge_driver.c: Update to use a const char *

13 years agoFix up ordering of private symbols file
Daniel P. Berrange [Fri, 18 Nov 2011 16:07:48 +0000 (16:07 +0000)]
Fix up ordering of private symbols file

Fix ordering of symbols after re-arranging network device
management API source files

* src/libvirt_private.syms: Fix ordering

13 years agoMove ifaceMacvtapLinkDump and ifaceGetNthParent functions
Daniel P. Berrange [Thu, 3 Nov 2011 13:41:40 +0000 (13:41 +0000)]
Move ifaceMacvtapLinkDump and ifaceGetNthParent functions

Move the ifaceMacvtapLinkDump and ifaceGetNthParent functions
into virnetdevvportprofile.c since they are specific to that
code. This avoids polluting the headers with the Linux specific
netlink data types

* src/util/interface.c, src/util/interface.h: Move
  ifaceMacvtapLinkDump and ifaceGetNthParent functions and delete
  remaining file
* src/util/virnetdevvportprofile.c: Add ifaceMacvtapLinkDump
  and ifaceGetNthParent functions
* src/network/bridge_driver.c, src/nwfilter/nwfilter_gentech_driver.c,
  src/nwfilter/nwfilter_learnipaddr.c, src/util/virnetdevmacvlan.c:
  Remove include of interface.h

13 years agoMove functions for dealing with physical/virtual devices
Daniel P. Berrange [Thu, 3 Nov 2011 12:40:33 +0000 (12:40 +0000)]
Move functions for dealing with physical/virtual devices

Move virNetDevIsVirtualFunction, virNetDevGetVirtualFunctionIndex
and virNetDevGetPhysicalFunction to virnetdev.c

* src/util/interface.c, src/util/interface.h, src/util/virnetdev.c,
  src/util/virnetdev.h: Move APIs

13 years agoRename APIs for dealing with virtual/physical functions
Daniel P. Berrange [Thu, 3 Nov 2011 12:37:07 +0000 (12:37 +0000)]
Rename APIs for dealing with virtual/physical functions

Rename ifaceIsVirtualFunction to virNetDevIsVirtualFunction,
ifaceGetVirtualFunctionIndex to virNetDevGetVirtualFunctionIndex
and ifaceGetPhysicalFunction to virNetDevGetPhysicalFunction

* src/util/interface.c, src/util/interface.h: Rename APIs
* src/util/virnetdevvportprofile.c: Update for API rename

13 years agoMove virNetDevValidateConfig to virnetdev.c
Daniel P. Berrange [Thu, 3 Nov 2011 12:32:38 +0000 (12:32 +0000)]
Move virNetDevValidateConfig to virnetdev.c

* src/util/interface.c, src/util/interface.h: Remove virNetDevValidateConfig
* src/util/virnetdev.c, src/util/virnetdev.h: Add virNetDevValidateConfig

13 years agoRename ifaceCheck to virNetDevValidateConfig
Daniel P. Berrange [Thu, 3 Nov 2011 12:28:17 +0000 (12:28 +0000)]
Rename ifaceCheck to virNetDevValidateConfig

Rename the ifaceCheck method to virNetDevValidateConfig and change
so that it always raises an error and returns -1 on error.

* src/util/interface.c, src/util/interface.h: Rename ifaceCheck
  to virNetDevValidateConfig
* src/nwfilter/nwfilter_gentech_driver.c,
  src/nwfilter/nwfilter_learnipaddr.c: Update for API rename

13 years agoMove virNetDevGetIPv4Address to virnetdev.c
Daniel P. Berrange [Thu, 3 Nov 2011 10:35:17 +0000 (10:35 +0000)]
Move virNetDevGetIPv4Address to virnetdev.c

Move the virNetDevGetIPv4Address function to virnetdev.c

* util/interface.c, util/interface.h: Remove virNetDevGetIPv4Address
* util/virnetdev.c, util/virnetdev.h: Add virNetDevGetIPv4Address

13 years agoRename ifaceGetIPAddress to virNetDevGetIPv4Address
Daniel P. Berrange [Thu, 3 Nov 2011 10:31:01 +0000 (10:31 +0000)]
Rename ifaceGetIPAddress to virNetDevGetIPv4Address

To match up with the existing virNetDevSetIPv4Address, rename
ifaceGetIPAddress to virNetDevGetIPv4Address

* util/interface.h, util/interface.c: Rename API
* network/bridge_driver.c: Update for API rename

13 years agoMove virNetDevGetIndex & virNetDevGetVLanID to virnetdev.c
Daniel P. Berrange [Thu, 3 Nov 2011 09:27:45 +0000 (09:27 +0000)]
Move virNetDevGetIndex & virNetDevGetVLanID to virnetdev.c

Move virNetDevGetIndex & virNetDevGetVLanID to virnetdev.c to
suit their functional purpose

* util/interface.c, util/interface.h: Remove virNetDevGetIndex &
  virNetDevGetVLanID
* util/virnetdev.c, util/virnetdev.h: Add virNetDevGetIndex &
  virNetDevGetVLanID

13 years agoRename ifaceGetIndex and ifaceGetVLAN
Daniel P. Berrange [Thu, 3 Nov 2011 09:21:35 +0000 (09:21 +0000)]
Rename ifaceGetIndex and ifaceGetVLAN

Rename the ifaceGetIndex method to virNetDevGetIndex and
ifaceGetVlanID to virNetDevGetVLanID. Also change the error
reporting behaviour to always raise errors and return -1 on
failure

* util/interface.c, util/interface.h: Rename ifaceGetIndex
  and ifaceGetVLAN
* nwfilter/nwfilter_gentech_driver.c, nwfilter/nwfilter_learnipaddr.c,
  nwfilter/nwfilter_learnipaddr.c, util/virnetdevvportprofile.c: Update
  for API renames and error handling changes

13 years agoMove MAC address replacement functions to virnetdev.c
Daniel P. Berrange [Wed, 2 Nov 2011 17:40:50 +0000 (17:40 +0000)]
Move MAC address replacement functions to virnetdev.c

Move virNetDevReplaceMacAddress and virNetDevRestoreMacAddress
to the virnetdev.c file where they naturally belong

* util/interface.c, util/interface.h: Remove
  virNetDevReplaceMacAddress and virNetDevRestoreMacAddress
* util/virnetdev.c, util/virnetdev.h: Add
  virNetDevReplaceMacAddress and virNetDevRestoreMacAddress

13 years agoRename interface MAC address replacement APIs
Daniel P. Berrange [Wed, 2 Nov 2011 17:38:26 +0000 (17:38 +0000)]
Rename interface MAC address replacement APIs

Rename ifaceReplaceMacAddress to virNetDevReplaceMacAddress
and ifaceRestoreMacAddress to virNetDevRestoreMacAddress.

* util/interface.c, util/interface.h, util/virnetdevmacvlan.c:
  Rename APIs

13 years agoMove the low level macvlan creation APIs
Daniel P. Berrange [Wed, 2 Nov 2011 17:34:41 +0000 (17:34 +0000)]
Move the low level macvlan creation APIs

Move the low level macvlan creation APIs into the
virnetdevmacvlan.c file where they more naturally
belong

* util/interface.c, util/interface.h: Remove virNetDevMacVLanCreate
  and virNetDevMacVLanDelete
* util/virnetdevmacvlan.c, util/virnetdevmacvlan.h: Add
  virNetDevMacVLanCreate and virNetDevMacVLanDelete

13 years agoRename low level macvlan creation APIs
Daniel P. Berrange [Wed, 2 Nov 2011 17:26:11 +0000 (17:26 +0000)]
Rename low level macvlan creation APIs

Rename ifaceMacvtapLinkAdd to virNetDevMacVLanCreate and
ifaceLinkDel to virNetDevMacVLanDelete. Strictly speaking
the latter isn't restricted to macvlan devices, but that's
the only use libvirt has for it.

* util/interface.c, util/interface.h,
  util/virnetdevmacvlan.c: Rename APIs

13 years agoRename high level macvlan creation APIs
Daniel P. Berrange [Wed, 2 Nov 2011 17:19:48 +0000 (17:19 +0000)]
Rename high level macvlan creation APIs

Rename virNetDevMacVLanCreate to virNetDevMacVLanCreateWithVPortProfile
and virNetDevMacVLanDelete to virNetDevMacVLanDeleteWithVPortProfile

To make way for renaming the other macvlan creation APIs in
interface.c

* util/virnetdevmacvlan.c, util/virnetdevmacvlan.h,
  qemu/qemu_command.c, qemu/qemu_hotplug.c, qemu/qemu_process.c:
  Rename APIs

13 years agoRename and split the macvtap.c file
Daniel P. Berrange [Wed, 2 Nov 2011 17:11:02 +0000 (17:11 +0000)]
Rename and split the macvtap.c file

Rename the macvtap.c file to virnetdevmacvlan.c to reflect its
functionality. Move the port profile association code out into
virnetdevvportprofile.c. Make the APIs available unconditionally
to callers

* src/util/macvtap.h: rename to src/util/virnetdevmacvlan.h,
* src/util/macvtap.c: rename to src/util/virnetdevmacvlan.c
* src/util/virnetdevvportprofile.c, src/util/virnetdevvportprofile.h:
  Pull in vport association code
* src/Makefile.am, src/conf/domain_conf.h, src/qemu/qemu_conf.c,
  src/qemu/qemu_conf.h, src/qemu/qemu_driver.c: Update include
  paths & remove conditional compilation

13 years agoRename Macvtap management APIs
Daniel P. Berrange [Wed, 2 Nov 2011 16:51:01 +0000 (16:51 +0000)]
Rename Macvtap management APIs

In preparation for code re-organization, rename the Macvtap
management APIs to have the following patterns

  virNetDevMacVLanXXXXX     - macvlan/macvtap interface management
  virNetDevVPortProfileXXXX - virtual port profile management

* src/util/macvtap.c, src/util/macvtap.h: Rename APIs
* src/conf/domain_conf.c, src/network/bridge_driver.c,
  src/qemu/qemu_command.c, src/qemu/qemu_command.h,
  src/qemu/qemu_driver.c, src/qemu/qemu_hotplug.c,
  src/qemu/qemu_migration.c, src/qemu/qemu_process.c,
  src/qemu/qemu_process.h: Update for renamed APIs

13 years agoFix use of uninitialized variable in QEMU driver
Daniel P. Berrange [Fri, 18 Nov 2011 16:09:35 +0000 (16:09 +0000)]
Fix use of uninitialized variable in QEMU driver

13 years agoqemu: Generate -numa option
Bharata B Rao [Fri, 11 Nov 2011 12:53:04 +0000 (18:23 +0530)]
qemu: Generate -numa option

Add routines to generate -numa QEMU command line option based on
<numa> ... </numa> XML specifications.

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
13 years agoXML definitions for guest NUMA and parsing routines
Bharata B Rao [Fri, 11 Nov 2011 12:51:45 +0000 (18:21 +0530)]
XML definitions for guest NUMA and parsing routines

This patch adds XML definitions for guest NUMA specification and contains
routines to parse the same. The guest NUMA specification looks like this:

<cpu>
        ...
        <topology sockets='2' cores='4' threads='2'/>
        <numa>
                <cell cpus='0-7' memory='512000'/>
                <cell cpus='8-15' memory='512000'/>
        </numa>
        ...
</cpu>

Signed-off-by: Bharata B Rao <bharata@linux.vnet.ibm.com>
13 years agosnapshot: refuse to generate names for non-regular backing files
Eric Blake [Wed, 16 Nov 2011 00:19:20 +0000 (17:19 -0700)]
snapshot: refuse to generate names for non-regular backing files

For whatever reason, the kernel allows you to create a regular
file named /dev/sdc.12345; although this file will disappear the
next time devtmpfs is remounted.  If you let libvirt generate
the name of the external snapshot for a disk image originally
using the block device /dev/sdc, then the domain will be rendered
unbootable once the qcow2 file is lost on the next devtmpfs
remount.  In this case, the user should have used 'virsh
snapshot-create --xmlfile' or 'virsh snapshot-create-as --diskspec'
to specify the name for the qcow2 file in a sane location, rather
than relying on libvirt generating a name that is most likely to
be wrong.  We can help avoid naive mistakes by enforcing that
the user provide the external name for any backing file that is
not a regular file.

* src/conf/domain_conf.c (virDomainSnapshotAlignDisks): Only
generate names if backing file exists as regular file.
Reported by MATSUDA Daiki.

13 years agoFix build with polkit0
Jim Fehlig [Wed, 16 Nov 2011 18:35:08 +0000 (11:35 -0700)]
Fix build with polkit0

I missed adding virNetServerGetDBusConn() to libvirtd_private.syms
in commit b8adfcc6, which didn't cause a problem in 0.9.6 but
results in this build error in 0.9.7

libvirtd-remote.o: In function `remoteDispatchAuthPolkit':
remote.c:(.text+0x188dd): undefined reference to `virNetServerGetDBusConn'

13 years agoRevert commit 0f590c62
Jim Fehlig [Wed, 16 Nov 2011 18:29:14 +0000 (11:29 -0700)]
Revert commit 0f590c62

As noted by Daniel Berrange [1], the proper fix for the older
PolicyKit build issue is to add virNetServerGetDBusConn to
libvirt_private.syms.  Revert unnecessary changes to
daemon/Makefile.am

[1] https://www.redhat.com/archives/libvir-list/2011-November/msg00852.html

13 years agovirsh: add iface-bridge and iface-unbridge commands
Laine Stump [Mon, 7 Nov 2011 16:15:58 +0000 (11:15 -0500)]
virsh: add iface-bridge and iface-unbridge commands

One of the top questions by libvirt users is how to create a host
bridge device so that guests can be directly on the physical
network. There are several example documents that explain how to do
this manually, but following them often results in confusion and
failure. virt-manager does a good job of creating a bridge based on an
existing network device, but not everyone wants to use virt-manager.

This patch adds a new command, iface-bridge that makes it just about
as simple as possible to create a new bridge device based on an
existing ethernet/vlan/bond device (including associating IP
configuration with the bridge rather than the now-attached device),
and start that new bridge up ready for action, eg:

    virsh iface-bridge eth0 br0

For symmetry's sake, it also adds a command to remove a device from a
bridge, restoring the IP config to the now-unattached device:

    virsh iface-unbridge br0

(I had a short debate about whether to do "iface-unbridge eth0"
instead, but that would involve searching through all bridge devices
for the one that contained eth0, which seems like a bit too much
trouble).

NOTE: These two commands require that the netcf library be available
on the host. Hopefully this will provide some extra incentive for
people using suse, debian, ubuntu, and other similar systems to polish
up (and push downstream) the ports to those distros recently pushed to
the upstream netcf repo by Dan Berrange. Anyone interested in helping
with that effort in any way should join the netcf-devel mailing list
(subscription info at
https://fedorahosted.org/mailman/listinfo/netcf-devel)

During creation of the bridge, it's possible to specify whether or not
the STP protocol should be started up on the bridge and, if so, how
many seconds the bridge should squelch traffic from newly added
devices while learning new topology (defaults are stp='on' and
delay='0', which seems to usually work best for bridges used in the
context of libvirt guests).

There is also an option to not immediately start the bridge (and a
similar option to not immediately start the un-attached device after
destroying the bridge. Default is to start the new device, because in
the case of iface-unbridge not starting is strongly discouraged as it
will leave the system with no network connectivity on that interface
(because it's necessary to destroy/undefine the bridge device before
the unattached device can be defined), and it seemed better to make
the option for iface-bridge behave consistently.

NOTE TO THOSE TRYING THESE COMMANDS FOR THE FIRST TIME: to guard
against any "unexpected" change to configuration, it is advisable to
issue an "virsh iface-begin" command before starting any interface
config changes, and "virsh iface-commit" only after you've verified
that everything is working as you expect. If something goes wrong,
you can always run "virsh iface-rollback" or reboot the system (which
should automatically do iface-rollback).

Aside from adding the code for these two functions, and the two
entries into the command table, the only other change to virsh.c was
to add the option name to vshCommandOptInterfaceBy(), because the
iface-unbridge command names its interface option as "bridge".

virsh.pod has also been updated with short descriptions of these two
new commands.

13 years agofix a bug in remoteSerializeTypedParameters
Hu Tao [Wed, 16 Nov 2011 08:38:11 +0000 (16:38 +0800)]
fix a bug in remoteSerializeTypedParameters

This is a fatal typo believed to be very likely to happen when using
both i and j at the same time for indexing.

13 years agoDon't return a fatal error if receiving unexpected stream data
Daniel P. Berrange [Wed, 9 Nov 2011 13:54:01 +0000 (13:54 +0000)]
Don't return a fatal error if receiving unexpected stream data

Due to the asynchronous nature of streams, we might continue to
receive some stream packets from the server even after we have
shutdown the stream on the client side. These should be discarded
silently, rather than raising an error in the RPC layer.

* src/rpc/virnetclient.c: Discard stream data silently

13 years agoFix handling of stream EOF
Daniel P. Berrange [Fri, 7 Oct 2011 16:38:59 +0000 (17:38 +0100)]
Fix handling of stream EOF

Very occasionally the sequence of events from poll would result
in getting a HANGUP on its own, instead of a HANGUP+READABLE
at the same time. In the former case we would send back an error
event to the client, but never send the empty packet to indicate
EOF.

13 years agoAllow non-blocking message sending on virNetClient
Daniel P. Berrange [Tue, 8 Nov 2011 09:13:27 +0000 (09:13 +0000)]
Allow non-blocking message sending on virNetClient

Add a new virNetClientSendNonBlock which returns 2 on
full send, 1 on partial send, 0 on no send, -1 on error

If a partial send occurs, then a subsequent call to any
of the virNetClientSend* APIs will finish any outstanding
I/O.

TODO: the virNetClientEvent event handler could be used
to speed up completion of partial sends if an event loop
is present.

* src/rpc/virnetsocket.h, src/rpc/virnetsocket.c: Add new
  virNetSocketHasPendingData() API to test for cached
  data pending send.
* src/rpc/virnetclient.c, src/rpc/virnetclient.h: Add new
  virNetClientSendNonBlock() API to send non-blocking API

13 years agoRefactor code for enabling/disabling I/O callback in remote client
Daniel P. Berrange [Fri, 11 Nov 2011 15:45:44 +0000 (15:45 +0000)]
Refactor code for enabling/disabling I/O callback in remote client

* src/rpc/virnetclient.c: Add helper for setting I/O callback events

13 years agoSplit virNetClientSend into 2 methods
Daniel P. Berrange [Fri, 11 Nov 2011 15:42:46 +0000 (15:42 +0000)]
Split virNetClientSend into 2 methods

Stop multiplexing virNetClientSend for two different purposes,
instead add virNetClientSendWithReply and virNetClientSendNoReply

* src/rpc/virnetclient.c, src/rpc/virnetclient.h: Replace
  virNetClientSend with virNetClientSendWithReply and
  virNetClientSendNoReply
* src/rpc/virnetclientprogram.c, src/rpc/virnetclientstream.c:
  Update for new API names

13 years agoRefactor code for passing the buck in the remote client
Daniel P. Berrange [Fri, 11 Nov 2011 15:34:08 +0000 (15:34 +0000)]
Refactor code for passing the buck in the remote client

Remove some duplication by pulling the code for passing the
buck out into a helper method

* src/rpc/virnetclient.c: Introduce virNetClientIOEventLoopPassTheBuck

13 years agoExplicitly track whether the buck is held in remote client
Daniel P. Berrange [Fri, 11 Nov 2011 15:28:41 +0000 (15:28 +0000)]
Explicitly track whether the buck is held in remote client

Instead of inferring whether the buck is held from the waitDispatch
pointer, use an explicit 'bool haveTheBuck' field

* src/rpc/virnetclient.c: Explicitly track the buck

13 years agoRemove all linked list handling from remote client event loop
Daniel P. Berrange [Fri, 11 Nov 2011 15:26:16 +0000 (15:26 +0000)]
Remove all linked list handling from remote client event loop

Directly messing around with the linked list is potentially
dangerous. Introduce some helper APIs to deal with list
manipulating the list

* src/rpc/virnetclient.c: Create linked list handlers

13 years agoutil: Add netdev helper functions to private symbols
Eli Qiao [Wed, 16 Nov 2011 02:59:57 +0000 (10:59 +0800)]
util: Add netdev helper functions to private symbols

Signed-off-by: Eli Qiao <taget@linux.vnet.ibm.com>
13 years agoqemu/rbd: improve rbd device specification
Sage Weil [Tue, 1 Nov 2011 01:29:07 +0000 (18:29 -0700)]
qemu/rbd: improve rbd device specification

This improves the support for qemu rbd devices by adding support for a few
key features (e.g., authentication) and cleaning up the way in which
rbd configuration options are passed to qemu.

An <auth> member of the disk source xml specifies how librbd should
authenticate. The username attribute is the Ceph/RBD user to authenticate as.
The usage or uuid attributes specify which secret to use. Usage is an
arbitrary identifier local to libvirt.

The old RBD support relied on setting an environment variable to
communicate information to qemu/librbd.  Instead, pass those options
explicitly to qemu.  Update the qemu argument parsing and tests
accordingly.

Signed-off-by: Sage Weil <sage@newdream.net>
Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
13 years agoFix build with polkit0
Jim Fehlig [Tue, 15 Nov 2011 22:11:49 +0000 (15:11 -0700)]
Fix build with polkit0

I missed adding libvirt_driver_remote.la to libvirtd_LDADD in
commit b8adfcc6, which didn't cause a problem in 0.9.6 but
results in this build error in 0.9.7

libvirtd-remote.o: In function `remoteDispatchAuthPolkit':
remote.c:(.text+0x188dd): undefined reference to `virNetServerGetDBusConn'

13 years agoFix strchr call triggering gcc 4.3 & 4.4 bug
Stefan Berger [Tue, 15 Nov 2011 17:48:07 +0000 (12:48 -0500)]
Fix strchr call triggering gcc 4.3 & 4.4 bug

Replacing the strchr call with two variables through a strstr call.
Calling strchr with two variables triggers a gcc 4.3/4.4
bug when used in combination with -Wlogical-op and at least -O1.

13 years agomaint: fix build
Stefan Berger [Tue, 15 Nov 2011 19:56:05 +0000 (14:56 -0500)]
maint: fix build

include stdint.h to fix the build

13 years agoRemove ifaceSetMac and ifaceGetMac APIs
Daniel P. Berrange [Wed, 2 Nov 2011 16:16:33 +0000 (16:16 +0000)]
Remove ifaceSetMac and ifaceGetMac APIs

The ifaceSetMac and ifaceGetMac APIs duplicate the functionality
of the virNetDevSetMAC and virNetDevGetMAC APIs, but returning
errno's instead of raising errors.

* src/util/interface.c, src/util/interface.h: Remove
  ifaceSetMac and ifaceGetMac APIs, adjusting callers
  for new error behaviour

13 years agoRemove ifaceUp, ifaceDown, ifaceCtrl & ifaceIsUp APIs
Daniel P. Berrange [Wed, 2 Nov 2011 16:10:56 +0000 (16:10 +0000)]
Remove ifaceUp, ifaceDown, ifaceCtrl & ifaceIsUp APIs

The ifaceUp, ifaceDown, ifaceCtrl & ifaceIsUp APIs can be replaced
with calls to virNetDevSetOnline and virNetDevIsOnline

* src/util/interface.c, src/util/interface.h: Delete ifaceUp,
  ifaceDown, ifaceCtrl & ifaceIsUp
* src/nwfilter/nwfilter_gentech_driver.c, src/util/macvtap.c:
  Update to use virNetDevSetOnline and virNetDevIsOnline

13 years agoMove LXC veth.c code into shared utility APIs
Daniel P. Berrange [Wed, 2 Nov 2011 16:03:09 +0000 (16:03 +0000)]
Move LXC veth.c code into shared utility APIs

Move the virNetDevSetName and virNetDevSetNamespace APIs out
of LXC's veth.c and into virnetdev.c.

Move the remaining content of the file to src/util/virnetdevveth.c

* src/lxc/veth.c: Rename to src/util/virnetdevveth.c
* src/lxc/veth.h: Rename to src/util/virnetdevveth.h
* src/util/virnetdev.c, src/util/virnetdev.h: Add
  virNetDevSetName and virNetDevSetNamespace
* src/lxc/lxc_container.c, src/lxc/lxc_controller.c,
  src/lxc/lxc_driver.c: Update include paths

13 years agoRename the LXC veth management APIs and delete duplicated APIs
Daniel P. Berrange [Wed, 2 Nov 2011 15:53:39 +0000 (15:53 +0000)]
Rename the LXC veth management APIs and delete duplicated APIs

The src/lxc/veth.c file contains APIs for managing veth devices,
but some of the APIs duplicate stuff from src/util/virnetdev.h.
Delete thed duplicate APIs and rename the remaining ones to
follow virNetDevVethXXXX

* src/lxc/veth.c, src/lxc/veth.h: Rename APIs & delete duplicates
* src/lxc/lxc_container.c, src/lxc/lxc_controller.c,
  src/lxc/lxc_driver.c: Update for API renaming

13 years agoSplit src/util/network.{c,h} into 5 pieces
Daniel P. Berrange [Wed, 2 Nov 2011 15:40:08 +0000 (15:40 +0000)]
Split src/util/network.{c,h} into 5 pieces

The src/util/network.c file is a dumping ground for many different
APIs. Split it up into 5 pieces, along functional lines

 - src/util/virnetdevbandwidth.c: virNetDevBandwidth type & helper APIs
 - src/util/virnetdevvportprofile.c: virNetDevVPortProfile type & helper APIs
 - src/util/virsocketaddr.c: virSocketAddr and APIs
 - src/conf/netdev_bandwidth_conf.c: XML parsing / formatting
   for virNetDevBandwidth
 - src/conf/netdev_vport_profile_conf.c: XML parsing / formatting
   for virNetDevVPortProfile

* src/util/network.c, src/util/network.h: Split into 5 pieces
* src/conf/netdev_bandwidth_conf.c, src/conf/netdev_bandwidth_conf.h,
  src/conf/netdev_vport_profile_conf.c, src/conf/netdev_vport_profile_conf.h,
  src/util/virnetdevbandwidth.c, src/util/virnetdevbandwidth.h,
  src/util/virnetdevvportprofile.c, src/util/virnetdevvportprofile.h,
  src/util/virsocketaddr.c, src/util/virsocketaddr.h: New pieces
* daemon/libvirtd.h, daemon/remote.c, src/conf/domain_conf.c,
  src/conf/domain_conf.h, src/conf/network_conf.c,
  src/conf/network_conf.h, src/conf/nwfilter_conf.h,
  src/esx/esx_util.h, src/network/bridge_driver.c,
  src/qemu/qemu_conf.c, src/rpc/virnetsocket.c,
  src/rpc/virnetsocket.h, src/util/dnsmasq.h, src/util/interface.h,
  src/util/iptables.h, src/util/macvtap.c, src/util/macvtap.h,
  src/util/virnetdev.h, src/util/virnetdevtap.c,
  tools/virsh.c: Update include files

13 years agoFix error reporting in port profile parsing/formatting APIs
Daniel P. Berrange [Wed, 2 Nov 2011 14:53:35 +0000 (14:53 +0000)]
Fix error reporting in port profile parsing/formatting APIs

The virtual port profile parsing/formatting APIs do not
correctly handle unknown profile type strings/numbers.
They behave as a no-op, instead of raising an error

* src/util/network.c, src/util/network.h: Fix error
  handling of port profile APIs
* src/conf/domain_conf.c, src/conf/network_conf.c: Update
  for API changes

13 years agoRename virVirtualPortProfileParams & APIs
Daniel P. Berrange [Wed, 2 Nov 2011 14:43:16 +0000 (14:43 +0000)]
Rename virVirtualPortProfileParams & APIs

Rename the virVirtualPortProfileParams struct to be
virNetDevVPortProfile, and rename the APIs to match
this prefix.

* src/util/network.c, src/util/network.h: Rename port profile
  APIs
* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/conf/network_conf.c, src/conf/network_conf.h,
  src/network/bridge_driver.c, src/qemu/qemu_hotplug.c,
  src/util/macvtap.c, src/util/macvtap.h: Update for
  renamed APIs/structs

13 years agomaint: Add Michael Wood as an author
Stefan Berger [Mon, 14 Nov 2011 20:26:55 +0000 (15:26 -0500)]
maint: Add Michael Wood as an author

Add Michael Wood <esiotrot@gmail.com> as an author.

13 years agoPATCH: Fix build without MACVTAP
Michael Wood [Sat, 12 Nov 2011 11:39:17 +0000 (13:39 +0200)]
PATCH: Fix build without MACVTAP

Hi

Commit c31d23a78715f1144c73862c46ab0436de8b5e85 removed the "conn"
parameter from qemuPhysIfaceConnect(), but it's still used if
WITH_MACVTAP is false.  Also, it's still mentioned in the comment
above the function:

/**
 * qemuPhysIfaceConnect:
 * @def: the definition of the VM (needed by 802.1Qbh and audit)
 * @conn: pointer to virConnect object
 * @driver: pointer to the qemud_driver
 * @net: pointer to he VM's interface description with direct device type
 * @qemuCaps: flags for qemu
 *
 * Returns a filedescriptor on success or -1 in case of error.
 */
int
qemuPhysIfaceConnect(virDomainDefPtr def,
                     struct qemud_driver *driver,
                     virDomainNetDefPtr net,
                     virBitmapPtr qemuCaps,
                     enum virVMOperationType vmop)
{
    int rc;
#if WITH_MACVTAP
[...]
#else
    (void)def;
    (void)conn;
    (void)net;
    (void)qemuCaps;
    (void)driver;
    (void)vmop;
    qemuReportError(VIR_ERR_INTERNAL_ERROR,
                    "%s", _("No support for macvtap device"));
    rc = -1;
#endif
    return rc;
}

--
Michael Wood <esiotrot@gmail.com>

From f4fc43b4111a4c099395c55902e497b8965e2b53 Mon Sep 17 00:00:00 2001
From: Michael Wood <esiotrot@gmail.com>
Date: Sat, 12 Nov 2011 13:37:53 +0200
Subject: [PATCH] Fix build without MACVTAP.

13 years agostorage: forbid rebuilding existing disk storage pools
Guido Günther [Sat, 12 Nov 2011 12:31:52 +0000 (13:31 +0100)]
storage: forbid rebuilding existing disk storage pools

which would blow away all volumes. Honor VIR_STORAGE_POOL_BUILD_OVERWRITE
to force a rebuild.

This was caught by libvirt-tck's storage/110-disk-pool.t.

13 years agoAPI: add trivial qemu support for VIR_TYPED_PARAM_STRING
Eric Blake [Tue, 1 Nov 2011 22:48:38 +0000 (16:48 -0600)]
API: add trivial qemu support for VIR_TYPED_PARAM_STRING

Qemu will be the first driver to make use of a typed string in the
next round of additions.  Separate out the trivial addition.

* src/qemu/qemu_driver.c (qemudSupportsFeature): Advertise feature.
(qemuDomainGetBlkioParameters, qemuDomainGetMemoryParameters)
(qemuGetSchedulerParametersFlags, qemudDomainBlockStatsFlags):
Allow typed strings flag where trivially supported.

13 years agoAPI: remote support for VIR_TYPED_PARAM_STRING
Eric Blake [Wed, 12 Oct 2011 09:26:34 +0000 (17:26 +0800)]
API: remote support for VIR_TYPED_PARAM_STRING

Send and receive string typed parameters across RPC.  This also
completes the back-compat mentioned in the previous patch - the
only time we have an older client talking to a newer server is
if RPC is in use, so filtering out strings during RPC prevents
returning an unknown type to the older client.

* src/remote/remote_protocol.x (remote_typed_param_value): Add
another union value.
* daemon/remote.c (remoteDeserializeTypedParameters): Handle
strings on rpc.
(remoteSerializeTypedParameters): Likewise; plus filter out
strings when replying to older clients.  Adjust callers.
* src/remote/remote_driver.c (remoteFreeTypedParameters)
(remoteSerializeTypedParameters)
(remoteDeserializeTypedParameters): Handle strings on rpc.
* src/rpc/gendispatch.pl: Properly clean up typed arrays.
* src/remote_protocol-structs: Update.
Based on an initial patch by Hu Tao, with feedback from
Daniel P. Berrange.

Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoAPI: add VIR_TYPED_PARAM_STRING
Eric Blake [Wed, 12 Oct 2011 09:26:34 +0000 (17:26 +0800)]
API: add VIR_TYPED_PARAM_STRING

This allows strings to be transported between client and server
in the context of name-type-value virTypedParameter functions.
For compatibility,

    o new clients will not send strings to old servers, based on
      a feature check
    o new servers will not send strings to old clients without the
      flag VIR_TYPED_PARAM_STRING_OKAY; this will be enforced at
      the RPC layer in the next patch, so that drivers need not
      worry about it in general.  The one exception is that
      virDomainGetSchedulerParameters lacks a flags argument, so
      it must not return a string; drivers that forward that
      function on to virDomainGetSchedulerParametersFlags will
      have to pay attention to the flag.
    o the flag VIR_TYPED_PARAM_STRING_OKAY is set automatically,
      based on a feature check (so far, no driver implements it),
      so clients do not have to worry about it

Future patches can then enable the feature on a per-driver basis.

This patch also ensures that drivers can blindly strdup() field
names (previously, a malicious client could stuff 80 non-NUL bytes
into field and cause a read overrun).

* src/libvirt_internal.h (VIR_DRV_FEATURE_TYPED_PARAM_STRING): New
driver feature.
* src/libvirt.c (virTypedParameterValidateSet)
(virTypedParameterSanitizeGet): New helper functions.
(virDomainSetMemoryParameters, virDomainSetBlkioParameters)
(virDomainSetSchedulerParameters)
(virDomainSetSchedulerParametersFlags)
(virDomainGetMemoryParameters, virDomainGetBlkioParameters)
(virDomainGetSchedulerParameters)
(virDomainGetSchedulerParametersFlags, virDomainBlockStatsFlags):
Use them.
* src/util/util.h (virTypedParameterArrayClear): New helper
function.
* src/util/util.c (virTypedParameterArrayClear): Implement it.
* src/libvirt_private.syms (util.h): Export it.
Based on an initial patch by Hu Tao, with feedback from
Daniel P. Berrange.

Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoutil: fix compile error on debian
Eli Qiao [Fri, 11 Nov 2011 05:50:46 +0000 (13:50 +0800)]
util: fix compile error on debian

Add virnetdev.h,virnetdevbridge.h,virnetdevtap.h to private symbols,
since debian linker no longer allows transitive link resolution

Signed-off-by: Eli Qiao <taget@linux.vnet.ibm.com>
13 years agoqemu: fix domjobabort regression
Eric Blake [Tue, 8 Nov 2011 19:01:48 +0000 (12:01 -0700)]
qemu: fix domjobabort regression

This reverts commit ef1065cf5ac; see also this bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=751900

In qemu 0.15.1 and earlier, during migration to file, the
qemu_savevm_state_begin and qemu_savevm_state_iterate methods
will both process as much migration data as possible until either

  1. The file descriptor returns EAGAIN
  2. The bandwidth rate limit is reached

If we set the rate limit to ULONG_MAX, test 2 never becomes true. We're
passing a plain file descriptor to QEMU and POSIX does not support EAGAIN on
regular files / block devices, so test 1 never becomes true either.

In the 'virsh save --bypass-cache' case, we pass a pipe instead of a
regular fd, but using a pipe adds I/O overhead, so always passing a
pipe just so qemu can see EAGAIN doesn't seem nice.

The ultimate fix needs to come from qemu - background migration must
respect asynchronous abort requests, or else periodically return
control to the main handling loop without an EAGAIN and without
waiting to hit an insanely large amount of data.  But until a
version of qemu is fixed to support "unlimited" data rates while
still allowing cancellation, the best we can do is avoid the
automatic use of unlimited rates from within libvirt (users can
still explicitly change the migration rates, if they are aware that
they are giving up the ability to cancel a job).

Reverting the lone use of QEMU_DOMAIN_FILE_MIG_BANDWIDTH_MAX is
the simplest patch; this slows migration back down to a default
32M/sec cap, but also ensures that the main qemu processing loop
will still be responsive to cancellation requests.  Hopefully
upstream qemu will provide us a means of safely using unlimited
speed, including a runtime probe of that capability.

* src/qemu/qemu_migration.c (qemuMigrationToFile): Revert attempt
to use unlimited migration bandwidth when migrating to file.

Signed-off-by: Daniel Veillard <veillard@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agofix two bugs in bridge_driver.c
Hu Tao [Fri, 11 Nov 2011 08:20:19 +0000 (16:20 +0800)]
fix two bugs in bridge_driver.c

steps to reproduce:

1. having a network xml file(named default.xml) like this one:

<network>
  <name>default</name>
  <uuid>c5322c4c-81d0-4985-a363-ad6389780d89</uuid>
  <bridge name="virbr0" />
  <forward/>
  <ip address="192.168.122.1" netmask="255.255.255.0">
    <dhcp>
      <range start="192.168.122.2" end="192.168.122.254" />
    </dhcp>
  </ip>
</network>

in /etc/libvirt/qemu/networks/, and mark it as autostart:

$ ls -l /etc/libvirt/qemu/networks/autostart
total 0
lrwxrwxrwx 1 root root 14 Oct 12 14:02 default.xml -> ../default.xml

2. start libvirtd and the device virbr0 is not automatically up.

The reason is that the function virNetDevExists is now returns 1 if
the device exists, comparing to the former one returns 0 if the device
exists. But with only this fix will cause a segmentation fault(the same
steps as above)  that is fixed by the second chunk of code.

13 years agobuild: drop useless dirent.h includes
Eric Blake [Mon, 7 Nov 2011 17:47:31 +0000 (10:47 -0700)]
build: drop useless dirent.h includes

* .gnulib: Update to latest, for improved syntax-check.
* src/lxc/lxc_container.c (includes): Drop unused include.
* src/network/bridge_driver.c: Likewise.
* src/node_device/node_device_linux_sysfs.c: Likewise.
* src/openvz/openvz_driver.c: Likewise.
* src/qemu/qemu_conf.c: Likewise.
* src/storage/storage_backend_iscsi.c: Likewise.
* src/storage/storage_backend_mpath.c: Likewise.
* src/uml/uml_conf.c: Likewise.
* src/uml/uml_driver.c: Likewise.

13 years agoxenapi: remove unused variable
Eric Blake [Fri, 11 Nov 2011 18:10:18 +0000 (11:10 -0700)]
xenapi: remove unused variable

  CC     libvirt_driver_xenapi_la-xenapi_driver.lo
xenapi/xenapi_driver.c: In function 'xenapiDomainGetVcpus':
xenapi/xenapi_driver.c:1209:21: error: variable 'cpus' set but not used [-Werror=unused-but-set-variable]

* src/xenapi/xenapi_driver.c (xenapiDomainGetVcpus): Silence
compiler warning.

13 years agomaint: use mailmap, not AUTHORS, for secondary addresses
Eric Blake [Fri, 11 Nov 2011 15:22:23 +0000 (08:22 -0700)]
maint: use mailmap, not AUTHORS, for secondary addresses

* AUTHORS: Move Stefan's second entry...
* .mailmap: ...here.

13 years agomaint: fix make syntax-check
Stefan Berger [Thu, 10 Nov 2011 16:34:53 +0000 (11:34 -0500)]
maint: fix make syntax-check

Add my 2nd email to the list of AUTHORS to get 'make syntax-check'
to pass.

13 years agoRemove code instantiating filters on direct interfaces
Stefan Berger [Thu, 10 Nov 2011 16:16:22 +0000 (11:16 -0500)]
Remove code instantiating filters on direct interfaces

Remove the code that instantiates network filters on direct type
of interfaces. The parser already does not accept it.

13 years agoDisable numactl on ARM architectures too
Daniel P. Berrange [Thu, 10 Nov 2011 11:33:17 +0000 (11:33 +0000)]
Disable numactl on ARM architectures too

* libvirt.spec.in: Disable numactl on ARM

13 years agoAdd libvirt confdir to files section in mingw32 spec
Daniel P. Berrange [Thu, 10 Nov 2011 11:30:57 +0000 (11:30 +0000)]
Add libvirt confdir to files section in mingw32 spec

* mingw32-libvirt.spec.in: Ensure we own the confdir

13 years agonwfilter: simplify execution of ebiptables scripts
Eric Blake [Wed, 9 Nov 2011 17:29:57 +0000 (10:29 -0700)]
nwfilter: simplify execution of ebiptables scripts

It's not worth even worrying about a temporary file, unless we
ever expect the script to exceed maximum command-line argument
length limits.

* src/nwfilter/nwfilter_ebiptables_driver.c (ebiptablesExecCLI):
Run the commands as an argument to /bin/sh, rather than worrying
about a temporary file.
(ebiptablesWriteToTempFile): Delete unused function.

13 years agonwfilter: avoid failure with noexec /tmp
Eric Blake [Wed, 9 Nov 2011 17:23:49 +0000 (10:23 -0700)]
nwfilter: avoid failure with noexec /tmp

If /tmp is mounted with the noexec flag (common on security-conscious
systems), then nwfilter will fail to initialize, because we cannot
run any temporary script via virRun("/tmp/script"); but we _can_
use "/bin/sh /tmp/script".  For that matter, using /tmp risks collisions
with other unrelated programs; we already have /var/run/libvirt as a
dedicated temporary directory for use by libvirt.

* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesWriteToTempFile): Use internal directory, not /tmp;
drop attempts to make script executable; and detect close error.
(ebiptablesExecCLI): Switch to virCommand, and invoke the shell to
read the script, rather than requiring an executable script.

13 years agoAdjust naming of network device bandwidth management APIs
Daniel P. Berrange [Wed, 2 Nov 2011 14:29:05 +0000 (14:29 +0000)]
Adjust naming of network device bandwidth management APIs

Rename virBandwidth to virNetDevBandwidth, and virRate to
virNetDevBandwidthRate.

* src/util/network.c, src/util/network.h: Rename bandwidth
  structs and APIs
* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/conf/network_conf.c, src/conf/network_conf.h,
  src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/qemu/qemu_command.c, src/util/macvtap.c,
  src/util/macvtap.h, tools/virsh.c: Update for API changes.

13 years agoSantize naming of socket address APIs
Daniel P. Berrange [Wed, 2 Nov 2011 14:06:59 +0000 (14:06 +0000)]
Santize naming of socket address APIs

The socket address APIs in src/util/network.h either take the
form  virSocketAddrXXX, virSocketXXX or virSocketXXXAddr.

Sanitize this so everything is virSocketAddrXXXX, and ensure
that the virSocketAddr parameter is always the first one.

* src/util/network.c, src/util/network.h: Santize socket
  address API naming
* src/conf/domain_conf.c, src/conf/network_conf.c,
  src/conf/nwfilter_conf.c, src/network/bridge_driver.c,
  src/nwfilter/nwfilter_ebiptables_driver.c,
  src/nwfilter/nwfilter_learnipaddr.c,
  src/qemu/qemu_command.c, src/rpc/virnetsocket.c,
  src/util/dnsmasq.c, src/util/iptables.c,
  src/util/virnetdev.c, src/vbox/vbox_tmpl.c: Update for
  API renaming

13 years agoSplit bridge.h into three separate files
Daniel P. Berrange [Wed, 2 Nov 2011 13:41:58 +0000 (13:41 +0000)]
Split bridge.h into three separate files

Following the renaming of the bridge management APIs, we can now
split the source file into 3 corresponding pieces

 * src/util/virnetdev.c: APIs for any type of network interface
 * src/util/virnetdevbridge.c: APIs for bridge interfaces
 * src/util/virnetdevtap.c: APIs for TAP interfaces

* src/util/virnetdev.c, src/util/virnetdev.h,
  src/util/virnetdevbridge.c, src/util/virnetdevbridge.h,
  src/util/virnetdevtap.c, src/util/virnetdevtap.h: Copied
  from bridge.{c,h}
* src/util/bridge.c, src/util/bridge.h: Split into 3 pieces
* src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/openvz/openvz_driver.c, src/qemu/qemu_command.c,
  src/qemu/qemu_conf.h, src/uml/uml_conf.c, src/uml/uml_conf.h,
  src/uml/uml_driver.c: Update #include directives

13 years agoRemove usage of brctl command line tool
Daniel P. Berrange [Wed, 2 Nov 2011 13:05:27 +0000 (13:05 +0000)]
Remove usage of brctl command line tool

Convert the virNetDevBridgeSetSTP and virNetDevBridgeSetSTPDelay
to use ioctls instead of spawning brctl.

Implement the virNetDevBridgeGetSTP and virNetDevBridgeGetSTPDelay
methods which were declared in the header but never existed

* src/util/bridge.c: Convert to use bridge ioctls instead of brctl

13 years agoAdd an API for retrieving the MAC address of an interface
Daniel P. Berrange [Wed, 2 Nov 2011 13:00:09 +0000 (13:00 +0000)]
Add an API for retrieving the MAC address of an interface

* src/util/bridge.c, src/util/bridge.h: Add virNetDevGetMAC

13 years agoExpose MTU management APIs
Daniel P. Berrange [Wed, 2 Nov 2011 12:57:41 +0000 (12:57 +0000)]
Expose MTU management APIs

The MTU management APIs are useful to other code inside libvirt,
so should be exposed as non-static APIs.

* src/util/bridge.c, src/util/bridge.h: Expose virNetDevSetMTU,
  virNetDevSetMTUFromDevice & virNetDevGetMTU

13 years agoTurn two int parameters into bools in bridge APIs
Daniel P. Berrange [Wed, 2 Nov 2011 12:54:45 +0000 (12:54 +0000)]
Turn two int parameters into bools in bridge APIs

* src/util/bridge.c, src/util/bridge.h: s/int/bool/ in
  virNetDevSetOnline and virNetDevBridgeSetSTP

13 years agoRename all brXXXX APIs to follow new convention
Daniel P. Berrange [Wed, 2 Nov 2011 12:35:18 +0000 (12:35 +0000)]
Rename all brXXXX APIs to follow new convention

The existing brXXX APIs in src/util/bridge.h are renamed to
follow one of three different conventions

 - virNetDevXXX       - operations for any type of interface
 - virNetDevBridgeXXX - operations for bridge interfaces
 - virNetDevTapXXX    - operations for tap interfaces

* src/util/bridge.h, src/util/bridge.c: Rename all APIs
* src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/qemu/qemu_command.c, src/uml/uml_conf.c,
  src/uml/uml_driver.c: Update for API renaming

13 years agoMake all brXXX APIs raise errors, instead of returning errnos
Daniel P. Berrange [Wed, 2 Nov 2011 12:00:28 +0000 (12:00 +0000)]
Make all brXXX APIs raise errors, instead of returning errnos

Currently every caller of the brXXX APIs has to store the returned
errno value and then raise an error message. This results in
inconsistent error messages across drivers, additional burden on
the callers and makes the error reporting inaccurate since it is
hard to distinguish different scenarios from 1 errno value.

* src/util/bridge.c: Raise errors instead of returning errnos
* src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/qemu/qemu_command.c, src/uml/uml_conf.c,
  src/uml/uml_driver.c: Remove error reporting code

13 years agoRemove 'brControl' object
Daniel P. Berrange [Wed, 2 Nov 2011 10:56:38 +0000 (10:56 +0000)]
Remove 'brControl' object

The bridge management APIs in src/util/bridge.c require a brControl
object to be passed around. This holds the file descriptor for the
control socket. This extra object complicates use of the API for
only a minor efficiency gain, which is in turn entirely offset by
the need to fork/exec the brctl command for STP configuration.

This patch removes the 'brControl' object entirely, instead opening
the control socket & closing it again within the scope of each method.

The parameter names for the APIs are also made to consistently use
'brname' for bridge device name, and 'ifname' for an interface
device name. Finally annotations are added for non-NULL parameters
and return check validation

* src/util/bridge.c, src/util/bridge.h: Remove brControl object
  and update API parameter names & annotations.
* src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/uml/uml_conf.h, src/uml/uml_conf.c, src/uml/uml_driver.c,
  src/qemu/qemu_command.c, src/qemu/qemu_conf.h,
  src/qemu/qemu_driver.c: Remove reference to 'brControl' object

13 years agobuild: fix mingw build of gnulib openpty
Eric Blake [Wed, 9 Nov 2011 00:14:34 +0000 (17:14 -0700)]
build: fix mingw build of gnulib openpty

Commit f7bd00c12 pulled in a gnulib module that fails to compile
on mingw.  Work around it while waiting for an upstream gnulib fix.

* gnulib/local/lib/pty.in.h (openpty): Provide forward
declarations of opaque structs not present on mingw.
* gnulib/local/lib/openpty.c (openpty): Provide stub for mingw.

13 years agobuild: allow for local gnulib diffs
Eric Blake [Wed, 9 Nov 2011 00:06:27 +0000 (17:06 -0700)]
build: allow for local gnulib diffs

Commit f7bd00c12 pulled in a gnulib module that fails to compile
on mingw.  While it would be nice to pull in a newer version of
.gnulib that fixes this, it is difficult to backport any .gnulib
update to older releases.  So, it makes sense to take advantage
of gnulib-tool's ability to support local diffs, where we can
apply specific diffs in our use of gnulib without waiting for
upstream gnulib to pick up those changes, as well as avoiding
a wholesale .gnulib update.  The existence of local diffs will
also make it easier to backport fixes against a tarball (as long
as a tarball and libvirt.git share the same .gnulib commit, then
the tarball can be patched by applying the same local diffs as
a post-release libvirt.git commit, without having to rerun an
entire gnulib-tool bootstrap).

This patch introduces the framework for supporting local diffs,
without actually introducing any.

* bootstrap.conf (local_gl_dir): New variable.
* autogen.sh (bootstrap_hash): Hash any local diffs, to force a
re-bootstrap if just diffs change.
* cfg.mk (_update_required): Likewise.

13 years agolxc: free error object to avoid memory leak
Alex Jia [Wed, 9 Nov 2011 06:20:28 +0000 (14:20 +0800)]
lxc: free error object to avoid memory leak

Detected by Coverity. Leak introduced in commit 9d201a5.

* src/lxc/lxc_driver.c: Clean up on failure.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agolxc: free 'ttyFDs' array on return from lxcVmStart
Alex Jia [Wed, 9 Nov 2011 06:51:26 +0000 (14:51 +0800)]
lxc: free 'ttyFDs' array on return from lxcVmStart

Detected by Coverity. Leak introduced in commit 0f31f7b.

* src/lxc/lxc_driver.c: Clean up on failure.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoqemu: Fix improper error message for disk detaching
Osier Yang [Wed, 9 Nov 2011 05:58:51 +0000 (13:58 +0800)]
qemu: Fix improper error message for disk detaching

s/virDomainDeviceTypeToString/virDomainDiskDeviceTypeToString/

Report by Xu He Jie <xuhj@linux.vnet.ibm.

13 years agovirsh: Add VSH_OFLAG_EMPTY_OK for attach-disk command
Xu He Jie [Tue, 8 Nov 2011 07:16:34 +0000 (15:16 +0800)]
virsh: Add VSH_OFLAG_EMPTY_OK for attach-disk command

As the description of removing CDROM media from
  http://wiki.libvirt.org/page/QEMUSwitchToLibvirt#eject_DEV

Add flag 'VSH_OFLAG_EMPTY_OK' to the option 'source' of attach-disk

Then avoid outputting <source> in the XML if 'source' was empty,
rather than trusting libvirt domain_conf.c to understand an empty
string.

Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoRelease of libvirt-0.9.7
Daniel Veillard [Tue, 8 Nov 2011 06:55:25 +0000 (14:55 +0800)]
Release of libvirt-0.9.7

* confiure.ac docs/news.html.in libvirt.spec.in: update for release
* po/*.po*: update localizations and rebuilt

13 years agobuild: fix build on platforms without ptsname_r
Eric Blake [Thu, 3 Nov 2011 20:56:13 +0000 (14:56 -0600)]
build: fix build on platforms without ptsname_r

MacOS lacks ptsname_r, and gnulib doesn't (yet) provide it.
But we can avoid it altogether, by using gnulib openpty()
instead.  Note that we do _not_ want the pt_chown module;
gnulib uses it only to implement a replacement openpty() if
the system lacks both openpty() and granpt(), but all
systems that we currently port to either have at least one of
openpty() and/or grantpt(), or lack ptys altogether.  That is,
we aren't porting to any system that requires us to deal with
the hassle of installing a setuid pt_chown helper just to use
gnulib's ability to provide openpty() on obscure platforms.

* .gnulib: Update to latest, for openpty fixes
* bootstrap.conf (gnulib_modules): Add openpty, ttyname_r.
(gnulib_tool_option_extras): Exclude pt_chown module.
* src/util/util.c (virFileOpenTty): Rewrite in terms of openpty
and ttyname_r.
* src/util/util.h (virFileOpenTtyAt): Delete dead prototype.

13 years agoAdd missing defaultConsoleTargetType callback for AppArmour
Daniel P. Berrange [Mon, 7 Nov 2011 10:17:28 +0000 (10:17 +0000)]
Add missing defaultConsoleTargetType callback for AppArmour

Every instance of virCapsPtr must have the defaultConsoleTargetType
field set.

* src/security/virt-aa-helper.c: Add defaultConsoleTargetType to
  virCapsPtr

13 years agoFix sending/receiving of FDs when stream returns EAGAIN
Daniel P. Berrange [Fri, 4 Nov 2011 16:02:14 +0000 (16:02 +0000)]
Fix sending/receiving of FDs when stream returns EAGAIN

The code calling sendfd/recvfd was mistakenly assuming those
calls would never block. They can in fact return EAGAIN and
this is causing us to drop the client connection when blocking
ocurrs while sending/receiving FDs.

Fixing this is a little hairy on the incoming side, since at
the point where we see the EAGAIN, we already thought we had
finished receiving all data for the packet. So we play a little
trick to reset bufferOffset again and go back into polling for
more data.

* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Update
  virNetSocketSendFD/RecvFD to return 0 on EAGAIN, or 1
  on success
* src/rpc/virnetclient.c: Move decoding of header & fds
  out of virNetClientCallDispatch and into virNetClientIOHandleInput.
  Handling blocking when sending/receiving FDs
* src/rpc/virnetmessage.h: Add a 'donefds' field to track
  how many FDs we've sent / received
* src/rpc/virnetserverclient.c: Handling blocking when
  sending/receiving FDs

13 years agobuild: silence compiler warning on BSD
Eric Blake [Fri, 4 Nov 2011 22:32:30 +0000 (16:32 -0600)]
build: silence compiler warning on BSD

Building on 64-bit FreeBSD 8.2 complained about a cast between
a pointer and a smaller integer.  Going through an intermediate
cast shuts up the compiler.

* src/util/threads-pthread.c (virThreadSelfID): Silence a warning.

13 years agobuild: fix linking on BSD
Eric Blake [Fri, 4 Nov 2011 20:53:15 +0000 (14:53 -0600)]
build: fix linking on BSD

While building on FreeBSD (and after fixing a ptsname_r link error),
I got this failure:

./.libs/libvirt_util.a(libvirt_util_la-threads.o)(.text+0x240): In function `virThreadCreate':
util/threads-pthread.c:185: undefined reference to `pthread_create'

It turns out that gnulib used only pthread_join for LIB_PTHREAD,
but on FreeBSD, libc provides that (as a stub function); whereas
the more complex pthread_create really does require -pthread,
which gnulib tracked under [LT]LIBMULTITHREAD.

* configure.ac (LIBS): Check LIBMULTITHREAD alongside LIB_PTHREAD.
* src/Makefile.am (THREAD_LIBS): New variable.
(libvirt_util_la_LIBADD, libvirt_lxc_LDADD): Use it.

13 years agoremote: fix mingw32 build
Laine Stump [Fri, 4 Nov 2011 20:10:54 +0000 (16:10 -0400)]
remote: fix mingw32 build

tty is initialized, and later set in code that is compiled for all
platforms, but is only used in a section that's inside #ifndef WIN32.

13 years agolxc: avoid use-after-free
Eric Blake [Thu, 3 Nov 2011 23:24:32 +0000 (17:24 -0600)]
lxc: avoid use-after-free

I got this weird failure:

error: Failed to start domain simple
error: internal error cannot mix caller fds with blocking execution

and tracked it down to a use-after-free - virCommandSetOutputFD
was storing the address of a stack-local variable, which then
went out of scope before the virCommandRun that dereferenced it.

Bug introduced in commit 451cfd05 (0.9.2).

* src/lxc/lxc_driver.c (lxcBuildControllerCmd): Move log fd
registration...
(lxcVmStart): ...to caller.

13 years agoFix naming of constant for disk event
Daniel P. Berrange [Fri, 4 Nov 2011 12:16:19 +0000 (12:16 +0000)]
Fix naming of constant for disk event

All constants related to events should have a prefix of
VIR_DOMAIN_EVENT_

* include/libvirt/libvirt.h.in, src/qemu/qemu_domain.c:
  Rename VIR_DOMAIN_DISK_CHANGE_MISSING_ON_START to
  VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START