]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lxc: Make lxcCreateHostdevDef() less versatile
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 25 Apr 2023 07:29:53 +0000 (09:29 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 25 Apr 2023 09:00:57 +0000 (11:00 +0200)
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>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/lxc/lxc_native.c

index d311f5a5add4df769a56a54ee01f5e264a3cba35..0ae208ef111d3c77a356018d3df5dc006e000f6d 100644 (file)
@@ -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