From nobody Tue Feb 10 01:31:47 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612600417; cv=none; d=zohomail.com; s=zohoarc; b=hr6IQ57unCeubUukPwdVKq9YMW4g7XNDI7b49rMkNpgkLk0iw5qO42dB9quF7Usx+ya5fginqjy5ngnrL9yrnCH74Yb5Wqj65pX9creHyWVyajObBRVlH37FWycqyPmjn867Zx1agsGb/Ymmk4P5Nn5H5WFzyw9fCn8sOLHTB00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600417; 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=c14x4+MYYUJHh+D6L+2h3HQWyxFseIncqH2lWm8K4Lw=; b=DzH9HVssJIBGT5DDsmLMF7zG2IqEkgcTNdzm4/sESSfI9BcXQO/UMiVBQ+66HMoNi+iJZaxplZUplvAVr591WsH90lPClE9EO921I525zS9QKC08/1EQoFfmVmeqTAQtKfub2FLLkGA/1Ai6FDq4Ywy0Mja0MItUrBhPce7ydCU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612600417159703.9827671604106; Sat, 6 Feb 2021 00:33:37 -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-292-5Fmiz_pWNsyPn02FO5KZoA-1; Sat, 06 Feb 2021 03:33:34 -0500 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 1A6221005501; Sat, 6 Feb 2021 08:33:29 +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 EBC4E6E512; Sat, 6 Feb 2021 08:33:28 +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 B375057DF9; Sat, 6 Feb 2021 08:33:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1168XDH6004685 for ; Sat, 6 Feb 2021 03:33:13 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2F29660C77; Sat, 6 Feb 2021 08:33:13 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DCC960C76 for ; Sat, 6 Feb 2021 08:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600416; 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=c14x4+MYYUJHh+D6L+2h3HQWyxFseIncqH2lWm8K4Lw=; b=EzFm+FUctFAju5G6AQOOUU/HnGV3X04QaelMTv+3BpK2XUTZDmBlj/vKbE58TLNGWsKB0h HNzHY/GrJQWxqhwJ3Es69sfGLdRoultTxP2+499AGDYU9XtsZrzJycTn4dlW3le643jQOv csY2LR96BCwK3ZvxTsmaAVZN6zOzvZ8= X-MC-Unique: 5Fmiz_pWNsyPn02FO5KZoA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/40] qemuDomainGetPreservedMounts: Refactor to return NULL-terminated string lists Date: Sat, 6 Feb 2021 09:32:26 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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) Content-Type: text/plain; charset="utf-8" Refactor the handling of internals so that NULL-terminated lists are always returned. Signed-off-by: Peter Krempa --- src/qemu/qemu_namespace.c | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 35fe177bef..27a78c86e4 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -108,7 +108,7 @@ qemuDomainGetPreservedMountPath(virQEMUDriverConfigPtr = cfg, * a) save all FSs mounted under /dev to @devPath * b) generate backup path for all the entries in a) * - * Any of the return pointers can be NULL. + * Any of the return pointers can be NULL. Both arrays are NULL-terminated. * * Returns 0 on success, -1 otherwise (with error reported) */ @@ -119,18 +119,20 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr c= fg, char ***devSavePath, size_t *ndevPath) { - char **paths =3D NULL, **mounts =3D NULL; - size_t i, j, nmounts; + g_auto(GStrv) mounts =3D NULL; + size_t nmounts =3D 0; + g_auto(GStrv) paths =3D NULL; + g_auto(GStrv) savePaths =3D NULL; + size_t i; - if (virFileGetMountSubtree(QEMU_PROC_MOUNTS, "/dev", - &mounts, &nmounts) < 0) - goto error; + if (ndevPath) + *ndevPath =3D 0; - if (!nmounts) { - if (ndevPath) - *ndevPath =3D 0; + if (virFileGetMountSubtree(QEMU_PROC_MOUNTS, "/dev", &mounts, &nmounts= ) < 0) + return -1; + + if (nmounts =3D=3D 0) return 0; - } /* There can be nested mount points. For instance * /dev/shm/blah can be a mount point and /dev/shm too. It @@ -142,7 +144,8 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg, * just the first element. Think about it. */ for (i =3D 1; i < nmounts; i++) { - j =3D i + 1; + size_t j =3D i + 1; + while (j < nmounts) { char *c =3D STRSKIP(mounts[j], mounts[i]); @@ -155,32 +158,33 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr c= fg, } } - paths =3D g_new0(char *, nmounts); + /* mounts may not be NULL-terminated at this point, but we convert it = into + * 'paths' which is NULL-terminated */ - for (i =3D 0; i < nmounts; i++) { - if (!(paths[i] =3D qemuDomainGetPreservedMountPath(cfg, vm, mounts= [i]))) - goto error; + paths =3D g_new0(char *, nmounts + 1); + + for (i =3D 0; i < nmounts; i++) + paths[i] =3D g_steal_pointer(&mounts[i]); + + if (devSavePath) { + savePaths =3D g_new0(char *, nmounts + 1); + + for (i =3D 0; i < nmounts; i++) { + if (!(savePaths[i] =3D qemuDomainGetPreservedMountPath(cfg, vm= , paths[i]))) + return -1; + } } if (devPath) - *devPath =3D mounts; - else - virStringListFreeCount(mounts, nmounts); + *devPath =3D g_steal_pointer(&paths); if (devSavePath) - *devSavePath =3D paths; - else - virStringListFreeCount(paths, nmounts); + *devSavePath =3D g_steal_pointer(&savePaths); if (ndevPath) *ndevPath =3D nmounts; return 0; - - error: - virStringListFreeCount(mounts, nmounts); - virStringListFreeCount(paths, nmounts); - return -1; } --=20 2.29.2