Commit Graph

43790 Commits

Author SHA1 Message Date
Laine Stump
dba9893831 Revert "conf: introduce support for acpi-bridge-hotplug feature"
This reverts commit 7300ccc9b3.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:41 -04:00
Laine Stump
26e8eda46e Revert "qemu: command: add support for acpi-bridge-hotplug feature"
This reverts commit bef0f0d8be.

Conflicts:
 tests/qemuxml2argvdata/q35-acpi-hotplug-bridge-disable.args

  * this file had been renamed from its original, then renamed back,
    which understandably confused git. It's being completely removed
    here anyway, so the contents don't matter.

 tests/qemuxml2argvtest.c

  * change in context around removed chunk

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:41 -04:00
Laine Stump
f338720ddb Revert "NEWS: document new acpi pci hotplug config option"
This reverts commit 5ee4f3e1d4.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:41 -04:00
Laine Stump
4f4fffc073 Revert "qemuValidateDomainDefPCIFeature: un-break error messages"
This reverts commit 7d074c5683.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:41 -04:00
Laine Stump
4aa75c3e4b Revert "qemuValidateDomainDefPCIFeature: Fix validation logic"
This reverts commit bdc3e8f47b.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:40 -04:00
Laine Stump
1a786fda0e Revert "qemuxml2argvtest: Use real-caps testing for 'acpi-hotplug-bridge-disable'"
This reverts commit 2d20f0bb05.

Conflicts:
 tests/qemuxml2argvdata/pc-i440fx-acpi-hotplug-bridge-disable.args
 tests/qemuxml2argvdata/q35-acpi-hotplug-bridge-disable.args

  the test output of these files was regenerated because the tests
  were changed upstream to use JSON on the commandline at a later
  commit than the commit being reverted here (where they were changed
  to use latest caps, but the patches to use JSON on the commandline
  hadn't been committed yet).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:40 -04:00
Laine Stump
85094a4d60 Revert "qemuxml2argvtest: Add '-enable' variants for ACPI-hotplug related cases"
This reverts commit 6414603105.

Conflicts:
 tests/qemuxml2argvdata/pc-i440fx-acpi-hotplug-bridge-enable.x86_64-latest.args
 tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-enable.x86_64-latest.args
 tests/qemuxml2argvdata/q35-acpi-hotplug-bridge-enable.x86_64-latest.args

These files are unrelated to the functionality we need to remove, so
they weren't removed, and the associated test cases weren't removed
from qemuxml2argvtest.c

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:40 -04:00
Laine Stump
ea373d6c07 Revert "qemuxml2xmltest: Convert all acpi-hotplug control related tests to DO_TEST_CAPS_LATEST"
This reverts commit da896d440c.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:40 -04:00
Laine Stump
d65eb5dd8d Revert "qemu: capabilities: Remove QEMU_CAPS_PIIX4_ACPI_HOTPLUG_BRIDGE"
This reverts commit 618e8665db.

This is the first in a series of 10 commits that revert (in reverse
order) the changes to add the <acpi-hotplug-bridge state='on|off'/>
switch to libvirt domain XML, which unfortunately needs to be removed
due to QEMU developers discovering a flaw with the design of the QEMU
commandline switch used to implement the libvirt switch that will
likely result in a new and different method of selecting hotplug
modes. Because the libvirt switch has not been in any official
releases of libvirt, we are still able to remove it completely, rather
than deprecating it.

The original commits began with commit
58ba0f6a3d. The other original commit
IDs are documented in each revert commit.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
2021-10-25 23:18:40 -04:00
Daniel P. Berrangé
460eda9b05 docs: fix docs output path with meson 0.60.0
The meson 0.60.0 release introduced a bug with the '/' operator when
using an empty path component. '/foo' / ''  will now result in '/foo'
not '/foo/'

  https://github.com/mesonbuild/meson/issues/9450

This breaks libvirt because xsltproc requires the trailing '/' on the
output directory path. Fortunately the explicit 'join_paths' function
is not affected by the regression

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-10-25 19:36:15 +01:00
Peter Krempa
8e3a7c6db9 qemublocktest: Don't leak 'disk' in testQemuImageCreateLoadDiskXML
The function returns only the source portion but forgot to free the disk
wrapper.

Fixes: 9696427ad6
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2021-10-25 16:11:49 +02:00
Or Ozeri
060f344c80 conf: add luks2 encryption format
This commit extends libvirt XML configuration to support luks2 encryption format.
This means that <encryption format="luks2" engine="librbd"> becomes valid.
Currently librbd is the only engine that supports this new format.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-10-25 14:06:15 +02:00
Or Ozeri
59090adf63 qemu: add librbd encryption engine
rbd encryption is new in qemu 6.1.0.
This commit adds a new encryption engine property which
allows the user to use this new encryption engine.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-10-25 14:06:15 +02:00
Or Ozeri
ab1d46d612 conf: add encryption engine property
This commit extends libvirt XML configuration to support a custom encryption engine.
This means that <encryption format="luks" engine="qemu">  becomes valid.
The only engine for now is qemu. However, a new engine (librbd) will be added in an upcoming commit.
If no engine is specified, qemu will be used (assuming qemu driver is used).

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-10-25 14:06:15 +02:00
Or Ozeri
0398be5da6 qemu: capablities: Detect presence of 'rbd-encryption' as QEMU_CAPS_RBD_ENCRYPTION
rbd encryption is new in qemu 6.1.0.
This commit adds capability probing for it.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-10-25 14:06:15 +02:00
Or Ozeri
9696427ad6 qemu: add disk post parse to qemublocktest
The post parse callback is part of the real (non-test) processing flow.
This commit adds it (for disks) to the qemublocktest flow as well.
Specifically, this will be needed for tests that use luks encryption,
so that the default encryption engine (which is added in an upcoming commit)
will be overridden by qemu.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-10-25 14:06:15 +02:00
Daniel P. Berrangé
9ff311f105 ci: regenerate container from manifest
This removes the libnetcf-dev package from Debian Sid, as it is no
longer available in that distro stream.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-10-25 12:45:31 +01:00
Michal Privoznik
91e206427f qemu_monitor_json: Drop pointless error labels
After previous cleanups, some 'error' labels were rendered
needless - they contain nothing more than a return statement.
Well, those labels can be dropped and 'goto error' can be
replaced with return statement directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:57 +02:00
Michal Privoznik
3361cc2f3c qemu_monitor_json: Drop pointless cleanup labels
After previous cleanups, some 'cleanup' labels were rendered
needless - they contain nothing more than a return statement.
Well, those labels can be dropped and 'goto cleanup' can be
replaced with return statement directly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:51 +02:00
Michal Privoznik
a8ab1dd4cb qemu_monitor_json: Use g_autofree
Let's replace VIR_FREE() calls with g_autofree. Not all calls can
be replaced though - the legitimate ones are kept (e.g. those
which free array, or which free a struct for which we don't have
g_autoptr() yet, and so on).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:47 +02:00
Michal Privoznik
551f91b4cb qemu_monitor_json: Use g_autoptr() for virJSONValue
A lot of explicit free calls can be saved when virJSONValue
variables are declared with g_autoptr(). There's one caveat:
there was a slight deviation from our usual pattern such that
@cmd variable was not initialized to NULL but as the very first
step it was assigned a value using qemuMonitorJSONMakeCommand().
While this works in theory it upset my GCC-11.2 (but only when
building with -O2). So I had to initialize the variable in such
case too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:43 +02:00
Michal Privoznik
40bbcb47cc qemuMonitorJSONExtractPRManagerInfo: Declare @entry inside the loop
The reason why @entry variable in qemuMonitorJSONExtractPRManagerInfo()
was declared at the top most level was that the variable is used under
the cleanup label.  However, if declared using g_autofree then the
variable can be declared inside the loop it is used in.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:39 +02:00
Michal Privoznik
3e27dbc029 qemu_monitor_json: Use g_autoptr() for qemuMonitorCPUModelInfo
There's one place (specifically qemuMonitorJSONParseCPUModel())
where we can avoid explicit free call for qemuMonitorCPUModelInfo
struct.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:36 +02:00
Michal Privoznik
c63955ab0f qemu_monitor_json: Use g_autoptr() for virCPUData
We have g_autoptr() for virCPUData struct defined already. Let's
use it in qemu_monitor_json.c and drop explicit free calls.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:32 +02:00
Michal Privoznik
3dfc47c1fd qemu_monitor: Declare and use g_autoptr for qemuMonitorEventPanicInfo
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:27 +02:00
Michal Privoznik
4b1b14170a qemuMonitorJSONQueryRxFilterParse: Set *filter only on success
The qemuMonitorJSONQueryRxFilterParse() function is called to
parse the output of 'query-rx-filter' and store results into
passed virNetDevRxFilter structure. However, it is doing so in a
bit clumsy way - the return pointer is set in all cases (i.e.
even in case of error) and thus the cleanup label is more
complicated than it needs to be. With a help of g_autoptr() and
g_steal_pointer() the return pointer can be set only in case of
success - which is what callers expect anyway.

The same applies to qemuMonitorJSONQueryRxFilter().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:22 +02:00
Michal Privoznik
4e8bb57859 qemuMonitorJSONGetMigrationStats: Don't clear @stats on failure
In the qemuMonitorJSONGetMigrationStats() there's a code under
cleanup label that's clearing returned @stats if the function
returns with an error. However, transitively there's just one
caller - qemuMigrationAnyFetchStats() - and it doesn't care for
this behaviour. Drop the code to simplify the cleanup label.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:19 +02:00
Michal Privoznik
a70ae22cfd qemuMonitorJSONHumanCommand: Require @reply_str
All callers of qemuMonitorJSONHumanCommand() pass a non-NULL pointer
as @reply_str therefore there's no need to check whether it is NULL.
NB, the sister function (qemuMonitorJSONArbitraryCommand()) doesn't
check for NULL either.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:14 +02:00
Michal Privoznik
2d7257d528 qemu_monitor_json: Don't transfer ownership to @msg
In qemuMonitorJSONCommandWithFd() given command (represented by
virJSONValue struct) is translated to string (represented by
virBuffer). The ownership of the string is then transferred to
the message which is then sent. The downside of this approach is
we have to have an explicit call to free the string from the
message. But if the message just "borrowed" the string (which it
can safely do because it is just reading from the string) then
automatic free of the buffer takes care of freeing the string.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:42:00 +02:00
Michal Privoznik
139338ab33 qemu_monitor_json: Don't check for qemuMonitorNextCommandID() retval
The qemuMonitorNextCommandID() function can never fail. There's
no need to check for its retval then. Moreover, the temporary
variable used to hold the retval can be declared in the inner
most block.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-10-25 13:41:25 +02:00
Michal Privoznik
857df2fe50 lib: Drop intermediary return variables
In a few places we declare a variable (which is optionally
followed by a code not touching it) then set the variable to a
value and return the variable immediately. It's obvious that the
variable is needless and the value can be returned directly
instead.

This patch was generated using this semantic patch:

  @@
  type T;
  identifier ret;
  expression E;
  @@
  - T ret;
  ... when != ret
      when strict
  - ret = E;
  - return ret;
  + return E;

After that I fixed couple of formatting issues because coccinelle
formatted some lines differently than our coding style.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-25 12:48:46 +02:00
Michal Privoznik
945942ebba qemuMonitorJSONGetMigrationCapabilities: Don't return early on CommandNotFound
The qemuMonitorJSONGetMigrationCapabilities() command executes
'query-migrate-capabilities' command and returns early if QEMU
doesn't know the command. Well, the command was introduced in
QEMU release 1.2 (specifically in commit v1.2.0-rc0~29^2~11) and
since the minimum required version is 2.11.0 we can be sure that
command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-22 07:00:44 +02:00
Michal Privoznik
4c1d40915a qemuMonitorJSONGetMemoryDeviceInfo: Don't return early on CommandNotFound
The qemuMonitorJSONGetMemoryDeviceInfo() command executes
'query-memory-devices' command and returns early if QEMU
doesn't know the command. Well, the command was introduced in
QEMU release 2.1 (specifically in commit v2.1.0-rc0~41^2~9) and
since the minimum required version is 2.11.0 we can be sure that
command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-22 07:00:44 +02:00
Michal Privoznik
dea2dcea72 qemuMonitorJSONGetKVMState: Don't return early on CommandNotFound
The qemuMonitorJSONGetKVMState() command executes 'query-kvm'
command and returns early if QEMU doesn't know the command. Well,
the command was introduced in QEMU release 0.14 and since the
minimum required version is 2.11.0 we can be sure that command
will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-22 07:00:44 +02:00
Michal Privoznik
432ff3166e qemuMonitorJSONGetDumpGuestMemoryCapability: Don't return early on CommandNotFound
The qemuMonitorJSONGetDumpGuestMemoryCapability() command
executes 'query-dump-guest-memory-capability' command and returns
early if QEMU doesn't know the command. Well, the command was
introduced in QEMU release 2.0 (specifically in commit
v2.0.0-rc0~43^2~16) and since the minimum required version is
2.11.0 we can be sure that command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-22 07:00:44 +02:00
Michal Privoznik
8534008c36 qemuMonitorJSONGetMigrationParams: Don't return early on CommandNotFound
The qemuMonitorJSONGetMigrationParams() function executes
'query-migrate-parameters' command and returns early if QEMU
doesn't know the command. Well, the command was introduced in
QEMU release 2.4 (specifically in commit v2.4.0-rc0~147^2~3) and
since the minimum required version is 2.11.0 we can be sure that
the command will always exist.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-22 07:00:44 +02:00
Michal Privoznik
7ce6a2f30e qemumigparamstest: Drop "unsupported" test case
The aim of "unsupported" test case is to check whether our code
handles 'CommandNotFound' error returned for
'query-migrate-parameters' monitor command. Well, the command is
pretty old and every QEMU that we are dealing with supports it.
Thus this test case is useless. Drop it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-22 07:00:44 +02:00
Dmitrii Shcherbakov
a2c40900ed news: Add PCI VPD parser & capability notes
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2021-10-21 17:34:15 +01:00
Dmitrii Shcherbakov
fab3513bf0 Add PCI VPD Capability Documentation
Describes the format of the newly added VPD capability and gives and
example for a real-world device.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2021-10-21 17:34:04 +01:00
Dmitrii Shcherbakov
3954378d06 Add PCI VPD Capability Support
* XML serialization and deserialization of PCI VPD;
* PCI VPD capability flags added and used in relevant places;
* XML to XML tests for the added capability.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2021-10-21 17:34:04 +01:00
Dmitrii Shcherbakov
38003e7551 Add PCI VPD-related helper functions to virpci
Add helper functions to virpci to provide means of checking for a VPD
file presence and for VPD resource retrieval using the PCI VPD parser.

The added test assesses the basic functionality of VPD retrieval while
the full parser is tested by virpcivpdtest.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2021-10-21 17:34:04 +01:00
Dmitrii Shcherbakov
59c1bc3a0e Add a PCI/PCIe device VPD Parser
Add support for deserializing the binary PCI/PCIe VPD format and storing
results in memory.

The VPD format is specified in "I.3. VPD Definitions" in PCI specs
(2.2+) and "6.28.1 VPD Format" PCIe 4.0. As section 6.28 in PCIe 4.0
notes, the PCI Local Bus and PCIe VPD formats are binary compatible
and PCIe 4.0 merely started incorporating what was already present in
PCI specs.

Linux kernel exposes a binary blob in the VPD format via sysfs since
v2.6.26 (commit 94e6108803469a37ee1e3c92dafdd1d59298602f) which requires
a parser to interpret.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
2021-10-21 17:34:04 +01:00
Ján Tomko
deb4971e96 NEWS: document virtiofs hotplug
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-10-21 18:15:20 +02:00
Andrea Bolognani
2772162316 conf: Add new/free functions for virDomainIOMMUDef
This will make it possible to limit changes to a single spot
later on, and is also just an overall nicer way to create and
destroy objects.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-20 16:53:09 +02:00
Andrea Bolognani
1fb84247b6 conf: Add IOMMU support to virDomainDeviceDefCopy()
There doesn't seem to be a reason for IOMMUs not to be handled
by this function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-20 16:53:07 +02:00
Andrea Bolognani
1cb48b00b5 qemu: Make qemuBuildVirtioDevProps() const correct
This involves a bit of a hack, but is overall preferable to
forcing callers to pass non-const devdata as argument.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-20 16:53:05 +02:00
Andrea Bolognani
8e3d58f245 qemu: Make qemuBuildDeviceAddressProps() const correct
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-20 16:53:04 +02:00
Andrea Bolognani
ea1a436cb5 conf: Make virDomainDeviceInfoFormat() const correct
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-20 16:53:01 +02:00
Andrea Bolognani
d2872fc47f tests: Add replies for QEMU 6.2.0 on aarch64
These were generated using a QEMU binary built from commit
v6.1.0-1552-g362534a643

Notably, this causes the arguments of -device to be generated
in JSON format.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-20 16:52:45 +02:00
Michal Privoznik
f3ab818984 rpc: Temporarily stop accept()-ing new clients on EMFILE
This commit is related to 5de203f879 which I pushed a few days
ago. While that commit prioritized closing clients socket over
the rest of I/O process, this one goes one step further and
temporarily suspends processing new connection requests.

A brief recapitulation of the problem:

1) assume that libvirt is at the top of RLIMIT_NOFILE (that is no
   new FDs can be opened).

2) we have a client trying to connect to a UNIX/TCP socket

Because of 2) our event loop sees POLLIN on the socket and thus
calls virNetServerServiceAccept(). But since no new FDs can be
opened (because of 1)) the request is not handled and we will get
the same event on next iteration. The poll() will exit
immediately because there is an event on the socket.  Thus we end
up in an endless loop.

To break the loop and stop burning CPU cycles we can stop
listening for events on the socket and set up a timer tho enable
listening again after some time (I chose 5 seconds because of no
obvious reason).

There's another area where we play with temporarily suspending
accept() of new clients - when a client disconnects and we check
max_clients against number of current clients. Problem here is
that max_clients can be orders of magnitude larger than
RLIMIT_NOFILE but more importantly, what this code considers
client disconnect is not equal to closing client's FD.
A client disconnecting means that the corresponding client
structure is removed from the internal list of clients. Closing
of the client's FD is done from event loop - asynchronously.

To avoid this part stepping on the toes of my fix, let's make the
code NOP if socket timer (as described above) is active.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-10-20 16:25:22 +02:00