]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/log
people/liuw/libxenctrl-split/libvirt.git
10 years agolibvirt-guests: Allow time sync on guests resume
Michal Privoznik [Wed, 18 Feb 2015 10:59:22 +0000 (11:59 +0100)]
libvirt-guests: Allow time sync on guests resume

Well, imagine domains were running, and as the host went down, they
were managesaved. Later, after some time, the host went up again and
domains got restored. But without correct time. And depending on how
long was the host shut off, it may take some time for ntp to sync the
time too. But hey, wait a minute. We have an API just for that! So:

1) Introduce SYNC_TIME variable in libvirt-guests.sysconf to allow
users control over the new functionality
2) Call 'virsh domtime --sync $dom' in the libvirt-guests script.

Unfortunately, this is all-or-nothing approach (just like anything
else with the script). Domains are required to have configured and
running qemu-ga inside.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemu: Fix AAVMF/OVMF #define names
Cole Robinson [Wed, 18 Feb 2015 19:26:02 +0000 (14:26 -0500)]
qemu: Fix AAVMF/OVMF #define names

The AAVMF and OVMF names were swapped. Reorder the one usage where it
matters so behavior doesn't change.

10 years agolibxl: support backend domain setting for disk and net devices
Marek Marczykowski [Fri, 20 Feb 2015 03:22:06 +0000 (04:22 +0100)]
libxl: support backend domain setting for disk and net devices

This implement handling of <backenddomain name=''/>  parameter introduced
in previous patch.

Works on Xen >= 4.3, because only there libxl supports setting backend
domain by name.  Specifying backend domain by ID or UUID is currently not
supported.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
10 years agoconf: support backend domain name in disk and network devices
Marek Marczykowski [Fri, 20 Feb 2015 03:22:05 +0000 (04:22 +0100)]
conf: support backend domain name in disk and network devices

At least Xen supports backend drivers in another domain (aka "driver
domain"). This patch introduces an XML config option for specifying the
backend domain name for <disk> and <interface> devices.  E.g.

  <disk>
    <backenddomain name='diskvm'/>
    ...
  </disk>
  <interface type='bridge'>
    <backenddomain name='netvm'/>
    ...
  </interface>

In the future, same option will be needed for USB devices (hostdev
objects), but for now libxl doesn't have support for PVUSB.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
10 years agonetwork: allow <pf> together with <interface>/<address> in network status
Laine Stump [Sun, 15 Feb 2015 03:43:16 +0000 (22:43 -0500)]
network: allow <pf> together with <interface>/<address> in network status

The function that parses the <forward> subelement of a network used to
fail/log an error if the network definition contained both a <pf>
element as well as at least one <interface> or <address> element. That
check was present because the configuration of a network should have
either one <pf>, one or more <interface>, or one or more <address>,
but never combinations of multiple kinds.

This caused a problem when libvirtd was restarted with a network
already active - when a network with a <pf> element is started, the
referenced PF (Physical Function of an SRIOV-capable network card) is
checked for VFs (Virtual Functions), and the <forward> is filled in
with a list of all VFs for that PF either in the form of their PCI
addresses (a list of <address>) or their netdev names (a list of
<interface>); the <pf> element is not removed though. When libvirtd is
restarted, it parses the network status and finds both the original
<pf> from the config, as well as the list of either <address> or
<interface>, fails the parse, and the network is not added to the
active list. This failure is often obscured because the network is
marked as autostart so libvirt immediately restarts it.

It seems odd to me that <interface> and <address> are stored in the
same array rather than keeping two separate arrays, and having
separate arrays would have made the check much simpler. However,
changing to use two separate arrays would have required changes in
more places, potentially creating more conflicts and (more
importantly) more possible regressions in the event of a backport, so
I chose to keep the existing data structure in order to localize the
change.

It appears that this problem has been in the code ever since support
for <pf> was added (0.9.10), but until commit
34cc3b2f106e296df5e64309620c79d16fd76c85 (first in libvirt 1.2.4)
networks with interface pools were not properly marked as active on
restart anyway, so there is no point in backporting this patch any
further than that.

10 years agoqemu: caps: Add capability bit for the "pc-dimm" device
Peter Krempa [Mon, 6 Oct 2014 12:16:47 +0000 (14:16 +0200)]
qemu: caps: Add capability bit for the "pc-dimm" device

The pc-dimm device represents a RAM memory module.

10 years agoconf: Hoist validation of memory size into the post parse callback
Peter Krempa [Tue, 10 Feb 2015 16:11:40 +0000 (17:11 +0100)]
conf: Hoist validation of memory size into the post parse callback

Later patches will need to access the full definition to do check the
memory size and thus the checking needs to be done after the whole
definition including devices is known.

10 years agoconf: numa: Check ABI stability of NUMA configuration
Peter Krempa [Mon, 16 Feb 2015 19:34:37 +0000 (20:34 +0100)]
conf: numa: Check ABI stability of NUMA configuration

Add helper to compare initial sizes of indivitual NUMA nodes and the map
of belonging vCPUs. Other configuration is not ABI.

10 years agoconf: ABI: Hugepage backing definition is not guest ABI
Peter Krempa [Wed, 11 Feb 2015 14:15:13 +0000 (15:15 +0100)]
conf: ABI: Hugepage backing definition is not guest ABI

The backing of the vm's memory isn't influencing the guest ABI thus
shouldn't be checked.

10 years agoconf: Move all NUMA configuration to virDomainNuma
Peter Krempa [Mon, 16 Feb 2015 16:28:48 +0000 (17:28 +0100)]
conf: Move all NUMA configuration to virDomainNuma

For historical reasons data regarding NUMA configuration were split
between the CPU definition and numatune. We cannot do anything about the
XML still being split, but we certainly can at least store the relevant
data in one place.

This patch moves the NUMA stuff to the right place.

10 years agoconf: numa: Add setter/getter for NUMA node memory size
Peter Krempa [Mon, 16 Feb 2015 18:14:23 +0000 (19:14 +0100)]
conf: numa: Add setter/getter for NUMA node memory size

Add the helpers and refactor places where the value is accessed without
them.

10 years agoconf: numa: Add accessor to NUMA node's memory access mode
Peter Krempa [Mon, 16 Feb 2015 17:51:36 +0000 (18:51 +0100)]
conf: numa: Add accessor to NUMA node's memory access mode

10 years agoconf: numa: Add accessor for the NUMA node cpu mask
Peter Krempa [Mon, 16 Feb 2015 17:38:43 +0000 (18:38 +0100)]
conf: numa: Add accessor for the NUMA node cpu mask

Add virDomainNumaGetNodeCpumask() and refactor a few places that would
get the cpu mask without the helper.

10 years agoconf: numa: Add helper to get guest NUMA node count and refactor users
Peter Krempa [Mon, 16 Feb 2015 17:11:46 +0000 (18:11 +0100)]
conf: numa: Add helper to get guest NUMA node count and refactor users

Add an accessor so that a later refactor is simpler.

10 years agoqemu: command: Unify retrieval of NUMA cell count in qemuBuildNumaArgStr
Peter Krempa [Mon, 16 Feb 2015 16:55:50 +0000 (17:55 +0100)]
qemu: command: Unify retrieval of NUMA cell count in qemuBuildNumaArgStr

The function uses the cell count in 6 places. Add a temp variable to
hold the count as it will greatly simplify the refactor.

10 years agoconf: numa: Don't pass double pointer to virDomainNumatuneParseXML
Peter Krempa [Mon, 16 Feb 2015 16:19:15 +0000 (17:19 +0100)]
conf: numa: Don't pass double pointer to virDomainNumatuneParseXML

virDomainNumatuneParseXML now doesn't allocate the def->numa object any
longer so we don't need to pass a double pointer.

10 years agonuma: conf: Tweak parameters of virDomainNumatuneSet
Peter Krempa [Mon, 16 Feb 2015 16:05:46 +0000 (17:05 +0100)]
numa: conf: Tweak parameters of virDomainNumatuneSet

As virDomainNumatuneSet now doesn't allocate the virDomainNuma object
any longer it's not necessary to pass the pointer to a pointer to store
the object as it will not change any longer.

While touching the parameter definitions I've also changed the name of
the parameter to "numa".

10 years agoconf: numa: Always allocate the NUMA config
Peter Krempa [Mon, 16 Feb 2015 15:42:13 +0000 (16:42 +0100)]
conf: numa: Always allocate the NUMA config

Since our formatter now handles well if the config is allocated and not
filled we can safely always-allocate the NUMA config and remove the
ad-hoc allocation code.

This will help in later patches as the parser will be refactored to just
fill the data.

10 years agoconf: Allocate domain definition with the new helper
Peter Krempa [Mon, 16 Feb 2015 15:30:11 +0000 (16:30 +0100)]
conf: Allocate domain definition with the new helper

Use the virDomainDefNew() helper to allocate the definition instead of
doing it via VIR_ALLOC.

10 years agoconf: Separate helper for creating domain objects
Peter Krempa [Mon, 16 Feb 2015 14:58:13 +0000 (15:58 +0100)]
conf: Separate helper for creating domain objects

Move the existing virDomainDefNew to virDomainDefNewFull as it's setting
a few things in the conf and re-introduce virDomainDefNew as a function
without parameters for common use.

10 years agoconf: numa: Format <numatune> XML only if necessary
Peter Krempa [Mon, 16 Feb 2015 13:17:41 +0000 (14:17 +0100)]
conf: numa: Format <numatune> XML only if necessary

Do a content-aware check if formatting of the <numatune> element is
necessary. Later on the def->numa structure will be always present so we
cannot decide only on the basis whether it's allocated.

10 years agoconf: numa: Refactor logic in virDomainNumatuneParseXML
Peter Krempa [Thu, 12 Feb 2015 15:04:45 +0000 (16:04 +0100)]
conf: numa: Refactor logic in virDomainNumatuneParseXML

Shuffling around the logic will allow to simplify the code quite a bit.
As an additional bonus the change in the logic now reports an error if
automatic placement is selected and individual placement is configured.

10 years agoconf: numa: Reformat virDomainNumatuneParseXML
Peter Krempa [Thu, 12 Feb 2015 14:34:05 +0000 (15:34 +0100)]
conf: numa: Reformat virDomainNumatuneParseXML

Collapse few of the conditions so that the program flow is more clear.

10 years agoconf: numa: Improve error message in case a numa node doesn't have cpus
Peter Krempa [Wed, 11 Feb 2015 16:38:29 +0000 (17:38 +0100)]
conf: numa: Improve error message in case a numa node doesn't have cpus

Currently the code would exit without reporting an error as
virBitmapParse reports one only if it fails to parse the bitmap, whereas
the code was jumping to the error label even in case 0 cpus were
correctly parsed in the map.

10 years agoconf: numa: Recalculate rather than remember total NUMA cpu count
Peter Krempa [Thu, 12 Feb 2015 08:37:13 +0000 (09:37 +0100)]
conf: numa: Recalculate rather than remember total NUMA cpu count

It's easier to recalculate the number in the one place it's used as
having a separate variable to track it. It will also help with moving
the NUMA code to the separate module.

10 years agoconf: Move enum virMemAccess to the NUMA code and rename it
Peter Krempa [Wed, 11 Feb 2015 14:40:27 +0000 (15:40 +0100)]
conf: Move enum virMemAccess to the NUMA code and rename it

Name it virNumaMemAccess and add it to conf/numa_conf.[ch]

Note that to avoid a circular dependency the type of the NUMA cell
memAccess variable was changed to int. It will be turned back later
after the circular dependency will not exist.

10 years agoconf: numa: Rename virDomainNumatune to virDomainNuma
Peter Krempa [Wed, 11 Feb 2015 13:54:59 +0000 (14:54 +0100)]
conf: numa: Rename virDomainNumatune to virDomainNuma

The structure will gradually become the only place for NUMA related
config, thus rename it appropriately.

10 years agoconf: Move NUMA cell formatter to numa_conf
Peter Krempa [Wed, 11 Feb 2015 13:26:19 +0000 (14:26 +0100)]
conf: Move NUMA cell formatter to numa_conf

Move the code that formats the /domain/cpu/numa element to numa_conf as
it belongs there.

10 years agoconf: numa: Don't duplicate NUMA cell cpumask
Peter Krempa [Wed, 11 Feb 2015 13:06:20 +0000 (14:06 +0100)]
conf: numa: Don't duplicate NUMA cell cpumask

The mask was stored both as a bitmap and as a string. The string is used
for XML output only. Remove the string, as it can be reconstructed from
the bitmap.

The test change is necessary as the bitmap formatter doesn't "optimize"
using the '^' operator.

10 years agoconf: Refactor virDomainNumaDefCPUParseXML
Peter Krempa [Wed, 11 Feb 2015 12:31:09 +0000 (13:31 +0100)]
conf: Refactor virDomainNumaDefCPUParseXML

Rewrite the function to save a few local variables and reorder the code
to make more sense.

Additionally the ncells_max member of the virCPUDef structure is used
only for tracking allocation when parsing the numa definition, which can
be avoided by switching to VIR_ALLOC_N as the array is not resized
after initial allocation.

10 years agoconf: Move NUMA cell parsing code from cpu conf to numa conf
Peter Krempa [Wed, 11 Feb 2015 11:27:53 +0000 (12:27 +0100)]
conf: Move NUMA cell parsing code from cpu conf to numa conf

For weird historical reasons NUMA cells are added as a subelement of
<cpu> while the actual configuration is done in <numatune>.

This patch splits out the cell parser code from cpu config to NUMA
config. Note that the changes to the code are minimal just to make it
work and the function will be refactored in the next patch.

10 years agoconf: Move numatune_conf to numa_conf
Peter Krempa [Wed, 11 Feb 2015 09:08:35 +0000 (10:08 +0100)]
conf: Move numatune_conf to numa_conf

For a while now there are two places that gather information about NUMA
related guest configuration. While the XML can't be changed we can at
least store the data in one place in the definition.

Rename the numatune_conf.[ch] files to numa_conf as later patches will
move the rest of the definitions from the cpu definition to this one.

10 years agovirsh: fix vcpupin info
Pavel Hrdina [Fri, 20 Feb 2015 07:21:05 +0000 (08:21 +0100)]
virsh: fix vcpupin info

The "virDomainGetInfo" will get for running domain only live info and for
offline domain only config info. There was no way how to get config info
for running domain. We will use "vshCPUCountCollect" instead to get the
correct cpu count that we need to pass to "virDomainGetVcpuPinInfo".

Also cleanup some unnecessary variables and checks that are done by
drivers.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agovirQEMUCapsCacheLookupCopy: Filter qemuCaps based on machineType
Michal Privoznik [Thu, 12 Feb 2015 13:50:31 +0000 (14:50 +0100)]
virQEMUCapsCacheLookupCopy: Filter qemuCaps based on machineType

Not all machine types support all devices, device properties, backends,
etc. So until we create a matrix of [machineType, qemuCaps], lets just
filter out some capabilities before we return them to the consumer
(which is going to make decisions based on them straight away).
Currently, as qemu is unable to tell which capabilities are (not)
enabled for given machine types, it's us who has to hardcode the matrix.
One day maybe the hardcoding will go away and we can create the matrix
dynamically on the fly based on a few monitor calls.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirQEMUCapsCacheLookupCopy: Pass machine type
Michal Privoznik [Thu, 12 Feb 2015 12:48:42 +0000 (13:48 +0100)]
virQEMUCapsCacheLookupCopy: Pass machine type

It will come handy in the near future when we will filter some
capabilities based on it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirsh-edit: Make force editing usable
Martin Kletzander [Thu, 19 Feb 2015 13:16:39 +0000 (14:16 +0100)]
virsh-edit: Make force editing usable

When editing a domain with 'virsh edit' and failing validation, the
usual message pops up:

  Failed. Try again? [y,n,f,?]:

Turning off validation can be useful, mainly for testing (but other
purposes too), so this patch adds support for relaxing definition in
virsh-edit and makes 'virsh edit <domain>' more usable.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoparallels: Set the first HDD from XML as bootable
Mikhail Feoktistov [Tue, 17 Feb 2015 11:52:33 +0000 (14:52 +0300)]
parallels: Set the first HDD from XML as bootable

1. Delete all boot devices for VM instance
2. Find the first HDD from XML and set it as bootable

Now we support only one boot device and it should be HDD.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoparallels: Use IS_CT() macro instead of STREQ("exe")
Mikhail Feoktistov [Tue, 17 Feb 2015 11:52:32 +0000 (14:52 +0300)]
parallels: Use IS_CT() macro instead of STREQ("exe")

10 years agoparallels: code aligment
Mikhail Feoktistov [Tue, 17 Feb 2015 11:52:31 +0000 (14:52 +0300)]
parallels: code aligment

10 years agoSearch for schemas and cpu_map.xml in source tree
Jiri Denemark [Fri, 13 Feb 2015 13:25:27 +0000 (14:25 +0100)]
Search for schemas and cpu_map.xml in source tree

Not all files we want to find using virFileFindResource{,Full} are
generated when libvirt is built, some of them (such as RNG schemas) are
distributed with sources. The current API was not able to find source
files if libvirt was built in VPATH.

Both RNG schemas and cpu_map.xml are distributed in source tarball.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoqemuMigrationDriveMirror: Listen to events
Michal Privoznik [Tue, 10 Feb 2015 15:25:27 +0000 (16:25 +0100)]
qemuMigrationDriveMirror: Listen to events

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

When migrating with storage, libvirt iterates over domain disks and
instruct qemu to migrate the ones we are interested in (shared, RO and
source-less disks are skipped). The disks are migrated in series. No
new disk is transferred until the previous one hasn't been quiesced.
This is checked on the qemu monitor via 'query-jobs' command. If the
disk has been quiesced, it practically went from copying its content
to mirroring state, where all disk writes are mirrored to the other
side of migration too. Having said that, there's one inherent error in
the design. The monitor command we use reports only active jobs. So if
the job fails for whatever reason, we will not see it anymore in the
command output. And this can happen fairly simply: just try to migrate
a domain with storage. If the storage migration fails (e.g. due to
ENOSPC on the destination) we resume the host on the destination and
let it run on partly copied disk.

The proper fix is what even the comment in the code says: listen for
qemu events instead of polling. If storage migration changes state an
event is emitted and we can act accordingly: either consider disk
copied and continue the process, or consider disk mangled and abort
the migration.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemuProcessHandleBlockJob: Take status into account
Michal Privoznik [Tue, 10 Feb 2015 15:24:45 +0000 (16:24 +0100)]
qemuProcessHandleBlockJob: Take status into account

Upon BLOCK_JOB_COMPLETED event delivery, we check if the job has
completed (in qemuMonitorJSONHandleBlockJobImpl()). For better image,
the event looks something like this:

"timestamp": {"seconds": 1423582694, "microseconds": 372666}, "event":
"BLOCK_JOB_COMPLETED", "data": {"device": "drive-virtio-disk0", "len":
8412790784, "offset": 409993216, "speed": 8796093022207, "type":
"mirror", "error": "No space left on device"}}

If "len" does not equal "offset" it's considered an error, and we can
clearly see "error" field filled in. However, later in the event
processing this case was handled no differently to case of job being
aborted via separate API. It's time that we start differentiate these
two because of the future work.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemuProcessHandleBlockJob: Set disk->mirrorState more often
Michal Privoznik [Tue, 10 Feb 2015 14:32:59 +0000 (15:32 +0100)]
qemuProcessHandleBlockJob: Set disk->mirrorState more often

Currently, upon BLOCK_JOB_* event, disk->mirrorState is not updated
each time. The callback code handling the events checks if a blockjob
was started via our public APIs prior to setting the mirrorState.
However, some block jobs may be started internally (e.g. during
storage migration), in which case we don't bother with setting
disk->mirror (there's nothing we can set it to anyway), or other
fields. But it will come handy if we update the mirrorState in these
cases too. The event wasn't delivered just for fun - we've started the
job after all.

So, in this commit, the mirrorState is set to whatever job status
we've obtained. Of course, there are some actions on some statuses
that we want to perform. But instead of if {} else if {} else {} ...
enumeration, let's move to switch().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemu: Exit job on error path of qemuDomainSetVcpusFlags()
Peter Krempa [Wed, 18 Feb 2015 17:05:21 +0000 (18:05 +0100)]
qemu: Exit job on error path of qemuDomainSetVcpusFlags()

Commit e105dc981438bc33fa771bd67cece6234dbf6c8d moved some code but
didn't adjust the jump labels so that the job would be terminated.

10 years agodaemon: Fix segfault by reloading daemon right after start
Pavel Hrdina [Wed, 18 Feb 2015 15:10:58 +0000 (16:10 +0100)]
daemon: Fix segfault by reloading daemon right after start

Libvirt could crash with segfault if user issue "service reload" right
after "service start". One possible way to crash libvirt is to run reload
during initialization of QEMU driver.

It could happen when qemu driver will initialize qemu_driver_lock but
don't have a time to set it's "config" and the SIGHUP arrives. The
reload handler tries to get qemu_drv->config during "virStorageAutostart"
and dereference it which ends with segfault.

Let's ignore all reload requests until all drivers are initialized. In
addition set driversInitialized before we enter virStateCleanup to
ignore reload request while we are shutting down.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agodocs: clarify nat range behavior
Ján Tomko [Wed, 18 Feb 2015 14:36:45 +0000 (15:36 +0100)]
docs: clarify nat range behavior

All the addresses from the range are used, not just those
that are in use on the host.

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

10 years agodocs: add page about virtlockd setup
Daniel P. Berrange [Mon, 16 Feb 2015 11:58:32 +0000 (11:58 +0000)]
docs: add page about virtlockd setup

Introduce some basic docs describing the virtlockd setup.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agodocs: split out sanlock setup docs
Daniel P. Berrange [Fri, 13 Feb 2015 17:02:44 +0000 (17:02 +0000)]
docs: split out sanlock setup docs

In preparation for adding docs about virtlockd, split out
the sanlock setup docs into a separate page.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agoqemu_cgroup: initialize mem_mask to NULL
Pavel Hrdina [Tue, 17 Feb 2015 13:08:22 +0000 (14:08 +0100)]
qemu_cgroup: initialize mem_mask to NULL

If 'virNumaGetHostNodeset()' fails then the error path will try to free
uninitialized pointer mem_mask. Introduced by commit af2a1f058.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoPowerPC : Forbid NULL CPU model with 'host-model' mode.
Prerna Saxena [Sun, 15 Feb 2015 04:24:15 +0000 (09:54 +0530)]
PowerPC : Forbid NULL CPU model with 'host-model' mode.

PowerPC : Forbid NULL CPU model with 'host-model' mode in qemu command line.

This ensures that an XML such as following:
...
  <cpu mode='host-model'>
    <model fallback='allow'/>
  </cpu>
...

will not generate a '-cpu host,compat=(null)' command line with qemu-system-ppc64.

Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
10 years agoPowerPC : Make 'qemu-system-ppc64' the default emulator on ppc64[le].
Prerna Saxena [Sun, 15 Feb 2015 04:18:00 +0000 (09:48 +0530)]
PowerPC : Make 'qemu-system-ppc64' the default emulator on ppc64[le].

PowerPC : Explicitly associate 'qemu-system-ppc64' as the
 default emulator for all 64-bit PowerPC guests ( both Big & Little Endian )

Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
10 years agoqemu: fix vm deadlock when try to use numatune in session mode
Luyao Huang [Tue, 17 Feb 2015 03:37:52 +0000 (11:37 +0800)]
qemu: fix vm deadlock when try to use numatune in session mode

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

Commit 43b67f introduced a deadlock issue when we use numatune
to change numa settings to a vm in session mode.

Jump to endjob instead of jump to cleanup.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoqemuBuildMemoryBackendStr: Report backend requirement more appropriately
Michal Privoznik [Thu, 12 Feb 2015 16:43:27 +0000 (17:43 +0100)]
qemuBuildMemoryBackendStr: Report backend requirement more appropriately

So, when building the '-numa' command line, the
qemuBuildMemoryBackendStr() function does quite a lot of checks to
chose the best backend, or to check if one is in fact needed. However,
it returned that backend is needed even for this little fella:

  <numatune>
    <memory mode="strict" nodeset="0,2"/>
  </numatune>

This can be guaranteed via CGroups entirely, there's no need to use
memory-backend-ram to let qemu know where to get memory from. Well, as
long as there's no <memnode/> element, which explicitly requires the
backend. Long story short, we wouldn't have to care, as qemu works
either way. However, the problem is migration (as always). Previously,
libvirt would have started qemu with:

  -numa node,memory=X

in this case and restricted memory placement in CGroups. Today, libvirt
creates more complicated command line:

  -object memory-backend-ram,id=ram-node0,size=X
  -numa node,memdev=ram-node0

Again, one wouldn't find anything wrong with these two approaches.
Both work just fine. Unless you try to migrated from the older libvirt
into the newer one. These two approaches are, unfortunately, not
compatible. My suggestion is, in order to allow users to migrate, lets
use the older approach for as long as the newer one is not needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoqemuxml2argvtest: Fake response from numad
Michal Privoznik [Thu, 12 Feb 2015 16:39:34 +0000 (17:39 +0100)]
qemuxml2argvtest: Fake response from numad

Well, we can pretend that we've asked numad for its suggestion and let
qemu command line be built with that respect. Again, this alone has no
big value, but see later commits which build on the top of this.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agonumatune_conf: Expose virDomainNumatuneNodeSpecified
Michal Privoznik [Thu, 12 Feb 2015 16:37:46 +0000 (17:37 +0100)]
numatune_conf: Expose virDomainNumatuneNodeSpecified

This function is going to be needed in the near future.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirsh: fix IP address in vncdisplay for listen type='network'
Luyao Huang [Sun, 15 Feb 2015 08:49:09 +0000 (16:49 +0800)]
virsh: fix IP address in vncdisplay for listen type='network'

Just like the fix for domdisplay in commit 1ba815.

10 years agolibxl: Resolve Coverity CHECKED_RETURN
John Ferlan [Fri, 13 Feb 2015 20:09:09 +0000 (15:09 -0500)]
libxl: Resolve Coverity CHECKED_RETURN

Periodically my Coverity scan will return a checked_return failure
for libxlDomainShutdownThread call to libxlDomainStart. Followed the
libxlAutostartDomain example in order to check the status, emit a
message, and continue on.

10 years agosecurity: Resolve Coverity RESOURCE_LEAK
John Ferlan [Fri, 13 Feb 2015 19:15:26 +0000 (14:15 -0500)]
security: Resolve Coverity RESOURCE_LEAK

Introduced by commit id 'c3d9d3bb' - return from virSecurityManagerCheckModel
wasn't VIR_FREE()'ing the virSecurityManagerGetNested allocated memory.

10 years agolxc: Fix container cleanup for LXCProcessStart
Luyao Huang [Wed, 4 Feb 2015 13:42:56 +0000 (21:42 +0800)]
lxc: Fix container cleanup for LXCProcessStart

Jumping to the cleanup label prior to starting the container failed to
properly clean everything up that is handled by the virLXCProcessCleanup
which is called if virLXCProcessStop is called on failure after the
container properly starts. Most importantly is prior to this patch none
of the stop/release hooks, host device reattachment, and network cleanup
(that is reverse of virLXCProcessSetupInterfaces).

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agolxc: Modify/add some debug messages
John Ferlan [Thu, 12 Feb 2015 19:32:39 +0000 (14:32 -0500)]
lxc: Modify/add some debug messages

Modify the VIR_DEBUG message in virLXCProcessCleanup to make it clearer
about the path.  Also add some more VIR_DEBUG messages in virLXCProcessStart
in order to help debug error flow.

10 years agolxc: Move console checks in LXCProcessStart
Luyao Huang [Thu, 12 Feb 2015 19:43:26 +0000 (14:43 -0500)]
lxc: Move console checks in LXCProcessStart

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

Move the two console checks - one for zero nconsoles present and the
other for an invalid console type to earlier in the processing rather than
getting after performing some setup that has to be undone for what amounts
to an invalid configuration.

This resolves the above bug since it's not not possible to have changed
the security labels when we cause the configuration check failure.

10 years agosecurity: Refactor virSecurityManagerGenLabel
Erik Skultety [Thu, 12 Feb 2015 17:32:41 +0000 (18:32 +0100)]
security: Refactor virSecurityManagerGenLabel

if (mgr == NULL || mgr->drv == NULL)
    return ret;

This check isn't really necessary, security manager cannot be a NULL
pointer as it is either selinux (by default) or 'none', if no other driver is
set in the config. Even with no config file driver name yields 'none'.

The other hunk checks for domain's security model validity, but we should
also check devices' security model as well, therefore this hunk is moved into
a separate function which is called by virSecurityManagerCheckAllLabel that
checks both the domain's security model and devices' security model.

https://bugzilla.redhat.com/show_bug.cgi?id=1165485
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agosecurity: introduce virSecurityManagerCheckAllLabel function
Erik Skultety [Thu, 12 Feb 2015 17:32:40 +0000 (18:32 +0100)]
security: introduce virSecurityManagerCheckAllLabel function

We do have a check for valid per-domain security model, however we still
do permit an invalid security model for a domain's device (those which
are specified with <source> element).
This patch introduces a new function virSecurityManagerCheckAllLabel
which compares user specified security model against currently
registered security drivers. That being said, it also permits 'none'
being specified as a device security model.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1165485
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoWire up mrg_rxbuf option for qemu
Ján Tomko [Fri, 6 Feb 2015 14:40:19 +0000 (15:40 +0100)]
Wire up mrg_rxbuf option for qemu

<interface ...>
  ...
  <model type='virtio'/>
  <driver ...>
    <host mrg_rxbuf='off'/>
  </driver>
</interface>

will result in:
-device virtio-net-pci,mrg_rxbuf=off,...

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

10 years agoAdd mrg_rxbuf option to virtio interfaces
Ján Tomko [Fri, 6 Feb 2015 14:35:57 +0000 (15:35 +0100)]
Add mrg_rxbuf option to virtio interfaces

Add an XML attribute to allow disabling merge of rx buffers
on the host:
<interface ...>
  ...
  <model type='virtio'/>
  <driver ...>
    <host mrg_rxbuf='off'/>
  </driver>
</interface>

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

10 years agovirsh attach-interface: Allow macvtap hotplug
Michal Privoznik [Mon, 9 Feb 2015 15:17:51 +0000 (16:17 +0100)]
virsh attach-interface: Allow macvtap hotplug

Our hotplug code supports macvtap insertion to guests. However, we
somehow forgot about 'attach-interface' (which tries to build XML from
passed arguments and use virDomainAttachDeviceFlags()).
New type is accessible under 'direct' type, to keep the same type as
used in domain XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirsh attach-interface: Use virDomainNetType{From,To}String()
Michal Privoznik [Mon, 9 Feb 2015 15:04:58 +0000 (16:04 +0100)]
virsh attach-interface: Use virDomainNetType{From,To}String()

Instead of verbose string to enum conversion (if STREQ() else if
STREQ() else if STREQ() ...) lets use virDomainNetType{From,To}String.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirsh attach-interface: Use enum instead of arbitrary integers
Michal Privoznik [Mon, 9 Feb 2015 14:53:54 +0000 (15:53 +0100)]
virsh attach-interface: Use enum instead of arbitrary integers

The type of interface to attach is held in the variable 'typ'.
Depending on interface type selected by user, the variable is set
either to 1 (network), or 2 (bridge). Lets use already existing
enum from domain_conf.h instead: virDomainNetType.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agolibvirt_private.syms: Expose virDomainNetTypeFromString
Michal Privoznik [Mon, 9 Feb 2015 15:07:30 +0000 (16:07 +0100)]
libvirt_private.syms: Expose virDomainNetTypeFromString

The enum converters are defined in the domain_conf.h (so
accessible widely across the code), but on the symbol layer, only
virDomainNetTypeToString was exposed. However, FromString variant
is going to be needed shortly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirprocess: fix MinGW build and RHEL-5 build
Pavel Hrdina [Thu, 12 Feb 2015 12:46:08 +0000 (13:46 +0100)]
virprocess: fix MinGW build and RHEL-5 build

Commit b6a2828e introduced new functions to set process scheduler. There
is a small typo in ELSE path for systems where scheduler is not
available.

Also some of the definitions were introduced later in kernel. For
example RHEL-5 is running on kernel 2.6.18, but SCHED_IDLE was introduces
in 2.6.23 [1] and SCHED_BATCH in 2.6.16 [1]. We should not count only on
existence of function sched_setscheduler(), we must also check for
existence of used macros as they might not be defined.

[1] see 'man 7 sched'

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoFix a syntax error in the description text of libvirtd.conf
Zhang Bo [Thu, 12 Feb 2015 04:22:40 +0000 (12:22 +0800)]
Fix a syntax error in the description text of libvirtd.conf

not yet not -> not yet.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
10 years agodocs: Fix version reference in vcpu/iothread scheduling
Martin Kletzander [Thu, 12 Feb 2015 12:29:08 +0000 (13:29 +0100)]
docs: Fix version reference in vcpu/iothread scheduling

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoAllow shrinking of file based volumes
Daniel P. Berrange [Thu, 15 Jan 2015 16:40:31 +0000 (16:40 +0000)]
Allow shrinking of file based volumes

While the main storage driver code allows the flag
VIR_STORAGE_VOL_RESIZE_SHRINK to be set, none of the backend
drivers are supporting it. At the very least this can work
for plain file based volumes since we just ftruncate() them
to the new size. It does not work with qcow2 volumes, but we
can arguably delegate to qemu-img for error reporting for that
instead of second guessing this for ourselves:

$ virsh vol-resize --shrink /home/berrange/VirtualMachines/demo.qcow2 2G
error: Failed to change size of volume 'demo.qcow2' to 2G

error: internal error: Child process (/usr/bin/qemu-img resize /home/berrange/VirtualMachines/demo.qcow2 2147483648) unexpected exit status 1: qemu-img: qcow2 doesn't support shrinking images yet
qemu-img: This image does not support resize

See also https://bugzilla.redhat.com/show_bug.cgi?id=1021802

10 years agoqemu: do upfront check for vcpupids being null when querying pinning
Daniel P. Berrange [Tue, 10 Feb 2015 16:23:16 +0000 (16:23 +0000)]
qemu: do upfront check for vcpupids being null when querying pinning

The qemuDomainHelperGetVcpus attempted to report an error when the
vcpupids info was NULL. Unfortunately earlier code would clamp the
value of 'maxinfo' to 0 when nvcpupids was 0, so the error reporting
would end up being skipped.

This lead to 'virsh vcpuinfo <dom>' just returning an empty list
instead of giving the user a clear error.

10 years agoqemu: fix setting of VM CPU affinity with TCG
Daniel P. Berrange [Tue, 10 Feb 2015 15:59:57 +0000 (15:59 +0000)]
qemu: fix setting of VM CPU affinity with TCG

If a previous commit I fixed the incorrect handling of vcpu pids
for TCG mode QEMU:

  commit b07f3d821dfb11a118ee75ea275fd6ab737d9500
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Thu Dec 18 16:34:39 2014 +0000

    Don't setup fake CPU pids for old QEMU

    The code assumes that def->vcpus == nvcpupids, so when we setup
    fake CPU pids for old QEMU with nvcpupids == 1, we cause the
    later code to read off the end of the array. This has fun results
    like sche_setaffinity(0, ...) which changes libvirtd's own CPU
    affinity, or even better sched_setaffinity($RANDOM, ...) which
    changes the affinity of a random OS process.

The intent was that this would merely disable the ability to set
per-vCPU affinity. It should still have been possible to set VM
level host CPU affinity.

Unfortunately, when you set  <vcpu cpuset='0-1'>4</vcpu>, the XML
parser will internally take this & initialize an entry in the
def->cputune.vcpupin array for every VCPU. IOW this is implicitly
being treated as

  <cputune>
    <vcpupin cpuset='0-1' vcpu='0'/>
    <vcpupin cpuset='0-1' vcpu='1'/>
    <vcpupin cpuset='0-1' vcpu='2'/>
    <vcpupin cpuset='0-1' vcpu='3'/>
  </cputune>

Even more fun, the faked cputune elements are hidden from view when
querying the live XML, because their cpuset mask is the same as the
VM default cpumask.

The upshot was that it was impossible to set VM level CPU affinity.

To fix this we must update qemuProcessSetVcpuAffinities so that it
only reports a fatal error if the per-VCPU cpu mask is different
from the VM level cpu mask.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
10 years agolibxl: disable VNC and SDL until explicitly enabled
Marek Marczykowski-Górecki [Tue, 10 Feb 2015 02:36:47 +0000 (03:36 +0100)]
libxl: disable VNC and SDL until explicitly enabled

When initializing a libxl_domain_build_info struct with
libxl_domain_build_info_init(), VNC is enabled by default.  As a
result, VMs configured with no graphics still have VNC enabled.
This behavior is a regression wrt to the legacy Xen driver.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
10 years agolibxl: pass ipaddr to libxl toolstack
Marek Marczykowski-Górecki [Tue, 10 Feb 2015 02:17:23 +0000 (03:17 +0100)]
libxl: pass ipaddr to libxl toolstack

Do not silently ignore its value. LibXL support only one address, so
refuse multiple IPs.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
10 years agoqemu: Add support for setting vCPU and I/O thread scheduler setting
Martin Kletzander [Thu, 8 Jan 2015 14:37:50 +0000 (15:37 +0100)]
qemu: Add support for setting vCPU and I/O thread scheduler setting

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agodocs, schema, conf: Add support for setting scheduler parameters of guest threads
Martin Kletzander [Thu, 8 Jan 2015 12:54:21 +0000 (13:54 +0100)]
docs, schema, conf: Add support for setting scheduler parameters of guest threads

In order for QEMU vCPU (and other) threads to run with RT scheduler,
libvirt needs to take care of that so QEMU doesn't have to run privileged.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoutil: Add virProcessSetScheduler() function for scheduler settings
Martin Kletzander [Thu, 8 Jan 2015 14:36:54 +0000 (15:36 +0100)]
util: Add virProcessSetScheduler() function for scheduler settings

This function uses sched_setscheduler() function so it works with
processes and threads as well (even threads not created by us, which is
what we'll need in the future).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agodomain: include portgroup in interface status xml
Laine Stump [Tue, 10 Feb 2015 21:17:11 +0000 (16:17 -0500)]
domain: include portgroup in interface status xml

Prior to commit 7d5bf484747 (first appearing in libvirt 1.2.2), the
status XML of a domain's interface was missing a lot of important
information; mainly it just output the config of the interface, plus
the name of the tap device and qemu device alias. Commit 7d5bf484747
changed the status XML to include many important bits of information
that were required to make network "hook" scripts useful - bandwidth
information, vlan tag, the name of the bridge (or physical device in
the case of macvtap) that the tap/macvtap device was attached to - the
commit log for 7d5bf484747 has a very detailed explanation of the
change. For quick reference - in the example given there, prior to the
change, status XML looked like figure [C]:

      <interface type='network'>
        <source network='testnet' portgroup='admin'/>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

and after the change, it looked like figure [E]:

      <interface type='direct'>
        <source dev='p4p1_0' mode='bridge'/>
        <bandwidth>
            <inbound average='1000' peak='5000' burst='1024'/>
            <outbound average='128' peak='256' burst='256'/>
        </bandwidth>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

You'll notice that bandwidth info, physdev, and macvtap mode have been
added, but the network and portgroup names are now missing - I didn't
think that this information was of any use once the needed
bandwidth/vlan/etc config had been pulled from the network/portgroup.

I was wrong.

A few months after that change a user on IRC asked what happened to
portgroup in the status XML and described how he used it (more or less
as a tag to decide what external information to use in a hook script
that was run at startup/migration time - see
http://wiki.libvirt.org/page/OVS_and_PVLANS ). At that time I planned
to make a patch to re-add portgroup, but life intervened as that was
just prior to a transatlantic move involving several weeks of
"vacation". During this time I somehow forgot to make the patch, and
also mistakenly remembered that I *had* made it.

Subsequent to this, as a part of mprivozn's work to add support for
network-specific hooks, I did re-add the output of the network name in
status XML, but once again completely forgot about portgroup. This was
in commit a3609121 (first appearing in libvirt 1.2.11). This made the
status XML from the above example look like this:

      <interface type='direct'>
        <source network='testnet' dev='p4p1_0' mode='bridge'/>
        <bandwidth>
            <inbound average='1000' peak='5000' burst='1024'/>
            <outbound average='128' peak='256' burst='256'/>
        </bandwidth>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

*This* patch just adds the portgroup back to the status XML, so the
 same example interface will look like this:

      <interface type='direct'>
        <source network='testnet' portgroup='admin'
                dev='p4p1_0' mode='bridge'/>
        <bandwidth>
            <inbound average='1000' peak='5000' burst='1024'/>
            <outbound average='128' peak='256' burst='256'/>
        </bandwidth>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

The result is that the status XML now contains all information about
how the interface is setup (bandwidth, physical device, tap device,
etc), in addition to pointers to its origin (the network and
portgroup).

10 years agodomain: avoid potential memory leak in virDomainGraphicsListenSet*()
Laine Stump [Tue, 10 Feb 2015 19:04:40 +0000 (14:04 -0500)]
domain: avoid potential memory leak in virDomainGraphicsListenSet*()

virDomainGraphicsListenSetAddress() and
virDomainGraphicsListenSetNetwork() both set their respective char* to
NULL directly when asked to set it to NULL, which is okay as long as
it's already set to NULL. If these functions are ever called to clear
a listen object that has a valid string in address or network, it will
end up leaking the old value. Currently that doesn't happen, so this
is just a preemptive strike.

10 years agodomain: backfill listen address to parent <graphics> listen attribute
Laine Stump [Tue, 10 Feb 2015 18:49:16 +0000 (13:49 -0500)]
domain: backfill listen address to parent <graphics> listen attribute

Prior to 0.9.4, libvirt only supported a single listen, and it had to
be an IP address:

   <graphics listen='1.2.3.4' ..../>

Starting with 0.9.4, a graphics element could have a <listen>
subelement (actually the grammar supports multiples, but all of the
drivers only support a single <listen> per <graphics>), and that
listen element can be of type='address' or type='network'. For
type='address', <listen> also has an attribute called 'address' which
contains the IP address for listening:

    <graphics ....>
      <listen type='address' address='1.2.3.4' .../>
    </graphics>

type can also be "network", and in that case listen will have a
"network" attribute which will contain the name of a libvirt
network:

    <graphics ....>
      <listen type='network' network='testnet' .../>
    </graphics>

At domain start (or migrate) time, libvirt will attempt to
find an IP address associated with that network (e.g. the IP address
of the bridge device used by the network, or the physical device
listed in <forward dev='physdev'/>) and fill in that address in the
status XML:

    <graphics ....>
      <listen type='network' network='testnet' address='1.2.3.4' .../>
    </graphics>

In the case that a <graphics> element has a <listen> subelement of
type='address', that listen subelement's "address" attribute is
backfilled into the parent graphics element's "listen" *attribute* for
backward compatibility (so that a management application unaware of
the separate <listen> element can still learn the listen
address). This backfill should be done with the IP learned from
type='network' as well, and that's what this patch does:

    <graphics listen='1.2.3.4' ....>
      <listen type='network' network='testnet' address='1.2.3.4' .../>
    </graphics>

This is a continuation of the fix for:

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

10 years agovirsh: fix IP address in domdisplay for listen type='network'
Luyao Huang [Tue, 10 Feb 2015 09:35:56 +0000 (17:35 +0800)]
virsh: fix IP address in domdisplay for listen type='network'

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

virsh's domdisplay command looks in /domain/devices/graphics/@listen
of the domain's XML for the listen address, however for listen
type='network' (added in libvirt 0.9.4), the <graphics> element
doesn't have a listen attribute, but has a <listen> subelement,
*still* with no address (this is the inactive XML):

 <graphics type='spice' autoport='yes' keymap='en-us'>
  <listen type='network' network='default'/>
 </graphics>

However, at domain start time the <listen> subelement gets its address
attribute filled in once libvirt figures out the IP address associated
with the named network (this is the status XML):

 <graphics type='spice' port='5901' autoport='yes' keymap='en-us'>
  <listen type='network' address='192.168.122.1' network='default'/>
 </graphics>

So in these cases, we need to look at
/domain/devices/graphics/listen/@address instead.

Even though another patch is being pushed that will backfill
listen/@address into @listen, this patch is still useful, as it fixes
domdisplay for cases of a new virsh (with this patch) connecting to a
libvirtd that is newer than 0.9.4 but doesn't have the followup patch.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Laine Stump <laine@laine.org>
10 years agobhyvexml2argvmock: change int to size_t for tapfdSize
Pavel Hrdina [Tue, 10 Feb 2015 09:50:38 +0000 (10:50 +0100)]
bhyvexml2argvmock: change int to size_t for tapfdSize

Commit c5b6a4a5 forget to update also this mock function.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
10 years agoqemu: qemuOpenFileAs - set flag VIR_FILE_OPEN_FORCE_MODE
John Ferlan [Mon, 26 Jan 2015 19:28:25 +0000 (14:28 -0500)]
qemu: qemuOpenFileAs - set flag VIR_FILE_OPEN_FORCE_MODE

In the event we're falling into the code that tries to create the file
in a forked environment (VIR_FILE_OPEN_FORK) we pass different mode bits,
but those are never set because the virFileOpenForceOwnerMode has a check
if the OPEN_FORCE_MODE bit is set before attempting to change the mode.

Since this is a special case it seems reasonable to set u+rw,g+rw,o

10 years agovirfile: Adjust error path for virFileOpenForked
John Ferlan [Wed, 28 Jan 2015 17:34:54 +0000 (12:34 -0500)]
virfile: Adjust error path for virFileOpenForked

Rather than have a dummy waitpid loop and return of the failure status
from recvfd, adjust the logic to save the recvfd error & fd and then
in priority order:

- if waitpid failed, use that errno value
- waitpid succeeded, but if the child exited abnormally, report failure
(use EACCES to report as return failure, since either EACCES or EPERM is
what caused us to fall into the fork+setuid path)
- waitpid succeeded, but if the child reported non-zero status, report
failure (use the errno value that the child encoded into exit status)
- waitpid succeeded, but if recvfd failed, report recvfd_errno
- waitpid and recvfd succeeded, use the fd

NOTE: Original logic to retry the open and force owner mode was
"documented" as only being attempted if we had already tried opening
with the fork+setuid, but checked flags vs. VIR_FILE_OPEN_NOFORK which
is counter to how we would get to that point. So that code was removed.

10 years agoqemu: fix crash when migrateuri has no scheme
Luyao Huang [Wed, 11 Feb 2015 08:30:32 +0000 (16:30 +0800)]
qemu: fix crash when migrateuri has no scheme

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

When we attempt to migrate a vm with a migrateuri that has no scheme:

 # virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1

target libvirtd will crash because uri->scheme is NULL in
qemuMigrationPrepareDirect on this line:

     if (STRNEQ(uri->scheme, "tcp") &&

Add a value check before this line. Also fix a bug like this in
doNativeMigrate, that could only happen when destination libvirtd
returned an incorrect URI.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
10 years agoconf: Fix libvirtd crash and memory leak caused by virDomainVcpuPinDel()
Zhang Bo [Wed, 11 Feb 2015 08:48:24 +0000 (16:48 +0800)]
conf: Fix libvirtd crash and memory leak caused by virDomainVcpuPinDel()

The function virDomainVcpuPinDel() used vcpupin_list to stand for
def->cputune.vcpupin, which made the codes more readable.
However, in this function, it will realloc vcpupin_list later.
As the definition of realloc(), it may free vcpupin_list and then
points it to a new-realloced address, but def->cputune.vcpupin doesn't
point to the new address(it's freed however).
Thus,
1) When we refer to the def->cputune.vcpupin afterwards, which was freed
by realloc(), an INVALID READ occurs, and libvirtd may crash.
2) As no one will use vcpupin_list any more, and no one frees it(it's just
alloced by realloc()), memory leak occurs.

Part of the valgrind logs are shown as below:
==1837== Thread 15:
==1837== Invalid read of size 8
==1837==    at 0x5367337: virDomainDefFormatInternal (domain_conf.c:18392)
        which is : virBufferAsprintf(buf, "<vcpupin vcpu='%u' ",
                          def->cputune.vcpupin[i]->vcpuid);
==1837==    by 0x536966C: virDomainObjFormat (domain_conf.c:18970)
==1837==    by 0x5369743: virDomainSaveStatus (domain_conf.c:19166)
==1837==    by 0x117B26DC: qemuDomainPinVcpuFlags (qemu_driver.c:4586)
==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)
==1837==    by 0x171E6E: virNetServerHandleJob (virnetserver.c:193)
==1837==    by 0x5318E78: virThreadPoolWorker (virthreadpool.c:145)
==1837==  Address 0x12ea2870 is 0 bytes inside a block of size 16 free'd
==1837==    at 0x4C291AC: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==1837==    by 0x52A3D14: virReallocN (viralloc.c:245)
==1837==    by 0x52A3DFB: virShrinkN (viralloc.c:372)
==1837==    by 0x52A3F57: virDeleteElementsN (viralloc.c:503)
==1837==    by 0x533939E: virDomainVcpuPinDel (domain_conf.c:15405)  //doReset为true时才会进到。
==1837==    by 0x117B2642: qemuDomainPinVcpuFlags (qemu_driver.c:4573)
==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)

Steps to reproduce the problem:
1) use virDomainPinVcpuFlags() to pin a guest's vcpu to all the pcpus
of the host.

This patch uses def->cputune.vcpupin instead of vcpupin_list to do the
realloc() job, to avoid invalid read or memory leaking.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Yue Wenyuan <yuewenyuan@huawei.com@huawei.com>
10 years agoconf: forbid seclabel duplicates for domain devices
Erik Skultety [Tue, 10 Feb 2015 16:17:35 +0000 (17:17 +0100)]
conf: forbid seclabel duplicates for domain devices

Parser checks for per-domain seclabel duplicates, so it would be nice if
it checked for per-device seclabel duplicates the same way

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

10 years agoschema: allow multiple seclabel for devices in domaincommon.rng
Erik Skultety [Tue, 10 Feb 2015 16:17:36 +0000 (17:17 +0100)]
schema: allow multiple seclabel for devices in domaincommon.rng

In our RNG schema we do allow multiple (different) seclabels per-domain,
but don't allow this for devices, yet we neither have a check in our XML parser,
nor in a post-parse callback. In that case we should allow multiple
(different) seclabels for devices as well.

10 years agoFix qemu job handling in SetSchedulerParameters
Ján Tomko [Tue, 10 Feb 2015 13:36:03 +0000 (14:36 +0100)]
Fix qemu job handling in SetSchedulerParameters

Commit c5ee5cf added a job to SetSchedulerParameters, but
forgot to change one label in the SCHED_RANGE_CHECK macro.

10 years agoqemu: Implement random number generator hotunplug
Luyao Huang [Sat, 17 Jan 2015 05:09:38 +0000 (13:09 +0800)]
qemu: Implement random number generator hotunplug

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
10 years agoqemu: Implement random number generator hotplug
Luyao Huang [Sat, 17 Jan 2015 05:09:37 +0000 (13:09 +0800)]
qemu: Implement random number generator hotplug

Export the required helpers and add backend code to hotplug RNG devices.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
10 years agoqemu: Implement random number generator cold (un)plug
Peter Krempa [Thu, 5 Feb 2015 12:46:06 +0000 (13:46 +0100)]
qemu: Implement random number generator cold (un)plug

Add support for using the attach/detach device APIs on the inactive
configuration to add RNG devices.

10 years agoconf: Add helpers to insert/remove/find RNG devices in domain def
Luyao Huang [Sat, 17 Jan 2015 05:09:32 +0000 (13:09 +0800)]
conf: Add helpers to insert/remove/find RNG devices in domain def

The helpers will be useful when implementing hotplug and coldplug of
random number generator devices.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
10 years agoaudit: export virDomainAuditRNG
Luyao Huang [Sat, 17 Jan 2015 05:09:36 +0000 (13:09 +0800)]
audit: export virDomainAuditRNG

Signed-off-by: Luyao Huang <lhuang@redhat.com>
10 years agoqemu: command: Refactor creation of RNG device commandline
Peter Krempa [Tue, 3 Feb 2015 09:31:33 +0000 (10:31 +0100)]
qemu: command: Refactor creation of RNG device commandline

As the RNG device is using an -object as backend refactor the code to
use the JSON to commandline generator so that we can reuse the code
later in hotplug.

10 years agoqemu: command: Break some very long lines in qemuBuildRNGDevStr()
Peter Krempa [Tue, 3 Feb 2015 09:26:40 +0000 (10:26 +0100)]
qemu: command: Break some very long lines in qemuBuildRNGDevStr()

10 years agoqemu: command: Shuffle around formatting of alias for RNG device backend
Peter Krempa [Tue, 3 Feb 2015 09:14:42 +0000 (10:14 +0100)]
qemu: command: Shuffle around formatting of alias for RNG device backend

Move the alias name right after the object type for rng-egd backend so
that we can later use the JSON to commandline generator to create the
command line.