]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
10 years agostorage: better tests of lookup
Eric Blake [Fri, 13 Jun 2014 15:23:10 +0000 (09:23 -0600)]
storage: better tests of lookup

Add some more tests of what happens when we restrict a lookup
to begin at a point in the middle of a chain.  In particular,
we want to ensure that a parent is not found when starting at
the child.  This commit also demonstrates that we have a slight
difference in behavior on what parent we report when filtering
is in effect; as the determination of the parent affects the
code in block commit, exposing this in the testsuite will help
justify changes in future patches that tweak the semantics of
what lookups are allowed.

* tests/virstoragetest.c (testStorageLookup): Test user input.
(TEST_LOOKUP_TARGET): Add parameter.
(mymain): Add lookup tests.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agostorage: renumber lookup tests
Eric Blake [Fri, 13 Jun 2014 16:01:14 +0000 (10:01 -0600)]
storage: renumber lookup tests

The next patch will be adding tests, including adding a parameter
for testing more conditions.  For ease of review of that patch, I
want to create common context lines that don't change when the new
tests are added (it's easier to visually review additions than it
is to review an entire chunk of tests rewritten into another
larger chunk of tests).

* tests/virstoragetest.c (mymain): Add a parameter and renumber
the lookup tests.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agostorage: add alias for less typing
Eric Blake [Fri, 13 Jun 2014 14:44:09 +0000 (08:44 -0600)]
storage: add alias for less typing

Typing chain->backingStore->backingStore gets old after a while;
introduce some alias variables to make the test more compact.

* tests/virstoragetest.c (mymain): Introduce some shorthand.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoqemu: snapshot: Don't mark all block disks for metadata reuse
Peter Krempa [Mon, 16 Jun 2014 12:05:07 +0000 (14:05 +0200)]
qemu: snapshot: Don't mark all block disks for metadata reuse

For block devices used as snapshot source the new snapshot code would
set the reuse flag. This inhibits to take snapshot without specially
preparing the block image before taking the snapshot.

Fortunately this is not a regression as only the new way of specifying
snapshot source is affected.

For the followin snapshot XML:
 <domainsnapshot>
   <disks>
     <disk name='vda' type='block'>
       <driver type='qcow2'/>
       <source dev="/dev/andariel/testsnap" />
     </disk>
   </disks>
 </domainsnapshot>

You'd get:
error: internal error: unable to execute QEMU command 'transaction': Image is not in qcow2 format

After this patch the snapshot is created successfully.

10 years agoleaseshelper: fix another crash
Pavel Hrdina [Mon, 16 Jun 2014 12:16:22 +0000 (14:16 +0200)]
leaseshelper: fix another crash

We create a 'lease_new' when we are adding new lease entry, then later
in the code we add the 'lease_new' into a 'leases_array_new' which
leads into the crash because we double free the 'lease_new'.

To prevent the double free we set the 'lease_new' to NULL after
successful append into the 'leases_array_new'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agobhyve: silent destroy command errors on cleanup
Roman Bogorodskiy [Fri, 13 Jun 2014 18:51:18 +0000 (22:51 +0400)]
bhyve: silent destroy command errors on cleanup

When virBhyveProcessStart() fails, it tries to unload
a guest that could have been already loaded using
bhyveload(8) to make sure not to leave it hanging in memory.

However, we could fail before loading a VM into memory,
so 'bhyvectl --destroy' command will fail and print
an error message that looks confusing to users.

So ignore errors when running this in cleanup.

10 years agobhyve: do not cleanup unallocated networks on fail
Roman Bogorodskiy [Fri, 13 Jun 2014 14:56:59 +0000 (18:56 +0400)]
bhyve: do not cleanup unallocated networks on fail

virBhyveProcessStart() calls bhyveNetCleanup() if it fails. However,
it might fail earlier than networks are allocated, so modify
bhyveNetCleanup() to check if net->ifname is not NULL before
going further with the cleanup.

10 years agobhyve: fix crash in bhyveBuildNetArgStr
Roman Bogorodskiy [Fri, 13 Jun 2014 16:14:53 +0000 (20:14 +0400)]
bhyve: fix crash in bhyveBuildNetArgStr

bhyveBuildNetArgStr() calls virNetDevTapCreateInBridgePort() and
passes tapfd = NULL, but tapfdSize = 1. That is wrong, because
if virNetDevTapCreateInBridgePort() crashes after successfully
creating a TAP device, it'll jump to 'error' label, that
loops over tapfd and calls VIR_FORCE_CLOSE:

   for (i = 0; i < tapfdSize && tapfd[i] >= 0; i++)

In that case we get a segfault.

As the bhyve code doesn't use tapfd, pass NULL and set tapfdSize to 0.

10 years agostorage: report VIR_ERR_NO_STORAGE_VOL when the file doesn't exist
Giuseppe Scrivano [Fri, 13 Jun 2014 14:48:15 +0000 (16:48 +0200)]
storage: report VIR_ERR_NO_STORAGE_VOL when the file doesn't exist

Report VIR_ERR_NO_STORAGE_VOL instead of a system error when lstat
fails because the file doesn't exist.

Fixes this problem in virt-install:

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
10 years agobhyve: implement PCI address allocation
Roman Bogorodskiy [Sat, 12 Apr 2014 19:37:53 +0000 (23:37 +0400)]
bhyve: implement PCI address allocation

Automatically allocate PCI addresses for devices instead
of hardcoding them in the driver code. The current
allocation schema is to dedicate an entire slot for each devices.

Also, allow having arbitrary number of devices.

10 years agovirNetDevGetLinkInfo: Don't report link speed if NIC's not up
Michal Privoznik [Fri, 13 Jun 2014 09:29:48 +0000 (11:29 +0200)]
virNetDevGetLinkInfo: Don't report link speed if NIC's not up

The kernel's more broken than one would think. Various drivers report
various (usually spurious) values if the interface is in other state
than 'up' . While on some we experience -EINVAL when read()-ing the
speed sysfs file, with other drivers we might get anything from 0 to
UINT_MAX. If that's the case it's better to not report link speed.
Well, the interface is not up anyway.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agotests: virstoragetest: Fix output when hitting errors
Peter Krempa [Mon, 26 May 2014 14:39:38 +0000 (16:39 +0200)]
tests: virstoragetest: Fix output when hitting errors

When the test is failing but the debug output isn't enabled the
resulting line would look ugly like and would not contain the actual
difference.

TEST: virstoragetest
      .................chain member 1!chain member 1!chain member 1!

Store the member index in the actual checked string to hide this problem

10 years agoblockcommit: update error messages related to block jobs
Eric Blake [Tue, 3 Jun 2014 22:33:33 +0000 (16:33 -0600)]
blockcommit: update error messages related to block jobs

A future patch will add two-phase block commit jobs; as the
mechanism for managing them is similar to managing a block copy
job, existing errors should be made generic enough to occur
for either job type.

* src/conf/domain_conf.c (virDomainHasDiskMirror): Update
comment.
* src/qemu/qemu_driver.c (qemuDomainDefineXML)
(qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot)
(qemuDomainBlockJobImpl, qemuDomainBlockCopy): Update error
message.
* src/qemu/qemu_hotplug.c (qemuDomainDetachDiskDevice): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovirsh: improve blockcopy UI
Eric Blake [Wed, 11 Jun 2014 15:36:49 +0000 (09:36 -0600)]
virsh: improve blockcopy UI

Peter's review of an early version of my addition of active block
commit pointed out some issues that I was copying from the block
copy code; fix them up now before perpetuating them.

For virsh commands that manage a single API call, it's nice to have
a 1:1 mapping of options to flags, so that we can test that
lower-layer software handles flag combinations correctly.  But where
virsh is introducing syntactic sugar to combine multiple API calls
into a single user interface, we might as well make that interface
compact.  That is, we should allow the shorter command-line of
'blockcopy $dom $disk --pivot' without having to explicitly specify
--wait, because this isn't directly a flag passed to a single
underlying API call.

Also, my use of embedded ?: ternaries bordered on unreadable.

* tools/virsh-domain.c (cmdBlockCopy): Make --pivot, --finish,
and --timeout imply --wait. Drop excess ?: operators.
* tools/virsh.pod (blockcopy): Update documentation.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovirNodeDevCapPCIDevParseXML: Initialize numa_node variable
Michal Privoznik [Thu, 12 Jun 2014 09:14:20 +0000 (11:14 +0200)]
virNodeDevCapPCIDevParseXML: Initialize numa_node variable

With one of my recent patches (1c70277) libvirt's capable of
reporting NUMA node locality for PCI devices. The node ID is
stored in pci_dev.numa_node variable. However, since zero is
valid NUMA node ID, the default is -1 as it is in kernel too.
So, if the PCI device is not tied to any specific NUMA node, the
default is then NOT printed into XML. Therefore, when parsing
node device XML, the <node/> element is optional. But currently,
if it's not there, we must set sane default, otherwise after
parsing in the memory representation doesn't match the XML. We
are already doing this in other place: udevProcessPCI().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoblockcommit: fix regression with explicit top argument
Eric Blake [Wed, 11 Jun 2014 22:22:57 +0000 (16:22 -0600)]
blockcommit: fix regression with explicit top argument

Commit f586965 accidentally changed the semantics of the
virDomainBlockCommit command; where it previously looked for
an explicit top argument from the top of the chain, it now
starts from the backing file of the top.  Of course, until
we allow active commits, the only difference it makes is in
the quality of the error message, but with code for active
commit coming soon, we need to support an explicit mention
of the active layer.

* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Start looking
from top of chain.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovirsh: forbid negative vcpu argument to vcpupin
Jincheng Miao [Thu, 29 May 2014 03:34:40 +0000 (11:34 +0800)]
virsh: forbid negative vcpu argument to vcpupin

The vcpupin command allowed specifying a negative number for the --vcpu
argument. This would the overflow when the underlying virDomainPinVcpu
API was called.

 $ virsh vcpupin r7 -1 0
 error: numerical overflow: input too large: 4294967295

Switch the vCPU variable to a unsigned int and parse it using the
corresponding function.

Also improve the vcpupin test to cover all the defects.

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

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
10 years agovirsh: Reject negative numbers in vshCommandOptULongLong
Peter Krempa [Wed, 4 Jun 2014 09:08:08 +0000 (11:08 +0200)]
virsh: Reject negative numbers in vshCommandOptULongLong

To follow the new semantics of the vshCommandOptToU* functions convert
this one to reject negative numbers too. To allow using -1 for "maximum"
semantics for the vol-*load two bandwidth functions that use this helper
introduce vshCommandOptULongLongWrap.

10 years agovirsh: Reject negative numbers in vshCommandOptUL
Peter Krempa [Wed, 4 Jun 2014 09:08:08 +0000 (11:08 +0200)]
virsh: Reject negative numbers in vshCommandOptUL

To follow the new semantics of the vshCommandOptToU* functions convert
this one to reject negative numbers too. To allow using -1 for "maximum"
semantics for the two bandwidth functions that use this helper introduce
vshCommandOptULWrap. Although currently the migrate-setspeed function
for the qemu driver will reject -1 as maximum.

10 years agovirsh: Reject negative numbers in vshCommandOptUInt
Peter Krempa [Thu, 29 May 2014 11:12:26 +0000 (13:12 +0200)]
virsh: Reject negative numbers in vshCommandOptUInt

Use virStrToLong_uip instead of virStrToLong_ui to reject negative
numbers in the helper. None of the callers expects the wraparound
"feature" for negative numbers.

Also add a function that allows wrapping of negative numbers as it might
be used in the future and be explicit about the new semantics in the
function docs.

10 years agoFix crash when saving a domain with type none dac label
Ján Tomko [Thu, 12 Jun 2014 08:50:43 +0000 (10:50 +0200)]
Fix crash when saving a domain with type none dac label

qemuDomainGetImageIds did not check if there was a label
in the seclabel, thus crashing on
<seclabel type='none' model='dac'/>

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

10 years agovbox_snapshot_conf: Resolve Coverity warnings
John Ferlan [Wed, 11 Jun 2014 13:16:55 +0000 (09:16 -0400)]
vbox_snapshot_conf: Resolve Coverity warnings

Clean up some Coverity warnings from commit id '4dc5d8f1'

10 years agovbox_temp: Resolve Coverity warnings
John Ferlan [Wed, 11 Jun 2014 13:14:50 +0000 (09:14 -0400)]
vbox_temp: Resolve Coverity warnings

Clean up code to resolve Coverity RESOURCE_LEAK's from commit id's
'632b9600' and 'b739f807'.

10 years agosecurity: Don't skip labelling for network disks
Peter Krempa [Thu, 5 Jun 2014 13:56:33 +0000 (15:56 +0200)]
security: Don't skip labelling for network disks

A network disk might actually be backed by local storage. Also the path
iterator actually handles networked disks well now so remove the code
that skips the labelling in dac and selinux security driver.

10 years agostorage: volume: Rework lookup of volume objects
Peter Krempa [Thu, 5 Jun 2014 11:29:37 +0000 (13:29 +0200)]
storage: volume: Rework lookup of volume objects

Add a helper to do all the lookup steps and remove a ton of duplicated
code.

10 years agostorage: Clean up unlocking of storage pool objects
Peter Krempa [Thu, 12 Jun 2014 07:55:17 +0000 (09:55 +0200)]
storage: Clean up unlocking of storage pool objects

Most of the APIs now don't reach the cleanup section when the pool
object wasn't found and thus don't need to check before unlocking it.

10 years agostorage: pool: Fix handling of errors on pool lookup failure
Peter Krempa [Thu, 5 Jun 2014 08:40:59 +0000 (10:40 +0200)]
storage: pool: Fix handling of errors on pool lookup failure

Rework internal pool lookup code to avoid printing the raw UUID buffer
in the case a storage pool can't be found:

 $ virsh pool-name e012ace0-0460-5810-39ef-1bce5fa5a4dd
 error: failed to get pool 'e012ace0-0460-5810-39ef-1bce5fa5a4dd'
 error: Storage pool not found: no storage pool with matching uuid à¬à`X9ï_¥¤Ý

The rework is mostly done by switching the lookup code to the newly
introduced helper virStoragePoolObjFromStoragePool

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

10 years agobuild: prefer -fstack-protector-strong to -all
Ján Tomko [Wed, 11 Jun 2014 08:46:55 +0000 (10:46 +0200)]
build: prefer -fstack-protector-strong to -all

Try -fstack-protector-strong first on Linux. If that fails,
fall back to -fstack-protector-all.

10 years agobuild: remove ssp-buffer-size
Ján Tomko [Wed, 11 Jun 2014 08:44:26 +0000 (10:44 +0200)]
build: remove ssp-buffer-size

This option only makes sense for -fstack-protector.
With -fstack-protector-all or -fstack-protector-strong,
functions are protected regardless of buffer size.

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

10 years agobuild: remove duplicit warning suppression
Ján Tomko [Wed, 11 Jun 2014 08:38:18 +0000 (10:38 +0200)]
build: remove duplicit warning suppression

These warnings have already been added to $dontwarn.

10 years agolibxl: Resolve Coverity warnings
John Ferlan [Wed, 11 Jun 2014 13:31:19 +0000 (09:31 -0400)]
libxl: Resolve Coverity warnings

Resolve two Coverity issues introduced by commit id '9b8d6e1e'

Signed-off-by: John Ferlan <jferlan@redhat.com>
10 years agovirsh: include bhyve in virsh -V output
Roman Bogorodskiy [Tue, 10 Jun 2014 18:25:10 +0000 (22:25 +0400)]
virsh: include bhyve in virsh -V output

Add 'Bhyve' in hypervisor list reported by 'virsh -V'
if it's compiled it.

10 years agoleaseshelper: fix crash
Pavel Hrdina [Wed, 11 Jun 2014 15:17:15 +0000 (17:17 +0200)]
leaseshelper: fix crash

Commit baafe668 introduced new leaseshelper with a crash of freeing
env string. Calling 'getenv()' inside 'virGetEnvAllowSUID()' may
return a static string and we definitely should not free it.

The author probably want to free the copy of that string.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agomaint: exempt graphic binaries from syntax check
Eric Blake [Tue, 10 Jun 2014 19:34:07 +0000 (13:34 -0600)]
maint: exempt graphic binaries from syntax check

Roman Bogorodskiy reported a syntax-check failure when using
FreeBSD; complaining that:

prohibit_empty_first_line
tools/libvirt_win_icon_16x16.ico:1:
tools/libvirt_win_icon_32x32.ico:1:
tools/libvirt_win_icon_48x48.ico:1:
tools/libvirt_win_icon_64x64.ico:1:
maint.mk: Prohibited empty first line

In reality, the first 'line' of that file is NOT empty; but since
it is a binary file, awk is not required to handle it gracefully.
The simplest solution is to exempt all image files from syntax
checks in the first place - after all, we only store them in git
because they are inconvenient to regenerate, but they are not our
preferred format for making modifications, and syntax check should
only cover files that we are likely to modify.

* cfg.mk (VC_LIST_ALWAYS_EXCLUDE_REGEX): Exempt images.
(exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF): Simplify.
(exclude_file_name_regexp--sc_trailing_blank): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoqemu: Properly label FDs when restoring domain with static label
Shivaprasad G Bhat [Wed, 11 Jun 2014 13:48:34 +0000 (09:48 -0400)]
qemu: Properly label FDs when restoring domain with static label

When saving domain with relabel=no, the file that gets created must have the
context set anyway.  That way restore can be successful without the need of
relabelling the file.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
10 years agovmware: make version parsing more robust
Jean-Baptiste Rouault [Wed, 9 Apr 2014 09:59:53 +0000 (11:59 +0200)]
vmware: make version parsing more robust

Since commit d69415d4, vmware version is parsed from both stdout and
stderr. This patch makes version parsing work even if there is garbage
(libvirt debug messages for example) in the command output.

Add test data for this case.

10 years agovirnetdev: Use ifname in virNetDevGetLinkInfo
Michal Privoznik [Wed, 11 Jun 2014 11:05:17 +0000 (13:05 +0200)]
virnetdev: Use ifname in virNetDevGetLinkInfo

If we're compiling on non-Linux platform, the virNetDevGetLinkInfo()
is a dummy function which barely logs debug message that getting link
info is not supported. However, while the debug message was prepared
for printing the interface name too, I actually forgot to pass the
variable which resulted in build error on platforms like mingw or
FreeBSD.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agonode_device: Expose link state & speed
Michal Privoznik [Thu, 5 Jun 2014 15:36:31 +0000 (17:36 +0200)]
node_device: Expose link state & speed

While exposing the info under <interface/> in previous patch works, it
may work only in cases where interface is configured on the host.
However, orchestrating application may want to know the link state and
speed even in that case. That's why we ought to expose this in nodedev
XML too:

virsh # nodedev-dumpxml net_eth0_f0_de_f1_2b_1b_f3
<device>
  <name>net_eth0_f0_de_f1_2b_1b_f3</name>
  <path>/sys/devices/pci0000:00/0000:00:19.0/net/eth0</path>
  <parent>pci_0000_00_19_0</parent>
  <capability type='net'>
    <interface>eth0</interface>
    <address>f0:de:f1:2b:1b:f3</address>
    <link speed='1000' state='up'/>
    <capability type='80203'/>
  </capability>
</device>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agointerface_backend_udev: Implement link speed & state
Michal Privoznik [Thu, 5 Jun 2014 14:39:18 +0000 (16:39 +0200)]
interface_backend_udev: Implement link speed & state

In the previous commit the helper function was prepared, so now
we can wire it up and benefit from it. The Makefile change is
required because we're including virnedev,h which includes
virnetlink.h which tries to include netlink/msg.h. However this
file is not under /usr/include directly but is dependent on libnl
used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirnetdev: Introduce virNetDevGetLinkInfo
Michal Privoznik [Thu, 5 Jun 2014 14:14:49 +0000 (16:14 +0200)]
virnetdev: Introduce virNetDevGetLinkInfo

The purpose of this function is to fetch link state
and link speed for given NIC name from the SYSFS.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirInterface: Expose link state & speed
Michal Privoznik [Wed, 7 May 2014 12:21:35 +0000 (14:21 +0200)]
virInterface: Expose link state & speed

Currently it is not possible to determine the speed of an interface
and whether a link is actually detected from the API. Orchestrating
platforms want to be able to determine when the link has failed and
where multiple speeds may be available which one the interface is
actually connected at. This commit introduces an extension to our
interface XML (without implementation to interface driver backends):

  <interface type='ethernet' name='eth0'>
    <start mode='none'/>
    <mac address='aa:bb:cc:dd:ee:ff'/>
    <link speed='1000' state='up'/>
    <mtu size='1492'/>
    ...
  </interface>

Where @speed is negotiated link speed in Mbits per second, and state
is the current NIC state (can be one of the following:  "unknown",
"notpresent", "down", "lowerlayerdown","testing", "dormant", "up").

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agonodeinfo: avoid uninitialized variable on error
Eric Blake [Tue, 10 Jun 2014 22:23:09 +0000 (16:23 -0600)]
nodeinfo: avoid uninitialized variable on error

Commit 8ba0a58 introduced a compiler warning that I hit during
a run of ./autobuild.sh:

../../src/nodeinfo.c: In function 'nodeCapsInitNUMA':
../../src/nodeinfo.c:1853:43: error: 'nsiblings' may be used uninitialized in this function [-Werror=maybe-uninitialized]
         if (virCapabilitiesAddHostNUMACell(caps, n, memory,
                                           ^

Sure enough, nsiblings starts uninitialized, and is set by a call
to virNodeCapsGetSiblingInfo, but that function fails to assign
through the pointer if virNumaGetDistances fails.

* src/nodeinfo.c (nodeCapsInitNUMA): Initialize nsiblings.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agostorage: fix memory leak with encrypted images
Eric Blake [Mon, 9 Jun 2014 21:36:58 +0000 (15:36 -0600)]
storage: fix memory leak with encrypted images

Jim Fehlig reported a regression found by libvirt-TCK tests:

> ~ # perl /usr/share/libvirt-tck/tests/qemu/100-disk-encryption.t
...
> ok 4 - defined persistent domain config
> # Starting inactive domain config
> libvirt error code: 1, message: internal error: unable to execute QEMU command
> 'cont': 'drive-ide0-0-1'
> (/var/cache/libvirt-tck/300-disk-encryption/demo.qcow2) is encrypted

Commit 2279d560 converted a boolean into a pointer with the intent of
transferring that pointer out of a temporary object into the caller's
data structure.  The temporary structure meant that meta->encryption
was always NULL on entry, so we could get away with blindly allocating
the pointer when the header said so.  But later, commit 8823272d
tweaked things to do backing chain detection in-place, rather than via
a temporary object; this has the net result that meta->encryption can
be non-NULL on entry.  Not only did this turn the latent behavior into
a memory leak, it is also a behavior regression: blindly allocating a
new pointer wipes out what secrets we already knew about the chain,
making it impossible to restart the domain.

Of course, no one in their right mind should be relying on qcow2
encryption - it is fundamentally flawed.  And sadly, the TCK tests
don't get run often enough, and this shows that our virstoragetest
does not exercise encrypted images at all.  Otherwise, we could
have avoided a release containing this regression.

* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Don't nuke an already-existing encryption.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovbox: fix compilation error
Roman Bogorodskiy [Tue, 10 Jun 2014 17:08:13 +0000 (21:08 +0400)]
vbox: fix compilation error

clang complains about possibly uninitialized variable:

vbox/vbox_snapshot_conf.c:1355:9: error: variable 'ret' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
    if (!(xPathContext = xmlXPathNewContext(xml))) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So init 'ret' with NULL.

10 years agovirsh: Add details about specified migration host
Chen Fan [Mon, 9 Jun 2014 09:49:22 +0000 (17:49 +0800)]
virsh: Add details about specified migration host

the 'migration_host' description may be a bit difficult to
understand for some users, so enhance the manual

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockcommit: document semantics of committing active layer
Eric Blake [Fri, 16 May 2014 19:48:43 +0000 (13:48 -0600)]
blockcommit: document semantics of committing active layer

Now that qemu 2.0 allows commit of the active layer, people are
attempting to use virsh blockcommit and getting into a stuck
state, because libvirt is unprepared to handle the two-phase
commit required by qemu.

Stepping back a bit, there are two valid semantics for a
commit operation:

1. Maintain a 'golden' base, and a transient overlay. Make
changes in the overlay, and if everything appears to work,
commit those changes into the base, but still keep the overlay
for the next round of changes; repeat the cycle as desired.

2. Create an external snapshot, then back up the stable state
in the backing file. Once the backup is complete, commit the
overlay back into the base, and delete the temporary snapshot.

Since qemu doesn't know up front which of the two styles is
preferred, a block commit of the active layer merely gets
the job into a synchronized state, and sends an event; then
the user must either cancel (case 1) or complete (case 2),
where qemu then sends a second event that actually ends the
job.  However, until commit e6bcbcd, libvirt was blindly
assuming the semantics that apply to a commit of an
intermediate image, where there is only one sane conclusion
(the job automatically ends with fewer elements in the chain);
and getting stuck because it wasn't prepared for qemu to enter
a second phase of the job.

This patch adds a flag to the libvirt API that a user MUST
supply in order to acknowledge that they will be using two-phase
semantics.  It might be possible to have a mode where if the
flag is omitted, we automatically do the case 2 semantics on
the user's behalf; but before that happens, I must do additional
patches to track the fact that we are doing an active commit
in the domain XML.  Later patches will add support of the flag,
and once 2-phase semantics are working, we can then decide
whether to relax things to allow an omitted flag to cause an
automatic pivot.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)
(VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT): New enums.
* src/libvirt.c (virDomainBlockCommit): Document two-phase job
when committing active layer, through new flag.
(virDomainBlockJobAbort): Document that pivot also occurs after
active commit.
* tools/virsh-domain.c (vshDomainBlockJob): Cover new job.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Explicitly
reject active copy; later patches will add it in.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agodocs: fix a typo in hacking.html.in
Wangrui (K) [Tue, 10 Jun 2014 09:18:02 +0000 (09:18 +0000)]
docs: fix a typo in hacking.html.in

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovbox_tmpl.c: Add function for undefining snapshot
Yohan BELLEGUIC [Mon, 19 May 2014 12:47:33 +0000 (14:47 +0200)]
vbox_tmpl.c: Add function for undefining snapshot

All snapshots information will be deleted from the vbox XML, but
differencing disks will be kept so the user will be able to redefine the
snapshot.

10 years agovbox_tmpl.c: Patch for redefining snapshots
Yohan BELLEGUIC [Mon, 19 May 2014 12:47:32 +0000 (14:47 +0200)]
vbox_tmpl.c: Patch for redefining snapshots

The machine is unregistered and its vbox XML file is changed in order to
add snapshot information. The machine is then registered with the
snapshot to redefine.

10 years agoAdd vbox_snapshot_conf struct
Yohan BELLEGUIC [Mon, 19 May 2014 12:47:31 +0000 (14:47 +0200)]
Add vbox_snapshot_conf struct

This structure contains the data to be saved in the VirtualBox XML file
and can be manipulated with severals exposed functions.
The structure is created by vboxSnapshotLoadVboxFile taking the
machine XML file.
It also can rewrite the XML by using vboxSnapshotSaveVboxFile.

10 years agovbox_tmpl.c: Better XML description for snapshots
Manuel VIVES [Mon, 19 May 2014 12:47:30 +0000 (14:47 +0200)]
vbox_tmpl.c: Better XML description for snapshots

It will be needed for the future patches because we will
redefine snapshots

10 years agoSELinux: don't fail silently when no label is present
Ján Tomko [Mon, 9 Jun 2014 14:23:52 +0000 (16:23 +0200)]
SELinux: don't fail silently when no label is present

This fixes startup of a domain with:
<seclabel type='none' model='dac'/>
on a host with selinux and dac drivers and
security_default_confined = 0

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

10 years agoqemu: ignore -nodefconfig and -nodefaults when parsing commandline
Laine Stump [Fri, 6 Jun 2014 13:03:58 +0000 (16:03 +0300)]
qemu: ignore -nodefconfig and -nodefaults when parsing commandline

The qemu driver always adds these options to the qemu commandlines,
but the commandline parser didn't recognize them, so sending a
libvirt-generated qemu commandline to its own argvtoxml would always
result in a warning message and a qemu namespace added to the
xml. Since the options don't add any functionality to the domain, they
should just be ignored (similar to -S).

Note that we can't yet add a test for this to qemuargv2xmltest,
because we would have to add QEMU_CAPS_NODEFCONFIG and
QEMU_CAPS_DEVICE to the capabilities for any corresponding
xml2argvtest, and QEMU_CAPS_DEVICE would necessitate having support
for parsing a memballoon device in order for qemuargv2xmltest to
pass. So we wait to add a test for -nodefconfig and -nodefaults until
after adding support for parsing -device virtio-balloon-*.

10 years agotest: display qemuParseCommandline warnings when VIR_TEST_DEBUG > 0
Laine Stump [Fri, 6 Jun 2014 12:40:31 +0000 (15:40 +0300)]
test: display qemuParseCommandline warnings when VIR_TEST_DEBUG > 0

qmeuargv2xmltest.c would fail any test that logged anything during
qemuParseCommandline(), but then discard the log message, even with
VIR_TEST_DEBUG=2. This patch outputs the log messages with
fprintf(stderr,...) when debug logging is on.

In the process of modifying that logic, the testInfo data was made
more similar to that of qemuxml2argvtest.c - rather than turning
info->extraFlags into a bool, an enum of flags is defined, the info
struct is given an "unsigned int flags", and FLAG_EXPECT_WARNING is
saved into info->flags, to be checked during the test; this will make
it easier to add other FLAG_EXPECT_* items in the future.

10 years agoparallels: Avoid possible leak of "cpu" from parallelsBuildCapabilities
Peter Krempa [Mon, 9 Jun 2014 07:36:30 +0000 (09:36 +0200)]
parallels: Avoid possible leak of "cpu" from parallelsBuildCapabilities

4d06af97d38c3648937eb8f732704379b3cd9e59 introduced a possible memory
leak of the memory allocated into the "cpu" pointer in
parallelsBuildCapabilities in the case "nodeGetInfo()" would fail right
after the allocation. Rearrange the code to avoid the possibility of the
leak.

Found by Coverity.

10 years agom4: bhyve: Fix check for the required bhyve programs
Peter Krempa [Fri, 6 Jun 2014 15:25:11 +0000 (17:25 +0200)]
m4: bhyve: Fix check for the required bhyve programs

bhyveload and bhyvectl wouldn't be checked otherwise as the configure
script wouldn't execute one of the tests:

checking for bhyve... /usr/local/sbin/bhyve
checking for bhyvectl... /usr/local/sbin/bhyvectl
checking for bhyveload... /usr/local/sbin/bhyveload
./configure: line 62602: test: too many arguments

Fix the shell statement testing the 3 binaries.

10 years agovmx: Relax virtualHW.version check
Matthias Bolte [Sat, 10 May 2014 14:36:56 +0000 (16:36 +0200)]
vmx: Relax virtualHW.version check

The original implementation of the VMX config parser assumed that the
virtualHW.version would have more influence on the content of the VMX
file than it actually seems to have. It started with accepting only
version 4. Additonal versions were added later without any additional
changes in the parser itself. This suggests that the influence of the
virtualHW.version on the content and format of the VMX file is small
or non-existent.

The parser worked without any changes across several virtualHW and
vSphere versions. So instead of adding new virtualHW.version values to
the parser as they come along, or adding an extra flag to allow unknown
virtualHW.version values just relax the check to require version 4 or
later.

10 years agoconf: alter disk mirror xml output
Eric Blake [Thu, 22 May 2014 04:39:57 +0000 (22:39 -0600)]
conf: alter disk mirror xml output

Now that we track a disk mirror as a virStorageSource, we might
as well update the XML to theoretically allow any type of
mirroring destination (not just a local file).  A later patch
will also be reusing <mirror> to track the block commit of the
top layer of a chain, which is another case where libvirt needs
to update the backing chain after the job is finally pivoted,
and since backing chains can have network backing files as the
destination to commit into, it makes more sense to display that
in the XML.

This patch changes output-only XML; it was already documented
that <mirror> does not affect a domain definition at this point
(because qemu doesn't provide persistent bitmaps yet).  Any
application that was starting a block copy job with older libvirt
and then relying on the domain XML to determine if it was
complete will no longer be able to access the file= and format=
attributes of mirror that were previously used.  However, this is
not going to be a problem in practice: the only time a block copy
job works is on a transient domain, and any app that is managing
a transient domain probably already does enough of its own
bookkeeping to know which file it is mirroring into without
having to re-read it from the libvirt XML.  The one thing that
was likely to be used in a mirroring job was the ready=
attribute, which is unchanged.  Meanwhile, I made sure the schema
and parser still accept the old format, even if we no longer
output it, so that upgrading from an older version of libvirt is
seamless.

* docs/schemas/domaincommon.rng (diskMirror): Alter definition.
* src/conf/domain_conf.c (virDomainDiskDefParseXML): Parse two
styles of mirror elements.
(virDomainDiskDefFormat): Output new style.
* tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml: New
file, copied from...
* tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml: ...here
before modernizing.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old*: New
files.
* tests/qemuxml2xmltest.c (mymain): Test both styles.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoconf: store mirroring information in virStorageSource
Eric Blake [Wed, 21 May 2014 20:22:21 +0000 (14:22 -0600)]
conf: store mirroring information in virStorageSource

The current implementation of 'virsh blockcopy' (virDomainBlockRebase)
is limited to copying to a local file name.  But future patches want
to extend it to also copy to network disks.  This patch converts over
to a virStorageSourcePtr, although it should have no semantic change
visible to the user, in anticipation of those future patches being
able to use more fields for non-file destinations.

* src/conf/domain_conf.h (_virDomainDiskDef): Change type of
mirror information.
* src/conf/domain_conf.c (virDomainDiskDefParseXML): Localize
mirror parsing into new object.
(virDomainDiskDefFormat): Adjust clients.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockPivot)
(qemuDomainBlockJobImpl, qemuDomainBlockCopy): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoconf: store disk source as pointer, for easier manipulation
Eric Blake [Wed, 21 May 2014 23:13:12 +0000 (17:13 -0600)]
conf: store disk source as pointer, for easier manipulation

As part of the work on backing chains, I'm finding that it would
be easier to directly manipulate chains of pointers (adding a
snapshot merely adjusts pointers to form the correct list) rather
than copy data from one struct to another.  This patch converts
domain disk source to be a pointer.

In this patch, the pointer is ALWAYS allocated (thanks in part to
the previous patch forwarding all disk def allocation through a
common point), and all other changse are just mechanical fallout of
the new type; there should be no functional change.  It is possible
that we may want to leave the pointer NULL for a cdrom with no
medium in a later patch, but as that requires a closer audit of the
source to ensure we don't fault on a null dereference, I didn't do
it here.

* src/conf/domain_conf.h (_virDomainDiskDef): Change type of src.
* src/conf/domain_conf.c: Adjust all clients.
* src/security/security_selinux.c: Likewise.
* src/qemu/qemu_domain.c: Likewise.
* src/qemu/qemu_command.c: Likewise.
* src/qemu/qemu_conf.c: Likewise.
* src/qemu/qemu_process.c: Likewise.
* src/qemu/qemu_migration.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/lxc/lxc_driver.c: Likewise.
* src/lxc/lxc_controller.c: Likewise.
* tests/securityselinuxlabeltest.c: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoconf: consolidate disk def allocation
Eric Blake [Wed, 21 May 2014 22:50:41 +0000 (16:50 -0600)]
conf: consolidate disk def allocation

A future patch wants to create disk definitions with non-zero
default contents; to avoid crashes, all callers that allocate
a disk definition should go through a common point.

I found allocation points by looking for any code that increments
ndisks, as well as any matches for ALLOC.*disk.  Most places that
modified ndisks were covered by the parse from XML to domain/device
definition by initial domain creation or device hotplug; I also
hand-checked all drivers that generate a device struct on the
fly during getXMLDesc.

* src/conf/domain_conf.h (virDomainDiskDefNew): New prototype.
* src/conf/domain_conf.c (virDomainDiskDefNew): New function.
(virDomainDiskDefParseXML): Use it.
* src/parallels/parallels_driver.c (parallelsAddHddInfo):
Likewise.
* src/qemu/qemu_command.c (qemuParseCommandLine): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc): Likewise.
* src/vmx/vmx.c (virVMXParseDisk): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr):
Likewise.
* src/xenxs/xen_xm.c (xenParseXM): Likewise.
* src/libvirt_private.syms (domain_conf.h): Export it.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoconf: store snapshot source as pointer, for easier manipulation
Eric Blake [Wed, 21 May 2014 21:21:02 +0000 (15:21 -0600)]
conf: store snapshot source as pointer, for easier manipulation

As part of the work on backing chains, I'm finding that it would
be easier to directly manipulate chains of pointers (adding a
snapshot merely adjusts pointers to form the correct list) rather
than copy data from one struct to another. This patch converts
snapshot source to be a pointer.

In this patch, the pointer is ALWAYS allocated (any code that
increases ndisks now also allocates a source pointer for each
new disk), and all other changes are just mechanical fallout of
the new type; there should be no functional change.  It is
possible that we may want to leave the pointer NULL for internal
snapshots in a later patch, but as that requires a closer audit
of the source to ensure we don't fault on a null dereference, I
didn't do it here.

* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Change
type of src.
* src/conf/snapshot_conf.c: Adjust all clients.
* src/qemu/qemu_conf.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoFix virbitmaptest on 32-bit
Ján Tomko [Fri, 6 Jun 2014 14:50:33 +0000 (16:50 +0200)]
Fix virbitmaptest on 32-bit

My commit 7d8afc4 was passing the incorrect size to
virBitmapDataToString in the newly added test.

10 years agonodedev: Export NUMA node locality for PCI devices
Michal Privoznik [Wed, 7 May 2014 16:07:12 +0000 (18:07 +0200)]
nodedev: Export NUMA node locality for PCI devices

A PCI device can be associated with a specific NUMA node. Later, when
a guest is pinned to one NUMA node the PCI device can be assigned on
different NUMA node. This makes DMA transfers travel across nodes and
thus results in suboptimal performance. We should expose the NUMA node
locality for PCI devices so management applications can make better
decisions.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoImplement pretty flag for vcpuinfo and nodecpumap
Ján Tomko [Thu, 5 Jun 2014 11:16:00 +0000 (13:16 +0200)]
Implement pretty flag for vcpuinfo and nodecpumap

Report CPU affinities / online CPUs in human-readable form when
this flag is present:

Before:
CPU Affinity:   y-yy

After:
CPU Affinity:   0,2-3 (out of 4)

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

10 years agoIntroduce virBitmapDataToString
Ján Tomko [Thu, 5 Jun 2014 09:23:28 +0000 (11:23 +0200)]
Introduce virBitmapDataToString

For converting bitmap data to human-readable strings.

10 years agoAlways report an error if virBitmapFormat fails
Ján Tomko [Thu, 5 Jun 2014 09:24:24 +0000 (11:24 +0200)]
Always report an error if virBitmapFormat fails

It already reports an error if STRDUP fails.

10 years agoFormat NULL bitmap as an empty string
Ján Tomko [Thu, 5 Jun 2014 10:42:40 +0000 (12:42 +0200)]
Format NULL bitmap as an empty string

This simplifies the usage in {libxl,qemu}DomainGetNumaParameters
and it's needed for consistent error reporting in virBitmapFormat.

Also remove the forgotten ATTRIBUTE_NONNULL marker.

10 years agovirsh: Separate API calls and result printing in cmdVcpuinfo
Ján Tomko [Thu, 5 Jun 2014 08:42:23 +0000 (10:42 +0200)]
virsh: Separate API calls and result printing in cmdVcpuinfo

This allows reuse of the result printing code.

10 years agovirsh: Invert logic in cmdVcpuinfo
Ján Tomko [Thu, 5 Jun 2014 08:42:19 +0000 (10:42 +0200)]
virsh: Invert logic in cmdVcpuinfo

Initialize 'ret' to false and introduce a cleanup label.

10 years agoParallels: Include CPU info in the capabilities XML
Alexander Burluka [Thu, 5 Jun 2014 05:50:06 +0000 (09:50 +0400)]
Parallels: Include CPU info in the capabilities XML

Openstack uses (or will start to using) CPU info from the
capabilities XML. So this section is expanded, added CPU info
about arch, type and info about number of cores, sockets and threads.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoParallels: add connectBaselineCPU()
Alexander Burluka [Thu, 5 Jun 2014 05:50:05 +0000 (09:50 +0400)]
Parallels: add connectBaselineCPU()

Openstack Nova (starting at Icehouse release) requires this function
to start VM.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoParallels: add domainGetVcpus()
Alexander Burluka [Thu, 5 Jun 2014 05:50:04 +0000 (09:50 +0400)]
Parallels: add domainGetVcpus()

OpenStack Nova requires this function
to start VM instance. Cpumask info is obtained via prlctl utility.
Unlike KVM, Parallels Cloud Server is unable to set cpu affinity
mask for every VCpu. Mask is unique for all VCpu. You can set it
using 'prlctl set <vm_id|vm_name> --cpumask <{n[,n,n1-n2]|all}>'
command. For example, 'prlctl set SomeDomain --cpumask 0,1,5-7'
would set this mask to yy---yyy.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: prohibit empty first lines
Martin Kletzander [Tue, 18 Mar 2014 10:29:12 +0000 (11:29 +0100)]
maint: prohibit empty first lines

Based on discussion with Eric:

https://www.redhat.com/archives/libvir-list/2014-March/msg01001.html

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoRemove unnecessary empty first lines
Martin Kletzander [Fri, 6 Jun 2014 08:51:52 +0000 (10:51 +0200)]
Remove unnecessary empty first lines

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agotranslations: Don't leave default template fields in .po files
Martin Kletzander [Tue, 3 Jun 2014 15:18:33 +0000 (17:18 +0200)]
translations: Don't leave default template fields in .po files

New gettext-0.19 doesn't like it and we can't build without it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoFix storage format probing
Ján Tomko [Thu, 5 Jun 2014 16:47:21 +0000 (18:47 +0200)]
Fix storage format probing

Commit fff74b2 moved the probing into virStorageFileGetMetadataFromBuf
but didn't update the format in volume definition.

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

10 years agoSimplify conditions in virStorageBackendProbeTarget
Ján Tomko [Thu, 5 Jun 2014 16:22:48 +0000 (18:22 +0200)]
Simplify conditions in virStorageBackendProbeTarget

Jump out early if no metadata was detected (for directories).
Join the error and cleanup labels.

10 years agoDon't reuse 'ret' variable in virStorageBackendProbeTarget
Ján Tomko [Thu, 5 Jun 2014 16:19:16 +0000 (18:19 +0200)]
Don't reuse 'ret' variable in virStorageBackendProbeTarget

To match the convention:
ret - current function's return value
rc - other function's return values

10 years agoformatcaps: Rework and add stubs to document
Michal Privoznik [Thu, 5 Jun 2014 11:53:17 +0000 (13:53 +0200)]
formatcaps: Rework and add stubs to document

At the moment we are missing even basic documentation on our
capabilities XML. Without demand on completeness, I'm
reorganizing the document structure and adding very basic
documentation to two major components of the capabilities XML.
These stubs are intended to be enhanced in the future.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovircaps2xmltest: Introduce basic testing
Michal Privoznik [Thu, 5 Jun 2014 11:53:16 +0000 (13:53 +0200)]
vircaps2xmltest: Introduce basic testing

For now only one test is introduced. It's purpose in life
is to check we don't break NUMA host distances XML format.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agolibxl: add migration support
Jim Fehlig [Thu, 8 May 2014 21:56:51 +0000 (15:56 -0600)]
libxl: add migration support

This patch adds initial migration support to the libxl driver,
using the VIR_DRV_FEATURE_MIGRATION_PARAMS family of migration
functions.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agolibxl: introduce libxlDomainDefCheckABIStability
Jim Fehlig [Wed, 4 Jun 2014 20:02:27 +0000 (14:02 -0600)]
libxl: introduce libxlDomainDefCheckABIStability

Introduce a simple libxlDomainDefCheckABIStability() function that
can be used check ABI stability between two virDomainDef objects.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
10 years agomaint: detect VPATH builds when checking for gnulib update
Eric Blake [Wed, 4 Jun 2014 21:48:20 +0000 (15:48 -0600)]
maint: detect VPATH builds when checking for gnulib update

I accidentally typed 'make' in the srcdir of a VPATH build, and
was surprised to see this:

$ make
/bin/sh: s/^[ +-]//;s/ .*//: No such file or directory
INFO: gnulib update required; running ./autogen.sh first
make: -n: Command not found
./autogen.sh
I am going to run ./configure with no arguments - if you wish
to pass any to it, please specify them on the ./autogen.sh command line.
running bootstrap...
./bootstrap: Bootstrapping from checked-out libvirt sources...
./bootstrap: getting gnulib files...

Oops - we're trying to execute some fairly bogus command names,
and then trying to configure in-tree (which breaks all existing
VPATH builds, since automake refuses to do a VPATH build if it
detects an in-tree configure).  The third line (executing "-n")
is fixed by updating to the latest gnulib; the rest of the problem
is fixed by copying the same filtering in our cfg.mk as what
gnulib just added, so that we avoid any $(shell) invocations which
in turn depend on variables that are only populated by a working
Makefile.  With that in place, we are back to the much nicer:

$ make
There seems to be no Makefile in this directory.
You must run ./configure before running 'make'.
make: *** [abort-due-to-no-makefile] Error 1

Additionally, although harder to see - there was a trailing space in
the message warning us that autogen would run an in-tree configure.

* .gnulib: Update to latest, in part for maint.mk improvements.
* cfg.mk (_update_required): Don't check for update in
unconfigured directory.
* autogen.sh (no_git): Drop trailing space.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: optimize locale.h syntax check
Eric Blake [Wed, 4 Jun 2014 17:07:59 +0000 (11:07 -0600)]
maint: optimize locale.h syntax check

Reusing the maint.mk code allows for a more efficient syntax check
(fewer grep processes), and a more compact representation of what
we are really checking for in commit 1919e35.

* cfg.mk (sc_require_locale_h): Use maint.mk loop instead of
rolling our own.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovirnuma: Check for numa_bitmask_isbitset presence
Michal Privoznik [Wed, 4 Jun 2014 12:39:01 +0000 (14:39 +0200)]
virnuma: Check for numa_bitmask_isbitset presence

On some systems, libnuma can be present but it's so ancient that
it misses some symbols that virNumaGetDistances() needs. To be
more precise: numa_bitmask_isbitset() and numa_nodes_ptr are the
symbols in question. Fortunately, they were both introduced in
the same release so it's sufficient for us to check for only one
of them. And the winner is numa_bitmask_isbitset().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agocfg.mk: Introduce rule for setlocale()
Michal Privoznik [Wed, 4 Jun 2014 08:57:21 +0000 (10:57 +0200)]
cfg.mk: Introduce rule for setlocale()

In the past we had some issues where setlocale() was called without
corresponding include of locale.h. While on some systems this may
work, on others the compilation failed. We should have a syntax-check
rule for that to prevent this from happening again.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirnuma: Implement virNumaGetDistances stub for non-NUMA
Michal Privoznik [Wed, 4 Jun 2014 09:05:34 +0000 (11:05 +0200)]
virnuma: Implement virNumaGetDistances stub for non-NUMA

In case the libvirt is built without numactl support, we're
missing the virNumaGetDistances() stub so the linking fails:

  CCLD     libvirt_lxc
libvirt_lxc-nodeinfo.o: In function `virNodeCapsGetSiblingInfo':
/home/zippy/tmp/libvirt.git/src/nodeinfo.c:1763: undefined reference to `virNumaGetDistances'
collect2: error: ld returned 1 exit status
make[3]: *** [libvirt_lxc] Error 1

The issue was introduced in 77c830d8c4.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCaps: Expose distance between host NUMA nodes
Michal Privoznik [Tue, 3 Jun 2014 13:18:27 +0000 (15:18 +0200)]
virCaps: Expose distance between host NUMA nodes

If user or management application wants to create a guest,
it may be useful to know the cost of internode latencies
before the guest resources are pinned. For example:

<capabilities>

  <host>
    ...
    <topology>
      <cells num='2'>
        <cell id='0'>
          <memory unit='KiB'>4004132</memory>
          <distances>
            <sibling id='0' value='10'/>
            <sibling id='1' value='20'/>
          </distances>
          <cpus num='2'>
            <cpu id='0' socket_id='0' core_id='0' siblings='0'/>
            <cpu id='2' socket_id='0' core_id='2' siblings='2'/>
          </cpus>
        </cell>
        <cell id='1'>
          <memory unit='KiB'>4030064</memory>
          <distances>
            <sibling id='0' value='20'/>
            <sibling id='1' value='10'/>
          </distances>
          <cpus num='2'>
            <cpu id='1' socket_id='0' core_id='0' siblings='1'/>
            <cpu id='3' socket_id='0' core_id='2' siblings='3'/>
          </cpus>
        </cell>
      </cells>
    </topology>
    ...
  </host>
  ...
</capabilities>

We can see the distance from node1 to node0 is 20 and within nodes 10.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirnuma: Introduce virNumaGetDistances
Michal Privoznik [Mon, 2 Jun 2014 10:06:56 +0000 (12:06 +0200)]
virnuma: Introduce virNumaGetDistances

The API gets a NUMA node and find distances to other nodes.  The
distances are returned in an array. If an item X within the array
equals to value of zero, then there's no such node as X.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agotests: monitor: json: Fix error message when returning json in json
Peter Krempa [Tue, 3 Jun 2014 15:12:48 +0000 (17:12 +0200)]
tests: monitor: json: Fix error message when returning json in json

The qemu JSON monitor test allows to test also expected command
arguments. As the error from the monitor simulator is returned as a
simulated qemu error (in JSON) all other JSON contained in the error
message needs to be escaped. This will happen if the monitor command
under test receives a JSON array as an argument.

This will improve the error message from:
libvirt:  error : internal error: cannot parse json { "error":  { "desc":
"Invalid value of argument 'keys' of command 'send-key': expected 'ble'
got '[{"type":"number","data":43},{"type":"number","data":26},
{"type":"number","data":46},{"type":"number","data":32}]'",
"class": "UnexpectedCommand" } }: lexical error: invalid string in json text.

To:
libvirt: QEMU Driver error : internal error: unable to execute QEMU
command 'send-key': Invalid value of argument 'keys' of command
'send-key': expected 'ble' got '[{"type":"number","data":43},
{"type":"number","data":26},{"type":"number","data":46},
{"type":"number","data":32}]'

This improvement will not have any effect on tests executing as
expected, but it will help test development.

10 years agonetwork: bridge: Avoid memory leak from networkBuildDhcpDaemonCommandLine
Peter Krempa [Tue, 3 Jun 2014 12:34:23 +0000 (14:34 +0200)]
network: bridge: Avoid memory leak from networkBuildDhcpDaemonCommandLine

If the leasehelper_path couldn't be found the code would leak the
freshly constructed command structure. Re-arrange code to avoid the
problem.

Found by coverity, broken by baafe668fa56767c031468ccd5df3e62eaa11370.

10 years agotests: Build virstoragetest only when storage driver is compiled too
Peter Krempa [Tue, 3 Jun 2014 09:47:31 +0000 (11:47 +0200)]
tests: Build virstoragetest only when storage driver is compiled too

virstoragetest now requires parts of the storage driver to be built.
Without this change the test can't be compiled on platforms that don't
build the storage driver (mingw).

make[2]: *** No rule to make target `../src/libvirt_driver_storage_impl.la', needed by `virstoragetest.exe'.  Stop.

Broken by commit 713cc3b0a7ff8ad42b4c13429b624d1b2b5a99f2

10 years agoqemu: monitor: Fix type of holdtime argument in qemuMonitorJSONSendKey
Peter Krempa [Tue, 3 Jun 2014 09:19:51 +0000 (11:19 +0200)]
qemu: monitor: Fix type of holdtime argument in qemuMonitorJSONSendKey

qemuMonitorJSONSendKey declares the "holdtime" argument as unsigned int
while the command was constructed in qemuMonitorJSONMakeCommand using
the "P" modifier which took a unsigned long from the variable
arguments which then made it possible to access uninitialized memory.

This broke the qemumonitorjsontest on 32bit fedora 20:
64) qemuMonitorJSONSendKey
... libvirt: QEMU Driver error : internal error: unsupported data type 'W' for arg 'WVS\83ì \8bD$0è\91wÿÿ\81ÃAå' FAILED

Uncovered by upstream commit f744b831c66d9e82453f7a96cab5eddf7570c253.

Additionally add test for the hold-time option.

10 years agolibxl: Avoid possible use of uninitialized mem in libxlDomainStart
Daniel P. Berrange [Mon, 2 Jun 2014 10:53:03 +0000 (11:53 +0100)]
libxl: Avoid possible use of uninitialized mem in libxlDomainStart

The 'libxl_domain_config' object is stack allocated which means its
memory contents are undefined. The libxl_domain_config_dispose() call
is only safe if the memory is initialized to a defined state. Not all
code paths which reach libxl_domain_config_dispose() will ensure that
libxl_domain_config_init() is called. Move the libxl_domain_config_init()
call earlier in the function to ensure all codepaths have defined
memory state.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agolibxl: Move virDomainXMLOptionNew into libxlCreateXMLConf
Daniel P. Berrange [Fri, 30 May 2014 14:53:12 +0000 (15:53 +0100)]
libxl: Move virDomainXMLOptionNew into libxlCreateXMLConf

To allow the test suite to creat the XML option object,
move the virDomainXMLOptionNew call into a libxlCreateXMLConf
method.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agolibxl: Don't pass libxlDriverPrivatePtr into libxlBuildDomainConfig
Daniel P. Berrange [Fri, 30 May 2014 13:48:56 +0000 (14:48 +0100)]
libxl: Don't pass libxlDriverPrivatePtr into libxlBuildDomainConfig

To make it easier to test, change libxlBuildDomainConfig so
that it takes a virPortAllocatorPtr instead of the larger
libxlDriverPrivatePtr object.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agolibxl: Don't pass virDomainObjPtr to libxlBuildDomainConfig
Daniel P. Berrange [Fri, 30 May 2014 13:46:35 +0000 (14:46 +0100)]
libxl: Don't pass virDomainObjPtr to libxlBuildDomainConfig

To make it easier to unit test, change libxlBuildDomainConfig
so that it takes 'virDomainDefPtr' and 'libxl_ctx *' objects
as separate parameters.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agoqemu: Return in from qemuDomainRemove*Device
Jiri Denemark [Tue, 3 Jun 2014 08:18:48 +0000 (10:18 +0200)]
qemu: Return in from qemuDomainRemove*Device

Some of the APIs already return int since they can produce errors that
need to be propagated. For consistency reasons, this patch changes the
rest of the APIs to also return int even though they do not fail or
report any errors.

10 years agoqemu: Remove character device backend only after frontend is gone
Jiri Denemark [Tue, 27 May 2014 11:30:04 +0000 (13:30 +0200)]
qemu: Remove character device backend only after frontend is gone

In general, we should only remove a backend after seeing DEVICE_DELETED
event for a corresponding frontend.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>