]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agoSet aliases for LXC/UML console devices
Daniel P. Berrange [Thu, 20 Oct 2011 13:57:10 +0000 (14:57 +0100)]
Set aliases for LXC/UML console devices

To allow virDomainOpenConsole to access non-primary consoles,
device aliases are required to be set. Until now only the QEMU
driver has done this. Update LXC & UML to set aliases for any
console devices

* src/lxc/lxc_driver.c, src/uml/uml_driver.c: Set aliases
  for console devices

13 years agoDefault console target type with no <target> element
Daniel P. Berrange [Thu, 20 Oct 2011 13:56:30 +0000 (14:56 +0100)]
Default console target type with no <target> element

When no <target> element was set at all, the default console
target type was not being honoured

* src/conf/domain_conf.c: Set default target type for consoles
  with no <target>

13 years agoAdd support for multiple consoles in LXC
Daniel P. Berrange [Thu, 20 Oct 2011 08:44:31 +0000 (09:44 +0100)]
Add support for multiple consoles in LXC

Currently the LXC controller only supports setup of a single
text console. This is wired up to the container init's stdio,
as well as /dev/console and /dev/tty1. Extending support for
multiple consoles, means wiring up additional PTYs to /dev/tty2,
/dev/tty3, etc, etc. The LXC controller is passed multiple open
file handles, one for each console requested.

* src/lxc/lxc_container.c, src/lxc/lxc_container.h: Wire up
  all the /dev/ttyN links required to symlink to /dev/pts/NN
* src/lxc/lxc_container.h: Open more container side /dev/pts/NN
  devices, and adapt event loop to handle I/O from all consoles
* src/lxc/lxc_driver.c: Setup multiple host side PTYs

13 years agoRewrite LXC I/O forwarding to use main event loop
Daniel P. Berrange [Wed, 19 Oct 2011 15:22:24 +0000 (16:22 +0100)]
Rewrite LXC I/O forwarding to use main event loop

The current I/O code for LXC uses a hand crafted event loop
to forward I/O between the container & host app, based on
epoll to handle EOF on PTYs. This event loop is not easily
extensible to add more consoles, or monitor other types of
file descriptors.

Remove the custom event loop and replace it with a normal
libvirt event loop. When detecting EOF on a PTY, disable
the event watch on that FD, and fork off a background thread
that does a edge-triggered epoll() on the FD. When the FD
finally shows new incoming data, the thread re-enables the
watch on the FD and exits.

When getting EOF from a read() on the PTY, the existing code
would do waitpid(WNOHANG) to see if the container had exited.
Unfortunately there is a race condition, because even though
the process has closed its stdio handles, it might still
exist.

To deal with this the new event loop uses a SIG_CHILD handler
to perform the waitpid only when the container is known to
have actually exited.

* src/lxc/lxc_controller.c: Rewrite the event loop to use
  the standard APIs.

13 years agoFix crash formatting virtio console
Daniel P. Berrange [Wed, 19 Oct 2011 10:45:10 +0000 (11:45 +0100)]
Fix crash formatting virtio console

qemuBuildVirtioSerialPortDevStr was mistakenly accessing the
target.name field in the virDomainChrDef object for chardevs
belonging to a console. Those chardevs only have port set,
and if there's > 1 console, the > 1port number results in
trying to access a target.name with address 0x1

* src/qemu/qemu_command.c: Fix target.name handling and
  make code more robust wrt error reporting

* src/qemu/qemu_command.c: Conditionally access target.name

13 years agoAllow multiple consoles per virtual guest
Daniel P. Berrange [Wed, 23 Feb 2011 18:27:23 +0000 (18:27 +0000)]
Allow multiple consoles per virtual guest

While Xen only has a single paravirt console, UML, and
QEMU both support multiple paravirt consoles. The LXC
driver can also be trivially made to support multiple
consoles. This patch extends the XML to allow multiple
<console> elements in the XML. It also makes the UML
and QEMU drivers support this config.

* src/conf/domain_conf.c, src/conf/domain_conf.h: Allow
  multiple <console> devices
* src/lxc/lxc_driver.c, src/xen/xen_driver.c,
  src/xenxs/xen_sxpr.c, src/xenxs/xen_xm.c: Update for
  internal API changes
* src/security/security_selinux.c, src/security/virt-aa-helper.c:
  Only label consoles that aren't a copy of the serial device
* src/qemu/qemu_command.c, src/qemu/qemu_driver.c,
  src/qemu/qemu_process.c, src/uml/uml_conf.c,
  src/uml/uml_driver.c: Support multiple console devices
* tests/qemuxml2xmltest.c, tests/qemuxml2argvtest.c: Extra
  tests for multiple virtio consoles. Set QEMU_CAPS_CHARDEV
  for all console /channel tests
* tests/qemuxml2argvdata/qemuxml2argv-channel-virtio-auto.args,
  tests/qemuxml2argvdata/qemuxml2argv-channel-virtio.args
  tests/qemuxml2argvdata/qemuxml2argv-console-virtio.args: Update
  for correct chardev syntax
* tests/qemuxml2argvdata/qemuxml2argv-console-virtio-many.args,
  tests/qemuxml2argvdata/qemuxml2argv-console-virtio-many.xml: New
  test file

13 years agoRemove translations in socket test case
Daniel P. Berrange [Thu, 3 Nov 2011 10:52:44 +0000 (10:52 +0000)]
Remove translations in socket test case

The test case errors should not be translated since they're only
targetted at developers, not users.

* tests/virnetsockettest.c: Remove error reporting with translations

13 years agovirnetsockettest: Use a temporary directory in /tmp
Guido Günther [Wed, 2 Nov 2011 21:06:44 +0000 (22:06 +0100)]
virnetsockettest: Use a temporary directory in /tmp

to avoid exceeding UNIX_PATH_MAX

13 years agoUse ENAMETOOLONG if the the socket path is longer than UNIX_PATH_MAX
Guido Günther [Wed, 2 Nov 2011 20:39:31 +0000 (21:39 +0100)]
Use ENAMETOOLONG if the the socket path is longer than UNIX_PATH_MAX

13 years agoxen: allow getting < max typed parameters
Eric Blake [Wed, 2 Nov 2011 17:57:29 +0000 (11:57 -0600)]
xen: allow getting < max typed parameters

Allow the user to call with nparams too small, per API documentation.

* src/xen/xen_hypervisor.c (xenHypervisorGetSchedulerParameters):
Allow fewer than max.
* src/xen/xend_internal.c (xenDaemonGetSchedulerParameters):
Likewise.

13 years agotest: drop redundant check
Eric Blake [Wed, 2 Nov 2011 17:53:33 +0000 (11:53 -0600)]
test: drop redundant check

libvirt.c guarantees that nparams is non-zero for scheduler parameters.

* src/test/test_driver.c (testDomainGetSchedulerParamsFlags): Drop
redundant check.  Avoid strcpy.

13 years agolxc: allow getting < max typed parameters
Eric Blake [Wed, 2 Nov 2011 17:50:08 +0000 (11:50 -0600)]
lxc: allow getting < max typed parameters

Allow the user to call with nparams too small, per API documentation.
Also, libvirt.c filters out nparams of 0 for scheduler parameters.

* src/lxc/lxc_driver.c (lxcDomainGetMemoryParameters): Allow fewer
than max.
(lxcGetSchedulerParametersFlags): Drop redundant check.

13 years agolibxl: allow getting < max typed parameters
Eric Blake [Wed, 2 Nov 2011 17:42:38 +0000 (11:42 -0600)]
libxl: allow getting < max typed parameters

Allow the user to call with nparams too small, per API documentation.

* src/libxl/libxl_driver.c
(libxlDomainGetSchedulerParametersFlags): Allow fewer than max.

13 years agoesx: allow getting < max typed parameters
Eric Blake [Wed, 2 Nov 2011 17:36:12 +0000 (11:36 -0600)]
esx: allow getting < max typed parameters

Allow the user to call with nparams too small, per API documentation.

* src/esx/esx_driver.c (esxDomainGetMemoryParameters): Drop
redundant check.
(esxDomainGetSchedulerParametersFlags): Allow fewer than max.

13 years agoAPI: document scheduler parameter names
Eric Blake [Tue, 1 Nov 2011 20:38:42 +0000 (14:38 -0600)]
API: document scheduler parameter names

Document the parameter names that will be used by
virDomain{Get,Set}SchedulerParameters{,Flags}, rather than
hard-coding those names in each driver, to match what is
done with memory, blkio, and blockstats parameters.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SCHEDULER_CPU_SHARES)
(VIR_DOMAIN_SCHEDULER_VCPU_PERIOD)
(VIR_DOMAIN_SCHEDULER_VCPU_QUOTA, VIR_DOMAIN_SCHEDULER_WEIGHT)
(VIR_DOMAIN_SCHEDULER_CAP, VIR_DOMAIN_SCHEDULER_RESERVATION)
(VIR_DOMAIN_SCHEDULER_LIMIT, VIR_DOMAIN_SCHEDULER_SHARES): New
field name macros.
* src/qemu/qemu_driver.c (qemuSetSchedulerParametersFlags)
(qemuGetSchedulerParametersFlags): Use new defines.
* src/test/test_driver.c (testDomainGetSchedulerParamsFlags)
(testDomainSetSchedulerParamsFlags): Likewise.
* src/xen/xen_hypervisor.c (xenHypervisorGetSchedulerParameters)
(xenHypervisorSetSchedulerParameters): Likewise.
* src/xen/xend_internal.c (xenDaemonGetSchedulerParameters)
(xenDaemonSetSchedulerParameters): Likewise.
* src/lxc/lxc_driver.c (lxcSetSchedulerParametersFlags)
(lxcGetSchedulerParametersFlags): Likewise.
* src/esx/esx_driver.c (esxDomainGetSchedulerParametersFlags)
(esxDomainSetSchedulerParametersFlags): Likewise.
* src/libxl/libxl_driver.c (libxlDomainGetSchedulerParametersFlags)
(libxlDomainSetSchedulerParametersFlags): Likewise.

13 years agoFix off-by-one printing month in logging code
Daniel P. Berrange [Mon, 24 Oct 2011 16:33:00 +0000 (17:33 +0100)]
Fix off-by-one printing month in logging code

The field 'mon' in 'struct tm' gives months 0-11, where as
humans tend to expect months 1-12. Thus the month number
needing adjusting by 1

* src/util/logging.c: Use human friendly month number

13 years agoAdd missing param initialization in qemuDomainBlockStatsFlags
Daniel P. Berrange [Wed, 2 Nov 2011 10:28:05 +0000 (10:28 +0000)]
Add missing param initialization in qemuDomainBlockStatsFlags

* src/qemu/qemu_driver.c: Fix use of uninitialized 'params'

13 years agofix crash when starting network
Wen Congyang [Wed, 2 Nov 2011 05:17:16 +0000 (13:17 +0800)]
fix crash when starting network

commit 27908453 introduces a regression, and it will
cause libvirt crashed when starting network.

The reason is that tapfd may be NULL, but we dereference
it without checking whether it is NULL.

13 years agoqemu: allow getting < max typed parameters
Eric Blake [Mon, 31 Oct 2011 23:17:12 +0000 (17:17 -0600)]
qemu: allow getting < max typed parameters

Since all virTypedParameter APIs allow us to return the number
of slots we actually populated, we should allow the user to
call with nparams too small (without overrunning their array)
or too large (ignoring the tail of the array that we can't fill),
rather than requiring that they get things exactly right.

Making this change will make it easier for a future patch to
introduce VIR_TYPED_PARAM_STRING, with filtering in libvirt.c
rather than in every single driver, since users already have
to be prepared for *nparams to be smaller on exit than on entry.

* src/qemu/qemu_driver.c (qemuDomainGetBlkioParameters)
(qemuDomainGetMemoryParameters): Allow variable nparams on entry.
(qemuGetSchedulerParametersFlags): Drop redundant check.
(qemudDomainBlockStats, qemudDomainBlockStatsFlags): Rename...
(qemuDomainBlockStats, qemuDomainBlockStatsFlags): ...to this.
Don't return unavailable stats.

13 years agodocs: improve typed parameter documentation
Eric Blake [Mon, 31 Oct 2011 22:35:26 +0000 (16:35 -0600)]
docs: improve typed parameter documentation

virDomainBlockStatsFlags was missing a check that was present in
virDomainGetMemoryParameters.  Additionally, I found that the
existing descriptions were a bit hard to read.  A later patch
will fix qemu to return fewer than max parameters if @nparams
was too small on input.

* src/libvirt.c (virDomainGetMemoryParameters)
(virDomainGetBlkioParameters, virDomainGetSchedulerParameters)
(virDomainGetSchedulerParametersFlags):
Tweak documentation wording.
(virDomainBlockStatsFlags): Likewise, and add sanity check.

13 years agoDon't overwrite error message during VM cleanup
Daniel P. Berrange [Tue, 1 Nov 2011 16:27:41 +0000 (16:27 +0000)]
Don't overwrite error message during VM cleanup

If an LXC VM fails to start, quite a few cleanup paths will
result in the original error message being overwritten. Some
other cleanup paths also forgot to actually terminate the VM.

* src/lxc/lxc_driver.c: Ensure VM is terminated on startup
  failure and preserve original error

13 years agoAdd support for probing filesystem with libblkid
Daniel P. Berrange [Tue, 1 Nov 2011 14:59:51 +0000 (14:59 +0000)]
Add support for probing filesystem with libblkid

The LXC code for mounting container filesystems from block devices
tries all filesystems in /etc/filesystems and possibly those in
/proc/filesystems. The regular mount binary, however, first tries
using libblkid to detect the format. Add support for doing the same
in libvirt, since Fedora's /etc/filesystems is missing many formats,
most notably ext4 which is the default filesystem Fedora uses!

* src/Makefile.am: Link libvirt_lxc to libblkid
* src/lxc/lxc_container.c: Probe filesystem format with libblkid

13 years agoFix error message when failing to detect filesystem
Daniel P. Berrange [Tue, 1 Nov 2011 14:34:02 +0000 (14:34 +0000)]
Fix error message when failing to detect filesystem

If we looped through /etc/filesystems trying to mount with each
type and failed all options, we forget to actually raise an
error message.

* src/lxc/lxc_container.c: Raise error if unable to detect
  the filesystems. Also fix existing error message

13 years agoWorkaround for broken kernel autofs mounts
Daniel P. Berrange [Tue, 1 Nov 2011 12:56:53 +0000 (12:56 +0000)]
Workaround for broken kernel autofs mounts

The kernel automounter is mostly broken wrt to containers. Most
notably if you start a new filesystem namespace and then attempt
to unmount any autofs filesystem, it will typically fail with a
weird error message like

  Failed to unmount '/.oldroot/sys/kernel/security':Too many levels of symbolic links

Attempting to detach the autofs mount using umount2(MNT_DETACH)
will also fail with the same error. Therefore if we get any error on
unmount()ing a filesystem from the old root FS when starting a
container, we must immediately break out and detach the entire
old root filesystem (ignoring any mounts below it).

This has the effect of making the old root filesystem inaccessible
to anything inside the container, but at the cost that the mounts
live on in the kernel until the container exits. Given that SystemD
uses autofs by default, we need LXC to be robust this scenario and
thus this tradeoff is worthwhile.

* src/lxc/lxc_container.c: Detach root filesystem if any umount
  operation fails.

13 years agoCorrectly handle '*' in /etc/filesystems
Daniel P. Berrange [Tue, 1 Nov 2011 12:29:25 +0000 (12:29 +0000)]
Correctly handle '*' in /etc/filesystems

The /etc/filesystems file can contain a '*' on the last line to
indicate that /proc/filessystems should be tried next. We have
a check that this '*' only occurs on the last line. Unfortunately
when we then start reading /proc/filesystems, we mistakenly think
we've seen '*' in /proc/filesystems and fail

* src/lxc/lxc_container.c: Skip '*' validation when we're reading
  /proc/filesystems

13 years agoEnsure errno is valid when returning from lxcContainerWaitForContinue
Daniel P. Berrange [Tue, 1 Nov 2011 12:28:26 +0000 (12:28 +0000)]
Ensure errno is valid when returning from lxcContainerWaitForContinue

Only some of the return paths of lxcContainerWaitForContinue will
have set errno. In other paths we need to set it manually to avoid
the caller getting a random stale errno value

* src/lxc/lxc_container.c: Set errno in lxcContainerWaitForContinue

13 years agoCreate /var/lib/libvirt/filesystems for LXC trees
Daniel P. Berrange [Tue, 1 Nov 2011 11:21:21 +0000 (11:21 +0000)]
Create /var/lib/libvirt/filesystems for LXC trees

We already have a /var/lib/libvirt/images for OS install images.
We need a separate /var/lib/libvirt/filesystems for OS install
trees, since SELinux labelling will be different

* libvirt.spec.in: Add /var/lib/libvirt/filesystems
* src/Makefile.am: Create /var/lib/libvirt/filesystems

13 years agoesx: Support folders in the path of vpx:// connection URIs
Matthias Bolte [Tue, 1 Nov 2011 16:12:37 +0000 (17:12 +0100)]
esx: Support folders in the path of vpx:// connection URIs

Allow the datacenter and compute resource parts of the path
to be prefixed with folders. Therefore, the way the path is
parsed has changed. Before, it was split in 2 or 3 items and
the items' meanings were determined by their positions. Now
the path can have 2 or more items and the the vCenter server
is asked whether a folder, datacenter of compute resource
with the specified name exists at the current hierarchy level.

Before the datacenter and compute resource lookup automatically
traversed folders during lookup. This is logic got removed
and folders have to be specified explicitly.

The proper datacenter path including folders is now used when
accessing a datastore over HTTPS. This makes virsh dumpxml
and define work for datacenters in folders.

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

13 years agoesx: Support vSphere 5.x
Patrice LACHANCE [Fri, 21 Oct 2011 05:56:07 +0000 (07:56 +0200)]
esx: Support vSphere 5.x

And virtual hardware version 8.

13 years agoFix URI alias prefix matching
Wen Ruo Lv [Tue, 1 Nov 2011 09:49:06 +0000 (17:49 +0800)]
Fix URI alias prefix matching

with /etc/libvirt/libvirt.conf below:
uri_aliases = [
  "hail=qemu:///system",
  "sleet=qemu+ssh://root 9 115 122 57/system",
  "sam=qemu+unix:///system?socket=/var/run/libvirt/libvirt-sock",
]
Neither "virsh -c hailly" nor "hai" should result in matching "hail=qemu:///system"

Fix URI alias prefix matching when connecting

Signed-off-by: Wen Ruo Lv <lvroyce@linux.vnet.ibm.com>
13 years agodocs: fix typo in <disk>/<target> example
Eric Blake [Tue, 1 Nov 2011 16:39:48 +0000 (10:39 -0600)]
docs: fix typo in <disk>/<target> example

* docs/formatdomain.html.in: Use dev, not def.
Reported by Alexander Biryukov.

13 years agoServerClient: Flush cached data
Michal Privoznik [Tue, 1 Nov 2011 13:14:54 +0000 (14:14 +0100)]
ServerClient: Flush cached data

If daemon is using SASL it reads client data into a cache. This cache is
big (usually 65KB) and can thus contain 2 or more messages. However,
on socket event we can dispatch only one message. So if we read two
messages at once, the second will not be dispatched as the socket event
goes away with filling the cache.
Moreover, when dispatching the cache we need to remember to take care
of client max requests limit.

13 years agoFix storage pool source comparison to avoid comparing with self
Daniel P. Berrange [Fri, 7 Oct 2011 16:38:09 +0000 (17:38 +0100)]
Fix storage pool source comparison to avoid comparing with self

If we are comparing storage pools we must skip comparing with
ourself, so that re-defining an existing pool works

* conf/storage_conf.c: Skip self when comparing

13 years agoqemu: pass virConnectPtr into Domain{Attach,Detach}*
Sage Weil [Mon, 31 Oct 2011 19:06:23 +0000 (13:06 -0600)]
qemu: pass virConnectPtr into Domain{Attach,Detach}*

The qemu RBD driver needs access to the conn in order to get the secret
needed for connecting to the ceph cluster.

Signed-off-by: Sage Weil <sage@newdream.net>
13 years agoqemu: plug memory leak
Alex Jia [Sat, 29 Oct 2011 17:12:56 +0000 (01:12 +0800)]
qemu: plug memory leak

Detected by Coverity. Leak introduced in commit 6cabc0b.

* src/qemu/qemu_command.c: Clean up on failure.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agopython: Fix documentation of virStream recv
Matthias Bolte [Mon, 31 Oct 2011 16:11:33 +0000 (17:11 +0100)]
python: Fix documentation of virStream recv

This was fixed in be757a3f7baf93b for libvirt.c.

13 years agostartupPolicty: Minor cleanups
Michal Privoznik [Wed, 26 Oct 2011 09:12:45 +0000 (11:12 +0200)]
startupPolicty: Minor cleanups

This patch does some cleanups to my previous startupPolicy patchset.

13 years agoqemu: Restore the original states of PCI device when restarting daemon
Osier Yang [Thu, 20 Oct 2011 09:50:10 +0000 (17:50 +0800)]
qemu: Restore the original states of PCI device when restarting daemon

To support "managed" mode of host PCI device, we record the original
states (unbind_from_stub, remove_slot, and reprobe) so that could
reattach the device to host with original driver. But there is no XML
for theses attrs, and thus after daemon is restarted, we lose the
original states. It's easy to reproduce:

    1) virsh start domain
    2) virsh attach-device dom hostpci.xml (in 'managed' mode)
    3) service libvirtd restart
    4) virsh destroy domain

    You will see the device won't be bound to the original driver
if there was one.

This patch is to solve the problem by introducing internal XML
(won't be dumped to user, only dumped to status XML). The XML is:
    <origstates>
      <unbind/>
      <remove_slot/>
      <reprobe/>
    </origstates>

Which will be child node of <hostdev><source>...</souce></hostdev>.
(only for PCI device).

A new struct "virDomainHostdevOrigStates" is introduced for the XML,
and the according members are updated when preparing the PCI device.
And function "qemuUpdateActivePciHostdevs" is modified to honor
the original states. Use of qemuGetPciHostDeviceList is removed
in function "qemuUpdateActivePciHostdevs", and the "managed" value of
the device config is honored by the change. This fixes another problem
alongside:

    qemuGetPciHostDeviceList set the device as "managed" force
    regardless of whether the device is configured as "managed='yes'"
    or not in XML, which is not right.

13 years agovbox: Add support for VirtualBox 4.1
Matthias Bolte [Sat, 29 Oct 2011 19:26:57 +0000 (21:26 +0200)]
vbox: Add support for VirtualBox 4.1

Deal with the incompatible changes in the VirtualBox 4.1 API.

INetworkAdapter has its different AttachTo* method replaced by
a settable attachmentType property.

The maximum number of network adapters is now requestable per
chipset type.

The OpenMedium method got a bool parameter to request opening
a medium under a new IID.

13 years agovbox: Support shared folders
Matthias Bolte [Tue, 7 Jun 2011 11:29:34 +0000 (13:29 +0200)]
vbox: Support shared folders

Shared folders are handled as filesystems and can also be hotplugged.

13 years agoxenapi: Improve error reporting in xenapiOpen once again
Matthias Bolte [Thu, 21 Jul 2011 13:16:11 +0000 (15:16 +0200)]
xenapi: Improve error reporting in xenapiOpen once again

privP->session->error_description is a list and in order to get the
complete error message all parts of the list should be concatenated.
xenapiSessionErrorHandler does this when its third parameter is NULL.
The current code discards all but the first part of the error message
resulting in a potentially incomplete error message.

This partly reverts 006be75ee214f9b4, that tried to avoid reporting
a (null) in the error message. The actual problem is more general in
returnErrorFromSession that might return NULL if there is no error.

Make sure that returnErrorFromSession return non-NULL always. Also
don't skip the last error message part.

13 years agomacvtap: Fix error return value convention/inconsistencies
Roopa Prabhu [Fri, 28 Oct 2011 22:04:07 +0000 (15:04 -0700)]
macvtap: Fix error return value convention/inconsistencies

- changed some return 1's to return -1
- changed if (rc) error checks to if (rc < 0)
- fixed some other minor convention violations

I might have missed some. Can fix in another patch or can respin

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
Reported-by: Eric Blake <eblake@redhat.com>
Reported-by: Laine Stump <laine@laine.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoUse a common xml type for ceph secret usage.
Josh Durgin [Fri, 28 Oct 2011 21:19:34 +0000 (14:19 -0700)]
Use a common xml type for ceph secret usage.

The types used in domaincommon.rng and secret.rng should be the same.

Move genericName to basictypes.rng, then drop redundant types now
that secret.rng uses basictypes.rng.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agopci address conflict when virtio disk with drive type
Xu He Jie [Fri, 28 Oct 2011 09:57:21 +0000 (17:57 +0800)]
pci address conflict when virtio disk with drive type

When using the xml as below:
------------------------------------------------------
<devices>
  <emulator>/home/soulxu/data/work-code/qemu-kvm/x86_64-softmmu/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
    <driver name='qemu' type='qcow2'/>
    <source file='/home/soulxu/data/VM/images/linux.img'/>
    <target dev='vda' bus='virtio'/>
    <address type='drive' controller='0' bus='0' unit='0'/>
  </disk>
  <input type='mouse' bus='ps2'/>
  <graphics type='vnc' port='-1' autoport='yes'/>
  <video>
    <model type='cirrus' vram='9216' heads='1'/>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
  </video>
  <memballoon model='virtio'>
    <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
  </memballoon>
</devices>
------------------------------------------------------

Then can't startup qemu, the error message as below:
virsh # start test-vm
error: Failed to start domain test-vm
error: internal error process exited while connecting to monitor: qemu-system-x86_64: -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3: PCI: slot 3 function 0 not available for virtio-balloon-pci, in use by virtio-blk-pci
qemu-system-x86_64: -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3: Device 'virtio-balloon-pci' could not be initialized

So adding check for bus type and address type. Only the address of pci type support by virtio bus.

Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
13 years agosecret: fix bad patch application
Eric Blake [Fri, 28 Oct 2011 18:55:04 +0000 (12:55 -0600)]
secret: fix bad patch application

In hand-applying Josh and Sage's patch, I missed out on a break.

* src/conf/secret_conf.c (virSecretDefFree): Fix my botch.

13 years agostorage: add auth to virDomainDiskDef
Josh Durgin [Fri, 28 Oct 2011 18:29:39 +0000 (12:29 -0600)]
storage: add auth to virDomainDiskDef

Add additional fields to let you specify the how to authenticate with a disk.
The secret to use may be referenced by a usage string or a UUID, i.e.:

<auth username='myuser'>
 <secret type='ceph' usage='secretname'/>
</auth>

or

<auth username='myuser'>
 <secret type='ceph' uuid='0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f'/>
</auth>

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
13 years agosecret: add Ceph secret type
Sage Weil [Fri, 28 Oct 2011 17:30:45 +0000 (11:30 -0600)]
secret: add Ceph secret type

Add a new secret type to store a Ceph authentication key. The name
is simply an identifier for easy human reference.

The xml looks like this:

<secret ephemeral='no' private='no'>
 <uuid>0a81f5b2-8403-7b23-c8d6-21ccc2f80d6f</uuid>
 <usage type='ceph'>
   <name>mycluster_admin</name>
 </usage>
</secret>

Signed-off-by: Sage Weil <sage@newdream.net>
Signed-off-by: Josh Durgin <josh.durgin@dreamhost.net>
13 years agoqemu: plug memory leak
Alex Jia [Fri, 28 Oct 2011 11:35:09 +0000 (19:35 +0800)]
qemu: plug memory leak

Leak introduced in commit c1bc3d89.
Detected by valgrind:

==18462== 1,100 bytes in 1 blocks are definitely lost in loss record 183 of 184
==18462==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==18462==    by 0x4A06167: realloc (vg_replace_malloc.c:525)
==18462==    by 0x4AADBB: virReallocN (memory.c:161)
==18462==    by 0x4A975E: virBufferGrow (buf.c:117)
==18462==    by 0x4A9D92: virBufferVasprintf (buf.c:290)
==18462==    by 0x4A9EF7: virBufferAsprintf (buf.c:263)
==18462==    by 0x429488: qemuBuildControllerDevStr (qemu_command.c:1993)
==18462==    by 0x42C4B6: qemuBuildCommandLine (qemu_command.c:3803)
==18462==    by 0x41A604: testCompareXMLToArgvHelper (qemuxml2argvtest.c:124)
==18462==    by 0x41BB81: virtTestRun (testutils.c:141)
==18462==    by 0x416DFF: mymain (qemuxml2argvtest.c:369)
==18462==    by 0x41B277: virtTestMain (testutils.c:696)
==18462==
==18462== LEAK SUMMARY:
==18462==    definitely lost: 1,100 bytes in 1 blocks
==18462==    indirectly lost: 0 bytes in 0 blocks

* src/qemu/qemu_command.c (qemuBuildCommandLine): Clean up on success.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoqemu: avoid leaking uninit data from hotplug to dumpxml
Eric Blake [Wed, 26 Oct 2011 23:40:12 +0000 (17:40 -0600)]
qemu: avoid leaking uninit data from hotplug to dumpxml

Detected by Coverity.  The fix in 2c27dfa didn't catch all bad
instances of memcpy().  Thankfully, on further analysis, all of
the problematic uses are only triggered by old qemu that lacks
-device.

* src/qemu/qemu_hotplug.c (qemuDomainAttachPciDiskDevice)
(qemuDomainAttachNetDevice, qemuDomainAttachHostPciDevice): Init
all fields since monitor only populates some of them.

13 years agoutil: Fix virUUIDGeneratePseudoRandomBytes
Ryota Ozaki [Fri, 28 Oct 2011 11:06:20 +0000 (20:06 +0900)]
util: Fix virUUIDGeneratePseudoRandomBytes

It forgets to move a pointer to a buffer for UUID and as a result
fills only the first byte of the buffer.

13 years agoImplement RPC driver support for virDomainOpenGraphics
Daniel P. Berrange [Fri, 21 Oct 2011 11:49:23 +0000 (12:49 +0100)]
Implement RPC driver support for virDomainOpenGraphics

Since it needs to access file descriptors passed in the msg,
the RPC driver for virDomainOpenGraphics needs to be manually
implemented.

* daemon/remote.c: RPC server dispatcher
* src/remote/remote_driver.c: RPC client dispatcher
* src/remote/remote_protocol.x: Define protocol

13 years agoExtend RPC server to allow FD passing
Daniel P. Berrange [Fri, 21 Oct 2011 11:12:28 +0000 (12:12 +0100)]
Extend RPC server to allow FD passing

The RPC server classes are extended to allow FDs to be received
from clients with calls. There is not currently any way for a
procedure to pass FDs back to the client with replies

* daemon/remote.c, src/rpc/gendispatch.pl: Change virNetMessageHeaderPtr
  param to virNetMessagePtr in dispatcher impls
* src/rpc/virnetserver.c, src/rpc/virnetserverclient.c,
  src/rpc/virnetserverprogram.c, src/rpc/virnetserverprogram.h:
  Extend to support FD passing

13 years agoAdd client side support for FD passing
Daniel P. Berrange [Fri, 21 Oct 2011 10:48:03 +0000 (11:48 +0100)]
Add client side support for FD passing

Extend the RPC client code to allow file descriptors to be sent
to the server with calls, and received back with replies.

* src/remote/remote_driver.c: Stub extra args
* src/libvirt_private.syms, src/rpc/virnetclient.c,
  src/rpc/virnetclient.h, src/rpc/virnetclientprogram.c,
  src/rpc/virnetclientprogram.h: Extend APIs to allow
  FD passing

13 years agoExtend RPC protocol to allow FD passing
Daniel P. Berrange [Fri, 21 Oct 2011 10:30:12 +0000 (11:30 +0100)]
Extend RPC protocol to allow FD passing

Define two new RPC message types VIR_NET_CALL_WITH_FDS and
VIR_NET_REPLY_WITH_FDS. These message types are equivalent
to VIR_NET_CALL and VIR_NET_REPLY, except that between the
message header, and payload there is a 32-bit integer field
specifying how many file descriptors have been passed.

The actual file descriptors are sent/recv'd out of band.

* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h,
  src/libvirt_private.syms: Add support for handling
  passed file descriptors
* src/rpc/virnetprotocol.x: Extend protocol for FD
  passing

13 years agoAdd APIs for virNetSocket for sending/receiving file descriptors
Daniel P. Berrange [Fri, 21 Oct 2011 10:13:21 +0000 (11:13 +0100)]
Add APIs for virNetSocket for sending/receiving file descriptors

Add APIs to the virNetSocket object, to allow file descriptors
to be sent/received over UNIX domain socket connections

* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h,
  src/libvirt_private.syms: Add APIs for FD send/recv

13 years agoWire up QEMU implementation for virDomainOpenGraphics
Daniel P. Berrange [Fri, 21 Oct 2011 08:00:13 +0000 (09:00 +0100)]
Wire up QEMU implementation for virDomainOpenGraphics

The QEMU monitor command 'add_client' can be used to connect to
a VNC or SPICE graphics display. This allows for implementation
of the virDomainOpenGraphics API

* src/qemu/qemu_driver.c: Implement virDomainOpenGraphics
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
  src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
  src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
  Add binding for 'add_client' command

13 years agoExtend graphics event to include UNIX socket
Daniel P. Berrange [Fri, 21 Oct 2011 08:14:02 +0000 (09:14 +0100)]
Extend graphics event to include UNIX socket

Not all VNC/SPICE servers use a TCP socket for their connections.
It is possible to configure a UNIX socket server. The graphics
event must thus include a UNIX socket address type.

* include/libvirt/libvirt.h.in: Add UNIX socket address type
  for graphics event
* src/qemu/qemu_monitor_json.c: Add 'unix' string to address
  type enum

13 years agoIntroduce the virDomainOpenGraphics API
Daniel P. Berrange [Fri, 21 Oct 2011 08:00:37 +0000 (09:00 +0100)]
Introduce the virDomainOpenGraphics API

The virDomainOpenGraphics API allows a libvirt client to pass in
a file descriptor for an open socket pair, and get it connected
to the graphics display of the guest. This is limited to working
with local libvirt hypervisors connected over a UNIX domain
socket, since it will use UNIX FD passing

* include/libvirt/libvirt.h.in: Define virDomainOpenGraphics
* src/driver.h: Define driver for virDomainOpenGraphics
* src/libvirt_public.syms, src/libvirt.c: Entry point for
  virDomainOpenGraphics
* src/libvirt_internal.h: VIR_DRV_FEATURE_FD_PASSING

13 years agoRemove trailing whitespace from all xfig files
Daniel P. Berrange [Fri, 28 Oct 2011 09:11:16 +0000 (10:11 +0100)]
Remove trailing whitespace from all xfig files

The 5th line of every xfig file has 'Letter   ' which
annoys GITs trailing-whitespace commit hook. Hand edit
the files to remove that trailing whitespace

* docs/*.fig: Remove trailing whitespace

13 years agoAdd documentation about migration.
Daniel P. Berrange [Fri, 2 Oct 2009 16:53:51 +0000 (17:53 +0100)]
Add documentation about migration.

This adds a page documenting many aspects of migration:

 - The types of migration (managed direct, p2p, unmanaged direct)
 - Data transports (native, tunnelled)
 - Migration URIs
 - Config file handling
 - Example scenarios

* libvirt.css: Rules for data tables and diagrams
* Makefile.am: Include extra png/fig files
* migration-managed-direct.fig, migration-managed-direct.png,
  migration-managed-direct.png, migration-managed-p2p.png,
  migration-native.fig, migration-native.png,
  migration-tunnel.fig, migration-tunnel.png,
  migration-unmanaged-direct.fig, migration-unmanaged-direct.png:
  Diagrams of migration
* migration.html.in, sitemap.html.in: New migration doc

13 years agovirsh: Fix error message on vol-create-from failure
Ryota Ozaki [Mon, 24 Oct 2011 11:44:04 +0000 (20:44 +0900)]
virsh: Fix error message on vol-create-from failure

If vol-create-from is failed due to 'input volume not found',
virsh outputs like this:
  $ sudo virsh vol-create-from testpool test-vol.xml test.img
  error: failed to get vol 'test.img', specifying --pool might help
  error: Storage volume not found: no storage vol with matching path
However, '--pool' is incorrect because it is already specified as
second argument ('testpool' in this case). It should be "--inputpool".

The patch fixes this by using pooloptname, which will be "inputpool"
in this case and "pool" in other cases, as error message.

13 years agobridge: modify for use when sVirt is enabled with qemu
Tyler Coumbes [Mon, 24 Oct 2011 23:43:47 +0000 (18:43 -0500)]
bridge: modify for use when sVirt is enabled with qemu

This refactors the TAP creation code out of brAddTap into a new
function brCreateTap to allow it to be used on its own. I have also
changed ifSetInterfaceMac to brSetInterfaceMac and exported it since
it is will be needed by code outside of util/bridge.c in the next
patch.

 AUTHORS                 |    1 +
 src/libvirt_bridge.syms |    2 +
 src/util/bridge.c       |  116 +++++++++++++++++++++++++++++++----------------
 src/util/bridge.h       |    9 ++++
 4 files changed, 89 insertions(+), 39 deletions(-)

13 years agoUse virXMLSaveFile when writing XML config
Jiri Denemark [Thu, 27 Oct 2011 16:55:47 +0000 (18:55 +0200)]
Use virXMLSaveFile when writing XML config

13 years agoIntroduce virXMLSaveFile as a wrapper for virFileRewrite
Jiri Denemark [Thu, 6 Oct 2011 09:57:06 +0000 (11:57 +0200)]
Introduce virXMLSaveFile as a wrapper for virFileRewrite

Every time we write XML into a file we call virEmitXMLWarning to write a
warning that the file is automatically generated. virXMLSaveFile
simplifies this into a single step and makes rewriting existing XML file
safe by using virFileRewrite internally.

13 years agoIntroduce virFileRewrite for safe file rewrite
Jiri Denemark [Thu, 13 Oct 2011 10:17:12 +0000 (12:17 +0200)]
Introduce virFileRewrite for safe file rewrite

When saving config files we just overwrite old content of the file. In
case something fails during that process (e.g. disk gets full) we lose
both old and new content. This patch makes the process more robust by
writing the new content into a separate file and only if that succeeds
the original file is atomically replaced with the new one.

13 years agoAdd a systemtap script for watching QEMU monitor interactions
Daniel P. Berrange [Mon, 24 Oct 2011 14:31:37 +0000 (15:31 +0100)]
Add a systemtap script for watching QEMU monitor interactions

This change adds some systemtap/dtrace probes to the QEMU monitor
client code. In particular it allows watching of all operations
for a VM

* examples/systemtap/qemu-monitor.stp: Watch all monitor commands
* src/Makefile.am: Passing libdir/bindir/sbindir to dtrace2systemtap.pl
* src/dtrace2systemtap.pl: Accept libdir/bindir/sbindir as args
  and look for '# binary:' comment to mark probes against libvirtd
  vs libvirt.so
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor_json.c,
  src/qemu/qemu_monitor_text.c: Add probes for key functions

13 years agolxc: Revert zeroing count of allocated items if VIR_REALLOC_N fails
Peter Krempa [Thu, 27 Oct 2011 08:24:30 +0000 (10:24 +0200)]
lxc: Revert zeroing count of allocated items if VIR_REALLOC_N fails

Previous commit clears number of items alocated in lxcSetupLoopDevices
if VIR_REALLOC_N fails. In that case, the pointer is not NULL, and
causes leaking FDs that have been allocated.

 *  src/lxc/lxc_controller.c: revert zeroing array size

13 years agoFix typo in virFileAccessibleAs
Daniel P. Berrange [Thu, 27 Oct 2011 08:25:02 +0000 (09:25 +0100)]
Fix typo in virFileAccessibleAs

* src/util/util.c: s/git_t/gid_t/ in parameter list of virFileAccessibleAs

13 years agolxc: avoid null deref on lxcSetupLoopDevices failure
Alex Jia [Thu, 27 Oct 2011 07:18:00 +0000 (15:18 +0800)]
lxc: avoid null deref on lxcSetupLoopDevices failure

If the function lxcSetupLoopDevices(def, &nloopDevs, &loopDevs) failed,
the variable loopDevs will keep a initial NULL value, however, the
function VIR_FORCE_CLOSE(loopDevs[i]) will directly deref it.

This patch also fixes returning a bogous number of devices from
lxcSetupLoopDevices on an error path.

* rc/lxc/lxc_controller.c: fixed a null pointer dereference.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agolxc: avoid missing '{' in the function
Alex Jia [Thu, 27 Oct 2011 07:17:59 +0000 (15:17 +0800)]
lxc: avoid missing '{' in the function

Cppcheck detected a syntaxError on lxcDomainInterfaceStats.

* src/lxc/lxc_driver.c: fixed missing '{' in the function lxcDomainInterfaceStats.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoqemu: simplify use of HAVE_YAJL
Eric Blake [Thu, 20 Oct 2011 20:36:32 +0000 (14:36 -0600)]
qemu: simplify use of HAVE_YAJL

Rather than making all clients of monitor commands that are JSON-only
check whether yajl support was compiled in, it is simpler to just
avoid setting the capability bit up front if we can't use the capability.

* src/qemu/qemu_capabilities.c (qemuCapsComputeCmdFlags): Only set
capability bit if we also have yajl library to use it.
* src/qemu/qemu_driver.c (qemuDomainReboot): Drop #ifdefs.
* src/qemu/qemu_process.c (qemuProcessStart): Likewise.
* tests/qemuhelptest.c (testHelpStrParsing): Pass test even
without yajl.
* tests/qemuxml2argvtest.c (mymain): Simplify use of json flag.
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-error-*.args:
Update expected results to match.

13 years agosnapshot: minor cleanups from reviewing indentation
Eric Blake [Wed, 26 Oct 2011 17:30:24 +0000 (11:30 -0600)]
snapshot: minor cleanups from reviewing indentation

Break some long lines, and use more efficient functions when possible,
such as relying on virBufferEscapeString to skip output on a NULL arg.
Ensure that output does not embed newlines, since auto-indent won't
work in those situations.

* src/conf/domain_conf.c (virDomainTimerDefFormat): Break output lines.
(virDomainDefFormatInternal, virDomainDiskDefFormat)
(virDomainActualNetDefFormat, virDomainNetDefFormat)
(virDomainHostdevDefFormat): Minor cleanups.

13 years agosnapshot: simplify indentation of disk encryption xml
Eric Blake [Thu, 22 Sep 2011 18:16:26 +0000 (12:16 -0600)]
snapshot: simplify indentation of disk encryption xml

Use auto-indent in more places.

* src/conf/storage_encryption_conf.h (virStorageEncryptionFormat):
Drop parameter.
* src/conf/storage_encryption_conf.c (virStorageEncryptionFormat)
(virStorageEncryptionSecretFormat): Simplify with auto-indent.
* src/conf/domain_conf.c (virDomainDiskDefFormat): Adjust caller.
* src/conf/storage_conf.c (virStorageVolTargetDefFormat): Likewise.

13 years agosnapshot: simplify indentation of nwfilter
Eric Blake [Thu, 22 Sep 2011 19:05:03 +0000 (13:05 -0600)]
snapshot: simplify indentation of nwfilter

Fixing this involved some refactoring of common code out of
domain_conf and nwfilter_conf into nwfilter_params.

* src/conf/nwfilter_params.h (virNWFilterFormatParamAttributes):
Adjust signature.
* src/conf/nwfilter_params.c (_formatParameterAttrs)
(virNWFilterFormatParamAttributes): Adjust indentation handling,
and handle filterref here.
(formatterParam): Delete unused struct.
* src/conf/domain_conf.c (virDomainNetDefFormat): Adjust caller.
* src/conf/nwfilter_conf.c (virNWFilterIncludeDefFormat): Likewise.

13 years agostorage: avoid null deref on qemu-img failure
Eric Blake [Fri, 21 Oct 2011 21:34:34 +0000 (15:34 -0600)]
storage: avoid null deref on qemu-img failure

Detected by Coverity.  Only possible if qemu-img gives bogus output,
but we might as well be robust.

* src/storage/storage_backend.c
(virStorageBackendQEMUImgBackingFormat): Check for strstr failure.

13 years agobuild: avoid RHEL 5 build failure on LXC
Eric Blake [Wed, 26 Oct 2011 16:11:50 +0000 (10:11 -0600)]
build: avoid RHEL 5 build failure on LXC

Per the discussion here, LXC on RHEL 5 makes no sense.
https://www.redhat.com/archives/libvir-list/2011-September/msg01169.html

* configure.ac (with_lxc): Reject RHEL 5.x LXC as too old.

13 years agobuild: use gnulib fdatasync
Eric Blake [Mon, 24 Oct 2011 22:40:05 +0000 (16:40 -0600)]
build: use gnulib fdatasync

Commit 1726a73 hacked around MacOS' lack of fdatasync, since
gnulib did not have it at the time.  But now that we use newer
gnulib, we can avoid the hack.

* bootstrap.conf (gnulib_modules): Add fdatasync.
* configure.ac (AC_CHECK_FUNCS_ONCE): Drop our own check.

13 years agoAdd REMOTE_PROC_DOMAIN_EVENT_DISK_CHANGE to remote_protocol-structs
Daniel P. Berrange [Tue, 25 Oct 2011 12:07:34 +0000 (13:07 +0100)]
Add REMOTE_PROC_DOMAIN_EVENT_DISK_CHANGE to remote_protocol-structs

* src/remote_protocol-structs: Add new event

13 years agonwfilter: extend schema to support new targets
Stefan Berger [Tue, 25 Oct 2011 15:21:57 +0000 (11:21 -0400)]
nwfilter: extend schema to support new targets

Extend the nwfilter schema to support the continue and return targets.

13 years agoutil: Add virFileAccessibleAs to private symbols
Michal Privoznik [Tue, 25 Oct 2011 09:38:13 +0000 (11:38 +0200)]
util: Add virFileAccessibleAs to private symbols

Commit 458b7099b2e791b58f1286002974927d3e8bcc80 introduced this
function. However it was not added into libvirt_private.syms so
the compilation may not succeed on some hosts.

13 years agostartupPolicy: Emit event on disk source dropping
Michal Privoznik [Tue, 18 Oct 2011 14:15:42 +0000 (16:15 +0200)]
startupPolicy: Emit event on disk source dropping

If a disk source gets dropped because it is not accessible,
mgmt application might want to be informed about this. Therefore
we need to emit an event. The event presented in this patch
is however a bit superset of what written above. The reason is simple:
an intention to be easily expanded, e.g. on 'user ejected disk
in guest' events. Therefore, callback gets source string and disk alias
(which should be unique among a domain) and reason (an integer);

13 years agoqemu: implement startupPolicy
Michal Privoznik [Tue, 18 Oct 2011 08:51:06 +0000 (10:51 +0200)]
qemu: implement startupPolicy

This patch implements on_missing feature in qemu driver.
Upon qemu startup process an accessibility of CDROMs
and floppy disks is checked. The source might get dropped
if unavailable and on_missing is set accordingly.
No event is emit thought. Look for follow up patch.

13 years agoqemu: Move device alias assigning before command line construction
Michal Privoznik [Thu, 20 Oct 2011 12:45:12 +0000 (14:45 +0200)]
qemu: Move device alias assigning before command line construction

This patch is rather cosmetic as it only moves device alias
assignation from command line construction just before that.
However, it is needed in connotation of previous and next patch.

13 years agoutil: Create virFileAccessibleAs function
Michal Privoznik [Mon, 17 Oct 2011 16:00:28 +0000 (18:00 +0200)]
util: Create virFileAccessibleAs function

This function checks if a given path is accessible under
given uid and gid.

13 years agoconf: Introduce optional startupPolicy attribute for cdrom and floppy
Michal Privoznik [Mon, 17 Oct 2011 14:54:03 +0000 (16:54 +0200)]
conf: Introduce optional startupPolicy attribute for cdrom and floppy

This attribute says what to do with cdrom (or floppy) if
the source is missing. It accepts:
- mandatory - fail if missing for any reason (the default)
- requisite - fail if missing on boot up, drop if missing on
              migrate/restore/revert
- optional  - drop if missing at any start attempt.

However, this patch introduces only XML part of this new
functionality.

13 years agostorage: make previous leak less likely to regress
Eric Blake [Fri, 21 Oct 2011 22:44:52 +0000 (16:44 -0600)]
storage: make previous leak less likely to regress

Splitting into two functions allows the user to call the right
function, rather than having to remember that a *Free function is
an exception to the rule.

* src/conf/storage_conf.h (virStoragePoolSourceClear): New function.
* src/libvirt_private.syms (storage_conf.h): Export it.
* src/conf/storage_conf.c (virStoragePoolSourceFree): Split...
(virStoragePoolSourceClear): ...into new function.
(virStoragePoolDefFree, virStoragePoolDefParseSourceString):
Update callers.
* src/test/test_driver.c (testStorageFindPoolSources): Likewise.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemNetFindPoolSourcesFunc)
(virStorageBackendFileSystemNetFindPoolSources): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIFindPoolSources): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalFindPoolSources): Likewise.

13 years agostorage: plug iscsi memory leak
Eric Blake [Fri, 21 Oct 2011 22:30:22 +0000 (16:30 -0600)]
storage: plug iscsi memory leak

Detected by Coverity.  virStoragePoolSourceFree does not free the
actual passed-in pointer.  A bigger patch would be to rename it
virStoragePoolSourceClear to match behavior, or even split it into
two functions depending on needed behavior; but this is the minimal
fix to the one location out of eight that leaked memory.

* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIFindPoolSources): Free memory.

13 years agowaitpid: improve safety
Eric Blake [Fri, 21 Oct 2011 17:09:23 +0000 (11:09 -0600)]
waitpid: improve safety

Based on a report by Coverity.  waitpid() can leak resources if it
fails with EINTR, so it should never be used without checking return
status.  But we already have a helper function that does that, so
use it in more places.

* src/lxc/lxc_container.c (lxcContainerAvailable): Use safer
virWaitPid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput, virtTestMain):
Likewise.
* src/libvirt.c (virConnectAuthGainPolkit): Simplify with virCommand.

13 years agoqemu: avoid leaking uninit data from hotplug to dumpxml
Eric Blake [Fri, 21 Oct 2011 23:09:17 +0000 (17:09 -0600)]
qemu: avoid leaking uninit data from hotplug to dumpxml

Detected by Coverity.  Both text and JSON monitors set only the
bus and unit fields, which means driveAddr.controller spends
life as garbage on the stack, and is then memcpy()'d into the
in-memory representation which the user can see via dumpxml.

* src/qemu/qemu_hotplug.c (qemuDomainAttachSCSIDisk): Only copy
defined fields.

13 years agovirsh: Fix vol-info's 'Type' output
Ryota Ozaki [Sat, 22 Oct 2011 04:24:17 +0000 (13:24 +0900)]
virsh: Fix vol-info's 'Type' output

We have a new vol type "dir" in addition to "file" and "block", but
virsh doesn't know it. Fix it.

Additionally, the patch lets virsh output "unknown" if not matched
any of them.

13 years agodocs: Document filesystem type='block' for LXC
Ryota Ozaki [Fri, 21 Oct 2011 14:26:29 +0000 (23:26 +0900)]
docs: Document filesystem type='block' for LXC

Commit 77791dc0e allows LXC to use a host block device as a guest
filesystem, but it isn't documented yet.

13 years agosupport continue/return targets in nwfilter
David L Stevens [Tue, 18 Oct 2011 19:55:25 +0000 (12:55 -0700)]
support continue/return targets in nwfilter

This patch adds support for "continue" and "return" actions
in filter rules.

Signed-off-by: David L Stevens <dlstevens@us.ibm.com>
13 years agosnapshot: simplify indentation of network xml
Eric Blake [Thu, 22 Sep 2011 18:00:45 +0000 (12:00 -0600)]
snapshot: simplify indentation of network xml

More simplifications possible due to auto-indent.  Also,
<bandwidth> within <actual> was only using 6 instead of 8 spaces.

* src/util/network.h (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter signature.
* src/util/network.c (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter indentation.
(virBandwidthChildDefFormat): Tweak to make use easier.
* src/conf/network_conf.c (virPortGroupDefFormat)
(virNetworkDefFormat): Adjust callers.
* src/conf/domain_conf.c (virDomainNetDefFormat): Likewise.
(virDomainActualNetDefFormat): Likewise, and fix bandwidth
indentation.

13 years agosnapshot: simplify indentation of cpu features
Eric Blake [Wed, 21 Sep 2011 23:42:07 +0000 (17:42 -0600)]
snapshot: simplify indentation of cpu features

Auto-indent makes life a bit easier; this patch also drops unused
arguments and replaces a misspelled flag name with two entry points
instead, so that callers don't have to worry about how much spacing
is present when embedding cpu elements.

* src/conf/cpu_conf.h (virCPUFormatFlags): Delete.
(virCPUDefFormat): Drop unused argument.
(virCPUDefFormatBuf): Alter signature.
(virCPUDefFormatBufFull): New prototype.
* src/conf/cpu_conf.c (virCPUDefFormatBuf): Split...
(virCPUDefFormatBufFull): ...into new function.
(virCPUDefFormat): Adjust caller.
* src/conf/domain_conf.c (virDomainDefFormatInternal): Likewise.
* src/conf/capabilities.c (virCapabilitiesFormatXML): Likewise.
* src/cpu/cpu.c (cpuBaselineXML): Likewise.
* tests/cputest.c (cpuTestCompareXML): Likewise.

13 years agosnapshot: simplify indentation of sysinfo
Eric Blake [Wed, 21 Sep 2011 23:28:01 +0000 (17:28 -0600)]
snapshot: simplify indentation of sysinfo

The improvements to virBuffer, along with a paradigm shift to pass
the original buffer through rather than creating a second buffer,
allow us to shave off quite a few lines of code.

* src/util/sysinfo.h (virSysinfoFormat): Alter signature.
* src/util/sysinfo.c (virSysinfoFormat, virSysinfoBIOSFormat)
(virSysinfoSystemFormat, virSysinfoProcessorFormat)
(virSysinfoMemoryFormat): Change indentation parameter.
* src/conf/domain_conf.c (virDomainSysinfoDefFormat): Adjust
caller.
* src/qemu/qemu_driver.c (qemuGetSysinfo): Likewise.

13 years agosnapshot: test domainsnapshot indentation
Eric Blake [Thu, 22 Sep 2011 20:29:00 +0000 (14:29 -0600)]
snapshot: test domainsnapshot indentation

Add a test for the simple parts of my indentation changes, and
fix the fallout.

* tests/domainsnapshotxml2xmltest.c: New test.
* tests/Makefile.am (domainsnapshotxml2xmltest_SOURCES): Build it.
* src/conf/domain_conf.c (virDomainSnapshotDefFormat): Avoid NULL
deref, match documented order.
* src/conf/domain_conf.h (virDomainSnapshotDefFormat): Add const.
* tests/domainsnapshotxml2xmlout/all_parameters.xml: Tweak output.
* tests/domainsnapshotxml2xmlout/disk_snapshot.xml: Likewise.
* tests/domainsnapshotxml2xmlout/full_domain.xml: Likewise.
* .gitignore: Exempt new binary.

13 years agosnapshot: indent domain xml when nesting
Eric Blake [Sat, 17 Sep 2011 12:57:30 +0000 (06:57 -0600)]
snapshot: indent domain xml when nesting

<domainsnapshot> is the first public instance of <domain> being
used as a sub-element, although we have two other private uses
(runtime state, and migration cookie).  Although indentation has
no effect on XML parsing, using it makes the output more consistent.

This uses virBuffer auto-indentation to obtain the effect, for all
but the portions of <domain> that are not generated a line at a
time into the same virBuffer.  Further patches will clean up the
remaining problems.

* src/conf/domain_conf.h (virDomainDefFormatInternal): New prototype.
* src/conf/domain_conf.c (virDomainDefFormatInternal): Export.
(virDomainObjFormat, virDomainSnapshotDefFormat): Update callers.
* src/libvirt_private.syms (domain_conf.h): Add new export.
* src/qemu/qemu_migration.c (qemuMigrationCookieXMLFormat): Use
new function.
(qemuMigrationCookieXMLFormatStr): Update caller.

13 years agovirbuf: add auto-indentation support
Eric Blake [Thu, 20 Oct 2011 21:48:47 +0000 (15:48 -0600)]
virbuf: add auto-indentation support

Rather than having to adjust all callers in a chain to deal with
indentation, it is nicer to have virBuffer do auto-indentation.

* src/util/buf.h (_virBuffer): Increase size.
(virBufferAdjustIndent, virBufferGetIndent): New prototypes.
* src/libvirt_private.syms (buf.h): Export new functions.
* src/util/buf.c (virBufferAdjustIndent, virBufferGetIndent): New
functions.
(virBufferSetError, virBufferAdd, virBufferAddChar)
(virBufferVasprintf, virBufferStrcat, virBufferURIEncodeString):
Implement auto-indentation.
* tests/virbuftest.c (testBufAutoIndent): Test it.
(testBufInfiniteLoop): Don't rely on internals.
Idea by Daniel P. Berrange.

13 years agovirbuf: more detailed error reporting
Eric Blake [Tue, 27 Sep 2011 19:37:23 +0000 (13:37 -0600)]
virbuf: more detailed error reporting

The next patch wants to add some sanity checking, which would
be a different error than ENOMEM.  Many existing callers blindly
report OOM failure if virBuf reports an error, and this will be
wrong in the (unlikely) case that they actually had a usage error
instead; but since the most common error really is ENOMEM, I'm
not going to fix all callers.  Meanwhile, new discriminating
callers can react differently depending on what failure happened.

* src/util/buf.c (virBufferSetError): Add parameter.
(virBufferGrow, virBufferVasprintf, virBufferEscapeString)
(virBufferEscapeSexpr, virBufferEscapeShell): Adjust callers.

13 years agovirbuf: improve testsuite reporting
Eric Blake [Sat, 17 Sep 2011 13:57:26 +0000 (07:57 -0600)]
virbuf: improve testsuite reporting

I had some temporary test failures while working on virbuf
improvements in later patches, with output that looked like:

Expected [<]
Actual [  <]

which is pretty hard to figure out.  Adding an Offset designation
made it much easier to find which particular '<' was at the
wrong indentation, to fix the right part of the code.

* tests/testutils.c (virtTestDifference): Make it easier to
diagnose test failures.