Commit Graph

27745 Commits

Author SHA1 Message Date
Christian Ehrhardt
37a4e6d430 apparmor: allow qemu to read max_segments
Since qemu 2.9 via 9103f1ce "file-posix: Consider max_segments for
BlockLimits.max_transfer" this is a new access that is denied by the
qemu profile.

It is non fatal, but prevents the fix mentioned to actually work.
It should be safe to allow reading from that path.

Since qemu opens a symlink path we need to translate that for apparmor from
"/sys/dev/block/*/queue/max_segments" to
"/sys/devices/**/block/*/queue/max_segments"

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2017-11-07 16:57:32 +01:00
Peter Krempa
96be3e72e8 tests: Add testing of storage backend JSON props formatter
Add a new test program called 'qemublocktest' to test the block layer
related stuff and test storage source to JSON generator by comparing it
to the JSON parser.
2017-11-07 16:18:14 +01:00
Peter Krempa
31bbb15884 qemu: block: Add node-names to JSON backing storage strings
Format out the node-name if it was assigned for JSON-based storage
specification.
2017-11-07 16:12:52 +01:00
Peter Krempa
caf71b64fe qemu: block: Add JSON props generator for ssh storage backing 2017-11-07 16:12:52 +01:00
Peter Krempa
8da68d87ff qemu: block: Add JSON props generator for sheepdog storage backing 2017-11-07 16:12:52 +01:00
Peter Krempa
5e9e693262 qemu: block: Add JSON props generator for RBD storage backing 2017-11-07 16:12:29 +01:00
Peter Krempa
84955c6257 qemu: block: Add JSON props generator for NBD storage backing 2017-11-07 16:11:38 +01:00
John Ferlan
ea0cc4f4b0 qemu: block: Add JSON props generator for iSCSI protocol 2017-11-07 16:04:53 +01:00
Peter Krempa
97ee821a17 qemu: block: Add JSON props generator for 'curl' based storage backends
QEMU uses curl for accessing files using http(s) and ftp(s). They share
common options so let's generate them in one helper.
2017-11-07 14:58:48 +01:00
Peter Krempa
90521d0754 storage: Store RBD image name as pool and image name
Similarly to how we store gluster names, split the name into a pool and
image portions when paring the XML and store them separately.
2017-11-07 14:58:04 +01:00
Peter Krempa
bb14d9897b storage: Don't store leading '/' in image name when splitting out volume
Libvirt historically stores storage source path including the volume as
one string in the XML, but that is not really flexible enough when
dealing with the fields in the code. Previously we'd store the slash
separating the two as part of the image name. This was fine for gluster
but it's not necessary and does not scale well when converting other
protocols.

Don't store the slash as part of the path. The resulting change from
absolute to relative path within the gluster driver should be okay,
as the root directory is the default when accessing gluster.
2017-11-07 14:58:04 +01:00
Peter Krempa
1ee7d4d972 qemu: process: Split out useful parts from qemuBuildNetworkDriveURI
Extract the part formatting the basic URI part so that it can be reused
to format JSON backing definitions. Parts specific to the command line
format will remain in qemuBuildNetworkDriveURI. The new function is
called qemuBlockStorageSourceGetURI.
2017-11-07 14:57:58 +01:00
Peter Krempa
bd37213786 qemu: block: Use proper type for servers for VxHS disks
Original implementation used 'SocketAddress' equivalent from qemu for
the disk server field, while qemu documentation specifies
'InetSocketAddress'. The backing store parser uses the correct parsing
function but the formatter used the incorrect one (and also with the
legacy mode enabled which was wrong).
2017-11-07 14:43:12 +01:00
Peter Krempa
1f467d1ab1 qemu: command: Move disk serial validation to qemuCheckDiskConfig 2017-11-07 14:38:11 +01:00
Peter Krempa
cf1fcd7b51 qemu: command: Move blkiotune checks to qemuCheckDiskConfig 2017-11-07 14:33:38 +01:00
Peter Krempa
5121457cad qemu: command: Refactor blkiotune checks to tolerate NULL qemuCaps
To allow aggregating the checks, refactor the code to check capabilities
only if they were provided.
2017-11-07 14:33:23 +01:00
Peter Krempa
1055c1bf24 qemu: command: Merge checks from qemuBuildDriveStrValidate to qemuCheckDiskConfig
Stash all the disk definition and capability checks into one function.
2017-11-07 14:33:18 +01:00
Peter Krempa
5fb7ab2c9e qemu: command: Refactor qemuBuildDriveStrValidate to make qemuCaps optional
To allow merging this with other disk type checks we need to check
qemuCaps only when available, since some of the checks are executed on
disk cold-plug and thus capabilities should not be checked.

Make the checks optional by making them conditional on qemuCaps not
being NULL.
2017-11-07 14:31:21 +01:00
Peter Krempa
f15ed22757 qemu: command: Directly report bus type in qemuBuildDriveStrValidate
All of the error message are already in a conditional block with known
bus type. Inline the bus type rather than formatting it from a separate
variable.
2017-11-07 14:31:15 +01:00
Peter Krempa
dfd300a71d qemu: command: Move disk index validation closer to usage
The disk index validation is used only in very specific cases and does
not need to be performed otherwise. Move it out of the global check into
the usage place.
2017-11-07 14:29:37 +01:00
Peter Krempa
b60ce7b122 qemu: command: Remove dead code when formatting -drive
busid and unitid are ever used only if the device is an SD card due to
the check in qemuDiskBusNeedsDeviceArg. Since the SD card does not have
an bus or unit number, most of the code and command line formatter can
be removed since it will never be used.
2017-11-07 14:29:37 +01:00
Peter Krempa
e5580888f5 util: Fix condition check in virDiskNameToIndex
Use the more common '< 0' rather than the non-zero check.
2017-11-07 14:29:37 +01:00
Michal Privoznik
ae1b5d47e5 qemu: Move memPath generation from memoryBackingDir to a separate function
In near future we will need more than just a plain VIR_STRDUP().
Better implement that in a separate function and in
qemuBuildMemoryBackendStr() which is complicated enough already.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-07 13:43:06 +01:00
Michal Privoznik
fe70fd0c10 conf: s/virDomainObjGetShortName/virDomainDefGetShortName/
This function works over domain definition and not domain object.
Its name is thus misleading.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-11-07 13:43:00 +01:00
Nikolay Shirokovskiy
47eb77fb33 rpc,lockd: Add missing netserver refcount increment on reload
After the virNetDaemonAddServerPostExec call in virtlogd we should have
netserver refcount set to 2. One goes to netdaemon servers hashtable
and one goes to virt{logd,lock} own reference to netserver. Let's add
the missing increment in virNetDaemonAddServerPostExec itself while
holding the daemon lock.

Since lockd defers management of the @srv object by the presence
in the hash table, virLockDaemonNewPostExecRestart must Unref the
alloc'd Ref on the @srv object done as part of virNetDaemonAddServerPostExec
and virNetServerNewPostExecRestart processing. The virNetDaemonGetServer
in lock_daemon main will also take a reference which is Unref'd during
main cleanup.
2017-11-06 16:19:11 -05:00
John Ferlan
82fa7fc3ab lockd: Need to Unref @srv when done with it.
Commit id '252610f7d' used a hash table to store the @srv, but
didn't handle the virObjectUnref if virNetDaemonNew failed nor
did it use virObjectUnref once successfully placed into the table
which will now be managing it's lifetime (and would cause the
virObjectRef if successfully inserted into the table).
2017-11-06 15:53:41 -05:00
Jiri Denemark
bce925dada conf: Don't inline virDomainNetTypeSharesHostView
When coverage build is enabled, gcc complains about it:

In file included from qemu/qemu_agent.h:29:0,
                 from qemu/qemu_driver.c:47:
qemu/qemu_driver.c: In function 'qemuDomainSetInterfaceParameters':
./conf/domain_conf.h:3397:1: error: inlining failed in call to
'virDomainNetTypeSharesHostView': call is unlikely and code size would
grow [-Werror=inline]
 virDomainNetTypeSharesHostView(const virDomainNetDef *net)
 ^

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2017-11-06 10:58:46 +01:00
Michal Privoznik
27b67eba22 virsh: Define multi line macros properly
In some cases there's dangling backward slash at the end of multi
line macros. While technically the code works, it will stop if
some empty lines are removed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-04 08:38:08 +01:00
Dawid Zamirski
1ed22398c3 domain: Allow 'model' attribute for ide controller
The optional values are 'piix3', 'piix4' or 'ich6'. Those will be
needed to allow setting IDE controller model in VirtualBox driver.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
06c4fd10fd vbox: Add more IStorageController API mappings
This patch exposes additional methods of the native VBOX API to the
libvirt 'unified' vbox API to deal with IStorageController. The exposed
methods are:

* IStorageController->GetStorageControllerType()
* IStorageController->SetStorageControllerType()
* IMachine->GetStorageControllers()
2017-11-03 13:15:54 -04:00
Dawid Zamirski
1bf7e97733 vbox: Support empty removable drives.
Original code was checking for non empty disk source before proceeding
to actually attach disk device to VM. This prevented from creating
empty removable devices like DVD or floppy. Therefore, this patch
re-organizes the loop work-flow to allow such configurations as well as
makes the code follow better libvirt practices. Additionally, adjusted
debug logs to be more helpful - removed old ones and added new which
give more valuable info for troubleshooting.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
e3ecf4b8ce vbox: Errors in vboxAttachDrives are now critical
Previously, if one tried to define a VBOX VM and the API failed to
perform the requested actions for some reason, it would just log the
error and move on to process remaining disk definitions. This is not
desired as it could result in incorrectly defined VM without the caller
even knowing about it. So now all the code paths that call
virReportError are now treated as hard failures as they should have
been.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
60227fd5ee vbox: Remove unused mediumEmpty
Remove the setting since it's unused as of commit 34364df3 which should
have never copied it in from the old code which ended up getting removed
as part of commit c7c286c6.
2017-11-03 13:15:54 -04:00
Dawid Zamirski
ff67685b17 vbox: Cleanup vboxAttachDrives implementation
This commit primes vboxAttachDrives for further changes so when they
are made, the diff is less noisy:

* move variable declarations to the top of the function
* add disk variable to replace all the def->disks[i] instances
* add cleanup at the end of the loop body, so it's all in one place
  rather than scattered through the loop body. It's purposefully
  called 'cleanup' rather than 'skip' or 'continue' because future
  commit will treat errors as hard-failures.
2017-11-03 13:15:50 -04:00
Dawid Zamirski
c739a6bdfe vbox: vboxAttachDrives now relies on address info
Previously, the driver was computing VBOX's devicePort/deviceSlot values
based on device name and max port/slot values. While this worked, it
completely ignored <address> values. Additionally, libvirt's built-in
virDomainDiskDefAssignAddress already does a good job  setting default
values on virDomainDeviceDriveAddress struct which we can use to set
devicePort and deviceSlot and accomplish the same result while allowing
the customizing those via XML. Also, this allows to remove some code
which will make further patches smaller.
2017-11-03 13:13:09 -04:00
Dawid Zamirski
7651debbc1 vbox: Close media when undefining domains
When registering a VM we call OpenMedium on each disk image which adds it
to vbox's global media registry. Therefore, we should make sure to call
Close when unregistering VM so we cleanup the media registry entries
after ourselves - this does not remove disk image files. This follows
the behaviour of the VBoxManage unregistervm command.
2017-11-03 13:13:09 -04:00
Dawid Zamirski
6f8ddbb83b vbox: Update ATTRIBUTE_UNUSED usage
Since the removal of VBOX <= 3x, the function arguments are actually
used so they should not be marked with ATTRIBUTE_UNUSED anymore.
2017-11-03 13:13:09 -04:00
Andrea Bolognani
b5ce8bd034 cfg.mk: Prohibit backspace alignment attempts
Now that our codebase is clean, we can add a syntax-check rule
to ensure it will remain so.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-11-03 13:24:13 +01:00
Andrea Bolognani
3e7db8d3e8 Remove backslash alignment attempts
Right-aligning backslashes when defining macros or using complex
commands in Makefiles looks cute, but as soon as any changes is
required to the code you end up with either distractingly broken
alignment or unnecessarily big diffs where most of the changes
are just pushing all backslashes a few characters to one side.

Generated using

  $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
    grep -E '*\.([chx]|am|mk)$$' | \
    while read f; do \
      sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
    done

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-11-03 13:24:12 +01:00
Peter Krempa
a92c4f7537 qemu: domain: skip chain detection to end of backing chain
When a user provides the backing chain, we will not need to re-detect
all the backing stores again, but should move to the end of the user
specified chain. Additionally if a user provides a full terminated chain
we should not attempt any further detection.
2017-11-03 10:27:32 +01:00
Peter Krempa
b0a46b609e qemu: domain: Prepare TLS data for the whole backing chain
Iterate through the backing chain when setting up TLS for disks.
2017-11-03 10:23:21 +01:00
Peter Krempa
beb1661f3d qemu: domain: Remove pointless alias check
When attaching the disks, aliases are always generated.
2017-11-03 10:23:21 +01:00
Peter Krempa
d565877312 qemu: domain: Destroy secrets for complete backing chain 2017-11-03 10:23:21 +01:00
Peter Krempa
e53a42f0f6 qemu: domain: Extract setup for disk source secrets
Separate it so that it deals only with single virStorageSource, so that
it can later be reused for full backing chain support.

Two aliases are passed since authentication is more relevant to the
'storage backend' whereas encryption is more relevant to the protocol
layer. When using node names, the aliases will be different.
2017-11-03 10:23:16 +01:00
Peter Krempa
2b757b964b qemu: domain: Simplify using DAC permissions of top of backing chain
qemuDomainGetImageIds and qemuDomainStorageFileInit are helpful when
trying to access a virStorageSource from the qemu driver since they
figure out the correct uid and gid for the image.

When accessing members of a backing chain the permissions for the top
level would be used. To allow using specific permissions per backing
chain level but still allow inheritance from the parent of the chain we
need to add a new parameter to the image ID APIs.
2017-11-03 09:15:41 +01:00
Peter Krempa
cc16fa2a85 security: selinux: Take parent security label into account
Until now we ignored user-provided backing chains and while detecting
the code inherited labels of the parent device. With user provided
chains we should keep this functionality, so label of the parent image
in the backing chain will be applied if an image-specific label is not
present.
2017-11-03 09:15:41 +01:00
Peter Krempa
2742dfee28 security: dac: Take parent security label into account
Until now we ignored user-provided backing chains and while detecting
the code inherited labels of the parent device. With user provided
chains we should keep this functionality, so label of the parent image
in the backing chain will be applied if an image-specific label is not
present.
2017-11-03 09:15:41 +01:00
Peter Krempa
023da7ddbd security: selinux: Pass parent storage source into image labeling helper
virSecuritySELinuxSetImageLabelInternal assigns different labels to
backing chain members than to the parent image. This was done via the
'first' flag. Convert it to passing in pointer to the parent
virStorageSource. This will allow us to use the parent virStorageSource
in further changes.
2017-11-03 09:15:41 +01:00
Peter Krempa
b4daf6af9a storage: Extract error reporting for broken chains
Simplify reporting the error if backing chain is broken for further
callers by extracting it into a separate function.
2017-11-03 09:15:41 +01:00
Peter Krempa
a93d750a7e storage: Add feature check for storage file backend supporting access check
When the user provides backing chain, we don't need the full support for
traversing the backing chain. This patch adds a feature check for the
virStorageSourceAccess API.
2017-11-03 09:15:41 +01:00