libvirt/src/qemu
Laine Stump b03d9e9593 conf: add hypervisor agnostic, domain start-time, validation function for NetDef
<interface> devices (virDomainNetDef) are a bit different from other
types of devices in that their actual type may come from a network (in
the form of a port connection), and that doesn't happen until the
domain is started. This means that any validation of an <interface> at
parse time needs to be a bit liberal in what it accepts - when
type='network', you could think that something is/isn't allowed, but
once the domain is started and a port is created by the configured
network, the opposite might be true.

To solve this problem hypervisor drivers need to do an extra
validation step when the domain is being started. I recently (commit
3cff23f7, libvirt 5.7.0) added a function to peform such validation
for all interfaces to the QEMU driver -
qemuDomainValidateActualNetDef() - but while that function is a good
single point to call for the multiple places that need to "start" an
interface (domain startup, device hotplug, device update), it can't be
called by the other hypervisor drivers, since 1) it's in the QEMU
driver, and 2) it contains some checks specific to QEMU. For
validation that applies to network devices on *all* hypervisors, we
need yet another interface validation function that can be called by
any hypervisor driver (not just QEMU) right after its network port has
been created during domain startup or hotplug. This patch adds that
function - virDomainActualNetDefValidate(), in the conf directory,
and calls it in appropriate places in the QEMU, lxc, and libxl
drivers.

This new function is the place to put all network device validation
that 1) is hypervisor agnostic, and 2) can't be done until we know the
"actual type" of an interface.

There is no framework for validation at domain startup as there is for
post-parse validation, but I don't want to create a whole elaborate
system that will only be used by one type of device. For that reason,
I just made a single function that should be called directly from the
hypervisors, when they are initializing interfaces to start a domain,
right after conditionally allocating the network port (and regardless
of whether or not that was actually needed). In the case of the QEMU
driver, qemuDomainValidateActualNetDef() is already called in all the
appropriate places, so we can just call the new function from
there. In the case of the other hypervisors, we search for
virDomainNetAllocateActualDevice() (which is the hypervisor-agnostic
function that calls virNetworkPortCreateXML()), and add the call to our
new function right after that.

The new function itself could be plunked down into many places in the
code, but we already have 3 validation functions for network devices
in 2 different places (not counting any basic validation done in
virDomainNetDefParseXML() itself):

1) post-parse hypervisor-agnostic
   (virDomainNetDefValidate() - domain_conf.c:6145)
2) post-parse hypervisor-specific
   (qemuDomainDeviceDefValidateNetwork() - qemu_domain.c:5498)
3) domain-start hypervisor-specific
   (qemuDomainValidateActualNetDef() - qemu_domain.c:5390)

I placed (3) right next to (2) when I added it, specifically to avoid
spreading validation all over the code. For the same reason, I decided
to put this new function right next to (1) - this way if someone needs
to add validation specific to qemu, they go to one location, and if
they need to add validation applying to everyone, they go to the
other. It looks a bit strange to have a public function in between a
bunch of statics, but I think it's better than the alternative of
further fragmentation. (I'm open to other ideas though, of course.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-11-25 15:30:05 -05:00
..
EVENTHANDLERS.txt
libvirtd_qemu.aug
Makefile.inc.am qemu: Remove qemu_hotplugpriv.h and qemuDomainRemoveDeviceWaitTime 2019-11-13 15:03:40 -05:00
MIGRATION.txt
qemu_agent.c replace use of gnulib snprintf by g_snprintf 2019-11-15 15:07:40 +01:00
qemu_agent.h Add API to change qemu agent response timeout 2019-11-14 19:10:01 +01:00
qemu_alias.c
qemu_alias.h
qemu_block.c util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_block.h qemu: Separate image metadata removal into a function 2019-11-22 10:48:04 +01:00
qemu_blockjob.c qemu: Separate image metadata removal into a function 2019-11-22 10:48:04 +01:00
qemu_blockjob.h
qemu_capabilities.c qemu_capabilities: Use proper free function for caps->cpuModels 2019-11-25 17:13:05 +01:00
qemu_capabilities.h qemu: capabilities: Add detection of the 'savevm' fix for -blockdev 2019-11-22 12:51:27 +01:00
qemu_capspriv.h qemu: Introduce virQEMUCapsProbeCPUDefinitionsTest 2019-11-20 17:22:06 +01:00
qemu_cgroup.c qemu: remove unneeded cleanup labels 2019-11-19 15:22:37 +01:00
qemu_cgroup.h
qemu_checkpoint.c qemu: checkpoint: Use qemuMonitorTransactionBitmapMergeSourceAddBitmap 2019-11-20 15:43:11 +01:00
qemu_checkpoint.h
qemu_command.c conf: make virDomainNetGetActualBandwidth arg/return value const 2019-11-25 15:29:51 -05:00
qemu_command.h
qemu_conf.c util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_conf.h util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_dbus.c
qemu_dbus.h
qemu_domain_address.c qemu: remove unneeded cleanup labels 2019-11-19 15:22:37 +01:00
qemu_domain_address.h
qemu_domain.c conf: add hypervisor agnostic, domain start-time, validation function for NetDef 2019-11-25 15:30:05 -05:00
qemu_domain.h qemu: domain: Introduce helper to convert <loader> into virStorageSource 2019-11-22 08:32:25 +01:00
qemu_driver.c qemu: Rename virQEMUCaps{Get,Fetch}CPUDefinitions 2019-11-20 17:22:05 +01:00
qemu_driver.h
qemu_extdevice.c
qemu_extdevice.h
qemu_firmware.c
qemu_firmware.h
qemu_hostdev.c
qemu_hostdev.h
qemu_hotplug.c conf: return a const from virDomainNetGetActualVirtPortProfile 2019-11-25 15:29:56 -05:00
qemu_hotplug.h qemu_hotplug.c: adding qemuDomainGetUnplugTimeout 2019-11-13 15:03:40 -05:00
qemu_interface.c qemu: remove unneeded cleanup labels 2019-11-19 15:22:37 +01:00
qemu_interface.h qemu-process: prepare slirp-helper 2019-09-06 12:47:47 +02:00
qemu_interop_config.c
qemu_interop_config.h
qemu_migration_cookie.c conf: return a const from virDomainNetGetActualVirtPortProfile 2019-11-25 15:29:56 -05:00
qemu_migration_cookie.h
qemu_migration_params.c qemu/qemu_migration_params: use virStringParseYesNo helper 2019-11-14 08:14:50 -05:00
qemu_migration_params.h
qemu_migration_paramspriv.h
qemu_migration.c util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_migration.h Use G_GNUC_WARN_UNUSED_RESULT instead of ATTRIBUTE_RETURN_CHECK 2019-10-15 11:25:22 +02:00
qemu_monitor_json.c util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_monitor_json.h qemu: Introduce qemuMonitorCPUDefs struct 2019-11-20 17:22:05 +01:00
qemu_monitor_priv.h
qemu_monitor_text.c
qemu_monitor_text.h
qemu_monitor.c util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_monitor.h util: consolidate on one free callback for hash data 2019-11-22 14:21:28 +00:00
qemu_process.c conf: return a const from virDomainNetGetActualVirtPortProfile 2019-11-25 15:29:56 -05:00
qemu_process.h
qemu_processpriv.h
qemu_qapi.c qemu: qapi: Add support for command features 2019-11-22 12:51:27 +01:00
qemu_qapi.h
qemu_security.c
qemu_security.h
qemu_slirp.c
qemu_slirp.h
qemu_tpm.c qemu: remove unneeded cleanup labels 2019-11-19 15:22:37 +01:00
qemu_tpm.h
qemu_vhost_user_gpu.c qemu: gpu: Sanitize error values in qemuVhostUserGPUGetPid 2019-11-14 12:42:09 +01:00
qemu_vhost_user_gpu.h
qemu_vhost_user.c
qemu_vhost_user.h
qemu.conf
test_libvirtd_qemu.aug.in
THREADS.txt
virtqemud.service.in