[PATCH 0/2] lxc: Couple of almost trivial fixes

*** BLURB HERE *** Michal Prívozník (2): lxc: Make lxcCreateHostdevDef() less versatile lxc: Fix access to hostdev capabilities src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_hostdev.c | 4 ++-- src/lxc/lxc_native.c | 14 +++++--------- 3 files changed, 8 insertions(+), 12 deletions(-) -- 2.39.2

Usually, we want a function to be as reusable as possible. But in this specific case, when it's used just once we don't need that. The lxcCreateHostdevDef() function is meant to create a hostdev. The first argument selects the hostdev mode (caps/subsys) and the second argument selects the type of hostdev (NET/STORAGE/MISC). But because of how the function is written, it's impossible to create a subsys hostdev as the function sets hostdev->source.caps.type, regardless of mode. So the @mode argument can be dropped. Then, the function is called from one place and one place only. And in there, VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET is passed for @type so we can drop that argument too. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/lxc/lxc_native.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index d311f5a5ad..0ae208ef11 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -375,18 +375,16 @@ lxcCreateNetDef(const char *type, } static virDomainHostdevDef * -lxcCreateHostdevDef(int mode, int type, const char *data) +lxcCreateHostdevDef(const char *data) { virDomainHostdevDef *hostdev = virDomainHostdevDefNew(); if (!hostdev) return NULL; - hostdev->mode = mode; - hostdev->source.caps.type = type; - - if (type == VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET) - hostdev->source.caps.u.net.ifname = g_strdup(data); + hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES; + hostdev->source.caps.type = VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET; + hostdev->source.caps.u.net.ifname = g_strdup(data); return hostdev; } @@ -457,9 +455,7 @@ lxcAddNetworkDefinition(virDomainDef *def, lxcNetworkParseData *data) _("Missing 'link' attribute for NIC")); goto error; } - if (!(hostdev = lxcCreateHostdevDef(VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES, - VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET, - data->link))) + if (!(hostdev = lxcCreateHostdevDef(data->link))) goto error; /* This still requires the user to manually setup the vlan interface -- 2.39.2

In a few places, where a capabilities <hostdev/> is processed, a wrong union member is access: def->source.subsys.type instead of def->source.caps.type. Fortunately, both union members have .type as the very first member so no real harm is done. Nevertheless, we should access the correct union member. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_hostdev.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 60b961dcb5..86dcd880e8 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1788,7 +1788,7 @@ virLXCControllerSetupHostdevCaps(virDomainDef *vmDef, virDomainHostdevDef *def, virSecurityManager *securityDriver) { - switch (def->source.subsys.type) { + switch (def->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: return virLXCControllerSetupHostdevCapsStorage(vmDef, def, diff --git a/src/lxc/lxc_hostdev.c b/src/lxc/lxc_hostdev.c index d18d61cb19..8fe02a4276 100644 --- a/src/lxc/lxc_hostdev.c +++ b/src/lxc/lxc_hostdev.c @@ -85,7 +85,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, break; case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: - switch (dev->source.subsys.type) { + switch (dev->source.caps.type) { case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: @@ -93,7 +93,7 @@ int virLXCPrepareHostDevices(virLXCDriver *driver, default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported hostdev type %1$s"), - virDomainHostdevSubsysTypeToString(dev->source.subsys.type)); + virDomainHostdevSubsysTypeToString(dev->source.caps.type)); return -1; } break; -- 2.39.2

On a Tuesday in 2023, Michal Privoznik wrote:
*** BLURB HERE ***
Michal Prívozník (2): lxc: Make lxcCreateHostdevDef() less versatile lxc: Fix access to hostdev capabilities
src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_hostdev.c | 4 ++-- src/lxc/lxc_native.c | 14 +++++--------- 3 files changed, 8 insertions(+), 12 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (2)
-
Ján Tomko
-
Michal Privoznik