Commit Graph

1743 Commits

Author SHA1 Message Date
Daniel P. Berrangé
17b1ebf4ec conf: add support for parsing/formatting virNWFilterBindingDefPtr
A typical XML representation of the virNWFilterBindingDefPtr struct
looks like this:

  <filterbinding>
    <owner>
      <name>f25arm7</name>
      <uuid>12ac8b8c-4f23-4248-ae42-fdcd50c400fd</uuid>
    </owner>
    <portdev name='vnet1'/>
    <mac address='52:54:00:9d:81:b1'/>
    <filterref filter='clean-traffic'>
      <parameter name='MAC' value='52:54:00:9d:81:b1'/>
    </filterref>
  </filterbinding>

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-26 11:22:07 +01:00
Daniel P. Berrangé
7c7880dd98 conf: move virNWFilterBindingDefPtr into its own files
There's no code sharing between virNWFilterDef and
virNWFilterBindingDefPtr types, so it is clearer if they live in
separate source files and headers.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-26 11:22:07 +01:00
Daniel P. Berrangé
ce1144960c conf: change virNWFilterBindingPtr to virNWFilterBindingDefPtr
We are going to want to expose the NWFilter binding concept in the
public API, so the virNWFilterBindingPtr type needs to be used there.
Our internal type will shortly gain an XML representation, so rename
it to virNWFilterBindingDefPtr which follows our normal conventions.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-26 11:22:07 +01:00
Cole Robinson
9bda139537 conf: Remove unused virDomainDefNewFull
The last usages were removed with the xend driver in 1dac5fbbbb

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2018-06-20 14:00:13 -04:00
Brijesh Singh
d4005609f3 qemu: Provide support to query the SEV capability
QEMU version >= 2.12 provides support for launching an encrypted VMs on
AMD x86 platform using Secure Encrypted Virtualization (SEV) feature.
This patch adds support to query the SEV capability from the qemu.

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-06-12 09:51:59 +02:00
Martin Kletzander
f1d7625e13 Move virCacheKernel enum implemetation from conf/ to util/
It will be used in that file later on, plus it makes sense for all the
implementations to be in same place.  Also comment each one of them nicely and
add a comment explaining why they all need to end with the same _LAST value.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-08 10:28:46 +02:00
Martin Kletzander
c95b9557b5 util: Initialize virResctrlInfo struct right away
There is no need to have virResctrlGetInfo() when it must be called after
virResctrlInfoNew() anyway, otherwise it's just an unusable object.  When we
wrap the logic inside the New() function we'll save some calls later as well.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-08 10:28:46 +02:00
Martin Kletzander
5a0a5f7fb5 util: Introduce virFileFlock
We already have virFileLock(), but we are now using flock() in the code as
well (due to requirements for mutual exclusion between libvirt and other
programs using flock() as well), so let's have a function for that as well so we
don't need to have stubs for unsupported platforms in other files.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-08 10:28:46 +02:00
Stefan Berger
6d21d9bccb util: Implement and use virFileIsRegular() rather than d_type
The dirent's d_type field is not portable to all platforms. So we have
to use stat() to determine the type of file for the functions that need
to be cross-platform. Fix virFileChownFiles() by calling the new
virFileIsRegular() function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-06-06 12:51:18 -04:00
Stefan Berger
2fc665bb11 security: Label the external swtpm with SELinux labels
In this patch we label the swtpm process with SELinux labels. We give it the
same label as the QEMU process has. We label its state directory and files
as well. We restore the old security labels once the swtpm has terminated.

The file and process labels now look as follows:

Directory: /var/lib/libvirt/swtpm

[root@localhost swtpm]# ls -lZ
total 4
rwx------. 2 tss  tss  system_u:object_r:svirt_image_t:s0:c254,c932 4096 Apr  5 16:46 testvm

[root@localhost testvm]# ls -lZ
total 8
-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 3648 Apr  5 16:46 tpm-00.permall

The log in /var/log/swtpm/libvirt/qemu is labeled as follows:

-rw-r--r--. 1 tss tss system_u:object_r:svirt_image_t:s0:c254,c932 2237 Apr  5 16:46 vtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep swtpm | grep ctrl | grep -v grep
system_u:system_r:svirt_t:s0:c254,c932 tss 25664 0.0  0.0 28172  3892 ?        Ss   16:57   0:00 /usr/bin/swtpm socket --daemon --ctrl type=unixio,path=/var/run/libvirt/qemu/swtpm/testvm-swtpm.sock,mode=0660 --tpmstate dir=/var/lib/libvirt/swtpm/testvm/tpm1.2 --log file=/var/log/swtpm/libvirt/qemu/testvm-swtpm.log

[root@localhost 485d0004-a48f-436a-8457-8a3b73e28567]# ps auxZ | grep qemu | grep tpm | grep -v grep
system_u:system_r:svirt_t:s0:c254,c932 qemu 25669 99.0  0.0 3096704 48500 ?    Sl   16:57   3:28 /bin/qemu-system-x86_64 [..]

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-06 10:48:41 -04:00
Stefan Berger
eb46575a95 util: Implement virFileChownFiles()
Implement virFileChownFiles() which changes file ownership of all
files in a given directory.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-06 10:48:41 -04:00
Michal Privoznik
f785aa6c2b vircrypto: Drop virCryptoGenerateRandom
Now that virCryptoGenerateRandom() is plain wrapper over
virRandomBytes() we can drop it in favour of the latter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-06-05 10:31:19 +02:00
Filip Alac
dc34e78e21 capabilities: Extend capabilities with iommu_support
Signed-off-by: Filip Alac <filipalac@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-06-05 08:33:13 +02:00
Filip Alac
1597e155b2 qemu: hostdev: Move parts of qemuHostdevHostSupportsPassthroughVFIO() into separate function
Signed-off-by: Filip Alac <filipalac@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-06-05 08:33:13 +02:00
Peter Krempa
8ac8301366 util: storage: Add helper for determining whether a backing chain requires PR
With blockdev support we will need to introspect whether any of the
backing chain members requires PR rather just one of them. Add a helper
and reuse it in virDomainDefHasManagedPR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-05 08:14:00 +02:00
Peter Krempa
d766021c60 qemu: Delete old unused code for adding objects to qemu
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-05 08:13:59 +02:00
Peter Krempa
efd32528d0 util: qemu: Introduce helper for formatting command line from new object props
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-05 08:13:59 +02:00
Peter Krempa
bf26dd222f qemu: Rename virQEMUBuildObjectCommandlineFromJSON
s/virQEMUBuildObjectCommandlineFromJSON/virQEMUBuildObjectCommandlineFromJSONType/

The function adds the object of a certain type. Change the name so that
we make room for the generic function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-06-05 08:13:59 +02:00
Ján Tomko
0b9d4970b4 conf: introduce virDomainVsockDefEquals
Introduce a function for comparing two vsock definitions.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-06-05 07:51:18 +02:00
Ján Tomko
8eaa31c3ad qemu: implement vsock hotplug
Allow hotplugging the vsock device.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-06-05 07:51:13 +02:00
Ján Tomko
950c46f1a4 util: create virvsock.c
A file for vsock-related helper functions.
virVsockSetGuestCid to set an already-known CID,
virVsockAcquireGuestCid that will use the first available CID

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-05-29 15:42:03 +02:00
Ján Tomko
3858da2a14 Introduce virDomainVsockDef
A type to represent the new vsock device.
Also implement an allocation function to allow future addition
of private data.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-05-29 15:42:03 +02:00
Jiri Denemark
5ed6cf96bc cpu: Rename cpuBaseline as virCPUBaseline
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-05-28 15:59:10 +02:00
Peter Krempa
082266bf27 conf: domain: Export virDomainStorageSourceParse
It will be used when parsing the migration private data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-05-23 13:18:23 +02:00
Peter Krempa
26c72a76dc conf: domain: Add helper to check whether a domain def requires use of PR
Extract the lookup code so that it can be reused later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-05-16 06:32:29 +02:00
Peter Krempa
900fc66121 util: storage: Drop virStoragePRDefIsEnabled
The function now does not do anything useful. Replace it by the pointer
check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-05-16 06:32:28 +02:00
John Ferlan
9629fe258f storage_util: Rename virQEMUBuildLuksOpts
Rename to storageBackendCreateQemuImgOpts - which is what it's doing.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2018-05-15 16:54:58 -04:00
Shalini Chellathurai Saroja
2b9690b62d util: virhostdev: add virHostdevIsMdevDevice()
Add the function virHostdevIsMdevDevice() which detects whether a
hostdev is a mediated device or not. Also, replace all existing
conditionals.

Signed-off-by: Shalini Chellathurai Saroja <shalini@linux.vnet.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-05-14 12:12:06 -04:00
Ján Tomko
0eeedd61a9 Introduce virCryptoHashBuf
A function that keeps the hash in binary form instead of converting
it to human-readable hexadecimal form.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-05-14 13:57:45 +02:00
Michal Privoznik
2300c92fe0 conf: Introduce memoryBacking/discard
QEMU has possibility to call madvise(.., MADV_REMOVE) in some
cases. Expose this feature to users by new element/attribute
discard.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-05-14 09:42:20 +02:00
Michal Privoznik
13fe558fb4 qemu: Generate pr cmd line at startup
For command line we need two things:

1) -object pr-manager-helper,id=$alias,path=$socketPath
2) -drive file.pr-manager=$alias

In -object pr-manager-helper we tell qemu which socket to connect
to, then in -drive file-pr-manager we just reference the object
the drive in question should use.

For managed PR helper the alias is always "pr-helper0" and socket
path "${vm->priv->libDir}/pr-helper0.sock".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-05-11 09:02:56 +02:00
Michal Privoznik
c7c9dea0a0 qemuDomainDiskChangeSupported: Deny changing reservations
Couple of reasons for that:

a) there's no monitor command to change path where the pr-helper
connects to, or
b) there's no monitor command to introduce a new pr-helper for a
disk that already exists.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-05-11 09:02:56 +02:00
Michal Privoznik
687730540e virstoragefile: Introduce virStoragePRDef
This is a definition that holds information on SCSI persistent
reservation settings. The XML part looks like this:

  <reservations enabled='yes' managed='no'>
    <source type='unix' path='/path/to/qemu-pr-helper.sock' mode='client'/>
  </reservations>

If @managed is set to 'yes' then the <source/> is not parsed.
This design was agreed on here:

https://www.redhat.com/archives/libvir-list/2017-November/msg01005.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-05-11 09:02:56 +02:00
Peter Krempa
f3282d1f9b util: file: Add helper to determine whether a path is a CDROM
Add detection mechanism which will allow to check whether a path to a
block device is a physical CDROM drive. This will be useful once we will
need to pass it to hypervisors.

The linux implementation uses an ioctl to do the detection, while the
fallback uses a simple string prefix match.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-05-07 15:17:06 +02:00
Andrea Bolognani
026606caf2 util: Introduce virFileCanonicalizePath()
It's a trivial wrapper around canonicalize_file_name(),
which we need in order to fully mock file access on non-Linux
platforms.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2018-05-03 18:23:29 +02:00
Daniel P. Berrangé
593ba43f1f nwfilter: introduce virNWFilterBinding to decouple from virDomainNet
The virDomainNet struct contains everything related to configuring a
guest network device. Out of all of this info, only 5 fields are
relevant to configuring network filters. It will be more convenient for
future changes to the nwfilter driver if the relevant fields are kept in
a dedicated struct. Thus the virNWFilterBinding struct is created to
track this information.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-05-03 17:00:57 +01:00
Daniel P. Berrangé
1cf16d755e nwfilter: remove methods that are trivial wrappers for virHash APIs
This removes the virNWFilterHashTableFree, virNWFilterHashTablePut
and virNWFilterHashTableRemove methods, in favour of just calling
the virHash APIs directly.

The virNWFilterHashTablePut method was unreasonably complex because
the virHashUpdateEntry already knows how to create the entry if it
does not currently exist.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-05-03 17:00:57 +01:00
Daniel P. Berrangé
8b0f721f2e util: create new virmodule.{c,h} files for dlopen support code
The driver.{c,h} files are primarily targetted at loading hypervisor
drivers and some helper functions in that area. It also, however,
contains a generically useful function for loading extension modules
that is called by the storage driver. Split that functionality off
into a new virmodule.{c,h} file to isolate it.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-05-03 12:47:43 +01:00
John Ferlan
868136624f conf: Rework/rename virDomainObjListFindByIDRef
Rework the code such that virDomainObjListFindByID will always
return a locked/ref counted object so that the callers can
always do the same cleanup logic to call virDomainObjEndAPI.
Makes accessing the objects much more consistent.

NB:
There were 2 callers (lxcDomainLookupByID and qemuDomainLookupByID)
that were already using the ByID name, but not virDomainObjEndAPI -
these were changed as well in this update/patch.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2018-04-23 06:41:45 -04:00
John Ferlan
fd9ef3b31e conf: Rework/rename virDomainObjListFindByUUIDRef
Now that every caller is using virDomainObjListFindByUUIDRef,
let's just remove it and keep the name as virDomainObjListFindByUUID.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2018-04-23 06:41:45 -04:00
Clementine Hayat
749282d400 Add function that raises error if domain is not active
Add a function named virDomainObjCheckIsActive in src/conf/domain_conf.c.
It calls virDomainObjIsActive, raises error if necessary and returns.

There is a lot of occurence of this pattern and it will save 3 lines on
each call.

Signed-off-by: Clementine Hayat <clem@lse.epita.fr>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2018-04-18 10:22:07 +02:00
Jiri Denemark
bf856b6054 util: Introduce virJSONValueObjectStealObject
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-04-17 10:46:23 +02:00
John Ferlan
9e792d1aaa qemu: Use virDomainChrSourceDefNew for monConfig
Rather than VIR_ALLOC, use the New function for allocation. We
already use the Free function anyway.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
Reviewed-by: Marc Hartmayer <mhartmay@linux.vnet.ibm.com>
2018-04-10 08:11:09 -04:00
Jim Fehlig
412afdb8f4 util: introduce virSocketAddrParseAny
When preparing for migration, the libxl driver creates a new TCP listen
socket for the incoming migration by calling virNetSocketNewListenTCP,
passing the destination host name. virNetSocketNewListenTCP calls
virSocketAddrParse to check if the host name is a wildcard address, in
which case it avoids adding the AI_ADDRCONFIG flag to the hints passed to
getaddrinfo. If the host name is not an IP address, virSocketAddrParse
reports an error

error : virSocketAddrParseInternal:121 : Cannot parse socket address
'myhost.example.com': Name or service not known

But virNetSocketNewListenTCP succeeds regardless and the overall migration
operation succeeds.

Introduce virSocketAddrParseAny and use it when simply testing if a host
name/addr is parsable.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-04-05 14:50:15 -06:00
Michal Privoznik
fd9d1e686d util: Introduce virDevMapperGetTargets
This helper fetches dependencies for given device mapper target.

At the same time, we need to provide a dummy log function because
by default libdevmapper prints out error messages to stderr which
we need to suppress.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-04-05 09:58:44 +02:00
Peter Krempa
8fc5e5bfdc conf: Extract logic for updating 'detect_zeroes' mode
For some reason we've decided to silently translate the disk
detect_zeroes mode if it would be invalid. Extract the
logic so that it does not need to be copypasta'd across the code base.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 15:48:37 +02:00
Peter Krempa
295b128e09 conf: Refactor/rename virDomainDiskDefSourceParse
Make the function more usable by returning the full disk definition and
fix the only caller for the new semantics. The new name for the function
is virDomainDiskDefParse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 15:48:37 +02:00
Peter Krempa
1cbe6aa220 util: json: Add accessor for geting a VIR_JSON_TYPE_NUMBER as string
Sometimes it's desired to get a JSON number as string. Add a helper.
This will help in cases where we'd want to convert the internal type from
string to something else.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-04-03 13:34:33 +02:00
Peter Krempa
57cd22bc54 util: json: Add accessor for looking up JSON value type
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-23 14:52:07 +01:00
Chen Hanxiao
a176d67cdf util: introduce helper to parse message from RTM_GETNEIGH query
introduce helper to parse RTM_GETNEIGH query message and
store it in struct virArpTable.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-03-15 11:22:42 +01:00