From nobody Tue Nov 26 08:52:18 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1582516543; cv=none; d=zohomail.com; s=zohoarc; b=Alb+djKuqB/ldqiq5125h/liqQspvvQLH6wulTAQgcxfybiECtcUVV3xwZh8YjNM1LUd3RzBEzelbWsPxR1NoypeG/HyxWcNPPOLHCeTod55DnBiWnS/qhE/OoPTGdj+3AsT60hycklLI1XyCIs81QtaC6JzBV2ldn1hj8A7zeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582516543; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NEzyGFnFGJhU2DqYENBZi2U3oA1MQXU+0z5gPDoFLxA=; b=gb0I0z4VQcZel23XDn63ZCdl8jMTRhb6teF7lvJEH5XQaJ7QOGRTCPeKO5LfxwqxBgwN6NhvZGtwyYtJUkFcdZFPdDTrA3hM0qwHRxDscWd5ZbxS5mGzurv34QgkYsDF8Q3E3S4SBfdLjMlTlz/u/OR7H8Io+KDhQqDtxdXhrnE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1582516543251173.79024240297838; Sun, 23 Feb 2020 19:55:43 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-29-7Kqq93BiNVG0IspL5dmgNw-1; Sun, 23 Feb 2020 22:55:39 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B88708010E8; Mon, 24 Feb 2020 03:55:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E1725C241; Mon, 24 Feb 2020 03:55:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 435A9860E7; Mon, 24 Feb 2020 03:55:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01O3tN5p014610 for ; Sun, 23 Feb 2020 22:55:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 775D3AECB0; Mon, 24 Feb 2020 03:55:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 72FDEAF990 for ; Mon, 24 Feb 2020 03:55:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5547D8007A4 for ; Mon, 24 Feb 2020 03:55:23 +0000 (UTC) Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-314-DgvQiP1GMQGK0yw72gr_oA-1; Sun, 23 Feb 2020 22:55:21 -0500 Received: by mail-qv1-f68.google.com with SMTP id ek2so3621860qvb.0 for ; Sun, 23 Feb 2020 19:55:21 -0800 (PST) Received: from localhost.localdomain ([191.254.236.241]) by smtp.gmail.com with ESMTPSA id 64sm2652392qkd.78.2020.02.23.19.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Feb 2020 19:55:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582516542; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=NEzyGFnFGJhU2DqYENBZi2U3oA1MQXU+0z5gPDoFLxA=; b=Fl207BkbjV/MbQOhmntEFIiK0kwGRSm75cQZUqUQ/+F9UTc7zJvmXP3kxh5C6lbtVNVBqq l3seMJkY72ynmuZMyZYK1prvFsx3X8ZE8/Em0OG1KYNCp34lGpMlTYxM7b509k75e+CUr0 bRUOmKpha53mKkJlgoYWrX3jqLDzsVU= X-MC-Unique: 7Kqq93BiNVG0IspL5dmgNw-1 X-MC-Unique: DgvQiP1GMQGK0yw72gr_oA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kzp07a7vm7Sic0fCCsvaEUeW1Fs/MioMoDp+nfun45U=; b=qLbHUox+InpYJg5YTyEOG8V/wX/+9eaBL7q62MEfYVQsOyLrlwlnoA/A9mF0UTT9fh u8xVHYnfSJaDgmss5yepstjsjXQCpc4CFh6gBLr0mV4PvzZz5I2bDasZtg43FeJ1Q34x VC9DXI3BIdwsWeDJSxx8JB5cjNqk/YBcZ2uFO6WKp9JnmNqpeHFk/w58DnzHtINKRv5Y qLgNLswX0S3aAopRUpta4S3msBhRHBkra1Y5g7/yLFmGXHpvz4fI1Wcd8ToF/eafUH9E PZpMN0xw/EYZmT6ECwNNCP6bUz2LDVxXukUT+jjb+GbLOVOe95i0koS+TYYZB5oEeUMs JhVw== X-Gm-Message-State: APjAAAXKmuy+HhUM9coh42iRzhKS+VkiM2V/780HKxeeqj2t9mJ9adeh QgTGeWSHppGjeM/cvhdCx433wIpc X-Google-Smtp-Source: APXvYqy+zXnmy4XpTzk74QAmXHuXne37xnySbWIThszDFQ5KGE1tgVHTLqDLy26wFedV5/bhry9x4A== X-Received: by 2002:ad4:4e34:: with SMTP id dm20mr43692847qvb.163.1582516520024; Sun, 23 Feb 2020 19:55:20 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v2 3/5] lxc: Replacing default strings definitions by g_autofree statement. Date: Mon, 24 Feb 2020 00:54:28 -0300 Message-Id: <20200224035429.3973-4-jcfaracco@gmail.com> In-Reply-To: <20200224035429.3973-1-jcfaracco@gmail.com> References: <20200224035429.3973-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01O3tN5p014610 X-loop: libvir-list@redhat.com Cc: danielhb413@gmail.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" There are a lots of strings being handled inside some LXC functions. They can be moved to g_autofree to avoid declaring a return value to get proper code cleanups. This commit is changing functions from lxc_{controller,cgroup,fuse} only. Signed-off-by: Julio Faracco --- src/lxc/lxc_cgroup.c | 15 +++---- src/lxc/lxc_controller.c | 96 ++++++++++++++-------------------------- src/lxc/lxc_fuse.c | 23 +++------- 3 files changed, 44 insertions(+), 90 deletions(-) diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 997a5c3dfa..d29b65092a 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -54,8 +54,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr de= f, virCgroupPtr cgroup, virBitmapPtr nodemask) { - int ret =3D -1; - char *mask =3D NULL; + g_autofree char *mask =3D NULL; virDomainNumatuneMemMode mode; =20 if (def->placement_mode !=3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO && @@ -66,21 +65,17 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr = def, =20 if (virDomainNumatuneGetMode(def->numa, -1, &mode) < 0 || mode =3D=3D VIR_DOMAIN_NUMATUNE_MEM_STRICT) { - ret =3D 0; - goto cleanup; + return 0; } =20 if (virDomainNumatuneMaybeFormatNodeset(def->numa, nodemask, &mask, -1) < 0) - goto cleanup; + return -1; =20 if (mask && virCgroupSetCpusetMems(cgroup, mask) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(mask); - return ret; + return 0; } =20 =20 diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 518967ee83..c580b17f5f 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -802,8 +802,7 @@ static int virLXCControllerGetNumadAdvice(virLXCControl= lerPtr ctrl, virBitmapPtr *mask) { virBitmapPtr nodemask =3D NULL; - char *nodeset =3D NULL; - int ret =3D -1; + g_autofree char *nodeset =3D NULL; =20 /* Get the advisory nodeset from numad if 'placement' of * either or is 'auto'. @@ -812,20 +811,17 @@ static int virLXCControllerGetNumadAdvice(virLXCContr= ollerPtr ctrl, nodeset =3D virNumaGetAutoPlacementAdvice(virDomainDefGetVcpus(ctr= l->def), ctrl->def->mem.cur_balloon= ); if (!nodeset) - goto cleanup; + return -1; =20 VIR_DEBUG("Nodeset returned from numad: %s", nodeset); =20 if (virBitmapParse(nodeset, &nodemask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; *mask =3D nodemask; =20 - cleanup: - VIR_FREE(nodeset); - return ret; + return 0; } =20 =20 @@ -1434,9 +1430,8 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr= map, */ static int virLXCControllerSetupUserns(virLXCControllerPtr ctrl) { - char *uid_map =3D NULL; - char *gid_map =3D NULL; - int ret =3D -1; + g_autofree char *uid_map =3D NULL; + g_autofree char *gid_map =3D NULL; =20 /* User namespace is disabled for container */ if (ctrl->def->idmap.nuidmap =3D=3D 0) { @@ -1450,28 +1445,23 @@ static int virLXCControllerSetupUserns(virLXCContro= llerPtr ctrl) if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.uidmap, ctrl->def->idmap.nuidmap, uid_map) < 0) - goto cleanup; + return -1; =20 gid_map =3D g_strdup_printf("/proc/%d/gid_map", ctrl->initpid); =20 if (virLXCControllerSetupUsernsMap(ctrl->def->idmap.gidmap, ctrl->def->idmap.ngidmap, gid_map) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(uid_map); - VIR_FREE(gid_map); - return ret; + return 0; } =20 static int virLXCControllerSetupDev(virLXCControllerPtr ctrl) { - char *mount_options =3D NULL; - char *opts =3D NULL; - char *dev =3D NULL; - int ret =3D -1; + g_autofree char *mount_options =3D NULL; + g_autofree char *opts =3D NULL; + g_autofree char *dev =3D NULL; =20 VIR_DEBUG("Setting up /dev/ for container"); =20 @@ -1488,24 +1478,18 @@ static int virLXCControllerSetupDev(virLXCControlle= rPtr ctrl) opts =3D g_strdup_printf("mode=3D755,size=3D65536%s", mount_options); =20 if (virFileSetupDev(dev, opts) < 0) - goto cleanup; + return -1; =20 if (lxcContainerChown(ctrl->def, dev) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(opts); - VIR_FREE(mount_options); - VIR_FREE(dev); - return ret; + return 0; } =20 static int virLXCControllerPopulateDevices(virLXCControllerPtr ctrl) { size_t i; - int ret =3D -1; - char *path =3D NULL; + g_autofree char *path =3D NULL; const struct { int maj; int min; @@ -1521,7 +1505,7 @@ static int virLXCControllerPopulateDevices(virLXCCont= rollerPtr ctrl) }; =20 if (virLXCControllerSetupDev(ctrl) < 0) - goto cleanup; + return -1; =20 /* Populate /dev/ with a few important bits */ for (i =3D 0; i < G_N_ELEMENTS(devs); i++) { @@ -1534,19 +1518,14 @@ static int virLXCControllerPopulateDevices(virLXCCo= ntrollerPtr ctrl) virReportSystemError(errno, _("Failed to make device %s"), path); - goto cleanup; + return -1; } =20 if (lxcContainerChown(ctrl->def, path) < 0) - goto cleanup; - - VIR_FREE(path); + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 =20 @@ -2202,10 +2181,9 @@ virLXCControllerSetupPrivateNS(void) static int virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) { - char *mount_options =3D NULL; - char *opts =3D NULL; - char *devpts =3D NULL; - int ret =3D -1; + g_autofree char *mount_options =3D NULL; + g_autofree char *opts =3D NULL; + g_autofree char *devpts =3D NULL; gid_t ptsgid =3D 5; =20 VIR_DEBUG("Setting up private /dev/pts"); @@ -2220,7 +2198,7 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl) virReportSystemError(errno, _("Failed to make path %s"), devpts); - goto cleanup; + return -1; } =20 if (ctrl->def->idmap.ngidmap) @@ -2239,26 +2217,20 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctr= l) virReportSystemError(errno, _("Failed to mount devpts on %s"), devpts); - goto cleanup; + return -1; } =20 if (access(ctrl->devptmx, R_OK) < 0) { virReportSystemError(ENOSYS, "%s", _("Kernel does not support private devpts")); - goto cleanup; + return -1; } =20 if ((lxcContainerChown(ctrl->def, ctrl->devptmx) < 0) || (lxcContainerChown(ctrl->def, devpts) < 0)) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(opts); - VIR_FREE(devpts); - VIR_FREE(mount_options); - return ret; + return 0; } =20 =20 @@ -2279,8 +2251,7 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctr= l, char **containerTTYPaths) { size_t i; - int ret =3D -1; - char *ttyHostPath =3D NULL; + g_autofree char *ttyHostPath =3D NULL; =20 for (i =3D 0; i < ctrl->nconsoles; i++) { VIR_DEBUG("Opening tty on private %s", ctrl->devptmx); @@ -2289,20 +2260,17 @@ virLXCControllerSetupConsoles(virLXCControllerPtr c= trl, &containerTTYPaths[i], &ttyHostPath) < 0) { virReportSystemError(errno, "%s", _("Failed to allocate tty")); - goto cleanup; + return -1; } =20 /* Change the owner of tty device to the root user of container */ if (lxcContainerChown(ctrl->def, ttyHostPath) < 0) - goto cleanup; + return -1; =20 VIR_FREE(ttyHostPath); } =20 - ret =3D 0; - cleanup: - VIR_FREE(ttyHostPath); - return ret; + return 0; } =20 =20 diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 44f240a0b5..8cfccdd7e0 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -40,8 +40,7 @@ static const char *fuse_meminfo_path =3D "/meminfo"; =20 static int lxcProcGetattr(const char *path, struct stat *stbuf) { - int res; - char *mempath =3D NULL; + g_autofree char *mempath =3D NULL; struct stat sb; struct fuse_context *context =3D fuse_get_context(); virDomainDefPtr def =3D (virDomainDefPtr)context->private_data; @@ -49,16 +48,12 @@ static int lxcProcGetattr(const char *path, struct stat= *stbuf) memset(stbuf, 0, sizeof(struct stat)); mempath =3D g_strdup_printf("/proc/%s", path); =20 - res =3D 0; - if (STREQ(path, "/")) { stbuf->st_mode =3D S_IFDIR | 0755; stbuf->st_nlink =3D 2; } else if (STREQ(path, fuse_meminfo_path)) { - if (stat(mempath, &sb) < 0) { - res =3D -errno; - goto cleanup; - } + if (stat(mempath, &sb) < 0) + return -errno; =20 stbuf->st_uid =3D def->idmap.uidmap ? def->idmap.uidmap[0].target = : 0; stbuf->st_gid =3D def->idmap.gidmap ? def->idmap.gidmap[0].target = : 0; @@ -71,12 +66,10 @@ static int lxcProcGetattr(const char *path, struct stat= *stbuf) stbuf->st_ctime =3D sb.st_ctime; stbuf->st_mtime =3D sb.st_mtime; } else { - res =3D -ENOENT; + return -ENOENT; } =20 - cleanup: - VIR_FREE(mempath); - return res; + return 0; } =20 static int lxcProcReaddir(const char *path, void *buf, @@ -127,7 +120,7 @@ static int lxcProcReadMeminfo(char *hostpath, virDomain= DefPtr def, { int res; FILE *fd =3D NULL; - char *line =3D NULL; + g_autofree char *line =3D NULL; size_t n; struct virLXCMeminfo meminfo; virBuffer buffer =3D VIR_BUFFER_INITIALIZER; @@ -229,7 +222,6 @@ static int lxcProcReadMeminfo(char *hostpath, virDomain= DefPtr def, memcpy(buf, virBufferCurrentContent(new_meminfo), res); =20 cleanup: - VIR_FREE(line); virBufferFreeAndReset(new_meminfo); VIR_FORCE_FCLOSE(fd); return res; @@ -242,7 +234,7 @@ static int lxcProcRead(const char *path G_GNUC_UNUSED, struct fuse_file_info *fi G_GNUC_UNUSED) { int res =3D -ENOENT; - char *hostpath =3D NULL; + g_autofree char *hostpath =3D NULL; struct fuse_context *context =3D NULL; virDomainDefPtr def =3D NULL; =20 @@ -256,7 +248,6 @@ static int lxcProcRead(const char *path G_GNUC_UNUSED, res =3D lxcProcHostRead(hostpath, buf, size, offset); } =20 - VIR_FREE(hostpath); return res; } =20 --=20 2.20.1