[PATCH V5] libxl: adjust handling of libxl_device_nic objects

Jim Fehlig posted 1 patch 2 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20210526201323.13087-1-jfehlig@suse.com
src/libxl/libxl_conf.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
[PATCH V5] libxl: adjust handling of libxl_device_nic objects
Posted by Jim Fehlig 2 years, 11 months ago
libxl objects are supposed to be initialized and disposed. Adjust
libxlMakeNic to use an already initialized object owned by the caller.

Adjust libxlMakeNicList to initialize the list of objects, before they
are filled by libxlMakeNic. The libxl_domain_config object passed to
libxlMakeNicList is owned by the caller and will be disposed with
libxl_domain_config_dispose, which also disposes embedded objects such
as libxl_device_nic.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 src/libxl/libxl_conf.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 91cebf1498..fc4268db01 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -1313,8 +1313,6 @@ libxlMakeNic(virDomainDef *def,
         return -1;
     }
 
-    libxl_device_nic_init(x_nic);
-
     virMacAddrGetRaw(&l_nic->mac, x_nic->mac);
 
     /*
@@ -1502,6 +1500,7 @@ libxlMakeNicList(virDomainDef *def,  libxl_domain_config *d_config)
     size_t nnics = def->nnets;
     libxl_device_nic *x_nics;
     size_t i, nvnics = 0;
+    int ret = -1;
 
     x_nics = g_new0(libxl_device_nic, nnics);
 
@@ -1509,8 +1508,9 @@ libxlMakeNicList(virDomainDef *def,  libxl_domain_config *d_config)
         if (virDomainNetGetActualType(l_nics[i]) == VIR_DOMAIN_NET_TYPE_HOSTDEV)
             continue;
 
+        libxl_device_nic_init(&x_nics[nvnics]);
         if (libxlMakeNic(def, l_nics[i], &x_nics[nvnics], false))
-            goto error;
+            goto out;
         /*
          * The devid (at least right now) will not get initialized by
          * libxl in the setup case but is required for starting the
@@ -1521,18 +1521,14 @@ libxlMakeNicList(virDomainDef *def,  libxl_domain_config *d_config)
 
         nvnics++;
     }
+    ret = 0;
 
+ out:
     VIR_SHRINK_N(x_nics, nnics, nnics - nvnics);
     d_config->nics = x_nics;
     d_config->num_nics = nvnics;
 
-    return 0;
-
- error:
-    for (i = 0; i < nnics; i++)
-        libxl_device_nic_dispose(&x_nics[i]);
-    VIR_FREE(x_nics);
-    return -1;
+    return ret;
 }
 
 int
-- 
2.31.1


Re: [PATCH V5] libxl: adjust handling of libxl_device_nic objects
Posted by Olaf Hering 2 years, 11 months ago
Am Wed, 26 May 2021 14:13:23 -0600
schrieb Jim Fehlig <jfehlig@suse.com>:

> Adjust libxlMakeNicList to initialize the list of objects, before they
> are filled by libxlMakeNic. The libxl_domain_config object passed to
> libxlMakeNicList is owned by the caller and will be disposed with
> libxl_domain_config_dispose, which also disposes embedded objects such
> as libxl_device_nic.
> 
> Signed-off-by: Jim Fehlig <jfehlig@suse.com>

Acked-by: Olaf Hering <olaf@aepfle.de>

Olaf
Re: [PATCH V5] libxl: adjust handling of libxl_device_nic objects
Posted by Jim Fehlig 2 years, 11 months ago
On 5/26/21 2:28 PM, Olaf Hering wrote:
> Am Wed, 26 May 2021 14:13:23 -0600
> schrieb Jim Fehlig <jfehlig@suse.com>:
> 
>> Adjust libxlMakeNicList to initialize the list of objects, before they
>> are filled by libxlMakeNic. The libxl_domain_config object passed to
>> libxlMakeNicList is owned by the caller and will be disposed with
>> libxl_domain_config_dispose, which also disposes embedded objects such
>> as libxl_device_nic.
>>
>> Signed-off-by: Jim Fehlig <jfehlig@suse.com>
> 
> Acked-by: Olaf Hering <olaf@aepfle.de>

Thanks. I'll wait until after the freeze to push it.

Jim