Commit Graph

27674 Commits

Author SHA1 Message Date
Marc Hartmayer
5fec1c3a5c util: Fix deadlock across fork()
This commit fixes the deadlock introduced by commit
0980764dee. The call getgrouplist() of
the glibc library isn't safe to be called in between fork and
exec (see commit 75c125641a).

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Fixes: 0980764dee ("util: share code between virExec and virCommandExec")
Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2017-10-10 09:27:00 +01:00
Marc Hartmayer
2e88eeebb1 util: Add virCommandGetGID and virCommandGetUID
These functions are used by an upcoming commit.

Signed-off-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2017-10-10 09:27:00 +01:00
Kothapally Madhu Pavan
9020c7d7e4 qemu: Remove redundant code in qemuParseCommandLineDisk
Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
2017-10-10 08:36:22 +02:00
Jim Fehlig
c44b29aacb apparmor: add dnsmasq ptrace rule to libvirtd profile
Commit b482925c added ptrace rule for the apparmor profiles,
but one was missed in the libvirtd profile for dnsmasq. It was
overlooked since the test machine did not have an active libvirt
network requiring dnsmasq that was also set to autostart. With
one active and set to autostart, the following denial is observed
in audit.log when restarting libvirtd

type=AVC msg=audit(1507320136.306:298): apparmor="DENIED" \
operation="ptrace" profile="/usr/sbin/libvirtd" pid=5472 \
comm="libvirtd" requested_mask="trace" denied_mask="trace" \
peer="/usr/sbin/dnsmasq"

With an active network, I suspect a libvirtd restart causes access
to /proc/<dnsmasq-pid>/*, hence the resulting denial. As a nasty
side affect of the denial, libvirtd thinks it needs to spawn a
dnsmasq process even though one is already running for the network.
E.g. after two libvirtd restarts

dnsmasq   1683  0.0  0.0  51188  2612 ?        S    12:03   0:00 \
 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf \
 --leasefile-ro --dhcp-script=/usr/lib64/libvirt/libvirt_leaseshelper
root      1684  0.0  0.0  51160   576 ?        S    12:03   0:00 \
 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf \
 --leasefile-ro --dhcp-script=/usr/lib64/libvirt/libvirt_leaseshelper
dnsmasq   4706  0.0  0.0  51188  2572 ?        S    13:54   0:00 \
 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf \
 --leasefile-ro --dhcp-script=/usr/lib64/libvirt/libvirt_leaseshelper
root      4707  0.0  0.0  51160   572 ?        S    13:54   0:00 \
 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf \
 --leasefile-ro --dhcp-script=/usr/lib64/libvirt/libvirt_leaseshelper
dnsmasq   4791  0.0  0.0  51188  2580 ?        S    13:56   0:00 \
 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf \
 --leasefile-ro --dhcp-script=/usr/lib64/libvirt/libvirt_leaseshelper
root      4792  0.0  0.0  51160   572 ?        S    13:56   0:00 \
 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf \
 --leasefile-ro --dhcp-script=/usr/lib64/libvirt/libvirt_leaseshelper

A simple fix is to add a ptrace rule for dnsmasq.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-By: Guido Günther <agx@sigxcpu.org>
2017-10-06 16:39:15 -06:00
Wim ten Have
137391bda7 numa: rename function virDomainNumaDefCPUFormat
Rename virDomainNumaDefCPUFormat to virDomainNumaDefCPUFormatXML,
matching its peer virDomainNumaDefCPUParseXML and the general
vir*{Format,Parse}XML conventions.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by:   Jim Fehlig <jfehlig@suse.com>
2017-10-06 11:09:49 -06:00
Wim ten Have
6c200c76f1 build: isolate core libvirt libs deps from xen runtime
Generating libvirt packages per make rpm, "with-libxl=1" and "with-xen=1",
adds strict runtime dependencies per libxenlight for xen-libs package from
core libvirt-libs package.  This is not necessary and unfortunate since
those dependencies set demand to "xen-libs" package even when there's no
need for libvirt xen or libxl driver components.

This patch is to have two separate xenconfig lib tool libraries: one for
core libvirt (without XL), and a another that contains xl for libxl driver
(libvirt_driver_libxl_impl.la) which when loading the driver, loads the
remaining symbols (xen{Format,Parse}XL. For the user/sysadmin, this means
the xen dependencies are moved into libxl driver, instead of core libvirt.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by:   Jim Fehlig <jfehlig@suse.com>
2017-10-06 10:21:37 -06:00
John Ferlan
746a18dbe8 storage: Use virStoragePoolObjGetDef accessor for Gluster backend
In preparation for privatizing the object, use the accessor.
2017-10-06 07:09:47 -04:00
John Ferlan
759fbdd00b storage: Use virStoragePoolObjGetDef accessor for FS backend
In preparation for privatizing the object, use the accessor.
2017-10-06 07:09:47 -04:00
John Ferlan
2bbb66c4b7 storage: Use virStoragePoolObjGetDef accessor for Sheepdog backend
In preparation for privatizing the object, use the accessor.
2017-10-06 07:09:47 -04:00
John Ferlan
7920d97ab9 storage: Use virStoragePoolObjGetDef accessor for Logical backend
In preparation for privatizing the object, use the accessor.
2017-10-06 07:09:47 -04:00
John Ferlan
cd3eecd839 storage: Use virStoragePoolObjGetDef accessor for Disk backend
In preparation for privatizing the object, use the accessor.
2017-10-06 07:09:47 -04:00
John Ferlan
c0682800cd storage: Use virStoragePoolObjGetDef accessor for storage_util
In preparation for privatizing the object, use the accessor.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-06 07:09:47 -04:00
John Ferlan
296d6e2d93 test: Use virStoragePoolObjGetDef accessor
In preparation for privatizing the object, use the accessor.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-06 06:53:05 -04:00
John Ferlan
bb34b61bdf test: Create local virStoragePoolObjPtr VolLookup APIs
Rather than accessing privconn->pools.objs[i] in the for loop,
let's use an @obj variable to make it easier to read the code.
2017-10-06 06:53:05 -04:00
John Ferlan
3a867d9e52 test: Rename @vol to @volDef in testOpenVolumesForPool
Make it more obvious as we're about to need to change how
obj->def gets referenced.

Perform a couple of minor cleanups along the way too.
2017-10-06 06:53:05 -04:00
John Ferlan
bfcd8fc924 storage: Use virStoragePoolObjGetDef accessor for driver
In preparation for privatizing the object, use the accessor to fetch
the obj->def instead of the direct reference.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2017-10-06 06:53:05 -04:00
John Ferlan
adfa9b3044 tests: Fix possible NULL deref 2017-10-06 06:53:05 -04:00
John Ferlan
ee5498304f conf: Fix prototype/definition for virStoragePoolObj get functions
Modify virStoragePoolObjGetAutostartLink and
virStoragePoolObjGetConfigFile to return "const char *"
since that's how both are used and to ensure no one
tries to VIR_FREE the result.
2017-10-06 06:53:05 -04:00
Christian Ehrhardt
cbd609524d virt-aa-helper: put static rules in quotes
To avoid any issues later on if paths ever change (unlikely but
possible) and to match the style of other generated rules the paths
of the static rules have to be quoted as well.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-10-06 11:14:49 +02:00
Christian Ehrhardt
e79211ed23 virt-aa-helper: allow spaces in vm names
libvirt allows spaces in vm names, there were issues in the past but it
seems not removed so the assumption has to be that spaces are continuing
to be allowed.

Therefore virt-aa-helper should not reject spaces in vm names anymore if
it is going to be refused causing issues then the parser or xml schema
should do so.
Apparmor rules are in quotes, so a space in a path based on the name works.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-06 11:14:49 +02:00
Christian Ehrhardt
bf3a414087 virt-aa-helper: fix libusb access to udev usb data
libusb as used by qemu needs to read data from /run/udev/data/ about usb
devices. That is read once on the first initialization of libusb_init by
qemu.

Therefore generating just the device we need would not be sufficient as
another hotplug later can need another device which would fail as the
data is no more re-read at this point.

But we can restrict the paths very much to just the major number of
potential usb devices which will make it match approximately the detail
that e.g. an lsusb -v would reveal - that is much safer than the
"/run/udev/data/* r" blanket many users are using now as a workaround.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-10-06 11:14:49 +02:00
Christian Ehrhardt
750e08443a virt-aa-helper: fix paths for usb hostdevs
If users only specified vendor&product (the common case) then parsing
the xml via virDomainHostdevSubsysUSBDefParseXML would only set these.
Bus and Device would much later be added when the devices are prepared
to be added.

Due to that a hot-add of a usb hostdev works as the device is prepared
and virt-aa-helper processes the new internal xml. But on an initial
guest start at the time virt-aa-helper renders the apparmor rules the
bus/device id's are not set yet:

p ctl->def->hostdevs[0]->source.subsys.u.usb
$12 = {autoAddress = false, bus = 0, device = 0, vendor = 1921, product
= 21888}

That causes rules to be wrong:
  "/dev/bus/usb/000/000" rw,

The fix calls virHostdevFindUSBDevice after reading the XML from
virt-aa-helper to only add apparmor rules for devices that could be found
and now are fully known to be able to write the rule correctly.

It uncondtionally sets virHostdevFindUSBDevice mandatory attribute as
adding an apparmor rule for a device not found makes no sense no matter
what startup policy it has set.

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-06 11:14:49 +02:00
Peter Krempa
3cf0655c3a qemu: process: Don't redetect backing chain on reconnect
Skip purging the backing chain and redetecting it when it was not going
to change during the time we were not present.

The decision is based on the new flag which records whether there were
blockjobs running to the status XML.
2017-10-06 08:48:18 +02:00
Peter Krempa
1266495763 qemu: process: Simplify access to individual disk when reconnecting
Add a helper variable so that we don't have to access the disk via 3
indirections.
2017-10-06 08:48:10 +02:00
Peter Krempa
802fd24506 qemu: domain: Mark if no blockjobs are active in the status XML
Note when no blockjobs are running in the status XML so that we know
that the backing chain will not change until we reconnect.
2017-10-06 08:47:30 +02:00
Peter Krempa
d868366fe3 util: Add functions to simplify bool->virTristate(Bool|Switch) assignment
virTristateBoolFromBool and virTristateSwitchFromBool convert a boolean
to the correct enum value.
2017-10-06 08:47:30 +02:00
Michal Privoznik
8ffbc1f700 news: Document watchdog hot-(un)plug change
In 361c8dc17 and 662140fa68 I've implemented hot-(un)plug of
watchdog devices. Document this change.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-06 07:36:25 +02:00
Michal Privoznik
662140fa68 qemu: hot-unplug of watchdog
https://bugzilla.redhat.com/show_bug.cgi?id=1447169

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 14:23:20 +02:00
Michal Privoznik
361c8dc179 qemu: hot-plug of watchdog
https://bugzilla.redhat.com/show_bug.cgi?id=1447169

Since domain can have at most one watchdog it simplifies things a
bit. However, since we must be able to set the watchdog action as
well, new monitor command needs to be used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 14:23:20 +02:00
Michal Privoznik
8a54cc1d08 qemuDomainDeviceDefValidate: Validate watchdog
Currently we don't do it. Therefore we accept senseless
combinations of models and buses they are attached to.
Moreover, diag288 watchdog is exclusive to s390(x).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 14:23:20 +02:00
John Ferlan
5d7659027f docs,rng: Adjust storage pool name grammar checks
https://bugzilla.redhat.com/show_bug.cgi?id=1475250

It's possible to define and start a pool with a '.' in the
name; however, when trying to add a volume to a domain using
the storage pool source with a '.' in the storage pool name,
the domain RNG validation fails because RNG uses 'genericName'
which does not allow a '.' in the name.

Domain XML def parsing has a virXMLValidateAgainstSchema which
generates the error. The Storage Pool XML def parsing has no
call to virXMLValidateAgainstSchema. The only Storage Pool name
validation occurs in virStoragePoolDefParseXML to ensure the
name doesn't have a '/' in it and in storagePoolDefineXML to
call virXMLCheckIllegalChars using the same parameter "\n" as
qemuDomainDefineXMLFlags would check after the RNG check
could be succesful.

In order to resolve this, create a poolName definition in
storagecommon.rng that will mimic the domain name regex that
disallows a newline character, but add the "/" in the exclude
list. Then modify the pool and volume source name definitions
to key off that poolName.
2017-10-05 08:10:46 -04:00
Peter Krempa
41b28943da tests: qemuxml2xml: Simplify adding to the status XML expect string generator
Unindent the static XML block and move around the autoindent calls so
that further additions don't have to add more of them.

Also rename the string holding the static XML section.
2017-10-05 10:36:56 +02:00
Peter Krempa
cb1e4ca203 qemu: driver: Save status XML when starting a block job
Few jobs (which don't) use the 'mirror' element did not save the status
XML. It will be helpful to do so once we start tracking jobs fully.
2017-10-05 10:36:56 +02:00
Peter Krempa
d39173ff7a qemu: blockjob: Always save config XML when a blockjob is finished
For VMs with persistent config the config may change upon successful
completion of a job. Save it always if a persistent VM finishes a
blockjob. This will simplify further additions.
2017-10-05 10:36:56 +02:00
Peter Krempa
f7954d6b07 qemu: blockjob: Always save status XML after block event
The status XML would be saved only for the copy job (in case of success)
or on failure even for other jobs. As the status contains the backing
chain data, which change after success we should always save it on
block job completion.
2017-10-05 10:36:56 +02:00
Michal Privoznik
c7e3fc1112 news: Document domifstat and QoS changes made recently
In cea3715b2e and d86fd2402e I've fixed domifstat and QoS
that was reversed for some types of interfaces. Document this
in the news file.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-05 10:10:53 +02:00
Jiri Denemark
43d9cbd97b spec: Enable qemu driver on s390x on RHEL/CentOS
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-10-05 09:58:14 +02:00
Peter Krempa
8418aed978 qemu: process: move disk presence checking to host setup function
Checking of disk presence accesses storage on the host so it should be
done from the host setup function. Move the code to new function called
qemuProcessPrepareHostStorage and remove qemuDomainCheckDiskPresence.
2017-10-05 09:46:46 +02:00
Peter Krempa
0c09c5b0d1 qemu: process: Move TLS setup for storage source to qemuProcessPrepareDomainStorage 2017-10-05 09:45:59 +02:00
Peter Krempa
f1cec8829e qemu: process: Move 'volume' translation to domain prepare stage
Introduce a new function to prepare domain disks which will also do the
volume source to actual disk source translation.

The 'pretend' condition is not transferred to the new location since it
does not help in writing tests and also no tests abuse it.
2017-10-05 09:45:10 +02:00
Peter Krempa
76039bba87 qemu: domain: Document and export qemuDomainCheckDiskStartupPolicy 2017-10-05 09:40:15 +02:00
Peter Krempa
2e78c588d8 qemu: process: Pass flags to qemuProcessPrepareHost
Pass flags to the function rather than just whether we have incoming
migration. This also enforces correct startup policy for USB devices
when reverting from a snapshot.
2017-10-05 09:40:13 +02:00
Peter Krempa
b8c0262efa qemu: migration: Extract flags for starting VM into a variable
qemuMigrationPrepareAny called multiple of the functions starting the
qemu process for incoming migration by adding the flags explicitly.
Extract them to a variable so that they can be easily used for other
calls or changed in the future.
2017-10-05 09:38:15 +02:00
Peter Krempa
fda4298515 qemu: process: document parameters for startup preparing functions
Document mainly what flag values are passed in.
2017-10-05 09:37:47 +02:00
Peter Krempa
79edca277a qemu: command: Move PPC fdc check to domain validation
Apart from not littering the command line generator, the added benefit
is that new configs with a FDC will be rejected at define stage.
2017-10-05 09:28:37 +02:00
Peter Krempa
627f489e5d qemu: command: Separate validation from command line building for -drive
Remove validation code into a separate function so that it's not
interleaved with actual building of the command line.
2017-10-05 09:28:37 +02:00
Michal Privoznik
57b17c8d84 libvirt-domain: Document interface stats POV
Interestingly enough, we don't document the point of view of the
interface statistics. Therefore it's unknown to users if for
instance rx_packets is the number of packets received by domain or
received by host (from domain). Document this explicitly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-10-05 09:16:05 +02:00
Michal Privoznik
cea3715b2e QoS: Set classes and filters in proper direction
Similarly to previous patch, for some types of interface domain
and host are on the same side of RX/TX barrier. In that case, we
need to set up the QoS differently. Well, swapped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 09:16:05 +02:00
Michal Privoznik
d86fd2402e virNetDevTapInterfaceStats: Allow caller to not swap the statistics
https://bugzilla.redhat.com/show_bug.cgi?id=1497410

The comment in virNetDevTapInterfaceStats() implementation for
Linux states that packets transmitted by domain are received by
the host and vice versa. Well, this is true but not for all types
of interfaces. For instance, for macvtaps when TAP device is
hooked right onto a physical device any packet that domain sends
looks also like a packet sent to the host. Therefore, we should
allow caller to chose if the stats returned should be straight
copy or swapped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 09:16:05 +02:00
Michal Privoznik
c2c47b586f src: Use virDomainNetFindByName
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-05 09:16:05 +02:00