Commit Graph

37972 Commits

Author SHA1 Message Date
Laine Stump
ad668b98e9 nwfilter: define a typedef for struct ebtablesSubChainInst
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:13:22 -04:00
Laine Stump
b9f829b66f nwfilter: clear nrules when resetting virNWFilterInst
It's possible/probable the callers to virNWFilterInstReset() make it
unnecessary to set the object's nrules to 0 after freeing all its
rules, but that same function is setting nfilters to 0, so let's do
the same for the sake of consistency.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:13:21 -04:00
Laine Stump
4686116075 nwfilter: remove unnecessary code from ebtablesGetSubChainInsts()
On failure, this function would clear out and free the list of
subchains it had been called with. This is unnecessary, because the
*only* caller of this function will also clear out and free the list
of subchains if it gets a failure from ebtablesGetSubChainInsts().

(It also makes more logical sense for the function that is creating
the entire list to be the one freeing the entire list, rather than
having a function whose purpose is only to create *one item* on the
list freeing the entire list).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko redhat com>
2020-07-20 19:13:05 -04:00
Laine Stump
cab4a682de network: use g_free() in place of remaining VIR_FREE()
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:11:39 -04:00
Laine Stump
f931c85fb0 network: eliminate unnecessary labels
All these cleanup/error labels were reduced to having just "return
ret" by a previous patch, so get rid of them and return directly.

This patch coincidentally fixes a bug in
networkFindUnusedBridgeName(), where we would log an error yet still
return success if we failed to find a single unused "virbrNNN" name
after checking all values of "N" from 0 - 256. Said bug was introduced
when that function was originally written, in commit a28d3e485f
(libvirt 1.2.15, 2015)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:11:35 -04:00
Laine Stump
b32b2746ad network: use g_auto wherever appropriate
This includes standard g_autofree() as well as other objects that have
a cleanup function defined to use via g_autoptr (virCommand,
virJSONValue)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:08:39 -04:00
Laine Stump
9f51c3d6c0 network: replace VIR_ALLOC/REALLOC with g_new0/g_renew
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:08:07 -04:00
Laine Stump
750f371b62 define g_autoptr cleanup function for virNetworkDHCPLease
virNetworkDHCPLease and virNetworkDHCPLeaseFree() are declared in the
public API file libvirt-network.h, and we can't pollute that with glib
macro invocations, so put this in src/datatypes.h next to the other
virNetwork items.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:08:07 -04:00
Laine Stump
7ad6ad6867 util: define g_autoptr cleanups for a couple dnsmasq objects
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:08:07 -04:00
Laine Stump
cc5da62bbd replace g_new() with g_new0() for consistency
g_new() is used in only 3 places. Switching them to g_new0() will do
no harm, reduces confusion, and helps me sleep better at night knowing
that all allocated memory is initialized to 0 :-) (Yes, I *know* that
in all three cases the associated memory is immediately assigned some
other value. Today.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-20 19:08:07 -04:00
Andrea Bolognani
588d2834d7 spec: Drop explicit dependency on ncurses
We don't actually use ncurses directly: readline needs it, but
that's a readline implementation detail and not something that we
should concern ourselves with.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2020-07-20 17:16:55 +02:00
Prathamesh Chavan
aca37c3fb2 qemu_domainjob: introduce privateData for qemuDomainJob
To remove dependecy of `qemuDomainJob` on job specific
paramters, a `privateData` pointer is introduced.
To handle it, structure of callback functions is
also introduced.

Signed-off-by: Prathamesh Chavan <pc44800@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-07-20 15:34:58 +02:00
Ryan Schmidt
a9f1ac3a97 Include <sys/socket.h> before including <net/if.h>
This is necessary for OS X 10.8 and earlier.

Signed-off-by: Ryan Schmidt <git@ryandesign.com>
2020-07-20 09:41:23 +00:00
Andrea Bolognani
c4cd0ef917 spec: Don't require mdevctl on RHEL 7
mdevctl is a relatively new tool that's packaged for Fedora and
RHEL 8, but not for RHEL 7. Make the dependency conditional to
avoid the libvirt-daemon-driver-nodedev package becoming
uninstallable on that platform.

Fixes: 9691440ecb
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2020-07-20 09:02:50 +02:00
Andrea Bolognani
747ba4ed98 spec: Remove unnecessary version check
As of 65a883b349 we no longer support Fedora releases older than
31, so the version check has become unnecessary.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2020-07-18 23:47:42 +02:00
Daniel P. Berrangé
a4da0b2ac6 docs: fix compilation instructions to use separate build dir
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-07-17 17:34:30 +01:00
Michal Privoznik
0dcf9562e2 virNetSocketCheckProtocols: Actually check bool value
In 9536379da4 and 8b0cb0e666 I've tried to call
virNetSocketCheckProtocolByLookup() only if we are suspecting the
host is IPv4 or IPv6 capable (because we've found an interface
with such address). However, the code was missing dereference of
the boolean variables and thus was comparing pointers against
NULL.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2020-07-17 16:14:23 +02:00
Daniel P. Berrangé
7d488a7c45 Partially revert "qemu: fix missing error reports in capabilities probing"
This partially reverts commit 5331c4804f.

The original commit mistakenly thought virFileCacheLookup did not set
an error. In fact the only case it doesn't set an error for is when
the cache key is NULL. This in fact the fault of the caller for passing
an invalid cache key, so doesn't need to be handled.

This caller bug was fixed by checking for a NULL binary in the
virQEMUCapsCacheLookupDefault method.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2020-07-17 10:49:08 +01:00
Peter Krempa
fdab2f1a31 virDomainHostdevSubsysSCSIiSCSIDefParseXML: Use XPath to fetch elements
Conver the code to the new approach which uses XPath to fetch known
elements rather than looping through all XML children.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
a894223e7b virDomainHostdevSubsysSCSIDefParseXML: Use typecasted switch
Use a switch statement which will not be omitted when adding potential
new types.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
9cba714bd5 virDomainHostdevDefFormatSubsys: Split out formatting of mdev subsystem
Similarly to previous commit split out formatting of the mdev subsystem
related stuff.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
edae30c5d2 virDomainHostdevDefFormatSubsys: Split out formatting of vHBA subsystem
Similarly to previous commit split out formatting of the vHBA subsystem
related stuff.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
0c71413332 virDomainHostdevDefFormatSubsysSCSI: Avoid ternary operator when formatting address
Split up formatting of the '<address>' element rather that trying to
optimize it with formatting string hacks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
ccb27a08d5 virDomainHostdevDefFormatSubsys: Split out formatting of SCSI subsystem
Similarly to previous commit split out formatting of the SCSI subsystem
related stuff.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
986fe56f59 virDomainHostdevDefFormatSubsys: Split out formatting of PCI subsystem
Similarly to previous commit split out formatting of the PCI subsystem
related stuff.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
f551294506 virDomainHostdevDefFormatSubsys: Split out formatting of USB subsystem
Separate out bits related to USB so that the logic isn't entangled in
multiple conditional statements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
6885542369 virDomainHostdevDefFormatSubsys: Use virXMLFormatElement
Refactor the formatter to the new multiple buffer based approach so that
we can easily separate it into formatters per subsys type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 08:22:42 +02:00
Peter Krempa
97b6fd8911 qemuBuildSCSIHostdevDrvStr: unexport
The function is no longer called from other modules.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:21 +02:00
Peter Krempa
30932473e1 qemu: caps: Enable QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI
Enable it when regular QEMU_CAPS_BLOCKDEV is present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:21 +02:00
Peter Krempa
8d243d257f qemuDomainRemoveHostDevice: Use new infrastructure for (i)SCSI
Similarly to previous commits, modify the hostdev detach code to use
blockdev infrastructure to detach (i)SCSI hostdevs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:21 +02:00
Peter Krempa
3455acebf8 qemuDomainAttachHostSCSIDevice: Use new infrastructure
Similarly to command line creation, use the blockdev helpers when
hotplugging an (i)SCSI hostdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:21 +02:00
Peter Krempa
5e24aa4c58 qemuBuildHostdevSCSICommandLine: Use new infrastructure
In preparation for instantiating (i)SCSI hostdevs via -blockdev,
refactor qemuBuildHostdevSCSICommandLine to use the new infrastructure
which will do it automatically.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:21 +02:00
Peter Krempa
245ed36e97 qemu: command: Create qemuBlockStorageSourceAttachData for (i)SCSI hostdevs
Add convertor for creating qemuBlockStorageSourceAttachData which will
allow reusing the infrastructure which we have for attaching disks also
for hostdevs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:21 +02:00
Peter Krempa
bab9257a64 qemu: capabilities: Add QEMU_CAPS_BLOCKDEV_HOSTDEV_SCSI
We want to instantiate hostdevs via -blockdev too. Add a separate
capability for them for a clean transition. The new capability will be
enabled when QEMU_CAPS_BLOCKDEV is present once all code is prepared.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
78e8bb743b qemuBuildSCSIHostdevDevStr: Pass in backend alias
Don't (re)generate the backend alias (alias of the -drive backend for
now) internally but rather pass it in. Later on it will be replaced by
the nodename when blockdev is used depending on the capabilities.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
6cfcc0c68e qemuBuildHostdevCommandLine: Extract (i)SCSI code
Move all (i)SCSI related code into a new function named
'qemuBuildHostdevSCSICommandLine'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
ad3adcd5ec qemu: hotplug: Don't regenerate iSCSI secret alias
We now store the alias of the secrets in the status XML so there's no
need to generate it again.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
dd339e86db qemu: domain: Regenerate hostdev source private data
When upgrading from a libvirt which didn't format private data of a
virStorageSource representing an iSCSI hostdev source, we might need to
generate some internal data so that the code still works as if it was
present in the status XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
3aca4865a8 qemuDomainSecretHostdevDestroy: Don't clear secinfo alias
We need the alias to deal with hot-unplug of the hostdev. Use
qemuDomainSecretInfoDestroy which clears only the secrets and not the
alias. The same function is used also for handling disk secrets.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
6306f88df0 qemustatusxml2xmltest: Add tests for iSCSI hostdev private data handling
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
bb78cf0046 virDomainHostdevSubsysSCSIiSCSIDefParseXML: Parse private data of virStorageSource
We store the config of an iSCSI hostdev in a virStorageSource structure.
Parse the private data portion.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
4f708a15b6 virDomainHostdevDefFormatSubsys: Format private data for a virStorageSource
iSCSI subsystem hostdevs store the data as a virStorageSource. Format
the private data part of the virStorageSource in the appropriate place.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
0489a7c6ee qemuBlockStorageSourceAttachData: Add field for ad-hoc storage node name
SCSI hostdevs don't have a virStorageSource associated with the backend
in certain cases. Adding a separate field to hold memory for a copy of
the nodename of the storage backend will allow reusing the blockdev
machinery also for SCSI hostdevs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
4f28b1a51c qemuBlockStorageSourceGetBackendProps: Allow skipping "discard":"unmap"
It doesn't make sense to format "discard" when doing a -blockdev backend
of scsi-generic used with SCSI hostdevs. Add a way to skip it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Peter Krempa
d73c5eda63 qemuBlockStorageSourceGetBackendProps: Convert boolean arguments to flags
Upcoming commit will need to add another flag for the function so
convert it to a bitwise-or'd array of flags to prevent having 4
booleans.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-17 07:41:20 +02:00
Michal Privoznik
8b0cb0e666 virNetSocketCheckProtocols: Confirm IPv4 by lookup too
Historically, if we found an interface with an IPv6 address we
did not blindly trust that host is IPv6 capable (as in we can
successfully translate IPv4 addresses) but used getaddrinfo() to
confirm it. Turns out, we have use the same argument for IPv4.
For instance, in an namespace created by the following steps,
getaddrinfo("127.0.0.1", ...) fails (demonstrating by "Socket
TCP/IPv4 Accept" test case failing in virnetsockettest):

  unshare -n
  ip link set lo up
  ip link add dummy0 type dummy
  ip link set dummy0 up

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-16 12:19:31 +02:00
Michal Privoznik
9536379da4 virNetSocketCheckProtocols: lookup IPv6 only if suspecting IPv6
There is not much sense trying to disprove host is IPv6 capable
if we know after first round (getifaddrs()) that is is not.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-16 12:19:22 +02:00
Michal Privoznik
e146f4beef virNetSocketCheckProtocols: Separate out checking family via getaddrinfo()
The virNetSocketCheckProtocols() function is supposed to tell
caller whether IPv4 and/or IPv6 is supported on the system. In
the initial round, it uses getifaddrs() to see if an interface
has IPv4/IPv6 address assigned and then to double check IPv6 it
uses getaddrinfo() to lookup IPv6 loopback address. Separate out
this latter code because it is going to be reused.

Since the original code lived under an #ifdef and the new
function doesn't it is marked as unused - because on some systems
it may be so.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-07-16 12:19:05 +02:00
Michal Privoznik
e71e13488d Substitute security_context_t with char *
Historically, we've used security_context_t for variables passed
to libselinux APIs. But almost 7 years ago, libselinux developers
admitted in their API that in fact, it's just a 'char *' type
[1]. Ever since then the APIs accept 'char *' instead, but they
kept the old alias just for API stability. Well, not anymore [2].

1: 9eb9c93275
2: 7a124ca275

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2020-07-15 14:31:07 +02:00
Andrea Bolognani
deceb1e09f tests: Minimize variable scope
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-07-15 12:52:24 +02:00