]> xenbits.xensource.com Git - libvirt.git/commitdiff
lxc: replace VIR_ALLOC/REALLOC with g_new0/renew
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 12 May 2020 17:31:16 +0000 (18:31 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Wed, 3 Jun 2020 08:46:58 +0000 (09:46 +0100)
Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
12 files changed:
src/lxc/lxc_cgroup.c
src/lxc/lxc_conf.c
src/lxc/lxc_container.c
src/lxc/lxc_controller.c
src/lxc/lxc_domain.c
src/lxc/lxc_driver.c
src/lxc/lxc_fuse.c
src/lxc/lxc_fuse.h
src/lxc/lxc_hostdev.c
src/lxc/lxc_monitor.c
src/lxc/lxc_native.c
src/lxc/lxc_process.c

index 4ae34925e60cbb7f9e38eda52d50e081fb8d9c96..e71f37d2b18d309d30daa36846fad52135ad4a6b 100644 (file)
@@ -27,7 +27,6 @@
 #include "virfile.h"
 #include "virerror.h"
 #include "virlog.h"
-#include "viralloc.h"
 #include "virstring.h"
 #include "virsystemd.h"
 #include "virutil.h"
index 43e9b7065132cba68faee5748e53119c714c4662..13da6c4586e2c5947361bfa600d8814193f8fdb8 100644 (file)
@@ -29,7 +29,6 @@
 #include "lxc_domain.h"
 #include "virerror.h"
 #include "virconf.h"
-#include "viralloc.h"
 #include "virlog.h"
 #include "viruuid.h"
 #include "configmake.h"
@@ -145,8 +144,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
                                                VIR_DOMAIN_VIRT_LXC);
         type = virDomainVirtTypeToString(VIR_DOMAIN_VIRT_LXC);
         /* Allocate the primary security driver for LXC. */
-        if (VIR_ALLOC(caps->host.secModels) < 0)
-            goto error;
+        caps->host.secModels = g_new0(virCapsHostSecModel, 1);
         caps->host.nsecModels = 1;
         caps->host.secModels[0].model = g_strdup(model);
         caps->host.secModels[0].doi = g_strdup(doi);
index bd78fa7af6e3b0ec58e7c952899caee9bb6123e6..77df49ea751715f9800c7d10ca8fd90e0a590dcc 100644 (file)
@@ -156,8 +156,7 @@ int lxcContainerHasReboot(void)
     }
     cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
 
-    if (VIR_ALLOC_N(stack, stacksize) < 0)
-        return -1;
+    stack = g_new0(char, stacksize);
 
     childStack = stack + stacksize;
 
@@ -2322,8 +2321,7 @@ int lxcContainerStart(virDomainDefPtr def,
     };
 
     /* allocate a stack for the container */
-    if (VIR_ALLOC_N(stack, stacksize) < 0)
-        return -1;
+    stack = g_new0(char, stacksize);
 
     stacktop = stack + stacksize;
 
index 0438d725382967ed36e47011387e2d944b737cfb..467292057435f570e3bb8e634e1f40bfcdc272e2 100644 (file)
@@ -189,13 +189,10 @@ virLXCControllerDriverFree(virLXCDriverPtr driver)
 
 static virLXCControllerPtr virLXCControllerNew(const char *name)
 {
-    virLXCControllerPtr ctrl = NULL;
+    virLXCControllerPtr ctrl = g_new0(virLXCController, 1);
     virLXCDriverPtr driver = NULL;
     g_autofree char *configFile = NULL;
 
-    if (VIR_ALLOC(ctrl) < 0)
-        goto error;
-
     ctrl->timerShutdown = -1;
     ctrl->firstClient = true;
 
@@ -2333,12 +2330,9 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
     int rc = -1;
     int control[2] = { -1, -1};
     int containerhandshake[2] = { -1, -1 };
-    char **containerTTYPaths = NULL;
+    char **containerTTYPaths = g_new0(char *, ctrl->nconsoles);
     size_t i;
 
-    if (VIR_ALLOC_N(containerTTYPaths, ctrl->nconsoles) < 0)
-        goto cleanup;
-
     if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
         virReportSystemError(errno, "%s",
                              _("sockpair failed"));
@@ -2530,14 +2524,12 @@ int main(int argc, char *argv[])
             break;
 
         case 'v':
-            if (VIR_REALLOC_N(veths, nveths+1) < 0)
-                goto cleanup;
+            veths = g_renew(char *, veths, nveths+1);
             veths[nveths++] = g_strdup(optarg);
             break;
 
         case 'c':
-            if (VIR_REALLOC_N(ttyFDs, nttyFDs + 1) < 0)
-                goto cleanup;
+            ttyFDs = g_renew(int, ttyFDs, nttyFDs + 1);
             if (virStrToLong_i(optarg, NULL, 10, &ttyFDs[nttyFDs++]) < 0) {
                 fprintf(stderr, "malformed --console argument '%s'", optarg);
                 goto cleanup;
@@ -2545,8 +2537,7 @@ int main(int argc, char *argv[])
             break;
 
         case 'p':
-            if (VIR_REALLOC_N(passFDs, npassFDs + 1) < 0)
-                goto cleanup;
+            passFDs = g_renew(int, passFDs, npassFDs + 1);
             if (virStrToLong_i(optarg, NULL, 10, &passFDs[npassFDs++]) < 0) {
                 fprintf(stderr, "malformed --passfd argument '%s'", optarg);
                 goto cleanup;
@@ -2661,8 +2652,7 @@ int main(int argc, char *argv[])
         if (ns_fd[i] != -1) {
             if (!ctrl->nsFDs) {/*allocate only once */
                 size_t j = 0;
-                if (VIR_ALLOC_N(ctrl->nsFDs, VIR_LXC_DOMAIN_NAMESPACE_LAST) < 0)
-                    goto cleanup;
+                ctrl->nsFDs = g_new0(int, VIR_LXC_DOMAIN_NAMESPACE_LAST);
                 for (j = 0; j < VIR_LXC_DOMAIN_NAMESPACE_LAST; j++)
                     ctrl->nsFDs[j] = -1;
             }
index b9c3b4eec3dfe683b35ef6edffb7b6d1d7f7c17c..bf82844fd294f554e7c113622c54064cc22d4972 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "lxc_domain.h"
 
-#include "viralloc.h"
 #include "virlog.h"
 #include "virerror.h"
 #include "virstring.h"
@@ -153,10 +152,7 @@ virLXCDomainObjEndJob(virLXCDriverPtr driver G_GNUC_UNUSED,
 static void *
 virLXCDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED)
 {
-    virLXCDomainObjPrivatePtr priv;
-
-    if (VIR_ALLOC(priv) < 0)
-        return NULL;
+    virLXCDomainObjPrivatePtr priv = g_new0(virLXCDomainObjPrivate, 1);
 
     if (virLXCDomainObjInitJob(priv) < 0) {
         g_free(priv);
@@ -208,7 +204,7 @@ static int
 lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
                            void **data)
 {
-    lxcDomainDefPtr lxcDef = NULL;
+    lxcDomainDefPtr lxcDef = g_new0(lxcDomainDef, 1);
     g_autofree xmlNodePtr *nodes = NULL;
     bool uses_lxc_ns = false;
     xmlNodePtr node;
@@ -216,9 +212,6 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
     int n;
     size_t i;
 
-    if (VIR_ALLOC(lxcDef) < 0)
-        return -1;
-
     node = ctxt->node;
     if ((n = virXPathNodeSet("./lxc:namespace/*", ctxt, &nodes)) < 0)
         goto error;
@@ -470,9 +463,8 @@ virLXCDomainSetRunlevel(virDomainObjPtr vm,
     for (nfifos = 0; virInitctlFifos[nfifos]; nfifos++)
         ;
 
-    if (VIR_ALLOC_N(data.st, nfifos) < 0 ||
-        VIR_ALLOC_N(data.st_valid, nfifos) < 0)
-        goto cleanup;
+    data.st = g_new0(struct stat, nfifos);
+    data.st_valid = g_new0(bool, nfifos);
 
     for (i = 0; virInitctlFifos[i]; i++) {
         const char *fifo = virInitctlFifos[i];
index 2c63b0f3a34c64e708085d1a5570eac1691e9894..46a182be45bccc3bfeea00e36ccbf17eef4481c3 100644 (file)
@@ -44,7 +44,6 @@
 #include "lxc_driver.h"
 #include "lxc_native.h"
 #include "lxc_process.h"
-#include "viralloc.h"
 #include "virnetdevbridge.h"
 #include "virnetdevveth.h"
 #include "virnetdevopenvswitch.h"
@@ -1492,8 +1491,7 @@ static int lxcStateInitialize(bool privileged,
         return VIR_DRV_STATE_INIT_SKIPPED;
     }
 
-    if (VIR_ALLOC(lxc_driver) < 0)
-        return VIR_DRV_STATE_INIT_ERROR;
+    lxc_driver = g_new0(virLXCDriver, 1);
     lxc_driver->lockFD = -1;
     if (virMutexInit(&lxc_driver->lock) < 0) {
         g_free(lxc_driver);
@@ -3398,8 +3396,9 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
                              perms) < 0)
         goto cleanup;
 
-    if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks + 1) < 0)
-        goto cleanup;
+    vm->def->disks = g_renew(virDomainDiskDefPtr,
+                             vm->def->disks,
+                             vm->def->ndisks + 1);
 
     file = g_strdup_printf("/dev/%s", def->dst);
 
@@ -3451,8 +3450,9 @@ lxcDomainAttachDeviceNetLive(virLXCDriverPtr driver,
        return -1;
 
     /* preallocate new slot for device */
-    if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets+1) < 0)
-        return -1;
+    vm->def->nets = g_renew(virDomainNetDefPtr,
+                            vm->def->nets,
+                            vm->def->nnets + 1);
 
     /* If appropriate, grab a physical device from the configured
      * network's pool of devices, or resolve bridge device name
@@ -3606,8 +3606,9 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
-        goto cleanup;
+    vm->def->hostdevs = g_renew(virDomainHostdevDefPtr,
+                                vm->def->hostdevs,
+                                vm->def->nhostdevs + 1);
 
     if (virUSBDeviceFileIterate(usb,
                                 virLXCSetupHostUSBDeviceCgroup,
@@ -3675,8 +3676,9 @@ lxcDomainAttachDeviceHostdevStorageLive(virLXCDriverPtr driver,
         goto cleanup;
     }
 
-    if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
-        goto cleanup;
+    vm->def->hostdevs = g_renew(virDomainHostdevDefPtr,
+                                vm->def->hostdevs,
+                                vm->def->nhostdevs + 1);
 
     if (virCgroupAllowDevice(priv->cgroup,
                              'b',
@@ -3754,8 +3756,9 @@ lxcDomainAttachDeviceHostdevMiscLive(virLXCDriverPtr driver,
                              VIR_CGROUP_DEVICE_RWM) < 0)
         goto cleanup;
 
-    if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
-        goto cleanup;
+    vm->def->hostdevs = g_renew(virDomainHostdevDefPtr,
+                                vm->def->hostdevs,
+                                vm->def->nhostdevs + 1);
 
     if (lxcDomainAttachDeviceMknod(driver,
                                    0700 | S_IFBLK,
index c4223f4e06e25804dbf9408da357bca533848729..146629f67e724e00594966dae55f5990e8b8a0c2 100644 (file)
@@ -31,7 +31,6 @@
 #include "virfile.h"
 #include "virbuffer.h"
 #include "virstring.h"
-#include "viralloc.h"
 #include "virutil.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
@@ -284,10 +283,7 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def)
 {
     int ret = -1;
     struct fuse_args args = FUSE_ARGS_INIT(0, NULL);
-    virLXCFusePtr fuse = NULL;
-
-    if (VIR_ALLOC(fuse) < 0)
-        goto cleanup;
+    virLXCFusePtr fuse = g_new0(virLXCFuse, 1);
 
     fuse->def = def;
 
index e9cfd9a20a029c13a19fa1dfc28b33f434e7263d..6bba5669a80989f0df8256ad3974bcf810d24708 100644 (file)
@@ -50,6 +50,7 @@ struct virLXCFuse {
     struct fuse_chan *ch;
     virMutex lock;
 };
+typedef struct virLXCFuse virLXCFuse;
 typedef struct virLXCFuse *virLXCFusePtr;
 
 int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def);
index 6dbed9b9a45f6a352bb36eea8aa44e52ed89de48..609fbe5c87ad518a52140d963b29e2c5d1d4498f 100644 (file)
@@ -22,7 +22,6 @@
 #include <config.h>
 
 #include "lxc_hostdev.h"
-#include "viralloc.h"
 #include "virlog.h"
 #include "virerror.h"
 #include "virhostdev.h"
index e0d03f9d4cff7b58e983edd0fa91453d0b65bdab..96c325af49f379c99595853691d4a7abd4256aa7 100644 (file)
@@ -24,8 +24,6 @@
 #include "lxc_conf.h"
 #include "lxc_monitor_dispatch.h"
 
-#include "viralloc.h"
-
 #include "virerror.h"
 #include "virlog.h"
 #include "virthread.h"
index 622d50639865b7ededd6323d2528634ee7c7a011..9e879e438a7f0284dc0cfc643867d2ec64a93f4d 100644 (file)
@@ -151,9 +151,10 @@ lxcParseFstabLine(char *fstabLine)
     lxcFstabPtr fstab = NULL;
     char **parts;
 
-    if (!fstabLine || VIR_ALLOC(fstab) < 0)
+    if (!fstabLine)
         return NULL;
 
+    fstab = g_new0(lxcFstab, 1);
     if (!(parts = lxcStringSplit(fstabLine)))
         goto error;
 
@@ -561,10 +562,7 @@ lxcNetworkParseDataIPs(const char *name,
 {
     int family = AF_INET;
     char **ipparts = NULL;
-    g_autofree virNetDevIPAddrPtr ip = NULL;
-
-    if (VIR_ALLOC(ip) < 0)
-        return -1;
+    g_autofree virNetDevIPAddrPtr ip = g_new0(virNetDevIPAddr, 1);
 
     if (STREQ(name, "ipv6") || STREQ(name, "ipv6.address"))
         family = AF_INET6;
@@ -820,8 +818,7 @@ lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
         return -1;
     }
 
-    if (VIR_ALLOC_N(def->consoles, nbttys) < 0)
-        return -1;
+    def->consoles = g_new0(virDomainChrDefPtr, nbttys);
 
     def->nconsoles = nbttys;
     for (i = 0; i < nbttys; i++) {
index 998754062c2fb8e34cd33567c7ed28637b0b29b3..f3d57875ad04c67461bda93a6feed7c4603add61 100644 (file)
@@ -550,8 +550,7 @@ virLXCProcessSetupInterfaces(virLXCDriverPtr driver,
     virConnectPtr netconn = NULL;
     virErrorPtr save_err = NULL;
 
-    if (VIR_ALLOC_N(*veths, def->nnets + 1) < 0)
-        return -1;
+    *veths = g_new0(char *, def->nnets + 1);
 
     for (i = 0; i < def->nnets; i++) {
         char *veth = NULL;
@@ -1246,10 +1245,7 @@ int virLXCProcessStart(virConnectPtr conn,
     }
 
     if (!vm->def->resource) {
-        virDomainResourceDefPtr res;
-
-        if (VIR_ALLOC(res) < 0)
-            goto cleanup;
+        virDomainResourceDefPtr res = g_new0(virDomainResourceDef, 1);
 
         res->partition = g_strdup("/machine");
 
@@ -1298,8 +1294,7 @@ int virLXCProcessStart(virConnectPtr conn,
      * and forward I/O between them.
      */
     nttyFDs = vm->def->nconsoles;
-    if (VIR_ALLOC_N(ttyFDs, nttyFDs) < 0)
-        goto cleanup;
+    ttyFDs = g_new0(int, nttyFDs);
     for (i = 0; i < vm->def->nconsoles; i++)
         ttyFDs[i] = -1;