From nobody Mon May 13 13:22:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632146469; cv=none; d=zohomail.com; s=zohoarc; b=XbcR3jvwaLYtCyq4eJ0RN/78CWV4+WJ4l637O1Qo5jJo8u5ybqS2XmPLMZDJbbXn7dlHqZb/qOVuSyz4DRJKr4LdZ0EPQKc4QslGgdObvdWt0inWQVLoTkd1bParwWZcyeyKlF5DgJV79bQryJjoB/I7lxlD8a/XY/6CjQaK7e0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632146469; h=Content-Type:Content-Transfer-Encoding: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=Qb2IIFkAA0dCd0Sn6d+pSWWJIdKwma6uLGB0t3LH9/w=; b=jpfePudbOly6MfG5od/WyS92DEYKXmW7SjM/TQpWI9FtEL2gUGeZFlAPjOljNIpHEXgGPPm/kS6lNYm58qGJQAu+PQJi0W5D0CqYKbaaBovzql0FcOVNz21epNkRbRKgwgaXIyZBOMIGNN+QR3ObG6Xvaqssvy1+XMxVsA6vdQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632146469180711.6236552726987; Mon, 20 Sep 2021 07:01:09 -0700 (PDT) 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-270-dKmmkhKZM9al4_TKgDxeCg-1; Mon, 20 Sep 2021 10:01:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 62B1A1800D41; Mon, 20 Sep 2021 14:01:00 +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 41FD75DA2D; Mon, 20 Sep 2021 14:01:00 +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 D7F774EA30; Mon, 20 Sep 2021 14:00:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18KE0nSP010606 for ; Mon, 20 Sep 2021 10:00:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 02A546060F; Mon, 20 Sep 2021 14:00:49 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B60260938 for ; Mon, 20 Sep 2021 14:00:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632146468; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=Qb2IIFkAA0dCd0Sn6d+pSWWJIdKwma6uLGB0t3LH9/w=; b=U91V8zSykKPXJ4E6YXzGrjcELdJvGKIYmmRYavPXx2SXJok2OOxrDMzSrGB7Gb0RVLnGba xXfxvo9c6B6vZBXjlhkP+Jcod1bbCi+IcxS36VAVl+pFNOjbRbWi3Bk/evCyqbI5xeSPtN tsZ40qUevrbi1teHqCKWAMEP2NcmbQw= X-MC-Unique: dKmmkhKZM9al4_TKgDxeCg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/4] util: virdevmapper: Sanitize use of macros for buffer size Date: Mon, 20 Sep 2021 16:00:43 +0200 Message-Id: <226efd9b37b2ad951e09bd7a0480458203bfe7f8.1632146397.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.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.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632146489499100003 Content-Type: text/plain; charset="utf-8" There are two distinct uses of an arbitrary buffers size when querying the device mapper. One is related to loading the /proc/devices file, while the other is used as buffer for ioctls to the devmapper. Split up the macros used here so that it's clear that they are not meant for the same thing. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virdevmapper.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 2c4c2df999..301c8f3ba7 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -42,12 +42,13 @@ VIR_LOG_INIT("util.virdevmapper"); # define PROC_DEVICES "/proc/devices" +# define PROC_DEVICES_BUF_SIZE (16 * 1024) # define DM_NAME "device-mapper" # define DEV_DM_DIR "/dev/" DM_DIR # define CONTROL_PATH DEV_DM_DIR "/" DM_CONTROL_NODE -# define BUF_SIZE (16 * 1024) -G_STATIC_ASSERT(BUF_SIZE > sizeof(struct dm_ioctl)); +# define VIR_DEVMAPPER_IOCTL_BUF_SIZE_INCREMENT (16 * 1024) +G_STATIC_ASSERT(VIR_DEVMAPPER_IOCTL_BUF_SIZE_INCREMENT > sizeof(struct dm_= ioctl)); static int @@ -60,7 +61,7 @@ virDevMapperGetMajor(unsigned int *major) if (!virFileExists(CONTROL_PATH)) return -2; - if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0) + if (virFileReadAll(PROC_DEVICES, PROC_DEVICES_BUF_SIZE, &buf) < 0) return -1; lines =3D g_strsplit(buf, "\n", 0); @@ -92,7 +93,7 @@ virDevMapperGetMajor(unsigned int *major) static void * virDMIoctl(int controlFD, int cmd, struct dm_ioctl *dm, char **buf) { - size_t bufsize =3D BUF_SIZE; + size_t bufsize =3D VIR_DEVMAPPER_IOCTL_BUF_SIZE_INCREMENT; reread: *buf =3D g_new0(char, bufsize); @@ -113,7 +114,7 @@ virDMIoctl(int controlFD, int cmd, struct dm_ioctl *dm,= char **buf) memcpy(dm, *buf, sizeof(struct dm_ioctl)); if (dm->flags & DM_BUFFER_FULL_FLAG) { - bufsize +=3D BUF_SIZE; + bufsize +=3D VIR_DEVMAPPER_IOCTL_BUF_SIZE_INCREMENT; VIR_FREE(*buf); goto reread; } --=20 2.31.1 From nobody Mon May 13 13:22:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632146469; cv=none; d=zohomail.com; s=zohoarc; b=PwBS9XleJPF5+ZCLVaPSgLa4MZZ0Wmo8RvnXPUeC9clRhL29fvibc2d/uQ8Rs3v1/egDP7DjVUx3EA6vce7chBlOgXHrozCRq/yiS+mYX8Yd3Mogn2esv/tKeUTUh/T6Y3juXvOcWyJqjlVo/XWJUyE4N8VCIxwm0CBTSjOlAC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632146469; h=Content-Type:Content-Transfer-Encoding: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=/tJZtVWpMjjpZvz0ZdK/TzlWQ/Ayng+m/wBRoOOiCLs=; b=O1GyVMTp0E5oOCqjjN5rKqChjM976JenqCBH0skw7WFK0a0vx7QtmaAvmC35N4ULHZO4irKXyzqJ76gPZMG+Hq8qjNg+0GctlsRvxs0jikbzBE5PCC3BWQmmwnuB1LYdbYofqn4mvMRrAlSvwPSsBcNbdiceDS1EIj31mDA2w7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 16321464696181023.6815135986219; Mon, 20 Sep 2021 07:01:09 -0700 (PDT) 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-529-gMysD8xrNYWxoUx5e8S7Nw-1; Mon, 20 Sep 2021 10:01:01 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 802D310168C7; Mon, 20 Sep 2021 14:00:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62D8760938; Mon, 20 Sep 2021 14:00:53 +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 2D3751805986; Mon, 20 Sep 2021 14:00:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18KE0oLW010617 for ; Mon, 20 Sep 2021 10:00:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1AD3B60938; Mon, 20 Sep 2021 14:00:50 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65F066060F for ; Mon, 20 Sep 2021 14:00:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632146468; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=/tJZtVWpMjjpZvz0ZdK/TzlWQ/Ayng+m/wBRoOOiCLs=; b=NFN118bNSVas4w2TndTDG/jS4Iw+UDdVrNL0f6Ht5QJug0SOf/38+lwqa4v+7oMXfiOCZO zTeL6FxrvmAOnfAWifaLf+NbM/8ZmF4q6llg5Y4sXDpHCbCIrxKfMjkxnF8VljjLqpD8EH QWUqu9JpHHoFifeHR3zG+1U+MC2LcBM= X-MC-Unique: gMysD8xrNYWxoUx5e8S7Nw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/4] virDevMapperGetTargets: Use a linked list as return type Date: Mon, 20 Sep 2021 16:00:44 +0200 Message-Id: <8ce6e38ec2946294daedc5d1aba7d689283aa45a.1632146397.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632146490126100005 Content-Type: text/plain; charset="utf-8" Of the two callers one simply iterates over the returned paths and the second one appends the returned paths to another linked list. Simplify all of this by directly returning a linked list. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_cgroup.c | 11 ++++++----- src/qemu/qemu_namespace.c | 9 +++------ src/util/virdevmapper.c | 38 +++++++++++++++++--------------------- src/util/virdevmapper.h | 2 +- tests/qemuhotplugmock.c | 10 ++++------ 5 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 6d4a82b3cd..471cbc3b8f 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -38,6 +38,7 @@ #include "virnuma.h" #include "virdevmapper.h" #include "virutil.h" +#include "virglibutil.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -60,8 +61,8 @@ qemuSetupImagePathCgroup(virDomainObj *vm, { qemuDomainObjPrivate *priv =3D vm->privateData; int perms =3D VIR_CGROUP_DEVICE_READ; - g_auto(GStrv) targetPaths =3D NULL; - size_t i; + g_autoptr(virGSListString) targetPaths =3D NULL; + GSList *n; int rv; if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICE= S)) @@ -94,10 +95,10 @@ qemuSetupImagePathCgroup(virDomainObj *vm, return -1; } - for (i =3D 0; targetPaths && targetPaths[i]; i++) { - rv =3D virCgroupAllowDevicePath(priv->cgroup, targetPaths[i], perm= s, false); + for (n =3D targetPaths; n; n =3D n->next) { + rv =3D virCgroupAllowDevicePath(priv->cgroup, n->data, perms, fals= e); - virDomainAuditCgroupPath(vm, priv->cgroup, "allow", targetPaths[i], + virDomainAuditCgroupPath(vm, priv->cgroup, "allow", n->data, virCgroupGetDevicePermsString(perms), rv); if (rv < 0) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 728d77fc61..f1aaca86b1 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -251,8 +251,7 @@ qemuDomainSetupDisk(virStorageSource *src, if (!(tmpPath =3D virPCIDeviceAddressGetIOMMUGroupDev(&next->n= vme->pciAddr))) return -1; } else { - g_auto(GStrv) targetPaths =3D NULL; - GStrv tmp; + GSList *targetPaths; if (virStorageSourceIsEmpty(next) || !virStorageSourceIsLocalStorage(next)) { @@ -270,10 +269,8 @@ qemuDomainSetupDisk(virStorageSource *src, return -1; } - if (targetPaths) { - for (tmp =3D targetPaths; *tmp; tmp++) - *paths =3D g_slist_prepend(*paths, g_steal_pointer(tmp= )); - } + if (targetPaths) + *paths =3D g_slist_concat(g_slist_reverse(targetPaths), *p= aths); } *paths =3D g_slist_prepend(*paths, g_steal_pointer(&tmpPath)); diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 301c8f3ba7..e42324fd19 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -36,6 +36,7 @@ # include "virstring.h" # include "virfile.h" # include "virlog.h" +# include "virglibutil.h" # define VIR_FROM_THIS VIR_FROM_STORAGE @@ -217,18 +218,16 @@ virDMSanitizepath(const char *path) static int virDevMapperGetTargetsImpl(int controlFD, const char *path, - char ***devPaths_ret, + GSList **devPaths, unsigned int ttl) { g_autofree char *sanitizedPath =3D NULL; g_autofree char *buf =3D NULL; struct dm_ioctl dm; struct dm_target_deps *deps =3D NULL; - g_auto(GStrv) devPaths =3D NULL; size_t i; memset(&dm, 0, sizeof(dm)); - *devPaths_ret =3D NULL; if (ttl =3D=3D 0) { errno =3D ELOOP; @@ -258,24 +257,17 @@ virDevMapperGetTargetsImpl(int controlFD, return -1; } - devPaths =3D g_new0(char *, deps->count + 1); for (i =3D 0; i < deps->count; i++) { - devPaths[i] =3D g_strdup_printf("/dev/block/%u:%u", - major(deps->dev[i]), - minor(deps->dev[i])); - } - - for (i =3D 0; i < deps->count; i++) { - g_auto(GStrv) tmpPaths =3D NULL; + char *curpath =3D g_strdup_printf("/dev/block/%u:%u", + major(deps->dev[i]), + minor(deps->dev[i])); - if (virDevMapperGetTargetsImpl(controlFD, devPaths[i], &tmpPaths, = ttl - 1) < 0) - return -1; + *devPaths =3D g_slist_prepend(*devPaths, curpath); - if (virStringListMerge(&devPaths, &tmpPaths) < 0) + if (virDevMapperGetTargetsImpl(controlFD, curpath, devPaths, ttl -= 1) < 0) return -1; } - *devPaths_ret =3D g_steal_pointer(&devPaths); return 0; } @@ -283,11 +275,10 @@ virDevMapperGetTargetsImpl(int controlFD, /** * virDevMapperGetTargets: * @path: devmapper target - * @devPaths: returned string list of devices + * @devPaths: filled in by a GSList containing the paths * * For given @path figure out its targets, and store them in - * @devPaths array. Note, @devPaths is a string list so it's NULL - * terminated. + * @devPaths. * * If @path is not a devmapper device, @devPaths is set to NULL and * success is returned. @@ -301,10 +292,11 @@ virDevMapperGetTargetsImpl(int controlFD, */ int virDevMapperGetTargets(const char *path, - char ***devPaths) + GSList **devPaths) { VIR_AUTOCLOSE controlFD =3D -1; const unsigned int ttl =3D 32; + g_autoptr(virGSListString) paths =3D NULL; /* Arbitrary limit on recursion level. A devmapper target can * consist of devices or yet another targets. If that's the @@ -321,7 +313,11 @@ virDevMapperGetTargets(const char *path, return -1; } - return virDevMapperGetTargetsImpl(controlFD, path, devPaths, ttl); + if (virDevMapperGetTargetsImpl(controlFD, path, &paths, ttl) < 0) + return -1; + + *devPaths =3D g_slist_reverse(g_steal_pointer(&paths)); + return 0; } @@ -346,7 +342,7 @@ virIsDevMapperDevice(const char *dev_name) int virDevMapperGetTargets(const char *path G_GNUC_UNUSED, - char ***devPaths G_GNUC_UNUSED) + GSlist **devPaths G_GNUC_UNUSED) { errno =3D ENOSYS; return -1; diff --git a/src/util/virdevmapper.h b/src/util/virdevmapper.h index 834900692e..4d8d3ccdb8 100644 --- a/src/util/virdevmapper.h +++ b/src/util/virdevmapper.h @@ -24,7 +24,7 @@ int virDevMapperGetTargets(const char *path, - char ***devPaths) G_GNUC_NO_INLINE; + GSList **devPaths) G_GNUC_NO_INLINE; bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1); diff --git a/tests/qemuhotplugmock.c b/tests/qemuhotplugmock.c index d1fc50c5f0..3b5f858044 100644 --- a/tests/qemuhotplugmock.c +++ b/tests/qemuhotplugmock.c @@ -54,16 +54,14 @@ qemuDomainGetUnplugTimeout(virDomainObj *vm) int virDevMapperGetTargets(const char *path, - char ***devPaths) + GSList **devPaths) { *devPaths =3D NULL; if (STREQ(path, "/dev/mapper/virt")) { - *devPaths =3D g_new0(char *, 4); - (*devPaths)[0] =3D g_strdup("/dev/block/8:0"); /* /dev/sda */ - (*devPaths)[1] =3D g_strdup("/dev/block/8:16"); /* /dev/sdb */ - (*devPaths)[2] =3D g_strdup("/dev/block/8:32"); /* /dev/sdc */ - (*devPaths)[3] =3D NULL; + *devPaths =3D g_slist_prepend(*devPaths, g_strdup("/dev/block/8:32= ")); /* /dev/sdc */ + *devPaths =3D g_slist_prepend(*devPaths, g_strdup("/dev/block/8:16= ")); /* /dev/sdb */ + *devPaths =3D g_slist_prepend(*devPaths, g_strdup("/dev/block/8:0"= )); /* /dev/sda */ } return 0; --=20 2.31.1 From nobody Mon May 13 13:22:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632146468; cv=none; d=zohomail.com; s=zohoarc; b=n0u3bLckY+dlFV8d92QiT3dp2TL9r7NIyz4MW51tVpUSXVwzkyW6LhRGrjPu7vBj+v/CtGHrKjisH48BAJkJa+0DEJAtR5gSNVgxm4E0NmcmMU0O7VhuaYr3sNevDfjvoiN6ePbBdjibGOyhHt6Ya94+7Y13XyVa7g0R+HT3Z1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632146468; h=Content-Type:Content-Transfer-Encoding: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=br4UnyF0iYHjhjK+PKN1e7pi+1nXLhx57GEmdCEoyf4=; b=hHZv3gvCDTvnVwlPpAPQysF7/vDAUevccfXUMtTSzoPK+H7Jdd5VRc9efoiqSGIelMWQtNQYShSfG14Cad1y24F5bi41ehRJf2twYJtd+NFwlkfsw7g/ii/Pzaza9rjZD64WtDlBmBMVpcTP1mnyR+4ODWpPRnaR7PlRWG+126E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632146468466385.2787419260402; Mon, 20 Sep 2021 07:01:08 -0700 (PDT) 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-551-h_B0h3nEOb2gugG7vzx-Qw-1; Mon, 20 Sep 2021 10:01:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44F39A40C7; Mon, 20 Sep 2021 14:01:00 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A6EB19724; Mon, 20 Sep 2021 14:01:00 +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 DC7D71805989; Mon, 20 Sep 2021 14:00:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18KE0pBc010630 for ; Mon, 20 Sep 2021 10:00:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A6D36060F; Mon, 20 Sep 2021 14:00:51 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FBC960938 for ; Mon, 20 Sep 2021 14:00:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632146467; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=br4UnyF0iYHjhjK+PKN1e7pi+1nXLhx57GEmdCEoyf4=; b=Wh8kYPWsaBbRTY1qwutH/HW5OZazp+AkWlpqhOuxzKJqR0KU4En4noym4dxqQ1c4YcBuIi D2ehcfDqULgQk2SxkkEeedBnxDS1Zl6J6yzcW+LrwCASrse/qJo/vnlsJtlzzQacy/H496 GQXFZADYIkWGmw1ciwlYcPVW1R0w21w= X-MC-Unique: h_B0h3nEOb2gugG7vzx-Qw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/4] util: virstring: Remove unused 'virStringListMerge' Date: Mon, 20 Sep 2021 16:00:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632146488458100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virstring.c | 35 ----------------------------------- src/util/virstring.h | 3 --- 3 files changed, 39 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ace35d709f..25ee21463c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3298,7 +3298,6 @@ virStringHasControlChars; virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; -virStringListMerge; virStringMatch; virStringMatchesNameSuffix; virStringParsePort; diff --git a/src/util/virstring.c b/src/util/virstring.c index f416fed3c5..cee56debca 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -35,41 +35,6 @@ VIR_LOG_INIT("util.string"); -/** - * virStringListMerge: - * @dst: a NULL-terminated array of strings to expand - * @src: a NULL-terminated array of strings - * - * Merges @src into @dst. Upon successful return from this - * function, @dst is resized to $(dst + src) elements and @src is - * freed. - * - * Returns 0 on success, -1 otherwise. - */ -int -virStringListMerge(char ***dst, - char ***src) -{ - size_t dst_len, src_len, i; - - if (!src || !*src) - return 0; - - dst_len =3D g_strv_length(*dst); - src_len =3D g_strv_length(*src); - - VIR_REALLOC_N(*dst, dst_len + src_len + 1); - - for (i =3D 0; i <=3D src_len; i++) - (*dst)[i + dst_len] =3D (*src)[i]; - - /* Don't call g_strfreev() as it would free strings in - * @src. */ - VIR_FREE(*src); - return 0; -} - - /* Like strtol, but produce an "int" result, and check more carefully. Return 0 upon success; return -1 to indicate failure. When END_PTR is NULL, the byte after the final valid digit must be NUL. diff --git a/src/util/virstring.h b/src/util/virstring.h index ca81889c9b..45f07ddd7a 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -22,9 +22,6 @@ #define VIR_INT64_STR_BUFLEN 21 -int virStringListMerge(char ***dst, - char ***src); - int virStrToLong_i(char const *s, char **end_ptr, int base, --=20 2.31.1 From nobody Mon May 13 13:22:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1632146472; cv=none; d=zohomail.com; s=zohoarc; b=lRs6lVQ1x/JJV/WvEbidz/8ofoACFwcKLsFzcW/hJcnDnfjiSAgmh63az82B5mOt5YTM5tG1+15yA4mqmAlMcXW4Kf9QYTNlRg7x53owhrpxwEzocTuKpcQRHXRarajCZNiAEmDitk55JInkkCvMhNni8lfCDVcL/rQYP6ax4Pw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632146472; h=Content-Type:Content-Transfer-Encoding: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=iliMfcwun2X823I2gukS59Vje/vC2XJn/92loLMcn2A=; b=aZ00AJjL5TrCk1qFY6v2HdUTrThXptLJ/mBl2nFk/PwuXq4Lu8jGVGkjDkmsKsAkrKo2ldLreTZtXCS2Bk4nkE0RJ6MdTGlY80v8aGk9FOhjzJaWhMurtoue7SugcUR+euhIa09xh2YuRBkEMywrvliRYtnDnT1RnagDBLZIRV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1632146472655729.6712927668492; Mon, 20 Sep 2021 07:01:12 -0700 (PDT) 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-44-bPKjX0rdMWmI5-LMo7crMg-1; Mon, 20 Sep 2021 10:01:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEFFF8E506C; Mon, 20 Sep 2021 14:01:03 +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 CB2126B55A; Mon, 20 Sep 2021 14:01:03 +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 892BC4EA38; Mon, 20 Sep 2021 14:01:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18KE0qWt010637 for ; Mon, 20 Sep 2021 10:00:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3EA046060F; Mon, 20 Sep 2021 14:00:52 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99E8D60938 for ; Mon, 20 Sep 2021 14:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632146471; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=iliMfcwun2X823I2gukS59Vje/vC2XJn/92loLMcn2A=; b=irlcfZi+XgqJwIXTu4hQJhf/x2dV0k5Ouh6twA2RCjISwydQFfKEUlQRAEHYQ4jH90xFKu kdHU8PTfNDlUecXgdthfoZ7m3e8eCN5JDK5WX/CJhrIdPJKF+HpYke5zVPzkH25mx+Z7O8 BjGkG08AhuCYryIJySjY7Sjj2A9jtWU= X-MC-Unique: bPKjX0rdMWmI5-LMo7crMg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/4] qemuMonitorJSONGetStatus: Refactor cleanup Date: Mon, 20 Sep 2021 16:00:46 +0200 Message-Id: <7403b79ec236100a9f6fd4eca8677ac439624b73.1632146397.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1632146494586100001 Content-Type: text/plain; charset="utf-8" Use g_autofree for the JSON values to remove cleanup label and ret variable. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_monitor_json.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8d3c4031a6..37e9c05d27 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1710,10 +1710,9 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon, bool *running, virDomainPausedReason *reason) { - int ret =3D -1; const char *status; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValue *data; if (reason) @@ -1723,17 +1722,17 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon, return -1; if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; + return -1; if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) - goto cleanup; + return -1; data =3D virJSONValueObjectGetObject(reply, "return"); if (virJSONValueObjectGetBoolean(data, "running", running) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("query-status reply was missing running state")); - goto cleanup; + return -1; } if ((status =3D virJSONValueObjectGetString(data, "status"))) { @@ -1743,12 +1742,7 @@ qemuMonitorJSONGetStatus(qemuMonitor *mon, VIR_DEBUG("query-status reply was missing status details"); } - ret =3D 0; - - cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; + return 0; } --=20 2.31.1