]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/log
people/liuw/libxenctrl-split/libvirt.git
10 years agoqemu: domain: Introduce helper to retrieve domain monitor object
Peter Krempa [Tue, 31 Mar 2015 15:24:50 +0000 (17:24 +0200)]
qemu: domain: Introduce helper to retrieve domain monitor object

In some cases where the function does not need to access the private
data this helper may be used to retrieve the monitor object.

10 years agodoc: Add info (where necessary) that paths should be specified as absolute
Erik Skultety [Tue, 7 Apr 2015 10:46:13 +0000 (12:46 +0200)]
doc: Add info (where necessary) that paths should be specified as absolute

We documented this almost everywhere, but missed it on several places.

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

10 years agoOpen /proc/PID/ns/* read-only to avoid getting permission denied
Cédric Bosdonnat [Thu, 9 Apr 2015 07:22:43 +0000 (09:22 +0200)]
Open /proc/PID/ns/* read-only to avoid getting permission denied

lxc-enter-namespace stopped working on recent kernels (at least 3.19+)
due to /proc/PID/ns/* file descriptors being opened RW. From outside
the namespace these can only be opened RO.

10 years agoApparmor qemu abstraction fixes for SLES
Cédric Bosdonnat [Wed, 11 Mar 2015 10:09:40 +0000 (11:09 +0100)]
Apparmor qemu abstraction fixes for SLES

SLES 11 has legacy qemu-kvm package, /usr/bin/qemu-kvm and
/usr/share/qemu-kvm need to be accessed to domains.

10 years agolxc: create the required directories upon driver start
Lubomir Rintel [Wed, 8 Apr 2015 17:16:52 +0000 (19:16 +0200)]
lxc: create the required directories upon driver start

/var/run may reside on a tmpfs and we fail to create the PID file if
/var/run/lxc does not exist.

Since commit 0a8addc1, the lxc driver's state directory isn't
automatically created before starting a domain. Now, the lxc driver
makes sure the state directory exists when it initializes.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
10 years agoutil: file: Don't carelessly sanitize URIs
Peter Krempa [Wed, 8 Apr 2015 08:57:07 +0000 (10:57 +0200)]
util: file: Don't carelessly sanitize URIs

rfc3986 states that the separator in URI path is a single slash.
Multiple slashes may potentially lead to different resources and thus we
should not remove them.

10 years agotest: Add tests for virFileSanitizePath
Peter Krempa [Wed, 8 Apr 2015 08:27:30 +0000 (10:27 +0200)]
test: Add tests for virFileSanitizePath

Add test infrastructure for virFileSanitizePath so that it can be
sensibly refactored later.

10 years agovirLXCControllerSetupResourceLimits: Call virNuma*() iff needed
Michal Privoznik [Fri, 27 Mar 2015 10:44:55 +0000 (11:44 +0100)]
virLXCControllerSetupResourceLimits: Call virNuma*() iff needed

Like we are doing in qemu driver (ea576ee543d6fb95583), lets call
virNumaSetupMemoryPolicy() only if really needed. Problem is, if
we numa_set_membind() child, there's no way to change it from the
daemon afterwards. So any later attempts to change the pinning
will fail. But in very weird way - CGroups will be set, but due
to membind child will not allocate memory from any other node.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agofix memleak in qemuRestoreCgroupState
Luyao Huang [Wed, 8 Apr 2015 06:25:59 +0000 (14:25 +0800)]
fix memleak in qemuRestoreCgroupState

 131,088 bytes in 16 blocks are definitely lost in loss record 2,174 of 2,176
    at 0x4C29BFD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x4C2BACB: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x52A026F: virReallocN (viralloc.c:245)
    by 0x52BFCB5: saferead_lim (virfile.c:1268)
    by 0x52C00EF: virFileReadLimFD (virfile.c:1328)
    by 0x52C019A: virFileReadAll (virfile.c:1351)
    by 0x52A5D4F: virCgroupGetValueStr (vircgroup.c:763)
    by 0x1DDA0DA3: qemuRestoreCgroupState (qemu_cgroup.c:805)
    by 0x1DDA0DA3: qemuConnectCgroup (qemu_cgroup.c:857)
    by 0x1DDB7BA1: qemuProcessReconnect (qemu_process.c:3694)
    by 0x52FD171: virThreadHelper (virthread.c:206)
    by 0x82B8DF4: start_thread (pthread_create.c:308)
    by 0x85C31AC: clone (clone.S:113)

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agovbox: Implement virDomainSendKey
Dawid Zamirski [Tue, 7 Apr 2015 15:37:36 +0000 (11:37 -0400)]
vbox: Implement virDomainSendKey

Since the holdtime is not supported by VBOX SDK, it's being simulated
by sleeping before sending the key-up codes. The key-up codes are
auto-generated based on XT codeset rules (adding of 0x80 to key-down)
which results in the same behavior as for QEMU implementation.

10 years agovbox: Register IKeyboard with the unified API.
Dawid Zamirski [Tue, 7 Apr 2015 15:37:35 +0000 (11:37 -0400)]
vbox: Register IKeyboard with the unified API.

The IKeyboard COM object is needed to implement virDomainSendKey and is
available in all supported VBOX versions.

10 years agoqemuProcessHook: Call virNuma*() only when needed
Michal Privoznik [Fri, 27 Mar 2015 10:39:45 +0000 (11:39 +0100)]
qemuProcessHook: Call virNuma*() only when needed

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

Once upon a time, there was a little domain. And the domain was pinned
onto a NUMA node and hasn't fully allocated its memory:

  <memory unit='KiB'>2355200</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>

  <numatune>
    <memory mode='strict' nodeset='0'/>
  </numatune>

Oh little me, said the domain, what will I do with so little memory.
If I only had a few megabytes more. But the old admin noticed the
whimpering, barely audible to untrained human ear. And good admin he
was, he gave the domain yet more memory. But the old NUMA topology
witch forbade to allocate more memory on the node zero. So he
decided to allocate it on a different node:

virsh # numatune little_domain --nodeset 0-1

virsh # setmem little_domain 2355200

The little domain was happy. For a while. Until bad, sharp teeth
shaped creature came. Every process in the system was afraid of him.
The OOM Killer they called him. Oh no, he's after the little domain.
There's no escape.

Do you kids know why? Because when the little domain was born, her
father, Libvirt, called numa_set_membind(). So even if the admin
allowed her to allocate memory from other nodes in the cgroups, the
membind() forbid it.

So what's the lesson? Libvirt should rely on cgroups, whenever
possible and use numa_set_membind() as the last ditch effort.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovircgroup: Introduce virCgroupControllerAvailable
Michal Privoznik [Tue, 31 Mar 2015 09:39:13 +0000 (11:39 +0200)]
vircgroup: Introduce virCgroupControllerAvailable

This new internal API checks if given CGroup controller is
available.  It is going to be needed later when we need to make a
decision whether pin domain memory onto NUMA nodes using cpuset
CGroup controller or using numa_set_membind().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemu_driver: check caps after starting block job
Michael Chapman [Wed, 8 Apr 2015 06:51:51 +0000 (16:51 +1000)]
qemu_driver: check caps after starting block job

Currently we check qemuCaps before starting the block job. But qemuCaps
isn't available on a stopped domain, which means we get a misleading
error message in this case:

  # virsh domstate example
  shut off

  # virsh blockjob example vda
  error: unsupported configuration: block jobs not supported with this QEMU binary

Move the qemuCaps check into the block job so that we are guaranteed the
domain is running.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
10 years agoqemu_migrate: use nested job when adding NBD to cookie
Michael Chapman [Wed, 8 Apr 2015 06:51:42 +0000 (16:51 +1000)]
qemu_migrate: use nested job when adding NBD to cookie

qemuMigrationCookieAddNBD is usually called from within an async
MIGRATION_OUT or MIGRATION_IN job, so it needs to start a nested job.

(The one exception is during the Begin phase when change protection
isn't enabled, but qemuDomainObjEnterMonitorAsync will behave the same
as qemuDomainObjEnterMonitor in this case.)

This bug was encountered with a libvirt client that repeatedly queries
the disk mirroring block job info during a migration. If one of these
queries occurs just as the Perform migration cookie is baked, libvirt
crashes.

Relevant logs are as follows:

    6701: warning : qemuDomainObjEnterMonitorInternal:1544 : This thread seems to be the async job owner; entering monitor without asking for a nested job is dangerous
[1] 6701: info : qemuMonitorSend:972 : QEMU_MONITOR_SEND_MSG: mon=0x7fefdc004700 msg={"execute":"query-block","id":"libvirt-629"}
[2] 6699: info : qemuMonitorIOWrite:503 : QEMU_MONITOR_IO_WRITE: mon=0x7fefdc004700 buf={"execute":"query-block","id":"libvirt-629"}
[3] 6704: info : qemuMonitorSend:972 : QEMU_MONITOR_SEND_MSG: mon=0x7fefdc004700 msg={"execute":"query-block-jobs","id":"libvirt-630"}
[4] 6699: info : qemuMonitorJSONIOProcessLine:203 : QEMU_MONITOR_RECV_REPLY: mon=0x7fefdc004700 reply={"return": [...], "id": "libvirt-629"}
    6699: error : qemuMonitorJSONIOProcessLine:211 : internal error: Unexpected JSON reply '{"return": [...], "id": "libvirt-629"}'

At [1] qemuMonitorBlockStatsUpdateCapacity sends its request, then waits
on mon->notify. At [2] the request is written out to the monitor socket.
At [3] qemuMonitorBlockJobInfo sends its request, and also waits on
mon->notify. The reply from the first request is received at [4].
However, qemuMonitorJSONIOProcessLine is not expecting this reply since
the second request hadn't completed sending. The reply is dropped and an
error is returned.

qemuMonitorIO signals mon->notify twice during its error handling,
waking up both of the threads waiting on it. One of them clears mon->msg
as it exits qemuMonitorSend; the other crashes:

  qemuMonitorSend (mon=0x7fefdc004700, msg=<value optimized out>) at qemu/qemu_monitor.c:975
  975         while (!mon->msg->finished) {
  (gdb) print mon->msg
  $1 = (qemuMonitorMessagePtr) 0x0

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
10 years agoparallels: delete old networks in prlsdkDoApplyConfig before adding new ones
Maxim Nestratov [Mon, 6 Apr 2015 15:53:47 +0000 (18:53 +0300)]
parallels: delete old networks in prlsdkDoApplyConfig before adding new ones

In order to change an existing domain we delete all existing devices and add
new from scratch. In case of network devices we should also delete corresponding
virtual networks (if any) before removing actual devices from xml. In the patch,
we do it by extending prlsdkDoApplyConfig with a new parameter, which stands for
old xml, and calling prlsdkDelNet every time old xml is specified.

Signed-off-by: Maxim Nestratov <mnestratov@parallels.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoutil: fix removal of callbacks in virCloseCallbacksRun
Michael Chapman [Wed, 8 Apr 2015 03:22:39 +0000 (13:22 +1000)]
util: fix removal of callbacks in virCloseCallbacksRun

The close callbacks hash are keyed by a UUID-string, but
virCloseCallbacksRun was attempting to remove them by raw UUID. This
patch ensures the callback entries are removed by UUID-string as well.

This bug caused problems when guest migrations were abnormally aborted:

  # timeout --signal KILL 1 \
      virsh migrate example qemu+tls://remote/system \
        --verbose --compressed --live --auto-converge \
        --abort-on-error --unsafe --persistent \
        --undefinesource --copy-storage-all --xml example.xml
  Killed

  # virsh migrate example qemu+tls://remote/system \
      --verbose --compressed --live --auto-converge \
      --abort-on-error --unsafe --persistent \
      --undefinesource --copy-storage-all --xml example.xml
  error: Requested operation is not valid: domain 'example' is not being migrated

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
10 years agoqemu: fix race between disk mirror fail and cancel
Michael Chapman [Mon, 30 Mar 2015 02:41:00 +0000 (13:41 +1100)]
qemu: fix race between disk mirror fail and cancel

If a VM migration is aborted, a disk mirror may be failed by QEMU before
libvirt has a chance to cancel it. The disk->mirrorState remains at
_ABORT in this case, and this breaks subsequent mirrorings of that disk.

We should instead check the mirrorState directly and transition to _NONE
if it is already aborted. Do the check *after* aborting the block job in
QEMU to avoid a race.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
10 years agoqemu: fix error propagation in qemuMigrationBegin
Michael Chapman [Mon, 30 Mar 2015 02:40:59 +0000 (13:40 +1100)]
qemu: fix error propagation in qemuMigrationBegin

If virCloseCallbacksSet fails, qemuMigrationBegin must return NULL to
indicate an error occurred.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
10 years agoqemu: fix crash in qemuProcessAutoDestroy
Michael Chapman [Mon, 30 Mar 2015 02:40:58 +0000 (13:40 +1100)]
qemu: fix crash in qemuProcessAutoDestroy

The destination libvirt daemon in a migration may segfault if the client
disconnects immediately after the migration has begun:

  # virsh -c qemu+tls://remote/system list --all
   Id    Name                           State
  ----------------------------------------------------
  ...

  # timeout --signal KILL 1 \
      virsh migrate example qemu+tls://remote/system \
        --verbose --compressed --live --auto-converge \
        --abort-on-error --unsafe --persistent \
        --undefinesource --copy-storage-all --xml example.xml
  Killed

  # virsh -c qemu+tls://remote/system list --all
  error: failed to connect to the hypervisor
  error: unable to connect to server at 'remote:16514': Connection refused

The crash is in:

   1531 void
   1532 qemuDomainObjEndJob(virQEMUDriverPtr driver, virDomainObjPtr obj)
   1533 {
   1534     qemuDomainObjPrivatePtr priv = obj->privateData;
   1535     qemuDomainJob job = priv->job.active;
   1536
   1537     priv->jobs_queued--;

Backtrace:

  #0  at qemuDomainObjEndJob at qemu/qemu_domain.c:1537
  #1  in qemuDomainRemoveInactive at qemu/qemu_domain.c:2497
  #2  in qemuProcessAutoDestroy at qemu/qemu_process.c:5646
  #3  in virCloseCallbacksRun at util/virclosecallbacks.c:350
  #4  in qemuConnectClose at qemu/qemu_driver.c:1154
  ...

qemuDomainRemoveInactive calls virDomainObjListRemove, which in this
case is holding the last remaining reference to the domain.
qemuDomainRemoveInactive then calls qemuDomainObjEndJob, but the domain
object has been freed and poisoned by then.

This patch bumps the domain's refcount until qemuDomainRemoveInactive
has completed. We also ensure qemuProcessAutoDestroy does not return the
domain to virCloseCallbacksRun to be unlocked in this case. There is
similar logic in bhyveProcessAutoDestroy and lxcProcessAutoDestroy
(which call virDomainObjListRemove directly).

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
10 years agovirQEMUDriverGetConfig: Fix memleak
Michal Privoznik [Fri, 3 Apr 2015 18:58:20 +0000 (20:58 +0200)]
virQEMUDriverGetConfig: Fix memleak

==19015== 968 (416 direct, 552 indirect) bytes in 1 blocks are definitely lost in loss record 999 of 1,049
==19015==    at 0x4C2C070: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19015==    by 0x52ADF14: virAllocVar (viralloc.c:560)
==19015==    by 0x5302FD1: virObjectNew (virobject.c:193)
==19015==    by 0x1DD9401E: virQEMUDriverConfigNew (qemu_conf.c:164)
==19015==    by 0x1DDDF65D: qemuStateInitialize (qemu_driver.c:666)
==19015==    by 0x53E0823: virStateInitialize (libvirt.c:777)
==19015==    by 0x11E067: daemonRunStateInit (libvirtd.c:905)
==19015==    by 0x53201AD: virThreadHelper (virthread.c:206)
==19015==    by 0xA1EE1F2: start_thread (in /lib64/libpthread-2.19.so)
==19015==    by 0xA4EFC8C: clone (in /lib64/libc-2.19.so)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirDomainVirtioSerialAddrSetFree: Fix memleak
Michal Privoznik [Fri, 3 Apr 2015 18:14:01 +0000 (20:14 +0200)]
virDomainVirtioSerialAddrSetFree: Fix memleak

==19015== 8 bytes in 1 blocks are definitely lost in loss record 34 of 1,049
==19015==    at 0x4C29F80: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19015==    by 0x4C2C32F: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19015==    by 0x52AD888: virReallocN (viralloc.c:245)
==19015==    by 0x52AD97E: virExpandN (viralloc.c:294)
==19015==    by 0x52ADC51: virInsertElementsN (viralloc.c:436)
==19015==    by 0x5335864: virDomainVirtioSerialAddrSetAddController (domain_addr.c:816)
==19015==    by 0x53358E0: virDomainVirtioSerialAddrSetAddControllers (domain_addr.c:839)
==19015==    by 0x1DD5513B: qemuDomainAssignVirtioSerialAddresses (qemu_command.c:1422)
==19015==    by 0x1DD55A6E: qemuDomainAssignAddresses (qemu_command.c:1711)
==19015==    by 0x1DDA5818: qemuProcessStart (qemu_process.c:4616)
==19015==    by 0x1DDF1807: qemuDomainObjStart (qemu_driver.c:7265)
==19015==    by 0x1DDF1A66: qemuDomainCreateWithFlags (qemu_driver.c:7320)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemuSetupCgroupForVcpu: Fix memleak
Michal Privoznik [Fri, 3 Apr 2015 18:06:17 +0000 (20:06 +0200)]
qemuSetupCgroupForVcpu: Fix memleak

==19015== 1,064 (656 direct, 408 indirect) bytes in 2 blocks are definitely lost in loss record 1,002 of 1,049
==19015==    at 0x4C2C070: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19015==    by 0x52AD74B: virAlloc (viralloc.c:144)
==19015==    by 0x52B47CA: virCgroupNew (vircgroup.c:1057)
==19015==    by 0x52B53E5: virCgroupNewVcpu (vircgroup.c:1451)
==19015==    by 0x1DD85A40: qemuSetupCgroupForVcpu (qemu_cgroup.c:1013)
==19015==    by 0x1DDA66EA: qemuProcessStart (qemu_process.c:4844)
==19015==    by 0x1DDF1807: qemuDomainObjStart (qemu_driver.c:7265)
==19015==    by 0x1DDF1A66: qemuDomainCreateWithFlags (qemu_driver.c:7320)
==19015==    by 0x1DDF1ACD: qemuDomainCreate (qemu_driver.c:7337)
==19015==    by 0x53F87EA: virDomainCreate (libvirt-domain.c:6820)
==19015==    by 0x12690A: remoteDispatchDomainCreate (remote_dispatch.h:3481)
==19015==    by 0x126827: remoteDispatchDomainCreateHelper (remote_dispatch.h:3457)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agostorage: Introduce storagePoolUpdateAllState function
Erik Skultety [Mon, 16 Mar 2015 15:30:03 +0000 (16:30 +0100)]
storage: Introduce storagePoolUpdateAllState function

The 'checkPool' callback was originally part of the storageDriverAutostart function,
but the pools need to be checked earlier during initialization phase,
otherwise we can't start a domain which mounts a volume after the
libvirtd daemon restarted. This is because qemuProcessReconnect is called
earlier than storageDriverAutostart. Therefore the 'checkPool' logic has been
moved to storagePoolUpdateAllState which is called inside storageDriverInitialize.

We also need a valid 'conn' reference to be able to execute 'refreshPool'
during initialization phase. Though it isn't available until storageDriverAutostart
all of our storage backends do ignore 'conn' pointer, except for RBD,
but RBD doesn't support 'checkPool' callback, so it's safe to pass
conn = NULL in this case.

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

10 years agoconf: Introduce virStoragePoolLoadAllState && virStoragePoolLoadState
Erik Skultety [Tue, 10 Mar 2015 12:59:51 +0000 (13:59 +0100)]
conf: Introduce virStoragePoolLoadAllState && virStoragePoolLoadState

These functions operate exactly the same as their network equivalents
virNetworkLoadAllState, virNetworkLoadState.

10 years agostorage: Add support for storage pool state XML
Erik Skultety [Mon, 9 Mar 2015 14:36:44 +0000 (15:36 +0100)]
storage: Add support for storage pool state XML

This patch introduces new virStorageDriverState element stateDir.
Also adds necessary changes to storageStateInitialize, so that
directories initialization becomes more generic.

10 years agohostdev: Report the domain name for used hostdevs during nodedev-detach
Shivaprasad G Bhat [Wed, 1 Apr 2015 10:58:05 +0000 (16:28 +0530)]
hostdev: Report the domain name for used hostdevs during nodedev-detach

The nodedev-detach can report the name of the domain using the device
just the way nodedev-reattach does it.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agovirsh: Improve change-media success message
Cole Robinson [Mon, 6 Apr 2015 17:59:46 +0000 (13:59 -0400)]
virsh: Improve change-media success message

$ sudo virsh change-media f19 hdc /mnt/data/devel/media/Fedora-16-x86_64-Live-KDE.iso
succeeded to complete action update on media

Change the message to:

  Successfully {inserted,ejected,changed} media.

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

10 years agointerface: allow multiple IPv4 addresses in interface XML
Laine Stump [Fri, 27 Mar 2015 00:15:53 +0000 (20:15 -0400)]
interface: allow multiple IPv4 addresses in interface XML

An upcoming netcf release will support multiple ipv4 addresses, so
let's loosen up libvirt's interface.rng to allow it.

10 years agovirsh.pod: Remove redundant --config from attach-interface
Jiri Denemark [Fri, 3 Apr 2015 12:56:36 +0000 (14:56 +0200)]
virsh.pod: Remove redundant --config from attach-interface

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agolibvirt: virsh: Kill all uses of __FUNCTION__ in error messages
Noella Ashu [Fri, 3 Apr 2015 10:33:44 +0000 (11:33 +0100)]
libvirt: virsh: Kill all uses of __FUNCTION__ in error messages

The error output of snapshot-revert should be more friendly.
There is no need to show virDomainRevertToSnapshot to user.
virReportError already includes __FUNCTION__ information in a
separate member of the struct, so repeating it in the message is
redundant and leads to situations where higher level code ends up
reporting the lower level name. We correctly converted the error
output making it more succinct and user-friendly.

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

10 years agovirsh: Fix domifaddr output in quiet mode
Luyao Huang [Fri, 3 Apr 2015 09:41:03 +0000 (17:41 +0800)]
virsh: Fix domifaddr output in quiet mode

In virsh we have two printing functions: vshPrint() which prints a
string onto stdout and vshPrintExtra() which does not print anything
if virsh is run in quiet mode. Usually, the former is used to print
actual results, while the latter to print strings like table headers
and other formatting stuff. However, in cmdDomIfAddr we have
mistakenly used vshPrintExtra even for actual data. After this patch,
the output should look like the following:

  # virsh -q domifaddr test3 --source agent
  lo         00:00:00:00:00:00    ipv4         127.0.0.1/8
  -          -                    ipv6         ::1/128
  ens8       52:54:00:1a:cb:3f    ipv6         fe80::5054:ff:fe1a:cb3f/64
  virbr0     52:54:00:db:51:e7    ipv4         192.168.122.1/24
  virbr0-nic 52:54:00:db:51:e7    N/A          N/A

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoesx: esxNodeGetFreeMemory return info from host.
Dawid Zamirski [Mon, 9 Mar 2015 15:54:05 +0000 (11:54 -0400)]
esx: esxNodeGetFreeMemory return info from host.

Before this patch, when connected via vCenter, the free memory returned
was from the resorcePool (usually a cluster). This is in conflict with
e.g esxNodeGetInfo which always pulls info from the ESX host.
Since libvirt ESX driver works primarily with ESX hosts, this patch
changes esxNodeGetFreeMemory to pull that information from ESX host so
it's consistent with behavior of esxNodeGetInfo.

10 years agoesx: add esxVI_GetInt
Dawid Zamirski [Mon, 9 Mar 2015 15:54:04 +0000 (11:54 -0400)]
esx: add esxVI_GetInt

Modeled after the already existing esxVI_GetLong.

10 years agoconf: Change virStoragePoolSaveConfig prototype s/configDir/configFile
Erik Skultety [Fri, 3 Apr 2015 08:41:04 +0000 (10:41 +0200)]
conf: Change virStoragePoolSaveConfig prototype s/configDir/configFile

Just a minor change which might be a little confusing for someone
looking only at the API.

10 years agoconf: Introduce virStoragePoolSaveState
Erik Skultety [Thu, 2 Apr 2015 14:41:51 +0000 (16:41 +0200)]
conf: Introduce virStoragePoolSaveState

Introduce virStoragePoolSaveState to properly format the state XML in
the same manner as virStoragePoolDefFormat, except for adding a
<poolstate> ... </poolstate> around the definition. This is similar to
virNetworkObjFormat used to save the live/active network information.

10 years agoconf: Introduce virStoragePoolDefFormatBuf
Erik Skultety [Thu, 26 Mar 2015 15:44:38 +0000 (16:44 +0100)]
conf: Introduce virStoragePoolDefFormatBuf

When modifying config/status XML, it might be handy to include some
additional XML elements (e.g. <poolstate>). In order to do so,
introduce new formatting function virStoragePoolDefFormatBuf and make
virStoragePoolDefFormat call it.

10 years agolibxl: fix dom0 balloon logic
Jim Fehlig [Fri, 20 Mar 2015 23:08:34 +0000 (17:08 -0600)]
libxl: fix dom0 balloon logic

Recent testing on large memory systems revealed a bug in the Xen xl
tool's freemem() function.  When autoballooning is enabled, freemem()
is used to ensure enough memory is available to start a domain,
ballooning dom0 if necessary.  When ballooning large amounts of memory
from dom0, freemem() would exceed its self-imposed wait time and
return an error.  Meanwhile, dom0 continued to balloon.  Starting the
domain later, after sufficient memory was ballooned from dom0, would
succeed.  The libvirt implementation in libxlDomainFreeMem() suffers
the same bug since it is modeled after freemem().

In the end, the best place to fix the bug on the Xen side was to
slightly change the behavior of libxl_wait_for_memory_target().
Instead of failing after caller-provided wait_sec, the function now
blocks as long as dom0 memory ballooning is progressing.  It will return
failure only when more memory is needed to reach the target and wait_sec
have expired with no progress being made.  See xen.git commit fd3aa246.
There was a dicussion on how this would affect other libxl apps like
libvirt

http://lists.xen.org/archives/html/xen-devel/2015-03/msg00739.html

If libvirt containing this patch was build against a Xen containing
the old libxl_wait_for_memory_target() behavior, libxlDomainFreeMem()
will fail after 30 sec and domain creation will be terminated.
Without this patch and with old libxl_wait_for_memory_target() behavior,
libxlDomainFreeMem() does not succeed after 30 sec, but returns success
anyway.  Domain creation continues resulting in all sorts of fun stuff
like cpu soft lockups in the guest OS.  It was decided to properly fix
libxl_wait_for_memory_target(), and if anything improve the default
behavior of apps using the freemem reference impl in xl.

xl was patched to accommodate the change in libxl_wait_for_memory_target()
with xen.git commit 883b30a0.  This patch does the same in the libxl
driver.  While at it, I changed the logic to essentially match
freemem() in $xensrc/tools/libxl/xl_cmdimpl.c.  It was a bit cleaner
IMO and will make it easier to spot future, potentially interesting
divergences.

10 years agoTypos: Get rid of dependan(t|cies)
Martin Kletzander [Thu, 26 Mar 2015 06:36:07 +0000 (07:36 +0100)]
Typos: Get rid of dependan(t|cies)

Dependant is flagged as wrong in US dictionary (only valid in UK
dictionary, and even then, it has only the financial sense and not the
inter-relatedness sense that we are more prone to be wanting throughout
code).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agodocs: Add Host sFlow into monitoring apps
Martin Kletzander [Wed, 25 Mar 2015 15:34:58 +0000 (16:34 +0100)]
docs: Add Host sFlow into monitoring apps

Reported-by: Peter Phaal <peter.phaal@gmail.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agohostdev: Fix index error in loop after remove an element
Huanle Han [Thu, 26 Mar 2015 14:23:46 +0000 (22:23 +0800)]
hostdev: Fix index error in loop after remove an element

'virPCIDeviceList' is actually an array. Removing one element makes the
rest of the element move.

Use while loop, increase index only when not virPCIDeviceListDel(pcidevs, dev)

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
10 years agoFix xlconfigtest with older libxl
Ján Tomko [Thu, 2 Apr 2015 12:57:54 +0000 (14:57 +0200)]
Fix xlconfigtest with older libxl

Commit cd5dc30 added this test, but it fails if
LIBXL_HAVE_BUILDINFO_USBDEVICE_LIST is not defined:

6) Xen XM-2-XML Format fullvirt-multiusb
... libvirt:  error : unsupported configuration: multiple USB
devices not supported
FAILED

10 years agoAuto add virtio-serial controllers
Ján Tomko [Tue, 24 Mar 2015 14:23:46 +0000 (15:23 +0100)]
Auto add virtio-serial controllers

In virDomainVirtioSerialAddrNext, add another controller
if we've exhausted all ports of the existing controllers.

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

10 years agoAssign an address when hotplugging a virtio-serial device
Ján Tomko [Mon, 2 Mar 2015 09:59:52 +0000 (10:59 +0100)]
Assign an address when hotplugging a virtio-serial device

10 years agoExpand the address set when attaching a virtio-serial controller
Ján Tomko [Mon, 2 Mar 2015 09:59:25 +0000 (10:59 +0100)]
Expand the address set when attaching a virtio-serial controller

10 years agoAllocate virtio-serial addresses when starting a domain
Ján Tomko [Mon, 2 Mar 2015 09:58:48 +0000 (10:58 +0100)]
Allocate virtio-serial addresses when starting a domain

Instead of always using controller 0 and incrementing port number,
respect the maximum port numbers of controllers and use all of them.

Ports for virtio consoles are quietly reserved, but not formatted
(neither in XML nor on QEMU command line).

Also rejects duplicate virtio-serial addresses.
https://bugzilla.redhat.com/show_bug.cgi?id=890606
https://bugzilla.redhat.com/show_bug.cgi?id=1076708

Test changes:
* virtio-auto.args
  Filling out the port when just the controller is specified.
  switched from using
    maxport + 1
  to:
    first free port on the controller
* virtio-autoassign.args
  Filling out the address when no <address> is specified.
  Started using all the controllers instead of 0, also discards
  the bus value.
* xml -> xml output of virtio-auto
  The port assignment is no longer done as a part of XML parsing,
  so the unspecified values stay 0.

10 years agoAdd functions to track virtio-serial addresses
Ján Tomko [Mon, 2 Mar 2015 09:57:51 +0000 (10:57 +0100)]
Add functions to track virtio-serial addresses

Create a sorted array of virtio-serial controllers.
Each of the elements contains the controller index
and a bitmap of available ports.

Buses are not tracked, because they aren't supported by QEMU.

10 years agoAdd test for virtio serial port assignment
Ján Tomko [Thu, 29 May 2014 13:16:47 +0000 (15:16 +0200)]
Add test for virtio serial port assignment

Add a test to demonstrate the effect of automatic virtio-serial
address assignment.

10 years agoscsi: Remove unused 'type_path' in processLU
John Ferlan [Wed, 1 Apr 2015 12:45:11 +0000 (08:45 -0400)]
scsi: Remove unused 'type_path' in processLU

Seems to be a remnant that was never cleaned up from original submit...

Signed-off-by: John Ferlan <jferlan@redhat.com>
10 years agoiscsi: Fix exit path for virStorageBackendISCSIFindLUs failure
John Ferlan [Wed, 1 Apr 2015 10:46:25 +0000 (06:46 -0400)]
iscsi: Fix exit path for virStorageBackendISCSIFindLUs failure

If the call to virStorageBackendISCSIGetHostNumber failed, we set
retval = -1, but yet still called virStorageBackendSCSIFindLUs.
Need to add a goto cleanup - while at it, adjust the logic to
initialize retval to -1 and only changed to 0 (zero) on success.

Signed-off-by: John Ferlan <jferlan@redhat.com>
10 years agoiscsi: Use error message from virStorageBackendSCSIFindLUs
John Ferlan [Mon, 30 Mar 2015 22:49:36 +0000 (18:49 -0400)]
iscsi: Use error message from virStorageBackendSCSIFindLUs

Don't supercede the error message virStorageBackendSCSIFindLUs as the
message such as "error: Failed to find LUs on host 60: ..." is not overly
clear as to what the real problem might be.

Signed-off-by: John Ferlan <jferlan@redhat.com>
10 years agoconf: Introduce virStoragePoolSaveXML
Erik Skultety [Thu, 26 Mar 2015 15:49:20 +0000 (16:49 +0100)]
conf: Introduce virStoragePoolSaveXML

Make XML definition saving more generic by moving the common code into
virStoragePoolSaveXML and leave case specific code to
PoolSave{Status,Config,...} functions.

10 years agostorage: Remove unused attribute conn from 'checkPool' callback
Erik Skultety [Mon, 9 Mar 2015 14:34:35 +0000 (15:34 +0100)]
storage: Remove unused attribute conn from 'checkPool' callback

In order to be able to use 'checkPool' inside functions which do not
have any connection reference, 'conn' attribute needs to be discarded
from the checkPool's signature, since it's not used by any storage backend
anyway.

10 years agoqemuDomainBlockCopy: Check @granularity to be a power of two
Luyao Huang [Fri, 27 Mar 2015 09:56:30 +0000 (17:56 +0800)]
qemuDomainBlockCopy: Check @granularity to be a power of two

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

As described in virDomainBlockCopy() parameters description, the
VIR_DOMAIN_BLOCK_COPY_GRANULARITY parameter may require the value to
have some specific attributes (e.g. be a power of two or fall within a
certain range). And in qemu, a power of two is required. However, our
code does not check that and let qemu operation fail. Moreover, the
virsh man page is not as exact as it could be in this respect.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agonodeinfodata: Remove broken symlinks and uneeded files
Michal Privoznik [Wed, 1 Apr 2015 08:48:04 +0000 (10:48 +0200)]
nodeinfodata: Remove broken symlinks and uneeded files

The 7c3c7f217ebae5 and f5c2d6 commits introduced a nodeinfo test.
In order to do that, some parts of sysfs had to be copied.
However, sysfs is full of symlinks, so during copying some
symlinks broke. Remove them, as on different systems they can
point to different files or be broken. At the same time, we don't
need all files added in those commits. For instance we don't care
about 'uevent' files, 'power' folders, and others.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemu: lifecycle: make agent-mode shutdown and reboot timeout
zhang bo [Wed, 1 Apr 2015 09:13:08 +0000 (17:13 +0800)]
qemu: lifecycle: make agent-mode shutdown and reboot timeout

When we shutdown/reboot a guest using agent-mode, if the guest itself blocks infinitely,
libvirt would block in qemuAgentShutdown() forever.
Thus, we set a timeout for shutdown/reboot, from our experience, 60 seconds would be fine.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wang Yufei <james.wangyufei@huawei.com>
10 years agoFix indentation in cmdVcpuPin
Ján Tomko [Thu, 26 Mar 2015 14:10:50 +0000 (15:10 +0100)]
Fix indentation in cmdVcpuPin

10 years agovirsh: remove stale comment
Ján Tomko [Wed, 1 Apr 2015 17:53:28 +0000 (19:53 +0200)]
virsh: remove stale comment

Copied from the vcpupin command, which has two modes of operation.

10 years agoconf: Rename virDomainHasDiskMirror and detect block jobs properly
Shanzhi Yu [Tue, 24 Mar 2015 10:08:00 +0000 (18:08 +0800)]
conf: Rename virDomainHasDiskMirror and detect block jobs properly

virDomainHasDiskMirror() currently detects only jobs that add the mirror
elements. Since some operations like migration are interlocked by
existing block jobs on the given domain the check needs to be
instrumented to check regular jobs too.

This patch renames virDomainHasDiskMirror to virDomainHasDiskBlockjob
and adds an argument that allows to select that it returns true only for
block copy jobs as those interlock making the domain persistent.

Other two uses trigger on any block job type.

Signed-off-by: Shanzhi Yu <shyu@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
10 years agoqemu: snapshot: Check for block jobs individually
Peter Krempa [Mon, 30 Mar 2015 18:16:45 +0000 (20:16 +0200)]
qemu: snapshot: Check for block jobs individually

If any disk of a VM was involved in a (copy) block job we refused to do
a snapshot. As not only copy jobs interlock snapshots and the
interlocking is applicable to individual disks only we can make the
check in a more individual fashion and interlock all block job types
supported by libvirt.

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

10 years agoRemove unnecessary includes from virsh.h
Ján Tomko [Wed, 1 Apr 2015 15:09:04 +0000 (17:09 +0200)]
Remove unnecessary includes from virsh.h

Include them in the files that need them instead.

10 years agoRemove unused includes from virsh
Ján Tomko [Wed, 1 Apr 2015 14:50:17 +0000 (16:50 +0200)]
Remove unused includes from virsh

After splitting out most of virsh command, some includes
are no longer needed.

Some files have the libXML includes despite not needing them.

10 years agoClean up headers in src/util/virutil.h
Ján Tomko [Wed, 25 Mar 2015 12:12:00 +0000 (13:12 +0100)]
Clean up headers in src/util/virutil.h

* "verify.h" from gnulib is included in internal.h
* <sys/select.h> is no longer needed
  added by commit da196338 to use fd_set in virExec prototype

10 years agoDo not include cpu_map.h in libvirtd.c
Ján Tomko [Wed, 25 Mar 2015 17:34:41 +0000 (18:34 +0100)]
Do not include cpu_map.h in libvirtd.c

No longer needed after commit dd47723

10 years agoUse the DEFAULT_DRIVER_DIR macro
Ján Tomko [Wed, 1 Apr 2015 10:38:42 +0000 (12:38 +0200)]
Use the DEFAULT_DRIVER_DIR macro

Unused since commit bc2f42a0.

Move it under the WITHOUT_DRIVER_MODULES #ifdef
and start using it again.

10 years agoRemove unused macros
Ján Tomko [Wed, 1 Apr 2015 10:30:02 +0000 (12:30 +0200)]
Remove unused macros

In the order of appearance:

* MAX_LISTEN - never used
  added by 23ad665c (qemud) and addec57 (lock daemon)

* NEXT_FREE_CLASS_ID - never used, added by 07d1b6b

* virLockError - never used, added by eb8268a4

* OPENVZ_MAX_ARG, CMDBUF_LEN, CMDOP_LEN
  unused since the removal of ADD_ARG_LIT in d8b31306

* QEMU_NB_PER_CPU_STAT_PARAM - unused since 897808e

* QEMU_CMD_PROMPT, QEMU_PASSWD_PROMPT - unused since 1dc10a7

* TEST_MODEL_WORDSIZE - unused since c25c18f7

* TEMPDIR - never used, added by 714bef5

* NSIG - workaround around old headers
  added by commit 60ed1d2
  unused since virExec was moved by commit 02e8691

* DO_TEST_PARSE - never used, added by 9afa006

* DIFF_MSEC, GETTIMEOFDAY - unused since eee6eb6

10 years agoqemu: Copy bitmap in a sane way
Peter Krempa [Fri, 27 Mar 2015 12:56:30 +0000 (13:56 +0100)]
qemu: Copy bitmap in a sane way

Use virBitmapNewCopy instead of a combination of virBitmapNew and
virBitmapCopy.

10 years agoqemu: cgroup: Kill qemuSetupCgroupVcpuPin()
Peter Krempa [Fri, 27 Mar 2015 12:51:17 +0000 (13:51 +0100)]
qemu: cgroup: Kill qemuSetupCgroupVcpuPin()

The function doesn't make sense. There's a simpler way to achieve the
same.

10 years agoqemu: cgroup: Kill qemuSetupCgroupIOThreadsPin()
Peter Krempa [Fri, 27 Mar 2015 12:51:17 +0000 (13:51 +0100)]
qemu: cgroup: Kill qemuSetupCgroupIOThreadsPin()

The function doesn't make sense. There's a simpler way to achieve the
same.

10 years agoqemu: cgroup: Rename qemuSetupCgroupEmulatorPin to qemuSetupCgroupCpusetCpus
Peter Krempa [Fri, 27 Mar 2015 12:28:59 +0000 (13:28 +0100)]
qemu: cgroup: Rename qemuSetupCgroupEmulatorPin to qemuSetupCgroupCpusetCpus

The function is used to set cpuset.cpus in various other helpers.

10 years agoqemu: cgroup: Use priv->autoCpuset instead of using qemuPrepareCpumap()
Peter Krempa [Fri, 27 Mar 2015 12:11:37 +0000 (13:11 +0100)]
qemu: cgroup: Use priv->autoCpuset instead of using qemuPrepareCpumap()

Two places would call to qemuPrepareCpumap() with priv->autoNodeset to
convert it to a cpuset. Remove the function and use the prepared cpuset
automatically.

10 years agoqemu: cgroup: Properly set up vcpu pinning
Peter Krempa [Fri, 27 Mar 2015 09:23:19 +0000 (10:23 +0100)]
qemu: cgroup: Properly set up vcpu pinning

When the default cpuset or automatic numa placement is used libvirt
would place the whole parent cgroup in the specified cpuset. This then
disallowed to re-pin the vcpus to a different cpu.

This patch pins only the vcpu threads to the default cpuset and thus
allows to re-pin them later.

The following config would fail to start:
<domain type='kvm'>
  ...
  <vcpu placement='static' cpuset='0-1' current='2'>4</vcpu>
  <cputune>
    <vcpupin vcpu='0' cpuset='2-3'/>
    ...

This is a regression since a39f69d2b.

10 years agoqemu: cgroup: Refactor setup for IOThread cgroups
Peter Krempa [Fri, 27 Mar 2015 12:22:02 +0000 (13:22 +0100)]
qemu: cgroup: Refactor setup for IOThread cgroups

Use the default or auto cpuset if they are provided for IOThreads.

10 years agoqemu: cgroup: Store auto cpuset instead of re-creating it on demand
Peter Krempa [Fri, 27 Mar 2015 09:11:00 +0000 (10:11 +0100)]
qemu: cgroup: Store auto cpuset instead of re-creating it on demand

The automatic cpuset can be stored along with automatic nodeset and it
does not have to be recreated when used.

10 years agoBump version to 1.2.15 for new dev cycle
Peter Krempa [Thu, 2 Apr 2015 08:10:21 +0000 (10:10 +0200)]
Bump version to 1.2.15 for new dev cycle

10 years agoRelease of libvirt-1.2.14
Daniel Veillard [Thu, 2 Apr 2015 07:48:08 +0000 (15:48 +0800)]
Release of libvirt-1.2.14

- docs/news.html.in libvirt.spec.in: update for the release
- po/*.po*: regenerated localization

10 years agotests: nodeinfo: Add test for RHELSA on APM mustang
Cole Robinson [Tue, 31 Mar 2015 20:40:28 +0000 (14:40 -0600)]
tests: nodeinfo: Add test for RHELSA on APM mustang

This would have caught the bug fixed by Wei's commit c13de016

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agotests: nodeinfo: Test F21 aarch64 on APM mustang
Cole Robinson [Tue, 31 Mar 2015 20:38:41 +0000 (14:38 -0600)]
tests: nodeinfo: Test F21 aarch64 on APM mustang

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoqemu: blockjob: Synchronously update backing chain in XML on ABORT/PIVOT
Peter Krempa [Mon, 30 Mar 2015 09:26:20 +0000 (11:26 +0200)]
qemu: blockjob: Synchronously update backing chain in XML on ABORT/PIVOT

When the synchronous pivot option is selected, libvirt would not update
the backing chain until the job was exitted. Some applications then
received invalid data as their job serialized first.

This patch removes polling to wait for the ABORT/PIVOT job completion
and replaces it with a condition. If a synchronous operation is
requested the update of the XML is executed in the job of the caller of
the synchronous request. Otherwise the monitor event callback uses a
separate worker to update the backing chain with a new job.

This is a regression since 1a92c719101e5bfa6fe2b78006ad04c7f075ea28

When the ABORT job is finished synchronously you get the following call
stack:
 #0  qemuBlockJobEventProcess
 #1  qemuDomainBlockJobImpl
 #2  qemuDomainBlockJobAbort
 #3  virDomainBlockJobAbort

While previously or while using the _ASYNC flag you'd get:
 #0  qemuBlockJobEventProcess
 #1  processBlockJobEvent
 #2  qemuProcessEventHandler
 #3  virThreadPoolWorker

10 years agoqemu: Extract internals of processBlockJobEvent into a helper
Peter Krempa [Mon, 30 Mar 2015 09:26:19 +0000 (11:26 +0200)]
qemu: Extract internals of processBlockJobEvent into a helper

Later on I'll be adding a condition that will allow to synchronise a
SYNC block job abort. The approach will require this code to be called
from two different places so it has to be extracted into a helper.

10 years agoqemu: processBlockJob: Don't unlock @vm twice
Peter Krempa [Mon, 30 Mar 2015 09:26:18 +0000 (11:26 +0200)]
qemu: processBlockJob: Don't unlock @vm twice

Commit 1a92c719 moved code to handle block job events to a different
function that is executed in a separate thread. The caller of
processBlockJob handles locking and unlocking of @vm, so the we should
not do it in the function itself.

10 years agoqemu: blockCopy: Pass adjusted bandwidth when called via blockRebase
Peter Krempa [Mon, 30 Mar 2015 15:34:13 +0000 (17:34 +0200)]
qemu: blockCopy: Pass adjusted bandwidth when called via blockRebase

The block copy API takes the speed in bytes/s rather than MiB/s that was
the prior approach in virDomainBlockRebase. We correctly converted the
speed to bytes/s in the old API but we still called the common helper
virDomainBlockCopyCommon with the unadjusted variable.

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

10 years agovirsh: blockCopy: Add missing jump on error path
Luyao Huang [Fri, 27 Mar 2015 09:56:29 +0000 (17:56 +0800)]
virsh: blockCopy: Add missing jump on error path

The overflow check for the bandwidth parameter did not jump to the
cleanup label.

Additionally virsh should use vshError instead of virReportError.

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoqemuDomainGetNumaParameters: Check for the correct CGroup controller
Michal Privoznik [Fri, 27 Mar 2015 14:16:43 +0000 (15:16 +0100)]
qemuDomainGetNumaParameters: Check for the correct CGroup controller

When getting info on NUMA parameters for domain,
virCgroupGetCpusetMems() may be called. However, as of 43b67f2e
the call is guarded by check if memory controller is present.
Even though it may be not obvious instantly, NUMA parameters are
stored under cpuset controller. Therefore the check needs to look
like this:

  if (!virCgroupHasController(priv->cgroup,
                              VIR_CGROUP_CONTROLLER_CPUSET) ||
      virCgroupGetCpusetMems(priv->cgroup, &nodeset) < 0) {

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCgroupController: Check the enum fits into 'int'
Michal Privoznik [Fri, 27 Mar 2015 12:45:33 +0000 (13:45 +0100)]
virCgroupController: Check the enum fits into 'int'

Throughout our code, the virCgroupController enum is used in two ways.
First as an index to an array of cgroup controllers:

struct virCgroup {
    char *path;

    struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST];
};

Second way is that when calling virCgroupNew() a bitmask of the enum
items can be passed to selectively detect only some controllers. For
instance:

int
virCgroupNewVcpu(virCgroupPtr domain,
                 int vcpuid,
                 bool create,
                 virCgroupPtr *group)
{
    ...
    controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
                   (1 << VIR_CGROUP_CONTROLLER_CPUACCT) |
                   (1 << VIR_CGROUP_CONTROLLER_CPUSET));

    if (virCgroupNew(-1, name, domain, controllers, group) < 0)
        goto cleanup;
}

Even though it's highly unlikely that so many new controllers will be
invented so that we would overflow when constructing the bitmask, it
doesn't hurt to check at compile time either.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCgroupNew: Enhance debug message
Michal Privoznik [Fri, 27 Mar 2015 10:29:25 +0000 (11:29 +0100)]
virCgroupNew: Enhance debug message

When creating new internal representation of cgroups, all passed
arguments are logged. Well, except for two: pid and pointer for
return value. Lets log them too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirCgroupNewPartition: Fix comment
Michal Privoznik [Fri, 27 Mar 2015 10:24:16 +0000 (11:24 +0100)]
virCgroupNewPartition: Fix comment

The function has no argument named @name rather than @path
instead.  The comment is, however, referring to @name while it
should have been referring to @path really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agobuild: avoid variable named 'interface', for mingw
Eric Blake [Sat, 28 Mar 2015 20:04:27 +0000 (14:04 -0600)]
build: avoid variable named 'interface', for mingw

Commit 2f36e6944 (re-)introduced a use of an identifier 'interface',
which causes this build failure on mingw:

../../tools/virsh-domain-monitor.c: In function 'cmdDomIfAddr':
../../tools/virsh-domain-monitor.c:2233:17: error: expected identifier or '(' before 'struct'
     const char *interface = NULL;
                      ^

See also commit 6512c8b.  Sadly, I'm not quite sure how to write a
syntax check that can poison the use of this identifier.

* tools/virsh-domain-monitor.c (cmdDomIfAddr): Use ifacestr instead.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agovircgroup: Fix build issue mingw cross compile
John Ferlan [Fri, 27 Mar 2015 16:36:04 +0000 (12:36 -0400)]
vircgroup: Fix build issue mingw cross compile

Commit id '2dbfa716' exposed virCgroupDetectMountsFromFile, but did not
add the corresponding entry in the "#else /* !VIR_CGROUP_SUPPORTED */"
section of the module.

10 years agovircgroup: Fix build issue on mingw cross compile
John Ferlan [Fri, 27 Mar 2015 16:13:56 +0000 (12:13 -0400)]
vircgroup: Fix build issue on mingw cross compile

Commit id 'ba1dfc5' added virCgroupSetCpusetMemoryMigrate and
virCgroupGetCpusetMemoryMigrate, but did not add the corresponding
entry points into the "#else /* !VIR_CGROUP_SUPPORTED */" section

10 years agotests: introduce qemucaps2xmlmock
Pavel Hrdina [Wed, 25 Mar 2015 14:35:46 +0000 (15:35 +0100)]
tests: introduce qemucaps2xmlmock

We need to mock virFileExists to return true for "/dev/kvm" because the
test should not depend on host system.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoRevert "qemucaps2xmltest: fix test to successfully run without kvm support"
Pavel Hrdina [Wed, 25 Mar 2015 14:17:13 +0000 (15:17 +0100)]
Revert "qemucaps2xmltest: fix test to successfully run without kvm support"

This reverts commit 49bf09d16cb7050795f6963a2746d686a2fbaece.  That
commit is wrong and doesn't fix the issue.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agovirnetlink: fix build error
Pavel Hrdina [Fri, 27 Mar 2015 10:06:05 +0000 (11:06 +0100)]
virnetlink: fix build error

Commint 0473b45cc introduced new function virNetlinkDelLink, but in
it's counterpart for non-linux platform there should be ATTRIBUTE_UNUSED
instead of ATTRIBUTE_UNSUPPORTED.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoqemu: end the job when try to blockcopy to non-file destination
Shanzhi Yu [Fri, 27 Mar 2015 09:16:41 +0000 (17:16 +0800)]
qemu: end the job when try to blockcopy to non-file destination

Blockcopy to non-file destination is not supported according the code,
but a 'goto endjob' is missed after checking the destination.

This leads to calling drive-mirror with wrong parameters.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1206406
Signed-off-by: Shanzhi Yu <shyu@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agonodeinfo: Increase the num of CPU thread siblings to a larger value
Wei Huang [Thu, 26 Mar 2015 04:48:13 +0000 (00:48 -0400)]
nodeinfo: Increase the num of CPU thread siblings to a larger value

Current libvirt can only handle up to 1023 bytes when it
reads Linux sysfs topology/thread_siblings. This isn't enough for
Linux distributions that support a large value. This patch fixes
the problem by using VIR_ALLOC()/VIR_FREE(), instead of using a
fixed-size (1024) local char array. In the meanwhile
SYSFS_THREAD_SIBLINGS_LIST_LENGTH_MAX is increased to 8192 which
should be large enough for a foreseeable future.

Signed-off-by: Wei Huang <wei@redhat.com>
10 years agorelaxng: allow : in /dev/disk/by-path names
Eric Blake [Thu, 26 Mar 2015 22:48:07 +0000 (16:48 -0600)]
relaxng: allow : in /dev/disk/by-path names

On IRC, Hydrar pointed a problem where 'virsh edit' failed on
his domain created through an ISCSI pool managed by virt-manager,
all because the XML included a block device with colons in the
name.

* docs/schemas/basictypes.rng (absFilePath): Add colon as safe.
* tests/qemuxml2argvdata/qemuxml2argv-disk-iscsi.xml: New file.
* tests/qemuxml2argvdata/qemuxml2argv-disk-iscsi.args: Likewise.
* tests/qemuxml2argvtest.c (mymain): Test it.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agolibxl: Fix memory leak if pthread_create fails.
Konrad Rzeszutek Wilk [Thu, 26 Mar 2015 01:35:11 +0000 (21:35 -0400)]
libxl: Fix memory leak if pthread_create fails.

If we fail to create the thread we leak the shutdown_info
structure.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
10 years agoutil: use netlink to create bridge devices
Laine Stump [Mon, 23 Mar 2015 18:17:44 +0000 (14:17 -0400)]
util: use netlink to create bridge devices

Just as it is possible to delete a bridge device with the netlink
RTM_DELLINK message, one can be created with the RTM_NEWLINK
message. Because of differences in the format of the message, it's not
as straightforward as with virNetlinkDelLink() to create a single
utility function that can be used to create any type of interface, so
the new netlink version of virNetDevBridgeCreate() does its own
construction of the netlink message and calls virNetlinkCommand()
itself.

This doesn't provide any extra functionality, just provides symmetry
with the previous commit.

NB: We *could* alter the API of virNetDevBridgeCreate() to take a MAC
address, and directly program that mac address into the bridge (by
adding an IFLA_ADDRESS attribute, as is done in
virNetDevMacVLanCreate()) rather than separately creating the "dummy
tap" (e.g. virbr0-nic) to maintain a fixed mac address on the bridge,
but the commit history of virnetdevbridge.c shows that the presence of
this dummy tap is essential in some older versions of the kernel
(between 2.6.39 and 3.1 or 3.2, possibly?) to proper operation of IPv6
DAD, and I don't want to take the chance of breaking something that I
don't have the time/setup to test (my RHEL6 box is at kernel
2.6.32-544, and the next lowest kernel I have is 3.17)

10 years agoutil: use netlink to delete bridge devices
Laine Stump [Tue, 17 Mar 2015 19:45:01 +0000 (15:45 -0400)]
util: use netlink to delete bridge devices

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

reported that a stray bridge device was left on the system when a
libvirt network failed to start due to an illegal iptables rule caused
by bad config. Apparently the reason this was happening was that
NetworkManager was noticing immediately when the bridge device was
created and automatically setting it IFF_UP. libvirt would then try to
setup the iptables rules, get an error back, and since libvirt had
never IFF_UPed the bridge, it didn't expect that it needed to set it
~IFF_UP before deleting it during the cleanup process. But the
ioctl(SIOCBRDELBR) ioctl will fail to delete a bridge if it is IFF_UP.

Since that bug was reported, NetworkManager has gotten a bit more
polite in this respect, but just in case something similar happens in
the future, this patch switches to using the netlink RTM_DELLINK
message to delete the bridge - unlike SIOCBRDELBR, it will delete the
requested bridge no matter what the setting of IFF_UP.

10 years agoutil: replace body of virNetDevMacVLanDelete() with virNetlinkDelLink()
Laine Stump [Tue, 17 Mar 2015 18:42:24 +0000 (14:42 -0400)]
util: replace body of virNetDevMacVLanDelete() with virNetlinkDelLink()

These two functions are identical, so no sense in having the
duplication. I resisted the temptation to replace calls to
virNetDevMacVLanDelete() with calls to virNetlinkDelLink() just in
case some mythical future platform has macvtap devices that aren't
managed with netlink (or in case we some day need to do more than just
tell the kernel to delete the device).