From nobody Sun May 19 00:47:33 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=1612600404; cv=none; d=zohomail.com; s=zohoarc; b=MpsIB6/Uj1X6FhP2Uu27AYtSAQw3OUfyMVvq2VyBzBaQgCVQrmB2YqXkrfK/Xjxloo/mLmm8CjmqihZWVFewgOOOMc95YT8HBg/GDaoGcUZ/JcLNSUXPizzlWWubvqAayLb8FARQwkY5W1/qYO9erBbJWs6LyhFjOUPxpx2DhQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600404; 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=cs7BfB5d8dUSPKO6lzWY6V7Pjnk+72kMaxNG3+B5qjs=; b=GY4DpdWjs131nyGOuzoZvIHjAvE8z/K1j1B6mYJBwHk1Ob5gJX6q3vBjggiFfZul4/mnfJijV1q8y8KdPb5UhMIDM1gaREBqvVAv1Bp/jzWxz4/mM5Tul5qvjMeSzio12C6yI1VsBga1wE4FB2sG5Q5JSCdZqSWkrdy/tnwV52k= 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) header.from= 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 1612600404231399.0608946877461; Sat, 6 Feb 2021 00:33:24 -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-1--5FgI0zoOTqwDZMZYePMBQ-1; Sat, 06 Feb 2021 03:33:20 -0500 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 C2800107ACE3; Sat, 6 Feb 2021 08:33:14 +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 7183C5D9CC; Sat, 6 Feb 2021 08:33:13 +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 BD63118095C9; Sat, 6 Feb 2021 08:33:10 +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 1168X90Q004654 for ; Sat, 6 Feb 2021 03:33:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5CF9A60C76; Sat, 6 Feb 2021 08:33:09 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CA1A60C77 for ; Sat, 6 Feb 2021 08:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600403; 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=cs7BfB5d8dUSPKO6lzWY6V7Pjnk+72kMaxNG3+B5qjs=; b=EwHjFkG8bEx4MtH7PX1tmCfTh91imKKOx2vzjt4yXutiC3BWLemnwzcfzKCEuTh+q2AuRa yVserGZezQM9eO7kY4SUujZe/3R6PNl5Mkq8kiTV9iCIr15VRaP28dZpywcBBCvstPTmXU UOSMEIUsRLdWDf3TRXyaXkxtBOpTUmw= X-MC-Unique: -5FgI0zoOTqwDZMZYePMBQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/40] qemuMonitorJSONObjectProperty: Make 'str' member const Date: Sat, 6 Feb 2021 09:32:23 +0100 Message-Id: <4fb4383f7de82f85cf5e4b3aec4bb0a98e9ef4f4.1612599659.git.pkrempa@redhat.com> 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.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) Content-Type: text/plain; charset="utf-8" The code only reads it. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_monitor_json.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index ba1531fee8..64af758885 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -477,7 +477,7 @@ struct _qemuMonitorJSONObjectProperty { unsigned int ui; unsigned long long ul; double d; - char *str; + const char *str; } val; }; --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600418; cv=none; d=zohomail.com; s=zohoarc; b=jkfjQ98WXdmZFUlroqTUexKdB9qTxB61vsVcOWwoxs1OSs3mFNNvLih6IU34rv8+hjwh57+KFOyGmp+Thl9mh0nuCXC1V4zno31lqMxmGhpNgOnJTwTPWz9+yHuP2ejO6LjyfghlvevtyFW23wKUG6eCMCRv/8I7ak4JQmBIHQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600418; 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=UYIUiwgn1HiEWuwQlgXz8skoHTaZbqMLtK74gr4cRLk=; b=LEIB3omTRQjL3L8r464VEaUocybGjk/QuubJ7ZAeJIYIcSsKF5LpaHF9sOtyL/mtQKygagM7Aj2xYDoabyK0O2YpF4Av2SaYaVt4Ky7PfqUquGQ5UIrPJvjf0WyyvZcaXSq2q5+EFpQAQvfdY2dZPcJAfKCINf+ySSIBKYPRS8g= 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) header.from= 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 1612600418954201.64298636357069; Sat, 6 Feb 2021 00:33:38 -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-479-9w43n0pqNKqPaX6YRPiZsw-1; Sat, 06 Feb 2021 03:33:35 -0500 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 E2F57100CCC2; Sat, 6 Feb 2021 08:33:29 +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 BFCCD62954; Sat, 6 Feb 2021 08:33:29 +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 8907E18095CE; Sat, 6 Feb 2021 08:33:29 +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 1168XAHl004668 for ; Sat, 6 Feb 2021 03:33:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9A55960C77; Sat, 6 Feb 2021 08:33:10 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6B2360C76 for ; Sat, 6 Feb 2021 08:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600418; 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=UYIUiwgn1HiEWuwQlgXz8skoHTaZbqMLtK74gr4cRLk=; b=gagcnFHnm0EIZUNCxqXf0laHDRR3MALdkGkVE2mfqcuQvtSkk1LIp4FIADkvkk7+lp57tP 8uKs/636ZdPZ+9CQJVrqcyFvWa4se1DWEIKZ8lfF/49XdatfxX4Vt/sNY1zY5ESvjFj72+ gAKidmIq3VJbTvoz+BfbI2HtZMs73Rc= X-MC-Unique: 9w43n0pqNKqPaX6YRPiZsw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/40] util: virmacmap: Use g_autofree for virJSONValue Date: Sat, 6 Feb 2021 09:32:24 +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.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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virmacmap.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index e68742de10..0abb6cf580 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -130,7 +130,7 @@ virMacMapLoadFile(virMacMapPtr mgr, const char *file) { g_autofree char *map_str =3D NULL; - virJSONValuePtr map =3D NULL; + g_autoptr(virJSONValue) map =3D NULL; int map_str_len =3D 0; size_t i; int ret =3D -1; @@ -189,7 +189,6 @@ virMacMapLoadFile(virMacMapPtr mgr, ret =3D 0; cleanup: - virJSONValueFree(map); return ret; } @@ -199,14 +198,12 @@ virMACMapHashDumper(void *payload, const char *name, void *data) { - virJSONValuePtr obj =3D virJSONValueNewObject(); - virJSONValuePtr arr =3D NULL; + g_autoptr(virJSONValue) obj =3D virJSONValueNewObject(); + g_autoptr(virJSONValue) arr =3D virJSONValueNewArray(); const char **macs =3D payload; size_t i; int ret =3D -1; - arr =3D virJSONValueNewArray(); - for (i =3D 0; macs[i]; i++) { virJSONValuePtr m =3D virJSONValueNewString(macs[i]); @@ -228,8 +225,6 @@ virMACMapHashDumper(void *payload, ret =3D 0; cleanup: - virJSONValueFree(obj); - virJSONValueFree(arr); return ret; } @@ -238,11 +233,9 @@ static int virMacMapDumpStrLocked(virMacMapPtr mgr, char **str) { - virJSONValuePtr arr; + g_autoptr(virJSONValue) arr =3D virJSONValueNewArray(); int ret =3D -1; - arr =3D virJSONValueNewArray(); - if (virHashForEachSorted(mgr->macs, virMACMapHashDumper, arr) < 0) goto cleanup; @@ -251,7 +244,6 @@ virMacMapDumpStrLocked(virMacMapPtr mgr, ret =3D 0; cleanup: - virJSONValueFree(arr); return ret; } --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600404; cv=none; d=zohomail.com; s=zohoarc; b=exMdgeo4Yp6O/FwBi9bYL0ng2NI2f5HpGeKKYMIsdmKNQkgHJvpxdZ1smZV0gB8CpxAttKq21xnNGwXuYOJdzDWmZkCIwMqMk2L1An6ZXriEGc60s7R6Li9gTTzvw5sfzznjTB3oAKHoqxsJv/11aBMZAZi6d3Kr++3y2JQ5dFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600404; 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=xAgK2bKQXWS1fqFilMHMFrHtptJiI31NpEuuAj/m3MI=; b=YME33L+tdRv+LYh780TDfAzmkOeAeU77rVkYC1Ow8a3x6Fs8L4oZBuxw8C8Xr8+xu5aj8JsuicEqz6DcCwzujtjIweEbMxxOEiLamQoG/yy/WbwXiC5yL/ry3FaDBcc2aTJcr8jpXbLlqAneX3wTtevSUpnd/1z1j8aAMr91dMM= 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) header.from= 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 1612600404301458.8405594616596; Sat, 6 Feb 2021 00:33:24 -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-99-IJXHwouNMSm07RRNoUl93Q-1; Sat, 06 Feb 2021 03:33:20 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEB56100CCC0; Sat, 6 Feb 2021 08:33:14 +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 CC72972FAC; Sat, 6 Feb 2021 08:33:14 +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 AFD564EA69; Sat, 6 Feb 2021 08:33:13 +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 1168XBJj004675 for ; Sat, 6 Feb 2021 03:33:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id E5C0160C77; Sat, 6 Feb 2021 08:33:11 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C68860C76 for ; Sat, 6 Feb 2021 08:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600403; 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=xAgK2bKQXWS1fqFilMHMFrHtptJiI31NpEuuAj/m3MI=; b=N2o8dfHsN7WbFZxrGIOUrRKn2+h9FuIFd4ouhF4Vead1usSjAQyzgBJb2/E4fwX2Tuh7qt +k0HNnTBAm83xUHOAnzsKHF5sB0R231tSLX5xey0Dmfni3m4npUuALniBWTWpmWVXKpGCH 4SrVHi3xz27zitw2SPzqqqr+JP8nfiM= X-MC-Unique: IJXHwouNMSm07RRNoUl93Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/40] util: macmap: Remove unused cleanup labels and 'ret' variables Date: Sat, 6 Feb 2021 09:32:25 +0100 Message-Id: <635863d228a5f6f7652d42193e3d34fb0a570ee6.1612599659.git.pkrempa@redhat.com> 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.11 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" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virmacmap.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index 0abb6cf580..ec0a67b433 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -133,31 +133,28 @@ virMacMapLoadFile(virMacMapPtr mgr, g_autoptr(virJSONValue) map =3D NULL; int map_str_len =3D 0; size_t i; - int ret =3D -1; if (virFileExists(file) && (map_str_len =3D virFileReadAll(file, VIR_MAC_MAP_FILE_SIZE_MAX, &map_str)) < 0) - goto cleanup; + return -1; - if (map_str_len =3D=3D 0) { - ret =3D 0; - goto cleanup; - } + if (map_str_len =3D=3D 0) + return 0; if (!(map =3D virJSONValueFromString(map_str))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid json in file: %s"), file); - goto cleanup; + return -1; } if (!virJSONValueIsArray(map)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Malformed file structure: %s"), file); - goto cleanup; + return -1; } for (i =3D 0; i < virJSONValueArraySize(map); i++) { @@ -169,13 +166,13 @@ virMacMapLoadFile(virMacMapPtr mgr, if (!(domain =3D virJSONValueObjectGetString(tmp, "domain"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing domain")); - goto cleanup; + return -1; } if (!(macs =3D virJSONValueObjectGetArray(tmp, "macs"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing macs")); - goto cleanup; + return -1; } for (j =3D 0; j < virJSONValueArraySize(macs); j++) { @@ -183,13 +180,11 @@ virMacMapLoadFile(virMacMapPtr mgr, const char *mac =3D virJSONValueGetString(macJSON); if (virMacMapAddLocked(mgr, domain, mac) < 0) - goto cleanup; + return -1; } } - ret =3D 0; - cleanup: - return ret; + return 0; } @@ -202,7 +197,6 @@ virMACMapHashDumper(void *payload, g_autoptr(virJSONValue) arr =3D virJSONValueNewArray(); const char **macs =3D payload; size_t i; - int ret =3D -1; for (i =3D 0; macs[i]; i++) { virJSONValuePtr m =3D virJSONValueNewString(macs[i]); @@ -210,22 +204,20 @@ virMACMapHashDumper(void *payload, if (!m || virJSONValueArrayAppend(arr, m) < 0) { virJSONValueFree(m); - goto cleanup; + return -1; } } if (virJSONValueObjectAppendString(obj, "domain", name) < 0 || virJSONValueObjectAppend(obj, "macs", arr) < 0) - goto cleanup; + return -1; arr =3D NULL; if (virJSONValueArrayAppend(data, obj) < 0) - goto cleanup; + return -1; obj =3D NULL; - ret =3D 0; - cleanup: - return ret; + return 0; } @@ -234,17 +226,14 @@ virMacMapDumpStrLocked(virMacMapPtr mgr, char **str) { g_autoptr(virJSONValue) arr =3D virJSONValueNewArray(); - int ret =3D -1; if (virHashForEachSorted(mgr->macs, virMACMapHashDumper, arr) < 0) - goto cleanup; + return -1; if (!(*str =3D virJSONValueToString(arr, true))) - goto cleanup; + return -1; - ret =3D 0; - cleanup: - return ret; + return 0; } --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Sun May 19 00:47:33 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=1612600423; cv=none; d=zohomail.com; s=zohoarc; b=fBt7uIz4Q+bdrABiOLF7ZDj8Fo2674Z8XBLH1vajdSY/sBRC10RZ3/W6Xc+ueFC2tlcNR2oFC3RNNtUaKwZen0wA/uOsmycB8kihlSTZtyRuuYBejOHnXMCtJGa3vFxBis1CDcW6+/yYbhC9HJSGVJ57OLOPllGZUh0Oeovofw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600423; 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=7cYlvZR/0UaQzi3+YMJQKSTm9GdfXawJ/OHxFvx9QSI=; b=gq459LyAKTHHH0GIFD7C4iCgOLWZg7uTqSqs0CbhlUksIrwlxGn/bfyAUxZse3t11Bk2Aqzq/+XN7B4PKWHjjFu+hxQAVqBfQ8yI3vJT0+jM/wHUBQTvgami+kBBLurONMBrWRgQbDujFO0n8HtDkUHa0S+gx1Yp9K5ezLGuIn8= 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) header.from= 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 1612600423940565.2366806563672; Sat, 6 Feb 2021 00:33: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-533-rGXIqFD4NnmCbWeSVBoPjA-1; Sat, 06 Feb 2021 03:33:40 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF224107ACC7; Sat, 6 Feb 2021 08:33:34 +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 9CE3A72FAB; Sat, 6 Feb 2021 08:33:34 +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 6759758078; Sat, 6 Feb 2021 08:33:34 +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 1168XGum004703 for ; Sat, 6 Feb 2021 03:33:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 168F160C78; Sat, 6 Feb 2021 08:33:16 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EE9E60C77 for ; Sat, 6 Feb 2021 08:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600423; 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=7cYlvZR/0UaQzi3+YMJQKSTm9GdfXawJ/OHxFvx9QSI=; b=LnC630YNJZWVLv/C5ueNUGTBQvO71MKy2wcf4zls0rotRfU3FY3H72aecghbMWwxQvV6u+ uBMqvQnq+rfr8eRB58bFgOya6Xpz20sl03my3cnP1RNRzcwJNKp4Jgmfkx3v3qlfmfAD0M iWAwWJ6Bj6Zro7qRPrjKTRNtgbd3L90= X-MC-Unique: rGXIqFD4NnmCbWeSVBoPjA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/40] qemuNamespaceUnlinkPaths: Fix wrong use of iterator variable Date: Sat, 6 Feb 2021 09:32:27 +0100 Message-Id: <53854405b4397bd6cf93a72679b34c6fb30a0e81.1612599659.git.pkrempa@redhat.com> 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.11 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" 'i' is used in both outer and inner loop. Since 'devMountsPath' is now a NULL-terminated list, we can use a GStrv to iterate it; Additionally rewrite the conditional of adding to the 'unlinkPaths' array so that it's more clear what's happening. Fixes: 5c86fbb72d6e90025481db7 Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_namespace.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 27a78c86e4..03cc6379fe 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -1362,14 +1362,20 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm, const char *file =3D paths[i]; if (STRPREFIX(file, QEMU_DEVPREFIX)) { - for (i =3D 0; i < ndevMountsPath; i++) { - if (STREQ(devMountsPath[i], "/dev")) + GStrv mount; + bool inSubmount =3D false; + + for (mount =3D devMountsPath; *mount; mount++) { + if (STREQ(*mount, "/dev")) continue; - if (STRPREFIX(file, devMountsPath[i])) + + if (STRPREFIX(file, *mount)) { + inSubmount =3D true; break; + } } - if (i =3D=3D ndevMountsPath && + if (!inSubmount && virStringListAdd(&unlinkPaths, file) < 0) return -1; } --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600421; cv=none; d=zohomail.com; s=zohoarc; b=B2NnFpJTz5hXjv+nGmBiSThlYvSbHnHC2Q3ClMrOycpPZMK8IcaNv0T0ureCpM0YLl+vw9celSqVTWD5sZdWWtdJ5EonE0eC9gHVE65wEVyH/kAaQNDe1L+wyMOc4y7b8C1XgG83k6qpLcXgFdCwevUqPIj39o8hQ9jqO+5cnYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600421; 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=AyD15jAwVuQ52Q3XuLxT4U3XrN++vCNgZVas49fc6ck=; b=IhSMGB5ggEHqe1+zrRN36zHEWw8yZtkFhcgWruVkGcyOraj3okgDBYSil4olOGJ3fswowjpDlYDiOqTLTQi94vR857HTx3K2LNTHfE+W5SPkiw5mgyBVBWzFHV40M8ee7ht9mRSPeBsZY2+pBTAUu4kDXfUcVtMgUndeDrkHqWs= 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) header.from= 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 1612600421825390.47077198933766; Sat, 6 Feb 2021 00:33:41 -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-215-cpeiw-B5Op-LJzFG_i7i9A-1; Sat, 06 Feb 2021 03:33:38 -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 E86A68030D3; Sat, 6 Feb 2021 08:33:32 +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 C40645C290; Sat, 6 Feb 2021 08:33:32 +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 8BE7958074; Sat, 6 Feb 2021 08:33:32 +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 1168XH7R004709 for ; Sat, 6 Feb 2021 03:33:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3348660C78; Sat, 6 Feb 2021 08:33:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84A1E60C77 for ; Sat, 6 Feb 2021 08:33:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600420; 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=AyD15jAwVuQ52Q3XuLxT4U3XrN++vCNgZVas49fc6ck=; b=IjW18GmusYC7VXSP/JqtFlppUcGHpdZmCTN4DXKFxOYGoPEYMLM8teEHc+fAcKupWf9gya 1xh7Ch7gkoTaqoE4JM/qZj6h7dQoQmxwf/NmTZaR2IovCFlzVDrt2DFvZWf7R2dPsEcGWj dDYB0G49WJuU9Uiy7HAP9gt76axt2HE= X-MC-Unique: cpeiw-B5Op-LJzFG_i7i9A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/40] qemuNamespaceUnlinkPaths: Fix inconsistent cleanup handling Date: Sat, 6 Feb 2021 09:32:28 +0100 Message-Id: <62da6382801f3bddec3ca9798a712aaed0b270c5.1612599659.git.pkrempa@redhat.com> 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.16 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" Some code paths return -1 directly while others jump to 'cleanup' which cleans the list of mounts. Since qemuDomainGetPreservedMounts now returns a NULL-terminated list, convert devMountsPath to g_auto(GStrv) and remove the cleanup altoghether; Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_namespace.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index 03cc6379fe..af08b3e055 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -1341,11 +1341,9 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm, virQEMUDriverPtr driver =3D priv->driver; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; g_auto(GStrv) unlinkPaths =3D NULL; - char **devMountsPath =3D NULL; - size_t ndevMountsPath =3D 0; + g_auto(GStrv) devMountsPath =3D NULL; size_t npaths; size_t i; - int ret =3D -1; npaths =3D virStringListLength(paths); if (!npaths) @@ -1353,10 +1351,8 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm, cfg =3D virQEMUDriverGetConfig(driver); - if (qemuDomainGetPreservedMounts(cfg, vm, - &devMountsPath, NULL, - &ndevMountsPath) < 0) - goto cleanup; + if (qemuDomainGetPreservedMounts(cfg, vm, &devMountsPath, NULL, NULL) = < 0) + return -1; for (i =3D 0; i < npaths; i++) { const char *file =3D paths[i]; @@ -1387,10 +1383,7 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm, unlinkPaths) < 0) return -1; - ret =3D 0; - cleanup: - virStringListFreeCount(devMountsPath, ndevMountsPath); - return ret; + return 0; } --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600424; cv=none; d=zohomail.com; s=zohoarc; b=nqkeCiaZSLFZj6ZQzn9RaBY3CXHyQ3eVQXeT70oCUGZb0pmaWBg36UqhljtfpJVAk98njN2xn1ig/lLj+3UgKtYX4ppCxm4QW8clERbzpSlf9sVATPzKSxckRYvo+aedepNbjgqi17+4FF1IX2xJwJB4/hmJ//zNfPWzBRnw7A8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600424; 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=6JHo4q5yREiYCsamHL2B2ht/YFLAOoOqPuS+JASMAEQ=; b=jKRth7UU/n1UuzsnHZuh5gV329SFz1g+Se8D+5QOPCTosxaPoqLd+IDIS4LSzh7mnxNmn/Q1zvAlTtWdIlIb7bDZ6xljgAOfmjazzcaVWcwCVid3XcUmIKC0dE418k9CBV6cBSijq//cZj8Mhu7vC9F1+NY/4CNOHkyY/WKpsWw= 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) header.from= 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 1612600424303361.43494733851264; Sat, 6 Feb 2021 00:33:44 -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-34-QAxhikQONoa7JmFLZJuWmw-1; Sat, 06 Feb 2021 03:33:41 -0500 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 BDE2C107ACF8; Sat, 6 Feb 2021 08:33:35 +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 8F8B619C47; Sat, 6 Feb 2021 08:33:35 +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 552A71809C8F; Sat, 6 Feb 2021 08:33:35 +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 1168XIs9004719 for ; Sat, 6 Feb 2021 03:33:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4D0C160C78; Sat, 6 Feb 2021 08:33:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E10160C77 for ; Sat, 6 Feb 2021 08:33:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600423; 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=6JHo4q5yREiYCsamHL2B2ht/YFLAOoOqPuS+JASMAEQ=; b=gWN7/eGVNzgMjJ8pUvirClJKPm9n4vLAsvFDO01sBnJaCIJNruGpoYLbeZpLe8MHUL44jb zCuOGObbwEaZIIDeYNSr+lByVrBr7eKgGNDLFuu04MQ4oBtQwTogt4fBhIJcV+B2bbCvEN sWdozMwxsN3LtxlSI0Z03fOvR6Fzmto= X-MC-Unique: QAxhikQONoa7JmFLZJuWmw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/40] util: Add helpers for auto-freeing GSList filled with strings Date: Sat, 6 Feb 2021 09:32:29 +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.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) Content-Type: text/plain; charset="utf-8" glib's 'g_autoslist()' doesn't support lists of 'char *' strings. Add a type alias 'virGSListString' so that we can register an 'autoptr' function for it for simple usage of GSList with strings. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 4 ++++ src/util/meson.build | 1 + src/util/virglibutil.c | 27 +++++++++++++++++++++++++++ src/util/virglibutil.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 src/util/virglibutil.c create mode 100644 src/util/virglibutil.h diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0636b0d8c9..c2270208e4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2304,6 +2304,10 @@ virGICVersionTypeFromString; virGICVersionTypeToString; +# util/virglibutil.h +virGSListStringFree; + + # util/virhash.h virHashAddEntry; virHashAtomicNew; diff --git a/src/util/meson.build b/src/util/meson.build index e89d32c33d..0080825bd0 100644 --- a/src/util/meson.build +++ b/src/util/meson.build @@ -35,6 +35,7 @@ util_sources =3D [ 'virgdbus.c', 'virgettext.c', 'virgic.c', + 'virglibutil.c', 'virhash.c', 'virhashcode.c', 'virhook.c', diff --git a/src/util/virglibutil.c b/src/util/virglibutil.c new file mode 100644 index 0000000000..8d93e27fc9 --- /dev/null +++ b/src/util/virglibutil.c @@ -0,0 +1,27 @@ +/* + * virglibutil.c: Utilities helping with glib usage + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "virglibutil.h" + +void +virGSListStringFree(GSList *l) +{ + g_slist_free_full(l, g_free); +} diff --git a/src/util/virglibutil.h b/src/util/virglibutil.h new file mode 100644 index 0000000000..2bff69f22f --- /dev/null +++ b/src/util/virglibutil.h @@ -0,0 +1,28 @@ +/* + * virglibutil.h: Utilities helping with glib usage + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "internal.h" + +void +virGSListStringFree(GSList *l); + +typedef GSList virGSListString; + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virGSListString, virGSListStringFree); --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600427; cv=none; d=zohomail.com; s=zohoarc; b=PhPSLT/fUW5YA3GbFOmnRQT3cc7vld8nBHm3ymU7m0YUcBWNPo/cMqVW6A3/5XP8vEONK3ufAnaXtjnowvsBQtrwEJ+9DuiOsaxtyhf//2VxM34Ge/Sg0dN2wjzY0TwcdCaUYrggf4dSx98u6gHyctDsls4mIiTIQDY/WNvK8IY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600427; 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=GE8rBUeKtseU0b7BwKql9VaDqmUw4A+XslcC2ke5IBY=; b=foQUXj+klB4YGtRSlhzT0+DfJzOS+unb3y7Bvpn5RXVwGL78Cyy8dPY1WQxix75yu5jT5BYazCJuFGV4lR/6yMu65hVYAoLvhUqogR22yodbLQ2ytiuKthUGou5zov5jChX7f6ohst7qrNtJTBf4HJ++4iUk2SWS/LWG6BFVZv8= 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) header.from= 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 1612600427366944.1314648171281; Sat, 6 Feb 2021 00:33:47 -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-593-J6Tr8VNJMqq29jNfnGf5oQ-1; Sat, 06 Feb 2021 03:33:44 -0500 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 94C178030D7; Sat, 6 Feb 2021 08:33:37 +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 708775D9D7; Sat, 6 Feb 2021 08:33:37 +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 3AA7D1809C91; Sat, 6 Feb 2021 08:33:37 +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 1168XJc7004732 for ; Sat, 6 Feb 2021 03:33:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id D052860C78; Sat, 6 Feb 2021 08:33:19 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8D3D60C77 for ; Sat, 6 Feb 2021 08:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600426; 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=GE8rBUeKtseU0b7BwKql9VaDqmUw4A+XslcC2ke5IBY=; b=O+zKtBdSbEJvnDyljRyK90TxOxP8foBgt+EBK4CQIzA7tJ6e6zC5WdUDfj2VczMEeS1TWW HcTgntvQfDUmNAL7OZQMn9SswVb/GGCio5+WlIAjKu2zovFTeSOUp7/yrt6PUQf9XCA/bV nIk6fLALsq/FhGHMIclKyxiQtuc0Uss= X-MC-Unique: J6Tr8VNJMqq29jNfnGf5oQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/40] qemu: namespace: Don't use 'virStringListAdd' inside loops Date: Sat, 6 Feb 2021 09:32:30 +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.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) Content-Type: text/plain; charset="utf-8" 'virStringListAdd' calculates the string list length on every invocation so constructing a string list using it results in O(n^2) complexity. Use a GSList which has cheap insertion and iteration and doesn't need failure handling. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_namespace.c | 202 ++++++++++++++++++-------------------- 1 file changed, 98 insertions(+), 104 deletions(-) diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index af08b3e055..e8f205cfdd 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -40,6 +40,7 @@ #include "virlog.h" #include "virstring.h" #include "virdevmapper.h" +#include "virglibutil.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -190,7 +191,7 @@ qemuDomainGetPreservedMounts(virQEMUDriverConfigPtr cfg, static int qemuDomainPopulateDevices(virQEMUDriverConfigPtr cfg, - char ***paths) + GSList **paths) { const char *const *devices =3D (const char *const *) cfg->cgroupDevice= ACL; size_t i; @@ -199,8 +200,7 @@ qemuDomainPopulateDevices(virQEMUDriverConfigPtr cfg, devices =3D defaultDeviceACL; for (i =3D 0; devices[i]; i++) { - if (virStringListAdd(paths, devices[i]) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_strdup(devices[i])); } return 0; @@ -237,7 +237,7 @@ qemuDomainSetupDev(virSecurityManagerPtr mgr, static int qemuDomainSetupDisk(virStorageSourcePtr src, - char ***paths) + GSList **paths) { virStorageSourcePtr next; bool hasNVMe =3D false; @@ -252,6 +252,7 @@ qemuDomainSetupDisk(virStorageSourcePtr src, return -1; } else { g_auto(GStrv) targetPaths =3D NULL; + GStrv tmp; if (virStorageSourceIsEmpty(next) || !virStorageSourceIsLocalStorage(next)) { @@ -269,22 +270,19 @@ qemuDomainSetupDisk(virStorageSourcePtr src, return -1; } - if (virStringListMerge(paths, &targetPaths) < 0) - return -1; + for (tmp =3D targetPaths; *tmp; tmp++) + *paths =3D g_slist_prepend(*paths, g_steal_pointer(tmp)); } - if (virStringListAdd(paths, tmpPath) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_steal_pointer(&tmpPath)); } /* qemu-pr-helper might require access to /dev/mapper/control. */ - if (src->pr && - virStringListAdd(paths, QEMU_DEVICE_MAPPER_CONTROL_PATH) < 0) - return -1; + if (src->pr) + *paths =3D g_slist_prepend(*paths, g_strdup(QEMU_DEVICE_MAPPER_CON= TROL_PATH)); - if (hasNVMe && - virStringListAdd(paths, QEMU_DEV_VFIO) < 0) - return -1; + if (hasNVMe) + *paths =3D g_slist_prepend(*paths, g_strdup(QEMU_DEV_VFIO)); return 0; } @@ -292,7 +290,7 @@ qemuDomainSetupDisk(virStorageSourcePtr src, static int qemuDomainSetupAllDisks(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -313,20 +311,19 @@ static int qemuDomainSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev, bool hotplug, - char ***paths) + GSList **paths) { g_autofree char *path =3D NULL; if (qemuDomainGetHostdevPath(hostdev, &path, NULL) < 0) return -1; - if (path && virStringListAdd(paths, path) < 0) - return -1; + if (path) + *paths =3D g_slist_prepend(*paths, g_steal_pointer(&path)); if (qemuHostdevNeedsVFIO(hostdev) && - (!hotplug || !qemuDomainNeedsVFIO(vm->def)) && - virStringListAdd(paths, QEMU_DEV_VFIO) < 0) - return -1; + (!hotplug || !qemuDomainNeedsVFIO(vm->def))) + *paths =3D g_slist_prepend(*paths, g_strdup(QEMU_DEV_VFIO)); return 0; } @@ -334,7 +331,7 @@ qemuDomainSetupHostdev(virDomainObjPtr vm, static int qemuDomainSetupAllHostdevs(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -353,19 +350,21 @@ qemuDomainSetupAllHostdevs(virDomainObjPtr vm, static int qemuDomainSetupMemory(virDomainMemoryDefPtr mem, - char ***paths) + GSList **paths) { if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM && mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM) return 0; - return virStringListAdd(paths, mem->nvdimmPath); + *paths =3D g_slist_prepend(*paths, g_strdup(mem->nvdimmPath)); + + return 0; } static int qemuDomainSetupAllMemories(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -385,7 +384,7 @@ qemuDomainSetupChardev(virDomainDefPtr def G_GNUC_UNUSE= D, virDomainChrDefPtr dev, void *opaque) { - char ***paths =3D opaque; + GSList **paths =3D opaque; const char *path =3D NULL; if (!(path =3D virDomainChrSourceDefGetPath(dev->source))) @@ -396,13 +395,14 @@ qemuDomainSetupChardev(virDomainDefPtr def G_GNUC_UNU= SED, dev->source->data.nix.listen) return 0; - return virStringListAdd(paths, path); + *paths =3D g_slist_prepend(*paths, g_strdup(path)); + return 0; } static int qemuDomainSetupAllChardevs(virDomainObjPtr vm, - char ***paths) + GSList **paths) { VIR_DEBUG("Setting up chardevs"); @@ -419,12 +419,11 @@ qemuDomainSetupAllChardevs(virDomainObjPtr vm, static int qemuDomainSetupTPM(virDomainTPMDefPtr dev, - char ***paths) + GSList **paths) { switch (dev->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: - if (virStringListAdd(paths, dev->data.passthrough.source.data.file= .path) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_strdup(dev->data.passthrough.= source.data.file.path)); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: @@ -439,7 +438,7 @@ qemuDomainSetupTPM(virDomainTPMDefPtr dev, static int qemuDomainSetupAllTPMs(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -457,20 +456,21 @@ qemuDomainSetupAllTPMs(virDomainObjPtr vm, static int qemuDomainSetupGraphics(virDomainGraphicsDefPtr gfx, - char ***paths) + GSList **paths) { const char *rendernode =3D virDomainGraphicsGetRenderNode(gfx); if (!rendernode) return 0; - return virStringListAdd(paths, rendernode); + *paths =3D g_slist_prepend(*paths, g_strdup(rendernode)); + return 0; } static int qemuDomainSetupAllGraphics(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -488,12 +488,14 @@ qemuDomainSetupAllGraphics(virDomainObjPtr vm, static int qemuDomainSetupInput(virDomainInputDefPtr input, - char ***paths) + GSList **paths) { const char *path =3D virDomainInputDefGetPath(input); - if (path && virStringListAdd(paths, path) < 0) - return -1; + if (!path) + return 0; + + *paths =3D g_slist_prepend(*paths, g_strdup(path)); return 0; } @@ -501,7 +503,7 @@ qemuDomainSetupInput(virDomainInputDefPtr input, static int qemuDomainSetupAllInputs(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -518,12 +520,11 @@ qemuDomainSetupAllInputs(virDomainObjPtr vm, static int qemuDomainSetupRNG(virDomainRNGDefPtr rng, - char ***paths) + GSList **paths) { switch ((virDomainRNGBackend) rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: - if (virStringListAdd(paths, rng->source.file) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_strdup(rng->source.file)); break; case VIR_DOMAIN_RNG_BACKEND_EGD: @@ -539,7 +540,7 @@ qemuDomainSetupRNG(virDomainRNGDefPtr rng, static int qemuDomainSetupAllRNGs(virDomainObjPtr vm, - char ***paths) + GSList **paths) { size_t i; @@ -557,7 +558,7 @@ qemuDomainSetupAllRNGs(virDomainObjPtr vm, static int qemuDomainSetupLoader(virDomainObjPtr vm, - char ***paths) + GSList **paths) { virDomainLoaderDefPtr loader =3D vm->def->os.loader; @@ -566,17 +567,14 @@ qemuDomainSetupLoader(virDomainObjPtr vm, if (loader) { switch ((virDomainLoader) loader->type) { case VIR_DOMAIN_LOADER_TYPE_ROM: - if (virStringListAdd(paths, loader->path) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_strdup(loader->path)); break; case VIR_DOMAIN_LOADER_TYPE_PFLASH: - if (virStringListAdd(paths, loader->path) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_strdup(loader->path)); - if (loader->nvram && - virStringListAdd(paths, loader->nvram) < 0) - return -1; + if (loader->nvram) + *paths =3D g_slist_prepend(*paths, g_strdup(loader->nvram)= ); break; case VIR_DOMAIN_LOADER_TYPE_NONE: @@ -592,7 +590,7 @@ qemuDomainSetupLoader(virDomainObjPtr vm, static int qemuDomainSetupLaunchSecurity(virDomainObjPtr vm, - char ***paths) + GSList **paths) { virDomainSEVDefPtr sev =3D vm->def->sev; @@ -601,8 +599,7 @@ qemuDomainSetupLaunchSecurity(virDomainObjPtr vm, VIR_DEBUG("Setting up launch security"); - if (virStringListAdd(paths, QEMU_DEV_SEV) < 0) - return -1; + *paths =3D g_slist_prepend(*paths, g_strdup(QEMU_DEV_SEV)); VIR_DEBUG("Set up launch security"); return 0; @@ -611,14 +608,14 @@ qemuDomainSetupLaunchSecurity(virDomainObjPtr vm, static int qemuNamespaceMknodPaths(virDomainObjPtr vm, - const char **paths); + GSList *paths); int qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, virDomainObjPtr vm) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) { VIR_DEBUG("namespaces disabled for domain %s", vm->def->name); @@ -658,7 +655,7 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg, if (qemuDomainSetupLaunchSecurity(vm, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; @@ -1228,20 +1225,19 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodDataP= tr data, static int qemuNamespaceMknodPaths(virDomainObjPtr vm, - const char **paths) + GSList *paths) { qemuDomainObjPrivatePtr priv =3D vm->privateData; virQEMUDriverPtr driver =3D priv->driver; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; char **devMountsPath =3D NULL; size_t ndevMountsPath =3D 0; - size_t npaths =3D 0; qemuNamespaceMknodData data =3D { 0 }; size_t i; int ret =3D -1; + GSList *next; - npaths =3D virStringListLength(paths); - if (npaths =3D=3D 0) + if (!paths) return 0; cfg =3D virQEMUDriverGetConfig(driver); @@ -1253,8 +1249,10 @@ qemuNamespaceMknodPaths(virDomainObjPtr vm, data.driver =3D driver; data.vm =3D vm; - for (i =3D 0; i < npaths; i++) { - if (qemuNamespacePrepareOneItem(&data, cfg, vm, paths[i], + for (next =3D paths; next; next =3D next->next) { + const char *path =3D next->data; + + if (qemuNamespacePrepareOneItem(&data, cfg, vm, path, devMountsPath, ndevMountsPath) < 0) goto cleanup; } @@ -1299,7 +1297,7 @@ qemuNamespaceMknodPaths(virDomainObjPtr vm, static int qemuNamespaceMknodPaths(virDomainObjPtr vm G_GNUC_UNUSED, - const char **paths G_GNUC_UNUSED) + GSList *paths G_GNUC_UNUSED) { virReportSystemError(ENOSYS, "%s", _("Namespaces are not supported on this platform.= ")); @@ -1314,11 +1312,11 @@ static int qemuNamespaceUnlinkHelper(pid_t pid G_GNUC_UNUSED, void *opaque) { - char **paths =3D opaque; - size_t i; + g_autoptr(virGSListString) paths =3D opaque; + GSList *next; - for (i =3D 0; paths[i]; i++) { - const char *path =3D paths[i]; + for (next =3D paths; next; next =3D next->next) { + const char *path =3D next->data; VIR_DEBUG("Unlinking %s", path); if (unlink(path) < 0 && errno !=3D ENOENT) { @@ -1328,25 +1326,22 @@ qemuNamespaceUnlinkHelper(pid_t pid G_GNUC_UNUSED, } } - g_strfreev(paths); return 0; } static int qemuNamespaceUnlinkPaths(virDomainObjPtr vm, - const char **paths) + GSList *paths) { qemuDomainObjPrivatePtr priv =3D vm->privateData; virQEMUDriverPtr driver =3D priv->driver; g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - g_auto(GStrv) unlinkPaths =3D NULL; g_auto(GStrv) devMountsPath =3D NULL; - size_t npaths; - size_t i; + g_autoptr(virGSListString) unlinkPaths =3D NULL; + GSList *next; - npaths =3D virStringListLength(paths); - if (!npaths) + if (!paths) return 0; cfg =3D virQEMUDriverGetConfig(driver); @@ -1354,10 +1349,10 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm, if (qemuDomainGetPreservedMounts(cfg, vm, &devMountsPath, NULL, NULL) = < 0) return -1; - for (i =3D 0; i < npaths; i++) { - const char *file =3D paths[i]; + for (next =3D paths; next; next =3D next->next) { + const char *path =3D next->data; - if (STRPREFIX(file, QEMU_DEVPREFIX)) { + if (STRPREFIX(path, QEMU_DEVPREFIX)) { GStrv mount; bool inSubmount =3D false; @@ -1365,15 +1360,14 @@ qemuNamespaceUnlinkPaths(virDomainObjPtr vm, if (STREQ(*mount, "/dev")) continue; - if (STRPREFIX(file, *mount)) { + if (STRPREFIX(path, *mount)) { inSubmount =3D true; break; } } - if (!inSubmount && - virStringListAdd(&unlinkPaths, file) < 0) - return -1; + if (!inSubmount) + unlinkPaths =3D g_slist_prepend(unlinkPaths, g_strdup(path= )); } } @@ -1391,7 +1385,7 @@ int qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, virStorageSourcePtr src) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1399,7 +1393,7 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, if (qemuDomainSetupDisk(src, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; @@ -1435,7 +1429,7 @@ int qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1446,7 +1440,7 @@ qemuDomainNamespaceSetupHostdev(virDomainObjPtr vm, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; @@ -1468,7 +1462,7 @@ int qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1479,7 +1473,7 @@ qemuDomainNamespaceTeardownHostdev(virDomainObjPtr vm, &paths) < 0) return -1; - if (qemuNamespaceUnlinkPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceUnlinkPaths(vm, paths) < 0) return -1; return 0; @@ -1490,7 +1484,7 @@ int qemuDomainNamespaceSetupMemory(virDomainObjPtr vm, virDomainMemoryDefPtr mem) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1498,7 +1492,7 @@ qemuDomainNamespaceSetupMemory(virDomainObjPtr vm, if (qemuDomainSetupMemory(mem, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; @@ -1509,7 +1503,7 @@ int qemuDomainNamespaceTeardownMemory(virDomainObjPtr vm, virDomainMemoryDefPtr mem) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1517,7 +1511,7 @@ qemuDomainNamespaceTeardownMemory(virDomainObjPtr vm, if (qemuDomainSetupMemory(mem, &paths) < 0) return -1; - if (qemuNamespaceUnlinkPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceUnlinkPaths(vm, paths) < 0) return -1; return 0; @@ -1528,7 +1522,7 @@ int qemuDomainNamespaceSetupChardev(virDomainObjPtr vm, virDomainChrDefPtr chr) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1536,7 +1530,7 @@ qemuDomainNamespaceSetupChardev(virDomainObjPtr vm, if (qemuDomainSetupChardev(vm->def, chr, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; @@ -1547,7 +1541,7 @@ int qemuDomainNamespaceTeardownChardev(virDomainObjPtr vm, virDomainChrDefPtr chr) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1555,7 +1549,7 @@ qemuDomainNamespaceTeardownChardev(virDomainObjPtr vm, if (qemuDomainSetupChardev(vm->def, chr, &paths) < 0) return -1; - if (qemuNamespaceUnlinkPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceUnlinkPaths(vm, paths) < 0) return -1; return 0; @@ -1566,7 +1560,7 @@ int qemuDomainNamespaceSetupRNG(virDomainObjPtr vm, virDomainRNGDefPtr rng) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1574,7 +1568,7 @@ qemuDomainNamespaceSetupRNG(virDomainObjPtr vm, if (qemuDomainSetupRNG(rng, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; @@ -1585,7 +1579,7 @@ int qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm, virDomainRNGDefPtr rng) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1593,7 +1587,7 @@ qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm, if (qemuDomainSetupRNG(rng, &paths) < 0) return -1; - if (qemuNamespaceUnlinkPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceUnlinkPaths(vm, paths) < 0) return -1; return 0; @@ -1604,7 +1598,7 @@ int qemuDomainNamespaceSetupInput(virDomainObjPtr vm, virDomainInputDefPtr input) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1612,7 +1606,7 @@ qemuDomainNamespaceSetupInput(virDomainObjPtr vm, if (qemuDomainSetupInput(input, &paths) < 0) return -1; - if (qemuNamespaceMknodPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceMknodPaths(vm, paths) < 0) return -1; return 0; } @@ -1622,7 +1616,7 @@ int qemuDomainNamespaceTeardownInput(virDomainObjPtr vm, virDomainInputDefPtr input) { - g_auto(GStrv) paths =3D NULL; + g_autoptr(virGSListString) paths =3D NULL; if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) return 0; @@ -1630,7 +1624,7 @@ qemuDomainNamespaceTeardownInput(virDomainObjPtr vm, if (qemuDomainSetupInput(input, &paths) < 0) return -1; - if (qemuNamespaceUnlinkPaths(vm, (const char **) paths) < 0) + if (qemuNamespaceUnlinkPaths(vm, paths) < 0) return -1; return 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600566; cv=none; d=zohomail.com; s=zohoarc; b=kpL2BZOdUrcOp2RcZ5KRV/6nnBIPxfKXA5CKS7HLejhJSw+zlmDmrw7GanLzFbGYh+fRud8nbpMHJqinkXl3LlesQEVT9vAYWu1Hc9UNsnc9o2I1GhndM4kW1GtUSEPpJte1BrtXbLop9J+0ur2tjYD2Nuoy3szIgAclwXXfJKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600566; 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=E8gIBtONm8chYTud8Eb9jIT4lPlIRmkUqEthfWCyQMA=; b=GjjsVVCK4NCGV6Q5UILUS24NsBsIConvqMHK7JKgeYOgWZOQBYJGJ2bpBlwUeqF8UOU3A/8ujPBPkrocVdI8+elHNeUCPACwWWc6H2HiuoRRRZIZQWsKWINT7sKb8lA2Ro2zoUKJPeA0S7nvCyWRwJgoscVXMVv6jLgmdN0ZDEw= 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) header.from= 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 1612600566204173.2203473101997; Sat, 6 Feb 2021 00:36:06 -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-239-3PMwcYseO0CNzR9GH5lnUw-1; Sat, 06 Feb 2021 03:33:46 -0500 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 635B91DDE5; Sat, 6 Feb 2021 08:33:40 +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 3C90719C47; Sat, 6 Feb 2021 08:33:40 +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 08C5D18089CC; Sat, 6 Feb 2021 08:33:40 +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 1168XLn0004740 for ; Sat, 6 Feb 2021 03:33:21 -0500 Received: by smtp.corp.redhat.com (Postfix) id B3F8060C78; Sat, 6 Feb 2021 08:33:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D4D560C77 for ; Sat, 6 Feb 2021 08:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600565; 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=E8gIBtONm8chYTud8Eb9jIT4lPlIRmkUqEthfWCyQMA=; b=Wzxeyi8G+xfe4MY4kT9vKml8Vb/dbokl8PTJON7++8OLhdbvL68xyA5WrM8V0uoACoY21Z U+XxGf+I4zMzAWgjGFPbwJnqzw349WcrWPuV6NNxbM9V3hTBE0B3xQBwUo05D7XpEvtPsq fK1UASpiALUHhn299UoaoX6rEMKW8eY= X-MC-Unique: 3PMwcYseO0CNzR9GH5lnUw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/40] virHookCall: Don't use 'virStringListAdd' to construct list in loop Date: Sat, 6 Feb 2021 09:32:31 +0100 Message-Id: <4fe135233bd08fee668eb411e2464ab47a0e277c.1612599659.git.pkrempa@redhat.com> 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.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) Content-Type: text/plain; charset="utf-8" 'virStringListAdd' calculates the string list length on every invocation so constructing a string list using it results in O(n^2) complexity. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virhook.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index 05d46f259e..e4e1945225 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -34,6 +34,7 @@ #include "configmake.h" #include "vircommand.h" #include "virstring.h" +#include "virglibutil.h" #define VIR_FROM_THIS VIR_FROM_HOOK @@ -343,11 +344,11 @@ virHookCall(int driver, struct dirent *entry; g_autofree char *path =3D NULL; g_autofree char *dir_path =3D NULL; - g_auto(GStrv) entries =3D NULL; + g_autoptr(virGSListString) entries =3D NULL; const char *drvstr; const char *opstr; const char *subopstr; - size_t i, nentries; + GSList *next; if (output) *output =3D NULL; @@ -433,7 +434,7 @@ virHookCall(int driver, if (!virFileIsExecutable(entry_path)) continue; - virStringListAdd(&entries, entry_path); + entries =3D g_slist_prepend(entries, g_steal_pointer(&entry_path)); } if (ret < 0) @@ -442,18 +443,18 @@ virHookCall(int driver, if (!entries) return script_ret; - nentries =3D virStringListLength((const char **)entries); - qsort(entries, nentries, sizeof(*entries), virStringSortCompare); + entries =3D g_slist_sort(entries, (GCompareFunc) strcmp); - for (i =3D 0; i < nentries; i++) { + for (next =3D entries; next; next =3D next->next) { int entry_ret; const char *entry_input; g_autofree char *entry_output =3D NULL; + const char *filename =3D next->data; /* Get input from previous output */ entry_input =3D (!script_ret && output && !virStringIsEmpty(*output)) ? *output : input; - entry_ret =3D virRunScript(entries[i], id, opstr, + entry_ret =3D virRunScript(filename, id, opstr, subopstr, extra, entry_input, (output) ? &entry_output : NULL); if (entry_ret < script_ret) --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600503; cv=none; d=zohomail.com; s=zohoarc; b=YDva7j5AnR/yzgPfAzi1X/8kSe1jg5mqy7nfw4HZ8aKxuMz9F/rShZ1S3Wm/ogfVFEybRX2OrEVshIDb2PrpnY2DzHOgUq42cDxPwbYCSr5eVHTeGQ9x18aEy8YnY/RgkejT/CBytoiDsp4ekdj4tX4TFLlisfZLGNT9xAisqCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600503; 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=Lh5F4HJ3rrtTRO88dwbVdVAiSG2Bv0JK03NO/oZWEOU=; b=E7hGhe9c2Cto22hhTM1zFCcQySUn92LoHUvwEP5Ds6vSo/O2wN5RLjSHFIgNEmngzMMQ/DRC/XxhoPfYHQV+n0SUdz5Uqh94H8ywYV/2XqnEjNe4FZcI2afsGU9Q7pPdzlLbXEJPZAqpeHY9acSGdUvaNLsFd+vYSW9XNTr2GM0= 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) header.from= 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 161260050385491.60516884745277; Sat, 6 Feb 2021 00:35:03 -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-153-3Tu6kvpqN9aHwG2b1sX8pw-1; Sat, 06 Feb 2021 03:33:49 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15025100CCCF; Sat, 6 Feb 2021 08:33:43 +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 E1E806F447; Sat, 6 Feb 2021 08:33:42 +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 A827018089D4; Sat, 6 Feb 2021 08:33:42 +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 1168XQUm004760 for ; Sat, 6 Feb 2021 03:33:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3EE9360C78; Sat, 6 Feb 2021 08:33:26 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76AB360C77 for ; Sat, 6 Feb 2021 08:33:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600502; 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=Lh5F4HJ3rrtTRO88dwbVdVAiSG2Bv0JK03NO/oZWEOU=; b=huEbUgBQZqLYsTZtAuSLwrZjSfRqU7AW5AFFgPIwOBv+QB1f8zzLTPLjfO9HPXm9Ak6BS+ 6blNx/lSBF6LwKZ2mqcNc7qYwwLZYfuFqv7AIAXa92RcCmseQaot/XvIRnov2mPGu6gtCi QaLQAAIiXlFn1Ha5xsVp0kc2rsuwTTc= X-MC-Unique: 3Tu6kvpqN9aHwG2b1sX8pw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/40] qemuInteropFetchConfigs: Don't use 'virStringListAdd' to construct list Date: Sat, 6 Feb 2021 09:32:32 +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.11 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" 'virHashGetItems' already returns the number of entries which will be considered for addition to the list so we can allocate it to the upper bound upfront rather than growing it in a loop. This avoids the quadratic complexity of 'virStringListAdd'. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_interop_config.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index bcaddda446..9733df7194 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -94,7 +94,9 @@ qemuInteropFetchConfigs(const char *name, g_autofree char *sysLocation =3D virFileBuildPath(QEMU_SYSTEM_LOCATION= , name, NULL); g_autofree char *etcLocation =3D virFileBuildPath(QEMU_ETC_LOCATION, n= ame, NULL); g_autofree virHashKeyValuePairPtr pairs =3D NULL; + size_t npairs; virHashKeyValuePairPtr tmp =3D NULL; + size_t nconfigs =3D 0; *configs =3D NULL; @@ -132,11 +134,13 @@ qemuInteropFetchConfigs(const char *name, * where each filename (as key) has the highest priority full pathname * associated with it. */ - if (virHashSize(files) =3D=3D 0) + if (!(pairs =3D virHashGetItems(files, &npairs, true))) + return -1; + + if (npairs =3D=3D 0) return 0; - if (!(pairs =3D virHashGetItems(files, NULL, true))) - return -1; + *configs =3D g_new0(char *, npairs + 1); for (tmp =3D pairs; tmp->key; tmp++) { const char *path =3D tmp->value; @@ -158,8 +162,7 @@ qemuInteropFetchConfigs(const char *name, continue; } - if (virStringListAdd(configs, path) < 0) - return -1; + (*configs)[nconfigs++] =3D g_strdup(path); } return 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600428; cv=none; d=zohomail.com; s=zohoarc; b=lXgpjjIdZ1is7pfF/GurX3J2ASTjUqDi694juXPo4PzlF8chgfJiaZ/s3dK1JskDTPbyPRxBgptzQncj+qZFFdk1QKLFJyXOENGEJKIkWAC0kyndvZeIcPlrZpm0vnxw7kyS0EIkuhd+vtHNoupxzE3OP7mh/ol4CV97hsdfjHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600428; 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=Q+7klrTFh3e3HipJEUX1v97ptgwmgfEC2kk/stFWHVg=; b=DDdYGBKCltLrL2zBl1X4oaaYK0cfzTmRnSLUW4so9HVjlpfuTduTEtOezWmWe3AxK/ybDCk5XYhhFzsMInUW1oXDY7p11nLjhvtKVJxaRmBKpy/+OVisyO5tVVMaIDv7yemoU7zdE80rYsI7N69MyVZbnX2pJUQ5zJeCMwlrHP0= 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 1612600428674423.0933601741309; Sat, 6 Feb 2021 00:33:48 -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-266-Kihr09xNOXKKusN4Zhb27g-1; Sat, 06 Feb 2021 03:33:45 -0500 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 BF1D9192AB80; Sat, 6 Feb 2021 08:33:39 +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 9CF7A5D9CC; Sat, 6 Feb 2021 08:33:39 +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 3E4625807A; Sat, 6 Feb 2021 08:33:39 +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 1168XRMo004770 for ; Sat, 6 Feb 2021 03:33:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7E75660C78; Sat, 6 Feb 2021 08:33:27 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C574A60C77 for ; Sat, 6 Feb 2021 08:33:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600427; 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=Q+7klrTFh3e3HipJEUX1v97ptgwmgfEC2kk/stFWHVg=; b=UYy5Ojqf3x9VRfR1qGHhTEizBOdkNPbqGqhsCA2TL+e4Kw3/KJ8IA9CcxZ1bcBsiTG6dwc E5lVU8qdaXWdiHlZXdouiay5Xy0vVLL+57z3nAuTj9p/Qi1en5Bw7tb+TLL6R3rZ0oOqjf iJ7selQxbYJNhd/c0hwehGvfgHne+nQ= X-MC-Unique: Kihr09xNOXKKusN4Zhb27g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/40] virCPUDefCheckFeatures: Don't use 'virStringListAdd' to construct list Date: Sat, 6 Feb 2021 09:32:33 +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.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) Content-Type: text/plain; charset="utf-8" We already know the upper bound of items we might need so we can allocate the array upfront and avoid the quadratic complexity of 'virStringListAdd'. In this instance the returned data is kept only temporarily so a potential unused space due to filtered-out entries doesn't impose a long-term burden on memory. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/cpu_conf.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index f98b0a0eb3..1de4c1e417 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -985,21 +985,21 @@ virCPUDefCheckFeatures(virCPUDefPtr cpu, void *opaque, char ***features) { - g_auto(GStrv) list =3D NULL; size_t n =3D 0; size_t i; *features =3D NULL; + if (cpu->nfeatures =3D=3D 0) + return 0; + + *features =3D g_new0(char *, cpu->nfeatures + 1); + for (i =3D 0; i < cpu->nfeatures; i++) { - if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)= ) { - if (virStringListAdd(&list, cpu->features[i].name) < 0) - return -1; - n++; - } + if (filter(cpu->features[i].name, cpu->features[i].policy, opaque)) + (*features)[n++] =3D g_strdup(cpu->features[i].name); } - *features =3D g_steal_pointer(&list); return n; } --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600572; cv=none; d=zohomail.com; s=zohoarc; b=T1hIxZQenbMPR4w8NGmANLhj6JQCeEXxsV/M/37BcCyCULu6nqGsqM+Sib/S8wStdVcxJDd8g1WxTpLKjJWgenCkV2fiyIS9yi58PZC3bAROOYOdATqJeZ0Mpk/KoTEHD3CzbYKKhbB1MHJwXgHRJLeK6Z4NXG0U+Pu++bNogcE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600572; 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=XIe6Fa/2tmvj/xUYlsok8doQzKTR7bBfJ5aLkz4EY1s=; b=BZl2g+KHHy5wRwfCEo3IcnGaXh9/sGLsXNv3IeXZ9rJk41thRcGWfUDbPzzXIH3+bJ2kEEexOdE7uy+UUXqAGnTeYxjfHwxnxoJ/E5mGMdgEcKcMc7qBXVyWj89OfnyOx7J91+p8inmFz7Yv4ean469JpxIL9zjPiy3C53f0eTU= 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) header.from= 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 1612600572873182.46482450802546; Sat, 6 Feb 2021 00:36:12 -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-233-8rAk1GMvN-OEXp0NJc_Yxg-1; Sat, 06 Feb 2021 03:33:52 -0500 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 B1BB2192AB79; Sat, 6 Feb 2021 08:33:45 +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 8D95E62A0C; Sat, 6 Feb 2021 08:33:45 +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 571E358080; Sat, 6 Feb 2021 08:33:45 +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 1168XSIR004784 for ; Sat, 6 Feb 2021 03:33:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id C517660C78; Sat, 6 Feb 2021 08:33:28 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0788860C77 for ; Sat, 6 Feb 2021 08:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600571; 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=XIe6Fa/2tmvj/xUYlsok8doQzKTR7bBfJ5aLkz4EY1s=; b=GUG8oFdw7CJWCPL9P0cYvIwPbMLnP/sSuWnfzfrXE4lXr1KcF39ZOcm9Frr1Kd1XARlsvd qkn3gN0vEWLduE1cpIrw56XMpwwIaoH90nJbFvAQ+NI5utEwhmeVpRJF/EPJvdW7GBSOYj q7WzEBAkl5Ftmso3NTvvcjgo6SUvWiY= X-MC-Unique: 8rAk1GMvN-OEXp0NJc_Yxg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/40] x86ModelParseFeatures: Don't construct list using 'virStringListAdd' Date: Sat, 6 Feb 2021 09:32:34 +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.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) Content-Type: text/plain; charset="utf-8" Pre-allocate the list to the upper bound and fill it gradually. Since the data is kept long-term and the list won't be populated much shrink it to the actual size after parsing. While using 'virStringListAdd' here wouldn't be as expensive as this function is used just once, the removal will allow to remove 'virStringListAdd' altogether to discourage the antipattern it promotes. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/cpu/cpu_x86.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 2422e258ec..a64a971540 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1604,11 +1604,14 @@ x86ModelParseFeatures(virCPUx86ModelPtr model, { g_autofree xmlNodePtr *nodes =3D NULL; size_t i; + size_t nremoved =3D 0; int n; if ((n =3D virXPathNodeSet("./feature", ctxt, &nodes)) <=3D 0) return n; + model->removedFeatures =3D g_new0(char *, n + 1); + for (i =3D 0; i < n; i++) { g_autofree char *ftname =3D NULL; g_autofree char *removed =3D NULL; @@ -1640,8 +1643,7 @@ x86ModelParseFeatures(virCPUx86ModelPtr model, } if (rem =3D=3D VIR_TRISTATE_BOOL_YES) { - if (virStringListAdd(&model->removedFeatures, ftname) < 0) - return -1; + model->removedFeatures[nremoved++] =3D g_strdup(ftname); continue; } } @@ -1650,6 +1652,8 @@ x86ModelParseFeatures(virCPUx86ModelPtr model, return -1; } + model->removedFeatures =3D g_renew(char *, model->removedFeatures, nre= moved + 1); + return 0; } --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600443; cv=none; d=zohomail.com; s=zohoarc; b=b8s0sC9SU3xF/yOj0dQaLaIvzl/UTCu3A+o+CX4Aw9ZWC0sk8oiYEm9XPbqfueF5gxoKohTCw6WXoNHdYbI1v5R3hoChQj7kGRXazJtuq2ElJyC1JAy4N9DW40MNYvj7+JbhMrJBHC6cqlEf2s2a/5e8bMq0IMLJTp9eLqXxkCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600443; 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=L1D1FpU94e732u15nIjKiq/liOTNiFqnwEP+kfxrDgc=; b=QO9j29Rkm6NtD+toLf7l0Vgn7sUEOaKHEmWgzuAKcj/mtnm22zwaDqeYHlFSIHk4KnrqtBGucGfgUokvwvOFKdC2oYGLhzMhZiN7lRpQbw7KR8y9xO8uJvxB8xLmZZ99sMPbjYdq+GqAzViC+KiTQLQD0xZP0FWyg9pA2+552pU= 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 1612600443550918.3690862417294; Sat, 6 Feb 2021 00:34:03 -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-319-5dcd2_dKOdiZehikSa8PYg-1; Sat, 06 Feb 2021 03:33:48 -0500 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 5A104192AB87; Sat, 6 Feb 2021 08:33:42 +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 369045D9CC; Sat, 6 Feb 2021 08:33:42 +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 F14E55807E; Sat, 6 Feb 2021 08:33:41 +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 1168XUds004793 for ; Sat, 6 Feb 2021 03:33:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id 10DBD60C79; Sat, 6 Feb 2021 08:33:30 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59F8960C77 for ; Sat, 6 Feb 2021 08:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600442; 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=L1D1FpU94e732u15nIjKiq/liOTNiFqnwEP+kfxrDgc=; b=V6qHYOD7wVgC6CoAzixKL1qMOy4EqBarGKHnXAkcGMsuoG+eSKynCCcXUJEbBUbCAK3EoB AGsvfiFtIUpOE6a0Y4kXhKNjvCnXOSSB76UoEomkP4yTLGx3YMfCxwbyvBz8Yp3705nm4R 6w++5cb8vGgN4AE6KY7gP9EXdmUTbwM= X-MC-Unique: 5dcd2_dKOdiZehikSa8PYg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/40] virResctrlInfoGetMonitorPrefix: Don't use 'virStringListAdd' to construct list Date: Sat, 6 Feb 2021 09:32:35 +0100 Message-Id: <58b9318c75427c1aa9cf3d663d91404b5901bd60.1612599659.git.pkrempa@redhat.com> 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.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) Content-Type: text/plain; charset="utf-8" Pre-allocate a buffer for the upper limit and shrink it afterwards to avoid use of 'virStringListAdd' in a loop. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virresctrl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 29df51c652..86b4b9d73b 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1009,15 +1009,15 @@ virResctrlInfoGetMonitorPrefix(virResctrlInfoPtr re= sctrl, mon->cache_level =3D mongrp_info->cache_level; } + mon->features =3D g_new0(char *, mongrp_info->nfeatures + 1); + for (i =3D 0; i < mongrp_info->nfeatures; i++) { - if (STRPREFIX(mongrp_info->features[i], prefix)) { - if (virStringListAdd(&mon->features, - mongrp_info->features[i]) < 0) - goto cleanup; - mon->nfeatures++; - } + if (STRPREFIX(mongrp_info->features[i], prefix)) + mon->features[mon->nfeatures++] =3D g_strdup(mongrp_info->feat= ures[i]); } + mon->features =3D g_renew(char *, mon->features, mon->nfeatures + 1); + ret =3D 0; /* In case *monitor is pointed to some monitor, clean it. */ --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600816; cv=none; d=zohomail.com; s=zohoarc; b=OXuNHZcjpKLQVVUUEVU0xxN4laLXbedFaIZK50gZI9Lh0hIJp8GvQNkg46aRoc9QQrrBaIfFmr8F7USyPuIm2Fgj4Wb9ESZeD1nDReKrxNOZhK2hOlOQwZ8OhDD7U0kHnmFLjs2lchec0jVBor63i0eL8XZcmmHIj/q3Oaulu28= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600816; 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=72GNEN85R9t7A81FcG5kHzrduS10kd48Q3/glmREC/k=; b=WJuTci2bvkem5nL2fFuCLhdgXU/bWx+v/uOcwj96SaUEaLnye07j7Cyb8WvkuUkOfTsSDD8PuMOv3WCr7RozIGXa/YciDTsMfYmXRtmFdJlwa0gJ970qi5REnNqUyOY8FmHpWBfDtrUmZ3cMd/xEJf3MNggLiPGUQCQSCEJzclY= 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 161260081643154.09430019331171; Sat, 6 Feb 2021 00:40:16 -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-412-CjTPEQ1COICbYNIkdnvrXg-1; Sat, 06 Feb 2021 03:33:54 -0500 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 943701DDE5; Sat, 6 Feb 2021 08:33:48 +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 682D319C47; Sat, 6 Feb 2021 08:33:48 +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 308A0180881C; Sat, 6 Feb 2021 08:33:48 +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 1168XXp9004864 for ; Sat, 6 Feb 2021 03:33:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id EA1A360C78; Sat, 6 Feb 2021 08:33:33 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38A5B60C77 for ; Sat, 6 Feb 2021 08:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600815; 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=72GNEN85R9t7A81FcG5kHzrduS10kd48Q3/glmREC/k=; b=fCA4x62r/Uvnn92cSO0zo03uuRDRVYZJn1cmwWfkm3GZyl+QlF0dmdACS/YpZQ0Gk3BYgx 3hS5dIG9+CdQTqM6oPCyiBzU/ss2gzh5fMupMOarf6ELo3QEQMUkYrVdduHRMue2iyvJwk atUh6d3LfX1fgpuzzB4/yXw3DluynOg= X-MC-Unique: CjTPEQ1COICbYNIkdnvrXg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/40] virResctrlMonitorGetStats: Don't use 'virStringListAdd' Date: Sat, 6 Feb 2021 09:32:36 +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.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) Content-Type: text/plain; charset="utf-8" The iner loop copies the 'resources' array multiple times using 'virStringListAdd' which has O(n^2) complexity. Pre-calculate the length so we can allocate the array upfront and just copy the strings in the loop. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virresctrl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 86b4b9d73b..ab35bccfc5 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2662,6 +2662,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, char *filepath =3D NULL; struct dirent *ent =3D NULL; virResctrlMonitorStatsPtr stat =3D NULL; + size_t nresources =3D g_strv_length((char **) resources); if (!monitor) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2705,6 +2706,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, continue; stat =3D g_new0(virResctrlMonitorStats, 1); + stat->features =3D g_new0(char *, nresources + 1); /* The node ID number should be here, parsing it. */ if (virStrToLong_uip(node_id, NULL, 0, &stat->id) < 0) @@ -2724,8 +2726,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monito= r, if (VIR_APPEND_ELEMENT(stat->vals, stat->nvals, val) < 0) goto cleanup; - if (virStringListAdd(&stat->features, resources[i]) < 0) - goto cleanup; + stat->features[i] =3D g_strdup(resources[i]); } if (VIR_APPEND_ELEMENT(*stats, *nstats, stat) < 0) --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600446; cv=none; d=zohomail.com; s=zohoarc; b=gA5vcv/vJfP8/LJRqu1v5jFTX3F3eqSKhy+wT85z9RbxDeDBec+mRIN80JyI3JzhrZ9L48auRwpj8hAKipoWYwPZq99w/s6K6BGVj5UoWcj4w+XOD/9kqYrYKKUYS5J3gzo1GhYVSGMIljx5KZr6o/UZJY+Q/wvxwVZ4zmsA6Wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600446; 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=+bQbkA/8x9JPxyiuKfP538DJS532zbaPIUTCduuRmr8=; b=SyQboCjS3lAHmU6W1M2PZ5MFLoHtIJ6rSDyzJnBadexXFFMizWusA67V2FD8g38AFzJo0LJZaM1GYtshpi4u2sKGLyMUr16O+FuiQ3/i9awTxaFbegfkfhdJkfbwGpaWdMOHfpDe81APBOnGAylPREvZBepz7CYjfu5cvdH8uas= 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) header.from= 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 1612600446758245.3228393335537; Sat, 6 Feb 2021 00:34:06 -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-191-hznxeQreNBafkMtcCo64mg-1; Sat, 06 Feb 2021 03:33:51 -0500 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 175681DDE2; Sat, 6 Feb 2021 08:33:45 +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 E301A19746; Sat, 6 Feb 2021 08:33:44 +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 AE60518089DA; Sat, 6 Feb 2021 08:33:44 +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 1168XbaN004893 for ; Sat, 6 Feb 2021 03:33:37 -0500 Received: by smtp.corp.redhat.com (Postfix) id 67D3D60C77; Sat, 6 Feb 2021 08:33:37 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5DCA60C90 for ; Sat, 6 Feb 2021 08:33:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600445; 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=+bQbkA/8x9JPxyiuKfP538DJS532zbaPIUTCduuRmr8=; b=YqayeOiAaAUlL/yeb4PlG2y9WZ2Iwt2+r18BgZZdhcZB+8CXxEaOem33LKO6r4Xb9JTi5f mCKuKGfuUDvD5yxo4YdAK+tyWvkMX7gdSXobZON2e2YSREgnuatla791Mb++323md4S1vN uMGiJORfDxnatjT2eVCGyEJcLVXcKro= X-MC-Unique: hznxeQreNBafkMtcCo64mg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/40] qemu: Convert 'priv->dbusVMStateIds' to a GSList Date: Sat, 6 Feb 2021 09:32:37 +0100 Message-Id: <639dfbbaa386e38844c23bc1d38b4a2a6aac6d1f.1612599659.git.pkrempa@redhat.com> 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.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) Content-Type: text/plain; charset="utf-8" The conversion removes the use of virStringListAdd/virStringListRemove which try to add dynamic properties to a string list which is really inefficient. Storing the dbus VMState ids in a GSList is pretty straightforward and the slightly increased complexity of the code will be paid back by removing the string list helpers later. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_dbus.c | 19 ++++++++++++++++--- src/qemu/qemu_dbus.h | 2 +- src/qemu/qemu_domain.c | 4 ++-- src/qemu/qemu_domain.h | 2 +- src/qemu/qemu_migration.c | 10 ++++------ src/qemu/qemu_monitor.c | 19 +++++++++++++------ src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 5 ++--- src/qemu/qemu_monitor_json.h | 2 +- src/qemu/qemu_slirp.c | 7 ++----- 11 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 92036d26c0..ac6bec3389 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9605,7 +9605,7 @@ qemuBuildDBusVMStateCommandLine(virCommandPtr cmd, g_autoptr(virJSONValue) props =3D NULL; qemuDomainObjPrivatePtr priv =3D QEMU_DOMAIN_PRIVATE(vm); - if (virStringListLength((const char **)priv->dbusVMStateIds) =3D=3D 0) + if (!priv->dbusVMStateIds) return 0; if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) { diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c index ffcf83e5da..31ede2646f 100644 --- a/src/qemu/qemu_dbus.c +++ b/src/qemu/qemu_dbus.c @@ -287,15 +287,28 @@ qemuDBusStart(virQEMUDriverPtr driver, } -int +void qemuDBusVMStateAdd(virDomainObjPtr vm, const char *id) { - return virStringListAdd(&QEMU_DOMAIN_PRIVATE(vm)->dbusVMStateIds, id); + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + priv->dbusVMStateIds =3D g_slist_append(priv->dbusVMStateIds, g_strdup= (id)); } void qemuDBusVMStateRemove(virDomainObjPtr vm, const char *id) { - virStringListRemove(&QEMU_DOMAIN_PRIVATE(vm)->dbusVMStateIds, id); + qemuDomainObjPrivatePtr priv =3D vm->privateData; + GSList *next; + + for (next =3D priv->dbusVMStateIds; next; next =3D next->next) { + const char *elem =3D next->data; + + if (STREQ(id, elem)) { + priv->dbusVMStateIds =3D g_slist_remove_link(priv->dbusVMState= Ids, next); + g_slist_free_full(next, g_free); + break; + } + } } diff --git a/src/qemu/qemu_dbus.h b/src/qemu/qemu_dbus.h index e3ce1330fd..5900b99144 100644 --- a/src/qemu/qemu_dbus.h +++ b/src/qemu/qemu_dbus.h @@ -30,7 +30,7 @@ int qemuDBusStart(virQEMUDriverPtr driver, void qemuDBusStop(virQEMUDriverPtr driver, virDomainObjPtr vm); -int qemuDBusVMStateAdd(virDomainObjPtr vm, const char *id); +void qemuDBusVMStateAdd(virDomainObjPtr vm, const char *id); void qemuDBusVMStateRemove(virDomainObjPtr vm, const char *id); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0f09e321fb..31b1110887 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1785,8 +1785,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) priv->dbusDaemonRunning =3D false; - g_strfreev(priv->dbusVMStateIds); - priv->dbusVMStateIds =3D NULL; + if (priv->dbusVMStateIds) + g_slist_free_full(g_steal_pointer(&priv->dbusVMStateIds), g_free); priv->dbusVMState =3D false; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 7453881a31..29a5dd97d8 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -260,7 +260,7 @@ struct _qemuDomainObjPrivate { bool dbusDaemonRunning; /* list of Ids to migrate */ - char **dbusVMStateIds; + GSList *dbusVMStateIds; /* true if -object dbus-vmstate was added */ bool dbusVMState; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index f44d31c971..1bb4a9608e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1408,7 +1408,7 @@ qemuMigrationSrcIsAllowed(virQEMUDriverPtr driver, } } - if (virStringListLength((const char **)priv->dbusVMStateIds) > 0 && + if (priv->dbusVMStateIds && !virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DBUS_VMSTATE)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot migrate this domain without dbus-vmst= ate support")); @@ -2091,8 +2091,7 @@ qemuMigrationDstRun(virQEMUDriverPtr driver, if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0) return -1; - rv =3D qemuMonitorSetDBusVMStateIdList(priv->mon, - (const char **)priv->dbusVMStateI= ds); + rv =3D qemuMonitorSetDBusVMStateIdList(priv->mon, priv->dbusVMStateIds= ); if (rv < 0) goto exit_monitor; @@ -3602,7 +3601,7 @@ qemuMigrationSetDBusVMState(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv =3D vm->privateData; - if (virStringListLength((const char **)priv->dbusVMStateIds) > 0) { + if (priv->dbusVMStateIds) { int rv; if (qemuHotplugAttachDBusVMState(driver, vm, QEMU_ASYNC_JOB_NONE) = < 0) @@ -3611,8 +3610,7 @@ qemuMigrationSetDBusVMState(virQEMUDriverPtr driver, if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_NONE= ) < 0) return -1; - rv =3D qemuMonitorSetDBusVMStateIdList(priv->mon, - (const char **)priv->dbusVMSt= ateIds); + rv =3D qemuMonitorSetDBusVMStateIdList(priv->mon, priv->dbusVMStat= eIds); if (qemuDomainObjExitMonitor(driver, vm) < 0) rv =3D -1; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 14966d4096..0476d606f5 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2385,21 +2385,28 @@ qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon, int qemuMonitorSetDBusVMStateIdList(qemuMonitorPtr mon, - const char **list) + GSList *list) { g_autofree char *path =3D NULL; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + GSList *next; VIR_DEBUG("list=3D%p", list); - if (virStringListLength(list) =3D=3D 0) + QEMU_CHECK_MONITOR(mon); + + if (!list) return 0; - path =3D g_strdup_printf("/objects/%s", - qemuDomainGetDBusVMStateAlias()); + for (next =3D list; next; next =3D next->next) + virBufferAsprintf(&buf, "%s,", (const char *) next->data); - QEMU_CHECK_MONITOR(mon); + virBufferTrim(&buf, ","); + + path =3D g_strdup_printf("/objects/%s", qemuDomainGetDBusVMStateAlias(= )); - return qemuMonitorJSONSetDBusVMStateIdList(mon, path, list); + return qemuMonitorJSONSetDBusVMStateIdList(mon, path, + virBufferCurrentContent(&bu= f)); } diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index b0068f2a82..32dc96ee82 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -777,7 +777,7 @@ int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon, const char *path); int qemuMonitorSetDBusVMStateIdList(qemuMonitorPtr mon, - const char **list); + GSList *list); int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon, unsigned long bandwidth); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index d3b2a2c7a5..72b60daecc 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -2359,12 +2359,11 @@ qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitorPtr = mon, int qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr mon, const char *vmstatepath, - const char **list) + const char *idstr) { - g_autofree char *str =3D virStringListJoin(list, ","); qemuMonitorJSONObjectProperty prop =3D { .type =3D QEMU_MONITOR_OBJECT_PROPERTY_STRING, - .val.str =3D str, + .val.str =3D idstr, }; return qemuMonitorJSONSetObjectProperty(mon, vmstatepath, "id-list", &= prop); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 64af758885..a550dac33c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -699,7 +699,7 @@ qemuMonitorJSONTransactionBackup(virJSONValuePtr action= s, int qemuMonitorJSONSetDBusVMStateIdList(qemuMonitorPtr mon, const char *vmstatepath, - const char **list) + const char *idstr) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); int diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c index 62a6665679..7f6156fbc1 100644 --- a/src/qemu/qemu_slirp.c +++ b/src/qemu/qemu_slirp.c @@ -320,11 +320,8 @@ qemuSlirpStart(qemuSlirpPtr slirp, virCommandAddArgFormat(cmd, "--dbus-address=3D%s", dbus_addr); if (qemuSlirpHasFeature(slirp, QEMU_SLIRP_FEATURE_MIGRATE)) { - if (qemuDBusVMStateAdd(vm, id) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Failed to register slirp migration")); - goto error; - } + qemuDBusVMStateAdd(vm, id); + if (incoming) virCommandAddArg(cmd, "--dbus-incoming"); } --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600532; cv=none; d=zohomail.com; s=zohoarc; b=jmJMZyZlQRWd9auQuDT7D8NqbLKwv5VPMLqcX569nOqyHbFJxudSBYcIkANKOtGicZ4LXqp/VFOKATRo/sQzF35f6xlb+8mGobp4rfPqBBmnBM1AU+Gt0fSGvsjqam7S2J14r/2Sd10nOSzvVwsfmusHDvxUEx+zkFrY40jCIZw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600532; 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=tBXhK3PEVVo7U6uhalGIt7DkhJBz1gA0PiG2IWCO3vA=; b=WceWQlBH8UGdSfA2vppJylDEBu12oCSajVgZR4HmUx3lzgqeWDNqq97rB0Gy6oGrrF6OkdYV/t3Tyhq+CEaxRgLaz+XyDCeIY+P1HGZcdZhmLVnQ+NiK7i83ma0+mswgZmV0ItD3+NcakAM3nCYd5qd2njnaerBduJkpejNLR6U= 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) header.from= 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 1612600532230695.7945725173926; Sat, 6 Feb 2021 00:35:32 -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-465-bkzpZlCmNdekz5J36-pdOw-1; Sat, 06 Feb 2021 03:33:53 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC86C1DDEB; Sat, 6 Feb 2021 08:33:47 +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 B88C972FAE; Sat, 6 Feb 2021 08:33:47 +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 8298B58085; Sat, 6 Feb 2021 08:33:47 +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 1168Xevm004917 for ; Sat, 6 Feb 2021 03:33:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9F01E60C77; Sat, 6 Feb 2021 08:33:40 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id F00DC60C76 for ; Sat, 6 Feb 2021 08:33:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600531; 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=tBXhK3PEVVo7U6uhalGIt7DkhJBz1gA0PiG2IWCO3vA=; b=fBZHd/YdHDW8ZUW/9dnIvgZ3H/5sU8MOFHyMPUpieOBcKvUET5sfnpWeMSZ8dqEo0Q8op9 MiRqs4R6GPqVunH07TDzIk1pIPfFHpf72ERKt4vbJ37bou561JG/g+04Y32eoTrIxNS8bT 6GqDTlfAAr9S7atIjdlLsh6Q8Vyo+DU= X-MC-Unique: bkzpZlCmNdekz5J36-pdOw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/40] util: macmap: Convert to use GSList for storing macs instead of string lists Date: Sat, 6 Feb 2021 09:32:38 +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.11 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" Since adding and removing is the main use case for the macmap module, convert the code to a more efficient data structure. The refactor also optimizes the loading from file where previously we'd do a hash lookup + list lenght calculation for every entry. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virmacmap.c | 118 +++++++++++++++++++++++------------------- src/util/virmacmap.h | 6 ++- tests/virmacmaptest.c | 21 ++++---- 3 files changed, 81 insertions(+), 64 deletions(-) diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index ec0a67b433..0d458d7b7b 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -50,21 +50,18 @@ struct virMacMap { static virClassPtr virMacMapClass; -static int -virMacMapHashFree(void *payload, - const char *name G_GNUC_UNUSED, - void *opaque G_GNUC_UNUSED) -{ - g_strfreev(payload); - return 0; -} - - static void virMacMapDispose(void *obj) { virMacMapPtr mgr =3D obj; - virHashForEach(mgr->macs, virMacMapHashFree, NULL); + GHashTableIter htitr; + void *value; + + g_hash_table_iter_init(&htitr, mgr->macs); + + while (g_hash_table_iter_next(&htitr, NULL, &value)) + g_slist_free_full(value, g_free); + virHashFree(mgr->macs); } @@ -80,48 +77,57 @@ static int virMacMapOnceInit(void) VIR_ONCE_GLOBAL_INIT(virMacMap); -static int +static void virMacMapAddLocked(virMacMapPtr mgr, const char *domain, const char *mac) { - char **macsList =3D NULL; + GSList *orig_list; + GSList *list; + GSList *next; - if ((macsList =3D virHashLookup(mgr->macs, domain)) && - virStringListHasString((const char**) macsList, mac)) { - return 0; + list =3D orig_list =3D g_hash_table_lookup(mgr->macs, domain); + + for (next =3D list; next; next =3D next->next) { + if (STREQ((const char *) next->data, mac)) + return; } - if (virStringListAdd(&macsList, mac) < 0 || - virHashUpdateEntry(mgr->macs, domain, macsList) < 0) - return -1; + list =3D g_slist_append(list, g_strdup(mac)); - return 0; + if (list !=3D orig_list) + g_hash_table_insert(mgr->macs, g_strdup(domain), list); } -static int +static void virMacMapRemoveLocked(virMacMapPtr mgr, const char *domain, const char *mac) { - char **macsList =3D NULL; - char **newMacsList =3D NULL; + GSList *orig_list; + GSList *list; + GSList *next; - if (!(macsList =3D virHashLookup(mgr->macs, domain))) - return 0; + list =3D orig_list =3D g_hash_table_lookup(mgr->macs, domain); - newMacsList =3D macsList; - virStringListRemove(&newMacsList, mac); - if (!newMacsList) { - virHashSteal(mgr->macs, domain); - } else { - if (macsList !=3D newMacsList && - virHashUpdateEntry(mgr->macs, domain, newMacsList) < 0) - return -1; + if (!orig_list) + return; + + for (next =3D list; next; next =3D next->next) { + if (STREQ((const char *) next->data, mac)) { + list =3D g_slist_remove_link(list, next); + g_slist_free_full(next, g_free); + break; + } } - return 0; + if (list !=3D orig_list) { + if (list) + g_hash_table_insert(mgr->macs, g_strdup(domain), list); + else + g_hash_table_remove(mgr->macs, domain); + } } @@ -162,6 +168,7 @@ virMacMapLoadFile(virMacMapPtr mgr, virJSONValuePtr macs; const char *domain; size_t j; + GSList *vals =3D NULL; if (!(domain =3D virJSONValueObjectGetString(tmp, "domain"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -175,13 +182,21 @@ virMacMapLoadFile(virMacMapPtr mgr, return -1; } + if (g_hash_table_contains(mgr->macs, domain)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("duplicate domain '%s'"), domain); + return -1; + + } + for (j =3D 0; j < virJSONValueArraySize(macs); j++) { virJSONValuePtr macJSON =3D virJSONValueArrayGet(macs, j); - const char *mac =3D virJSONValueGetString(macJSON); - if (virMacMapAddLocked(mgr, domain, mac) < 0) - return -1; + vals =3D g_slist_prepend(vals, g_strdup(virJSONValueGetString(= macJSON))); } + + vals =3D g_slist_reverse(vals); + g_hash_table_insert(mgr->macs, g_strdup(domain), vals); } return 0; @@ -195,11 +210,11 @@ virMACMapHashDumper(void *payload, { g_autoptr(virJSONValue) obj =3D virJSONValueNewObject(); g_autoptr(virJSONValue) arr =3D virJSONValueNewArray(); - const char **macs =3D payload; - size_t i; + GSList *macs =3D payload; + GSList *next; - for (i =3D 0; macs[i]; i++) { - virJSONValuePtr m =3D virJSONValueNewString(macs[i]); + for (next =3D macs; next; next =3D next->next) { + virJSONValuePtr m =3D virJSONValueNewString((const char *) next->d= ata); if (!m || virJSONValueArrayAppend(arr, m) < 0) { @@ -279,8 +294,8 @@ virMacMapNew(const char *file) return NULL; virObjectLock(mgr); - if (!(mgr->macs =3D virHashNew(NULL))) - goto error; + + mgr->macs =3D virHashNew(NULL); if (file && virMacMapLoadFile(mgr, file) < 0) @@ -301,12 +316,10 @@ virMacMapAdd(virMacMapPtr mgr, const char *domain, const char *mac) { - int ret; - virObjectLock(mgr); - ret =3D virMacMapAddLocked(mgr, domain, mac); + virMacMapAddLocked(mgr, domain, mac); virObjectUnlock(mgr); - return ret; + return 0; } @@ -315,20 +328,19 @@ virMacMapRemove(virMacMapPtr mgr, const char *domain, const char *mac) { - int ret; - virObjectLock(mgr); - ret =3D virMacMapRemoveLocked(mgr, domain, mac); + virMacMapRemoveLocked(mgr, domain, mac); virObjectUnlock(mgr); - return ret; + return 0; } -const char *const * +/* note that the returned pointer may be invalidated by other APIs in this= module */ +GSList * virMacMapLookup(virMacMapPtr mgr, const char *domain) { - const char *const *ret; + GSList *ret; virObjectLock(mgr); ret =3D virHashLookup(mgr->macs, domain); diff --git a/src/util/virmacmap.h b/src/util/virmacmap.h index 4652295033..96e32256e3 100644 --- a/src/util/virmacmap.h +++ b/src/util/virmacmap.h @@ -20,6 +20,8 @@ #pragma once +#include "internal.h" + typedef struct virMacMap virMacMap; typedef virMacMap *virMacMapPtr; @@ -37,8 +39,8 @@ int virMacMapRemove(virMacMapPtr mgr, const char *domain, const char *mac); -const char *const *virMacMapLookup(virMacMapPtr mgr, - const char *domain); +GSList *virMacMapLookup(virMacMapPtr mgr, + const char *domain); int virMacMapWriteFile(virMacMapPtr mgr, const char *filename); diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 8fd9916b95..77fa2b3e98 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -36,7 +36,8 @@ testMACLookup(const void *opaque) { const struct testData *data =3D opaque; virMacMapPtr mgr =3D NULL; - const char * const * macs; + GSList *macs; + GSList *next; size_t i, j; char *file =3D NULL; int ret =3D -1; @@ -48,26 +49,27 @@ testMACLookup(const void *opaque) macs =3D virMacMapLookup(mgr, data->domain); - for (i =3D 0; macs && macs[i]; i++) { + for (next =3D macs; next; next =3D next->next) { for (j =3D 0; data->macs && data->macs[j]; j++) { - if (STREQ(macs[i], data->macs[j])) + if (STREQ((const char *) next->data, data->macs[j])) break; } if (!data->macs || !data->macs[j]) { fprintf(stderr, - "Unexpected %s in the returned list of MACs\n", macs[i= ]); + "Unexpected %s in the returned list of MACs\n", + (const char *) next->data); goto cleanup; } } for (i =3D 0; data->macs && data->macs[i]; i++) { - for (j =3D 0; macs && macs[j]; j++) { - if (STREQ(data->macs[i], macs[j])) + for (next =3D macs; next; next =3D next->next) { + if (STREQ(data->macs[i], (const char *) next->data)) break; } - if (!macs || !macs[j]) { + if (!next) { fprintf(stderr, "Expected %s in the returned list of MACs\n", data->ma= cs[i]); goto cleanup; @@ -87,7 +89,7 @@ testMACRemove(const void *opaque) { const struct testData *data =3D opaque; virMacMapPtr mgr =3D NULL; - const char * const * macs; + GSList *macs; size_t i; char *file =3D NULL; int ret =3D -1; @@ -107,7 +109,8 @@ testMACRemove(const void *opaque) if ((macs =3D virMacMapLookup(mgr, data->domain))) { fprintf(stderr, - "Not removed all MACs for domain %s: %s\n", data->domain, = macs[0]); + "Not removed all MACs for domain %s: %s\n", + data->domain, (const char *) macs->data); goto cleanup; } --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600570; cv=none; d=zohomail.com; s=zohoarc; b=aliIoW2rbmdExCH6NKQWorm8AMGBE/IoHWlqhrKCp+agzO42xkXfCBvzVm+yKQV+tRU291y6bbITr2vmS4XJDf7K7aAfDK0ZZBgodMyOjvBb33qvpCJQM9l7VAblZnipAhLdX8wC6x5ie4x96hXJ+zcjXQlpXMJcwwlc7vDshxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600570; 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=dZLnF9Axp/1383+QgeKFXQuaZks2vha5N23Haoo28pY=; b=lJrCs/6BlorzCjhq49AwSE3B2NzJZrcJnYBzlvI43NjUL6QwN827CaQflSUyt5fKaXzozqnhuLAC2dBz9o+rAmbkTTfk7GfzOEPHn0CNFzGqvCSKz3F46jWGOaZvYqy2bshIpQHcO/BGOkwW5l/s9wpVe8Ic9hvQa0rSmNpNfsM= 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) header.from= 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 1612600570025398.56866099430215; Sat, 6 Feb 2021 00:36:10 -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-331-KlTMH7TNNBmqBnS9-Cu9MQ-1; Sat, 06 Feb 2021 03:33:53 -0500 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 3BDE21DDE4; Sat, 6 Feb 2021 08:33:48 +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 187E262A23; Sat, 6 Feb 2021 08:33:48 +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 D542358088; Sat, 6 Feb 2021 08:33:47 +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 1168XkNT004955 for ; Sat, 6 Feb 2021 03:33:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB2FB60C77; Sat, 6 Feb 2021 08:33:46 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB0FF60C76 for ; Sat, 6 Feb 2021 08:33:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600569; 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=dZLnF9Axp/1383+QgeKFXQuaZks2vha5N23Haoo28pY=; b=hpr08ThYyNNDhvqAQS2XjGx/PUWB4fGcIEi+qwAXOS9mYxNLYHXuLYMJr+MBZDOYuMxgj9 Btv1POI9ESVLyzjs9CyR12yLT75qO4x795Tvvf8/WLzN/r3od7DZnur1eQzaDac1pwFlh2 I8/tuyyl8Gserx19WTtG/lngYAyyCKs= X-MC-Unique: KlTMH7TNNBmqBnS9-Cu9MQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/40] xenParseXLNamespaceData: Pre-calculate the length of array Date: Sat, 6 Feb 2021 09:32:39 +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.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) Content-Type: text/plain; charset="utf-8" Precalculate the lenght to avoid use of 'virStringListAdd' in a loop. The code is also simplified by using APIs which don't return errors. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libxl/xen_xl.c | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 941832ce4e..a8af54a845 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1150,33 +1150,36 @@ static int xenParseXLNamespaceData(virConfPtr conf, virDomainDefPtr def) { virConfValuePtr list =3D virConfGetValue(conf, "device_model_args"); - g_auto(GStrv) args =3D NULL; - size_t nargs; + virConfValuePtr next; + size_t nargs =3D 0; libxlDomainXmlNsDefPtr nsdata =3D NULL; + size_t n =3D 0; - if (list && list->type =3D=3D VIR_CONF_LIST) { - list =3D list->list; - while (list) { - if ((list->type !=3D VIR_CONF_STRING) || (list->str =3D=3D NUL= L)) { - list =3D list->next; - continue; - } + if (!list || list->type !=3D VIR_CONF_LIST) + return 0; - virStringListAdd(&args, list->str); - list =3D list->next; - } + list =3D list->list; + + for (next =3D list; next; next =3D next->next) { + if (next->type !=3D VIR_CONF_STRING || !next->str) + continue; + + nargs++; } - if (!args) + if (nargs =3D=3D 0) return 0; - nargs =3D g_strv_length(args); - if (nargs > 0) { - nsdata =3D g_new0(libxlDomainXmlNsDef, 1); + nsdata =3D g_new0(libxlDomainXmlNsDef, 1); + def->namespaceData =3D nsdata; + nsdata->args =3D g_new0(char *, nargs + 1); + nsdata->num_args =3D nargs; + + for (next =3D list; next; next =3D next->next) { + if (next->type !=3D VIR_CONF_STRING || !next->str) + continue; - nsdata->args =3D g_steal_pointer(&args); - nsdata->num_args =3D nargs; - def->namespaceData =3D nsdata; + nsdata->args[n++] =3D g_strdup(next->str); } return 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600440; cv=none; d=zohomail.com; s=zohoarc; b=KEckALuQCZql85Pq1UNQMcWaHlgAavnGrknp6jar9FAZ6NjoyqJQm1kv88ke1NXRNxXU1IpQNrwKZYxrxXd5xs7uDWWsuVbNFb1lLBxZ+/ZM/klZjG/UUNpUZbE0+fTAa8dXRLhSHJ+Xf+vG1WsZ7bz8OETVuja3rA77maqa1CA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600440; 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=rtCHeDIR0hd+3n0XXjAc0LfOxe19CouVaaKWHHH89+o=; b=aFY0pwi3ABEQDLHF+1Q5CiC1M6EqtgMbSBHKqZTr8l6GShOB5MVMTZm/B6cHRbXy/y2kW9gsFqT/XbtVso2aRpl4LSwC5G0w1oX/nHnB7agYdZAfHss7AcdiHqfpjQWTcpFzyNCwCsDafyVueS1odbUsHgjhByLUyJytrKiTqo8= 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) header.from= 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 1612600440707948.1925803367697; Sat, 6 Feb 2021 00:34:00 -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-441-_xXT7wrwPCa8GJk2XLQCZQ-1; Sat, 06 Feb 2021 03:33:57 -0500 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 B887D100CCCC; Sat, 6 Feb 2021 08:33:51 +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 9691919C47; Sat, 6 Feb 2021 08:33:51 +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 5FD725808B; Sat, 6 Feb 2021 08:33:51 +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 1168XnvB004989 for ; Sat, 6 Feb 2021 03:33:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id E234160C77; Sat, 6 Feb 2021 08:33:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05C5B60C76 for ; Sat, 6 Feb 2021 08:33:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600439; 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=rtCHeDIR0hd+3n0XXjAc0LfOxe19CouVaaKWHHH89+o=; b=JG0HF1f0vfg7jRpfFVCFD4CQ6k5xGlEkuBsAiP+g3kiczA73E6MUmMT5f+1XzgzD7GBrys B3Dzv+jtiKO/6yGjedsJkQNzJ3VaFqZNS6vtQggNvjZ8MSvRxLM6uaevjwU3IIW4C9pVsS rxMQd3V8EM6puuLGRUth80Mvgwfm8jA= X-MC-Unique: _xXT7wrwPCa8GJk2XLQCZQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 18/40] virfirewalltest: Shuffle the code around to remove a loop Date: Sat, 6 Feb 2021 09:32:40 +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.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) Content-Type: text/plain; charset="utf-8" We are already looping over the arguments to construct the list, so we can add them to fwBuf right away rather than in an extra loop if we move some of the 'fwBuf' parts earlier and merge the two loops. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/virfirewalltest.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 9f95520859..e14a34d7d2 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -108,12 +108,20 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, char *item =3D NULL; bool isAdd =3D false; bool doError =3D false; - size_t i; g_variant_get(params, "(&sas)", &type, &iter); nargs =3D g_variant_iter_n_children(iter); + if (fwBuf) { + if (STREQ(type, "ipv4")) + virBufferAddLit(fwBuf, IPTABLES_PATH); + else if (STREQ(type, "ipv6")) + virBufferAddLit(fwBuf, IP6TABLES_PATH); + else + virBufferAddLit(fwBuf, EBTABLES_PATH); + } + while (g_variant_iter_loop(iter, "s", &item)) { /* Fake failure on the command with this IP addr */ if (STREQ(item, "-A")) { @@ -123,21 +131,10 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, } virStringListAdd(&args, item); - } - - if (fwBuf) { - if (STREQ(type, "ipv4")) - virBufferAddLit(fwBuf, IPTABLES_PATH); - else if (STREQ(type, "ipv6")) - virBufferAddLit(fwBuf, IP6TABLES_PATH); - else - virBufferAddLit(fwBuf, EBTABLES_PATH); - } - for (i =3D 0; i < nargs; i++) { if (fwBuf) { virBufferAddLit(fwBuf, " "); - virBufferEscapeShell(fwBuf, args[i]); + virBufferEscapeShell(fwBuf, item); } } --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600444; cv=none; d=zohomail.com; s=zohoarc; b=K2FhVS8K4cDXqvis9Lwwjsuaaty4FW6B0JPGtHO8pJLxD9IcSFXdIotZP9tsWcVIrlYapuZu+YdyxxAGRMgx2byjp66oHkmC0uH/NmmR5FD2tk3AKUN/nCIgZewfMSsMtgWCuVpzysf0Vt1EYbst4HoQ4ww6XYIIQzgVFOObO5I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600444; 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=yWz6CFewaAIX4IRVezmt6oEYJiR0Vounw4xGFoefkTU=; b=jK/yvzh8kdFfCgyvyHRKz7NFOZINhMc287Ws+nYLHeooJiRLDRP6hUjchrKm1vT38sVQk7Dj4WYMr0JZCIm8nzi7E/l6zIaWUiQmjREwFkX3E32p1M7S5eHqEpsBbgY6RNLGz3U1NRG0IaG6sThvimjpbylMZtDl2mtLWZGfkmY= 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 1612600444017515.758350627717; Sat, 6 Feb 2021 00:34:04 -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-362-SocGtz9wPcyk7rIDcQhP2Q-1; Sat, 06 Feb 2021 03:33:59 -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 C1B941005501; Sat, 6 Feb 2021 08:33: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 9DB106315F; Sat, 6 Feb 2021 08:33:54 +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 6ADEF18077BA; Sat, 6 Feb 2021 08:33:54 +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 1168XrVj005069 for ; Sat, 6 Feb 2021 03:33:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1919760C77; Sat, 6 Feb 2021 08:33:53 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC77160C76 for ; Sat, 6 Feb 2021 08:33:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600442; 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=yWz6CFewaAIX4IRVezmt6oEYJiR0Vounw4xGFoefkTU=; b=JJCdSlycNze0v8MRaaG0+mAD1Up9DEiihD+1Nbq7yPzmkKU74yAaEkX4pJrXqJXCyZ3/0Z vPnFnenrqZcJ9G2dpPqTbi+nxCeh7TmFiqMFi0iFfQcbqTzkimxncXnh6/XIMj9ZNhbn6t YeX6uKefbFwEPP1fdcicKdqwUS8JBvQ= X-MC-Unique: SocGtz9wPcyk7rIDcQhP2Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 19/40] virfirewalltest: Avoid use of 'virStringListAdd' Date: Sat, 6 Feb 2021 09:32:41 +0100 Message-Id: <93bed5611d389891be319c9410d7835ab1f6674f.1612599659.git.pkrempa@redhat.com> 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.16 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" To allow later removal of 'virStringListAdd' add an arbitrary upper limit on the number of args we care about and don't store more than that until necessary later. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/virfirewalltest.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index e14a34d7d2..8bd73311fd 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -102,6 +102,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, } else if (STREQ(bus_name, VIR_FIREWALL_FIREWALLD_SERVICE) && STREQ(method_name, "passthrough")) { g_autoptr(GVariantIter) iter =3D NULL; + static const size_t maxargs =3D 5; g_auto(GStrv) args =3D NULL; size_t nargs =3D 0; char *type =3D NULL; @@ -111,7 +112,7 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, g_variant_get(params, "(&sas)", &type, &iter); - nargs =3D g_variant_iter_n_children(iter); + args =3D g_new0(char *, maxargs); if (fwBuf) { if (STREQ(type, "ipv4")) @@ -130,7 +131,9 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync, doError =3D true; } - virStringListAdd(&args, item); + if (nargs < maxargs) + args[nargs] =3D g_strdup(item); + nargs++; if (fwBuf) { virBufferAddLit(fwBuf, " "); --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600447; cv=none; d=zohomail.com; s=zohoarc; b=GxYtYJb5AYxhG2HC6a21FwAMVajPobX4R0487o1ARtISxuBWiclM4tFBD71i1DYHGOaG3WbyCn1oEAbdyc2kI969/hN3/Jdj0Lugi4h9A+CrvsFtYAC/b8QCky+qyQ1bPz/GI+BX1Uycga4A5lTDLfsjAGrHiN/z+Wdx+hITRSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600447; 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=wExZRxyzOF0gsYrgFFoPupZayVJFkXDUBDK1eSlF3Ic=; b=fP3nxnVnvpLqFkf8qq0cm4Co0Uk2jlOrxMpnY5VVwZL4k3Ao4HuzL+1NX7mfgTovVmvZwyUxMF2tUyOsMn+usZv7plX0OCC3Xl0/hifZL0VBaKlEcjek0xYY8LpBxv30sggEPpC2r0bHwVTveIzo+fJ24PV3uENICuntR6BGf3o= 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) header.from= 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 1612600447226655.8380800773243; Sat, 6 Feb 2021 00:34:07 -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-177-4v9B5_5VNGeIiwXVXuFbgw-1; Sat, 06 Feb 2021 03:34:03 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0C277100CCC6; Sat, 6 Feb 2021 08:33:58 +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 DC1451010F4E; Sat, 6 Feb 2021 08:33:57 +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 A451218077CE; Sat, 6 Feb 2021 08:33:57 +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 1168XtlY005091 for ; Sat, 6 Feb 2021 03:33:55 -0500 Received: by smtp.corp.redhat.com (Postfix) id B351360C77; Sat, 6 Feb 2021 08:33:55 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E850360C76 for ; Sat, 6 Feb 2021 08:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600446; 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=wExZRxyzOF0gsYrgFFoPupZayVJFkXDUBDK1eSlF3Ic=; b=ARHtKx13bDSlFiVugpFQWP0MwOZQ4oNPPmtQQ1GIaI8v8EhocZCMjvLDWvpUct5J0wLlB2 YL8cc/XSmjePyy1aMbFc9iLRYJYAtJ7aVR9WWSh7zHfi3o6aaeY5zpJeLpiHaXpXpBZKHv r14ecwg6807UQfuzgj26Qp+SUow0F8s= X-MC-Unique: 4v9B5_5VNGeIiwXVXuFbgw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 20/40] qemusecuritytest: Store 'notRestored' files in a hash table Date: Sat, 6 Feb 2021 09:32:42 +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.84 on 10.5.11.22 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" The validation code looks whether certain paths are in the 'notRestored' list. For the purpose of lookup it's better to use a hash table rather than a string list. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/qemusecuritymock.c | 19 +++++++++++-------- tests/qemusecuritytest.c | 14 ++++++-------- tests/qemusecuritytest.h | 4 +++- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/tests/qemusecuritymock.c b/tests/qemusecuritymock.c index 1fa4e522cc..5daf27ccd7 100644 --- a/tests/qemusecuritymock.c +++ b/tests/qemusecuritymock.c @@ -398,7 +398,7 @@ int virFileUnlock(int fd G_GNUC_UNUSED, typedef struct _checkOwnerData checkOwnerData; struct _checkOwnerData { - const char **paths; + GHashTable *paths; bool chown_fail; bool selinux_fail; }; @@ -413,7 +413,7 @@ checkSELinux(void *payload, char *label =3D payload; if (STRNEQ(label, DEFAULT_SELINUX_LABEL) && - !virStringListHasString(data->paths, name)) { + !g_hash_table_contains(data->paths, name)) { fprintf(stderr, "Path %s wasn't restored back to its original SELinux labe= l\n", name); @@ -434,7 +434,7 @@ checkOwner(void *payload, if ((owner % 16 !=3D DEFAULT_UID || owner >> 16 !=3D DEFAULT_GID) && - !virStringListHasString(data->paths, name)) { + !g_hash_table_contains(data->paths, name)) { fprintf(stderr, "Path %s wasn't restored back to its original owner\n", name); @@ -473,19 +473,22 @@ printXATTR(void *payload, * can be passed in @paths argument. If a path is not restored * but it's on the list no error is indicated. */ -int checkPaths(const char **paths) +int checkPaths(GHashTable *paths) { int ret =3D -1; checkOwnerData data =3D { .paths =3D paths, .chown_fail =3D false, .se= linux_fail =3D false }; bool xattr_fail =3D false; - size_t i; + GHashTableIter htitr; + void *key; virMutexLock(&m); init_hash(); - for (i =3D 0; paths && paths[i]; i++) { - if (!virHashLookup(chown_paths, paths[i])) { - fprintf(stderr, "Unexpected path restored: %s\n", paths[i]); + g_hash_table_iter_init(&htitr, paths); + + while (g_hash_table_iter_next(&htitr, &key, NULL)) { + if (!virHashLookup(chown_paths, key)) { + fprintf(stderr, "Unexpected path restored: %s\n", (const char = *) key); goto cleanup; } } diff --git a/tests/qemusecuritytest.c b/tests/qemusecuritytest.c index 1750018137..74a25f2be1 100644 --- a/tests/qemusecuritytest.c +++ b/tests/qemusecuritytest.c @@ -87,7 +87,7 @@ testDomain(const void *opaque) { const struct testData *data =3D opaque; g_autoptr(virDomainObj) vm =3D NULL; - g_auto(GStrv) notRestored =3D NULL; + g_autoptr(GHashTable) notRestored =3D virHashNew(NULL); size_t i; int ret =3D -1; @@ -102,14 +102,12 @@ testDomain(const void *opaque) continue; if (virStorageSourceIsLocalStorage(src) && src->path && - (src->shared || src->readonly) && - virStringListAdd(¬Restored, src->path) < 0) - return -1; + (src->shared || src->readonly)) + g_hash_table_insert(notRestored, g_strdup(src->path), NULL); for (n =3D src->backingStore; virStorageSourceIsBacking(n); n =3D = n->backingStore) { - if (virStorageSourceIsLocalStorage(n) && n->path && - virStringListAdd(¬Restored, n->path) < 0) - return -1; + if (virStorageSourceIsLocalStorage(n) && n->path) + g_hash_table_insert(notRestored, g_strdup(n->path), NULL); } } @@ -123,7 +121,7 @@ testDomain(const void *opaque) qemuSecurityRestoreAllLabel(data->driver, vm, false); - if (checkPaths((const char **) notRestored) < 0) + if (checkPaths(notRestored) < 0) goto cleanup; ret =3D 0; diff --git a/tests/qemusecuritytest.h b/tests/qemusecuritytest.h index cc3918ddf5..696cfb4b63 100644 --- a/tests/qemusecuritytest.h +++ b/tests/qemusecuritytest.h @@ -20,6 +20,8 @@ #define ENVVAR "LIBVIRT_QEMU_SECURITY_TEST" -extern int checkPaths(const char **paths); +#include "internal.h" + +extern int checkPaths(GHashTable *paths); extern void freePaths(void); --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600449; cv=none; d=zohomail.com; s=zohoarc; b=YXgUKuRjJrQMMH+kkn3AwrFzUex0yPS/9UZQRkk4N1CLSFazLIOSmo8jmvrmcxf1pVESfLe5rvgJXy2wacWVMSk689sTBg008dT3e6TD8t3fG348honBlgFIzWWKQBJ5fnzI02nmy6Q7sIvRU7kXK4wv+IQNQ5wU2WoYVQud+U4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600449; 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=LtPEaKGQSdbVtV54ymNhqs5piM2fFDnK33NyEUqyiD4=; b=XbCgOHW9o+LarWHRsS2Nnpx8jZ0uLA88tuzp1gn6BNms36c/tDKi580B1EofdykwJ3G9Su62hdj7QVFSh3gX3xpfyu42Hs6F2ex8XCyVDf6J0Z4l/5x5UtO4XtrRl/AvKJlyVyY14S95TxCFhXhGFTLa5D4ZlTjxPSJ5f/Zkh+w= 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) header.from= 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 1612600449686267.8976438557876; Sat, 6 Feb 2021 00:34:09 -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-279-9WTw6H2aPhG8GDCEj05OSw-1; Sat, 06 Feb 2021 03:34:06 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC95D1005501; Sat, 6 Feb 2021 08:34: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 B76FE1010F4E; Sat, 6 Feb 2021 08:34: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 7F99258078; Sat, 6 Feb 2021 08:34:00 +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 1168XwK5005120 for ; Sat, 6 Feb 2021 03:33:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id EE77E60C76; Sat, 6 Feb 2021 08:33:58 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DDD960C77 for ; Sat, 6 Feb 2021 08:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600448; 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=LtPEaKGQSdbVtV54ymNhqs5piM2fFDnK33NyEUqyiD4=; b=X3U/2TQ+yx/cw5jyXbrKIw010JDIh/WG15/KsDDSa7qv0ndkbaMH2uOYQCO3jytyDdpjkJ 792rK6ozEB7wKyM7EVy+af61DPSc2Kr/RXL+g/DecL43WKwqBjSkSGT39EvVTyZpbOL0fY qF2XvDbBvyorYxHIVAGq1jhhLrSSuKg= X-MC-Unique: 9WTw6H2aPhG8GDCEj05OSw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 21/40] util: virstring: Remove virStringListAdd and virStringListRemove Date: Sat, 6 Feb 2021 09:32:43 +0100 Message-Id: <03d32765f2b5b9c1bbad37ea506a658d105303d7.1612599659.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" virStringListAdd hides the fact that a O(n) count of elements is performed every time it's called which makes it inefficient. Stop supporting such semantics and remove the helpers. Users have a choice of using GSList or an array with a counter variable rather than repeated lookups. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 2 -- src/util/virstring.c | 61 ---------------------------------- src/util/virstring.h | 5 --- tests/virstringtest.c | 72 ---------------------------------------- 4 files changed, 140 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c2270208e4..86380d0853 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3240,14 +3240,12 @@ virStringHasControlChars; virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; -virStringListAdd; virStringListFreeCount; virStringListGetFirstWithPrefix; virStringListHasString; virStringListJoin; virStringListLength; virStringListMerge; -virStringListRemove; virStringMatch; virStringMatchesNameSuffix; virStringParsePort; diff --git a/src/util/virstring.c b/src/util/virstring.c index 521f2de3f6..bf861d4847 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -162,67 +162,6 @@ char *virStringListJoin(const char **strings, } -/** - * virStringListAdd: - * @strings: a NULL-terminated array of strings - * @item: string to add - * - * Appends @item into string list @strings. If *@strings is not - * allocated yet new string list is created. - * - * Returns: 0 on success, - * -1 otherwise - */ -int -virStringListAdd(char ***strings, - const char *item) -{ - size_t i =3D virStringListLength((const char **) *strings); - - if (VIR_EXPAND_N(*strings, i, 2) < 0) - return -1; - - (*strings)[i - 2] =3D g_strdup(item); - - return 0; -} - - -/** - * virStringListRemove: - * @strings: a NULL-terminated array of strings - * @item: string to remove - * - * Remove every occurrence of @item in list of @strings. - */ -void -virStringListRemove(char ***strings, - const char *item) -{ - size_t r, w =3D 0; - - if (!strings || !*strings) - return; - - for (r =3D 0; (*strings)[r]; r++) { - if (STREQ((*strings)[r], item)) { - VIR_FREE((*strings)[r]); - continue; - } - if (r !=3D w) - (*strings)[w] =3D (*strings)[r]; - w++; - } - - if (w =3D=3D 0) { - VIR_FREE(*strings); - } else { - (*strings)[w] =3D NULL; - ignore_value(VIR_REALLOC_N(*strings, w + 1)); - } -} - - /** * virStringListMerge: * @dst: a NULL-terminated array of strings to expand diff --git a/src/util/virstring.h b/src/util/virstring.h index cfd24f0b74..00c669b43b 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -37,11 +37,6 @@ char *virStringListJoin(const char **strings, const char *delim) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -int virStringListAdd(char ***strings, - const char *item); -void virStringListRemove(char ***strings, - const char *item); - int virStringListMerge(char ***dst, char ***src); diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 7305190691..9eabb5b299 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -163,74 +163,6 @@ static int testJoin(const void *args) } -static int testAdd(const void *args) -{ - const struct testJoinData *data =3D args; - char **list =3D NULL; - char *got =3D NULL; - int ret =3D -1; - size_t i; - - for (i =3D 0; data->tokens[i]; i++) { - if (virStringListAdd(&list, data->tokens[i]) < 0) - goto cleanup; - } - - if (!list) - list =3D g_new0(char *, 1); - - if (!(got =3D virStringListJoin((const char **)list, data->delim))) { - VIR_DEBUG("Got no result"); - goto cleanup; - } - - if (STRNEQ(got, data->string)) { - fprintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string); - goto cleanup; - } - - ret =3D 0; - cleanup: - g_strfreev(list); - VIR_FREE(got); - return ret; -} - - -static int testRemove(const void *args) -{ - const struct testSplitData *data =3D args; - char **list =3D NULL; - size_t ntokens; - size_t i; - int ret =3D -1; - - if (!(list =3D virStringSplitCount(data->string, data->delim, - data->max_tokens, &ntokens))) { - VIR_DEBUG("Got no tokens at all"); - return -1; - } - - for (i =3D 0; data->tokens[i]; i++) { - virStringListRemove(&list, data->tokens[i]); - if (virStringListHasString((const char **) list, data->tokens[i]))= { - fprintf(stderr, "Not removed %s", data->tokens[i]); - goto cleanup; - } - } - - if (list && list[0]) { - fprintf(stderr, "Not removed all tokens: %s", list[0]); - goto cleanup; - } - - ret =3D 0; - cleanup: - g_strfreev(list); - return ret; -} - - static int testStringSortCompare(const void *opaque G_GNUC_UNUSED) { @@ -683,10 +615,6 @@ mymain(void) ret =3D -1; \ if (virTestRun("Join " #str, testJoin, &joinData) < 0) \ ret =3D -1; \ - if (virTestRun("Add " #str, testAdd, &joinData) < 0) \ - ret =3D -1; \ - if (virTestRun("Remove " #str, testRemove, &splitData) < 0) \ - ret =3D -1; \ } while (0) VIR_WARNINGS_NO_DECLARATION_AFTER_STATEMENT --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600457; cv=none; d=zohomail.com; s=zohoarc; b=k60fQxojCRCtDbzNVOS9ztlUH2VidwzTEaJgSTwr6N4ZBEgQhYYw/g86wV1yKNTnFDf0+qHyJyAkvyY6GSwfYwYhZLJ40QT86VrkQLFSpP9TAiVF7ATiJlT/8P5AxtjR5de0iXjp+elEs2wOD+Eigp5pe6Tvex1H5uLV00KshjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600457; 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=RqsKYxfdAjaI5bwndVbSWtC3fP0XrlN7yCONt7p7a8Q=; b=bMcUPDCU9RqURUxfRoBzmns3Sk5L6lkhwo86/5r2nCOxbgVaMwmV675lf0ZbJwnaXMKaKMWW5dCXpA0DfWHy05yJcxzVbmfkURXbfnT83xTqQFPZnsaZLdF2c0EPPGmFW2CfkQS73GKFNolUPtg5jkQ7Jzso2p/ydTVR3BxV3CE= 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 161260045713432.03011252040301; Sat, 6 Feb 2021 00:34:17 -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-308-heF5Mn6BP_GzLuHPar24gA-1; Sat, 06 Feb 2021 03:34:12 -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 86B4D8030B7; Sat, 6 Feb 2021 08:34:07 +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 651F56F977; Sat, 6 Feb 2021 08:34:07 +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 2DDDF5808F; Sat, 6 Feb 2021 08:34:07 +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 1168Y5fo005191 for ; Sat, 6 Feb 2021 03:34:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id 95A4860C77; Sat, 6 Feb 2021 08:34:05 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03AB960C76 for ; Sat, 6 Feb 2021 08:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600456; 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=RqsKYxfdAjaI5bwndVbSWtC3fP0XrlN7yCONt7p7a8Q=; b=MbJjAraOlDObm6YdVHe9P8egrLPh/kr3w18qyarqPagSvhh+CxkADeR5qw7xG3r+Jqzl88 NiigmZJef6pJ/flV0bJ3pJzIDLAzRo8Pc+m443Pblop9Zx7D9J7zUB7f2PTpuQc9h/Ur17 pgTePnqUuxyBUj6/BNQeH4EerY3reNM= X-MC-Unique: heF5Mn6BP_GzLuHPar24gA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 22/40] virCgroupGetValueForBlkDev: Rewrite lookup of returned string Date: Sat, 6 Feb 2021 09:32:44 +0100 Message-Id: <90d6e95499904b7e4fdfb72f85cbecea4c599cda.1612599659.git.pkrempa@redhat.com> 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" Lookup the string with prefix locally so that we can remove the helper which isn't universal at all. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/vircgroup.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b5c74e94de..2c418cd84d 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -568,21 +568,21 @@ virCgroupGetValueForBlkDev(const char *str, char **value) { g_autofree char *prefix =3D NULL; - char **lines =3D NULL; - int ret =3D -1; + g_auto(GStrv) lines =3D NULL; + GStrv tmp; if (!(prefix =3D virCgroupGetBlockDevString(path))) - goto error; + return -1; if (!(lines =3D virStringSplit(str, "\n", -1))) - goto error; + return -1; - *value =3D g_strdup(virStringListGetFirstWithPrefix(lines, prefix)); + for (tmp =3D lines; *tmp; tmp++) { + if ((*value =3D g_strdup(STRSKIP(*tmp, prefix)))) + break; + } - ret =3D 0; - error: - g_strfreev(lines); - return ret; + return 0; } --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600460; cv=none; d=zohomail.com; s=zohoarc; b=kprkKSzpq6vvqBhh/Ct4GsqSUEjjsiH6gTuFnWHMSs8H7N7tPzBlZo+msdeM6EA2qqH1UrHVdtXvgmMT1tYauZ0j8Jnmicxuy5i7f2FY8nMeG6rIU9bzwPTZBEmo5jHY35AOfTJlhe3oDR11R1okWy6pnxGSNdMNyHYPwLa4lvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600460; 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=ZTjy5DQLY3mrNXBs9SK1Lk/MpJMg8yRZzp3JMLwHBMo=; b=luIN90P9hU5SRfnaGUc4hzEArQrsPK3x4AldVgbgAcWQm4Bu4xVedqkggj8v+ul0n1cWkbjcoPKpA0PMyqWiAgXyT+b0WaSbGb9w5hABWbKCcj4u10eq2sdqLMJIbPaQ8RvSoItB9R6B9i7O+weuS+CWUG6Oxt4bEQQ5jp1rbro= 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 1612600460693212.9650101877471; Sat, 6 Feb 2021 00:34:20 -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-408-LaqX1FJ_ORWd1u6uqPsMvw-1; Sat, 06 Feb 2021 03:34:17 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E97EA100CCC2; Sat, 6 Feb 2021 08:34:10 +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 C59F460C76; Sat, 6 Feb 2021 08:34:10 +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 868731809C8F; Sat, 6 Feb 2021 08:34:10 +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 1168Y9nY005213 for ; Sat, 6 Feb 2021 03:34:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2438060C77; Sat, 6 Feb 2021 08:34:09 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2556360C76 for ; Sat, 6 Feb 2021 08:34:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600459; 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=ZTjy5DQLY3mrNXBs9SK1Lk/MpJMg8yRZzp3JMLwHBMo=; b=Jms4EKPKLipjPtDJr/VFIvnlaGOYmvw0zqv1aokEDy8yIHauefdGy/7mtjIx6L+/qCDeA5 5aO0ydpC4t6hdD421ivrsecDJyXN2Uhp6XFLxN9iuTrw2uCLGg//tY/VVNeoQ0RxADb3xc a7T1nulHS+qM20eBQb0w1/KXfrkbZ5s= X-MC-Unique: LaqX1FJ_ORWd1u6uqPsMvw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 23/40] virStringListGetFirstWithPrefix: Remove unused helper Date: Sat, 6 Feb 2021 09:32:45 +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.12 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" This is a uncommon and trivial operation, so having an utility function for it is pointless. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 - src/util/virstring.c | 18 ------------------ src/util/virstring.h | 3 --- 3 files changed, 22 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 86380d0853..d215665ee0 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3241,7 +3241,6 @@ virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; virStringListFreeCount; -virStringListGetFirstWithPrefix; virStringListHasString; virStringListJoin; virStringListLength; diff --git a/src/util/virstring.c b/src/util/virstring.c index bf861d4847..516b898223 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -238,24 +238,6 @@ virStringListHasString(const char **strings, return false; } -char * -virStringListGetFirstWithPrefix(char **strings, - const char *prefix) -{ - size_t i =3D 0; - - if (!strings) - return NULL; - - while (strings[i]) { - if (STRPREFIX(strings[i], prefix)) - return strings[i] + strlen(prefix); - i++; - } - - return NULL; -} - /* 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 00c669b43b..4705b9c141 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -45,9 +45,6 @@ void virStringListFreeCount(char **strings, bool virStringListHasString(const char **strings, const char *needle); -char *virStringListGetFirstWithPrefix(char **strings, - const char *prefix) - ATTRIBUTE_NONNULL(2); int virStrToLong_i(char const *s, char **end_ptr, --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600567; cv=none; d=zohomail.com; s=zohoarc; b=IuAodO7PONJ8yEW+FR/UHJT2svpNwg8YtH7YxhNb2mUfode3Lw4g+B2H0j22Q33JSr1xruIwx9OyKcElC2b0lKZM7EyQmaphSIw9ChMu4r5NhqSincl6hsAN1FmoYj66M2lDPJCrCanfLjq/pg+huY2SbpmtDWMr3HeyDitSZ14= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600567; 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=2d1ozZK96bIUkUrvLSLfwqlBEdqp1qstmWhKKngSYzM=; b=U45FoHX6jfCMV9NlbtIh2fznqQDxnxOZkonGzq5HEfUyN+2QdhNNA/ZdP66zISwHfXW96dXailflm1xsoQnyVmQtCjmsGP4Yant7o8mL5CV9wbjtPc1M9OeBkhle1T5t5spm2zjdOAKTb2yUE4NetvJhKKMZBvM3H39jgJ+YBmg= 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) header.from= 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 161260056733767.64067856339796; Sat, 6 Feb 2021 00:36:07 -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-203-YHDzOEYuOfOTNAF6KiNxgg-1; Sat, 06 Feb 2021 03:34:20 -0500 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 66C32100CCC6; Sat, 6 Feb 2021 08:34:13 +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 429855D9CC; Sat, 6 Feb 2021 08:34:13 +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 0138958092; Sat, 6 Feb 2021 08:34:13 +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 1168YCgO005247 for ; Sat, 6 Feb 2021 03:34:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3BCF260C77; Sat, 6 Feb 2021 08:34:12 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 499A860C76 for ; Sat, 6 Feb 2021 08:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600566; 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=2d1ozZK96bIUkUrvLSLfwqlBEdqp1qstmWhKKngSYzM=; b=RHOFzW+Tl7lsZTqypAtSlD9cIeGAGNBFGe7B4r+QE2/oOav76RUT2V4XqNUhvCZ36C0KS6 3lpS/WrxYj8UMKOq7OGXHCiu/2HQXxHOgyOAl/BvD8lqx7rbXOZSGBBBOiF8814U+YbgRl KkVGmSwXXxvPj51Sc7/0zkBhx3xXDYQ= X-MC-Unique: YHDzOEYuOfOTNAF6KiNxgg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 24/40] vz: Replace virStringSplitCount(, , , NULL) with virStringSplit Date: Sat, 6 Feb 2021 09:32:46 +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.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) Content-Type: text/plain; charset="utf-8" The caller doesn't care about the number of tokens so use the function which doesn't return it. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/vz/vz_sdk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 00891dc16a..9ea0edaf97 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -745,7 +745,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk, goto cleanup; } - if (!(matches =3D virStringSplitCount(uri->path, "/", 0, NULL)) || + if (!(matches =3D virStringSplit(uri->path, "/", 0)) || !matches[0]) { virReportError(VIR_ERR_INTERNAL_ERROR, _("splitting StorageUrl failed %s"), uri->path); --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600506; cv=none; d=zohomail.com; s=zohoarc; b=lHIZurgDD+3P495rker1QyMkaTLYCT9WGNRq1eynNUT6Lz2tQhdxzBCwU6Aqu/E3yhA8TpoVQN+mKimAn0iDt7rCJwSPVu1C7rhmiQC/d8iKoEVJMLak50DTSRdkaGFYGWeN+aQQKuHdsZZjuMW82nU3idcEnpeBDrx6H3muIJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600506; 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=POeiAURAgBCyqtu7zEWjyR4+gYI6aRoU+/3GdlJoqAw=; b=ZGixVBlhC04BTS24jdek3txq6Ucn0kdVGKpgjJqhmZSlM+tY6JzXirSe2FdzOObHIcodXGmWU1baaOQA3DDiiLZ/XOCEsV2R6HMyeSfXgDoO4gL9QdO6WwRhfuO///1SmdMy7d6lOMUPRHslpwlRsqMEiICuSWl+uRHUijN+qOg= 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) header.from= 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 1612600506931620.4774224297898; Sat, 6 Feb 2021 00:35:06 -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-388-MgLKkoxDMnq0blLKYL4txQ-1; Sat, 06 Feb 2021 03:34:23 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21287107ACF2; Sat, 6 Feb 2021 08:34:17 +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 EC82D101E242; Sat, 6 Feb 2021 08:34:16 +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 B830B5807E; Sat, 6 Feb 2021 08:34:16 +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 1168YFvI005287 for ; Sat, 6 Feb 2021 03:34:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 218DB60C77; Sat, 6 Feb 2021 08:34:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 703B260C76 for ; Sat, 6 Feb 2021 08:34:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600505; 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=POeiAURAgBCyqtu7zEWjyR4+gYI6aRoU+/3GdlJoqAw=; b=b8cDPnstRbuLlz1Xg5ooJxjtDRZoeQCQ5bY093fuMAbpjN8/znmr2p4YgugFNCs8rx9H7C chgHD4FDc1THt06ruB41hB7CioKwsdzUKv4RZPFquCZM6O55CtbYK6mTPrpFzqqG+hBzt/ 2KT1+vCBV7uTjy9UzzP1WetJDYwOmI0= X-MC-Unique: MgLKkoxDMnq0blLKYL4txQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 25/40] qemuProcessUpdateDevices: Refactor cleanup and memory handling Date: Sat, 6 Feb 2021 09:32:47 +0100 Message-Id: <733f4200f6c5789ef4c88e5681a3d860fd01e816.1612599659.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" Use automatic memory freeing and remove the 'cleanup' label. Also make it a bit more obvious that nothing happens if the 'old' list wasn't present. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_process.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 30cfa4d485..1fd3230e97 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3798,32 +3798,23 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv =3D vm->privateData; virDomainDeviceDef dev; - const char **qemuDevices; - char **old; - char **tmp; - int ret =3D -1; + g_auto(GStrv) old =3D g_steal_pointer(&priv->qemuDevices); + GStrv tmp; - old =3D priv->qemuDevices; - priv->qemuDevices =3D NULL; if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) - goto cleanup; + return -1; - qemuDevices =3D (const char **)priv->qemuDevices; - if ((tmp =3D old)) { - while (*tmp) { - if (!virStringListHasString(qemuDevices, *tmp) && - virDomainDefFindDevice(vm->def, *tmp, &dev, false) =3D=3D = 0 && - qemuDomainRemoveDevice(driver, vm, &dev) < 0) { - goto cleanup; - } - tmp++; - } + if (!old) + return 0; + + for (tmp =3D old; *tmp; tmp++) { + if (!virStringListHasString((const char **) priv->qemuDevices, *tm= p) && + virDomainDefFindDevice(vm->def, *tmp, &dev, false) =3D=3D 0 && + qemuDomainRemoveDevice(driver, vm, &dev)) + return -1; } - ret =3D 0; - cleanup: - g_strfreev(old); - return ret; + return 0; } static int --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600470; cv=none; d=zohomail.com; s=zohoarc; b=HvWCXvOEv0DPPubDsIvcXLgUGdzsHaJH8vRGiPlK7t+Puapv9olHSazpXB2IUsEPdUWdMSIO3WyelNG8m7KoYV8i15riR3aGkFcI/K4eTEkTQu113UxRLfc8xyJM9vnK+bdCnlkYj9y3dw6VhhveT5wSeDZa3vShE+kx4VSLTFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600470; 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=Ok9sem5/Kb6ebN9qGCknGqg5LBkViEBQwRLy2MAfziw=; b=TBCBgwD9nRSyqSapOEDTtS2x0Ez2iQP1bQXTG5RaMgDtWmlZXssIE5EqolhOqXM9SMxf6YxVWOm6KSbDm23tZ/cR/oUilDvMrokNIsh/0euYfSqmMpIb0Cm1ba9o/ov+bhVqguYLuL7+7v0JPhJFJr8vcnq4wxXVGx1xTqIT7LM= 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) header.from= 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 1612600470203808.7594653430876; Sat, 6 Feb 2021 00:34:30 -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-259-Lm9v3dvpNtuBYjsqCGRZ-w-1; Sat, 06 Feb 2021 03:34:26 -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 F3BD980365B; Sat, 6 Feb 2021 08:34:20 +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 752A160C9C; Sat, 6 Feb 2021 08:34:20 +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 3F41018089C9; Sat, 6 Feb 2021 08:34:20 +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 1168YIk5005305 for ; Sat, 6 Feb 2021 03:34:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id C5C9160C7B; Sat, 6 Feb 2021 08:34:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D6CA60C78 for ; Sat, 6 Feb 2021 08:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600469; 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=Ok9sem5/Kb6ebN9qGCknGqg5LBkViEBQwRLy2MAfziw=; b=SbGtMbv5GXq0FSGSmqhUeeFbvMq/Km8tVSw+G7CFSQrh4luy9cakPvYpJAL+WnLpUudw3T fpkUqVmLzrMYzzTKRFIwpYvoi2JpguPpK5zniA8+LdLoGTZDYnDbOqbeIa/J3oKlNYa3cu DrcbSVBnovoXpIGOjyFdB46gcHHLAFs= X-MC-Unique: Lm9v3dvpNtuBYjsqCGRZ-w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 26/40] Replace virStringListHasString by g_strv_contains Date: Sat, 6 Feb 2021 09:32:48 +0100 Message-Id: <6ed390c37b8772824d946bfa438505a522a54aff.1612599659.git.pkrempa@redhat.com> 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" The glib variant doesn't accept NULL list, but there's just one caller where it wasn't checked explicitly, thus there's no need for our own wrapper. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/lxc/lxc_native.c | 4 ++-- src/qemu/qemu_capabilities.c | 8 ++++---- src/qemu/qemu_process.c | 4 ++-- tests/qemumonitorjsontest.c | 6 +++--- tools/virsh-completer.c | 3 ++- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 58b9db8f08..e68977dd99 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -304,7 +304,7 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) type =3D VIR_DOMAIN_FS_TYPE_BLOCK; /* Do we have ro in options? */ - readonly =3D virStringListHasString((const char **)options, "ro"); + readonly =3D g_strv_contains((const char **)options, "ro"); if (lxcAddFSDef(def, type, src, dst, readonly, usage) < 0) goto cleanup; @@ -1108,7 +1108,7 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr propert= ies) for (i =3D 0; i < VIR_DOMAIN_PROCES_CAPS_FEATURE_LAST; i++) { capString =3D virDomainProcessCapsFeatureTypeToString(i); if (toDrop !=3D NULL && - virStringListHasString((const char **)toDrop, capString)) + g_strv_contains((const char **)toDrop, capString)) def->caps_features[i] =3D VIR_TRISTATE_SWITCH_OFF; } diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d41b4a4753..8f60ddeb7d 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2185,10 +2185,10 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefsPtr de= fs, for (i =3D 0; i < defs->ncpus; i++) { qemuMonitorCPUDefInfoPtr cpu =3D defs->cpus + i; - if (modelAllowed && !virStringListHasString(modelAllowed, cpu->nam= e)) + if (modelAllowed && !g_strv_contains(modelAllowed, cpu->name)) continue; - if (modelForbidden && virStringListHasString(modelForbidden, cpu->= name)) + if (modelForbidden && g_strv_contains(modelForbidden, cpu->name)) continue; if (virDomainCapsCPUModelsAdd(cpuModels, cpu->name, cpu->usable, @@ -3193,7 +3193,7 @@ virQEMUCapsProbeQMPTPM(virQEMUCapsPtr qemuCaps, for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMModelsToCaps); i++) { const char *needle =3D virDomainTPMModelTypeToString( virQEMUCapsTPMModelsToCaps[i].type); - if (virStringListHasString((const char **)entries, needle)) + if (g_strv_contains((const char **)entries, needle)) virQEMUCapsSet(qemuCaps, virQEMUCapsTPMModelsToCaps[i].caps); } @@ -3207,7 +3207,7 @@ virQEMUCapsProbeQMPTPM(virQEMUCapsPtr qemuCaps, for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsTPMTypesToCaps); i++) { const char *needle =3D virDomainTPMBackendTypeToString( virQEMUCapsTPMTypesToCaps[i].type); - if (virStringListHasString((const char **)entries, needle)) + if (g_strv_contains((const char **)entries, needle)) virQEMUCapsSet(qemuCaps, virQEMUCapsTPMTypesToCaps[i].caps= ); } } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 1fd3230e97..d24ef789ab 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -3808,7 +3808,7 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver, return 0; for (tmp =3D old; *tmp; tmp++) { - if (!virStringListHasString((const char **) priv->qemuDevices, *tm= p) && + if (!g_strv_contains((const char **) priv->qemuDevices, *tmp) && virDomainDefFindDevice(vm->def, *tmp, &dev, false) =3D=3D 0 && qemuDomainRemoveDevice(driver, vm, &dev)) return -1; @@ -6098,7 +6098,7 @@ qemuProcessDropUnknownCPUFeatures(const char *name, policy !=3D VIR_CPU_FEATURE_FORBID) return true; - if (virStringListHasString(features, name)) + if (g_strv_contains(features, name)) return true; /* Features unknown to QEMU are implicitly disabled, we can just drop = them diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 956423f10f..5a5976dbe4 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1057,13 +1057,13 @@ testQemuMonitorJSONGetDeviceAliases(const void *opa= que) ret =3D 0; for (alias =3D (const char **) aliases; *alias; alias++) { - if (!virStringListHasString(expected, *alias)) { + if (!g_strv_contains(expected, *alias)) { fprintf(stderr, "got unexpected device alias '%s'\n", *alias); ret =3D -1; } } for (alias =3D expected; *alias; alias++) { - if (!virStringListHasString((const char **) aliases, *alias)) { + if (!g_strv_contains((const char **) aliases, *alias)) { fprintf(stderr, "missing expected alias '%s'\n", *alias); ret =3D -1; } @@ -2079,7 +2079,7 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabil= ities(const void *opaque) return -1; cap =3D qemuMigrationCapabilityTypeToString(QEMU_MIGRATION_CAP_XBZRLE); - if (!virStringListHasString((const char **) caps, cap)) { + if (!g_strv_contains((const char **) caps, cap)) { virReportError(VIR_ERR_INTERNAL_ERROR, "Expected capability %s is missing", cap); return -1; diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index c7aed7c779..fb42358bd0 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -114,7 +114,8 @@ virshCommaStringListComplete(const char *input, ret =3D g_new0(char *, optionsLen + 1); for (i =3D 0; i < optionsLen; i++) { - if (virStringListHasString((const char **)inputList, options[i])) + if (inputList && + g_strv_contains((const char **)inputList, options[i])) continue; if (inputCopy) --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600476; cv=none; d=zohomail.com; s=zohoarc; b=SYW2iaOmza3JhOe0TB1b4i0ACketBbqq8GVQlYTZcZ/k9/FRjmRZKrP3HVKFgxQqDiLTQDKeM8UUbzlqk4Ql37Z01Vbxf+IldV95a7J3UdQcFtMRjH4BLnNiHnOa2ccy0nRGuMGijFuaf4lusuk7Q2Mr30UrQNq+MA165B1DUZo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600476; 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=XvyYx5/C/slIitfus4NsclJujmTmf9NzojwnXvdCLZU=; b=CZXK2PjFdNK+qnWChNBHBwtdI6x8CGTxnKxWC8epfgQJu7C99hCdBoqwDfeZ8YvKpatDz2SlkoC73nWm+OKnyFk1+YXmLPPmmS1VniVpJOiuy+nQ4ODNcF6oJ89IAbhG4RexvnrkD1gz4xaRLYDZbFg7TTRDNh/tZY6X/tG6OiY= 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 1612600476760173.88343852503158; Sat, 6 Feb 2021 00:34:36 -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-328-qHZA1OGXO4uLyE3xNA2ejg-1; Sat, 06 Feb 2021 03:34:33 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A831D803F48; Sat, 6 Feb 2021 08:34:28 +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 865DB722F9; Sat, 6 Feb 2021 08:34: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 5427118089D4; Sat, 6 Feb 2021 08:34: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 1168YReL005356 for ; Sat, 6 Feb 2021 03:34:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2FD5160C7B; Sat, 6 Feb 2021 08:34:27 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AD2060C79 for ; Sat, 6 Feb 2021 08:34:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600475; 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=XvyYx5/C/slIitfus4NsclJujmTmf9NzojwnXvdCLZU=; b=B1m/WwOJFr9zhQEQ6cQbF9SpjYMBwUWNREEDqZDaM2Hi6ZoMD2ELvdaiBWmZvvZs7L/wpG 8kOEHyATVcJ9mc5obV4TM9vxZQ4NKcGX9ugGwWK8OI43DoKqbUeooV7T89eEyaM83Xyh96 6n/mzKNBTsbDV20nHd5snE0RhVlXz1Q= X-MC-Unique: qHZA1OGXO4uLyE3xNA2ejg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 27/40] util: virstring: Remove virStringListHasString Date: Sat, 6 Feb 2021 09:32:49 +0100 Message-Id: <87ae4086f58fc5ccd557855b69609bceb73b121d.1612599659.git.pkrempa@redhat.com> 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.11 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" All callers were converted to the glib alternative. Providing our own just to have NULL tolerance doesn't make sense. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 - src/util/virstring.c | 17 ----------------- src/util/virstring.h | 3 --- 3 files changed, 21 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d215665ee0..ab8cf62552 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3241,7 +3241,6 @@ virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; virStringListFreeCount; -virStringListHasString; virStringListJoin; virStringListLength; virStringListMerge; diff --git a/src/util/virstring.c b/src/util/virstring.c index 516b898223..c0393585e2 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -221,23 +221,6 @@ virStringListFreeCount(char **strings, } -bool -virStringListHasString(const char **strings, - const char *needle) -{ - size_t i =3D 0; - - if (!strings) - return false; - - while (strings[i]) { - if (STREQ(strings[i++], needle)) - return true; - } - - return false; -} - /* 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 4705b9c141..1a15812307 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -43,9 +43,6 @@ int virStringListMerge(char ***dst, void virStringListFreeCount(char **strings, size_t count); -bool virStringListHasString(const char **strings, - const char *needle); - int virStrToLong_i(char const *s, char **end_ptr, int base, --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600482; cv=none; d=zohomail.com; s=zohoarc; b=OJTJxI+mJiOB9rUxiuEpUsltD3nIEPPMqOvsWKf5FWRy/q4nAKMlk2eOagGNR9WeDCOkSC0d2a69g5Qw86zrBaTCS3xu2/hcIC5jYE4O5johvBNn4w33iaTrxcewzrSkQi3C/WmAyBxmMZvv++pj8AOmiIZxcUgw6YCqg06PUEA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600482; 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=4LdurI+17nsWr+b8Vdl1NenDRBIcK7qouHyFYf5udgM=; b=PRVGx/X5W0vdy9s+EdOvhqrhzSAi6DZU9zh+bQXRowcsPt8lDMnSKU65AvVCQAYEebxztv8WsmxZcU1bQv5uFcxaj17w2pE6I5yXddK5j5u6jVxQm7dj+4i+4uO15xEKj7SDmcVvm1Celokyk05JJ5bD+4N4+9KKZBDhUc2jQyM= 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) header.from= 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 1612600482392484.7028035850601; Sat, 6 Feb 2021 00:34:42 -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-439-socnZL8lPYyLgNGkpjLShg-1; Sat, 06 Feb 2021 03:34:38 -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 A8B71107ACFC; Sat, 6 Feb 2021 08:34:32 +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 8423F5C290; Sat, 6 Feb 2021 08:34:32 +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 49C0E1800237; Sat, 6 Feb 2021 08:34:32 +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 1168YVHU005389 for ; Sat, 6 Feb 2021 03:34:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2AD5060C79; Sat, 6 Feb 2021 08:34:31 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BA9F61987 for ; Sat, 6 Feb 2021 08:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600481; 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=4LdurI+17nsWr+b8Vdl1NenDRBIcK7qouHyFYf5udgM=; b=czWrt5OcYC9Pz7qxMI9VuoOaTIt5ViCI/UpMtvrmaRvvYWjij5ut+FLKZwfX2l909BVTVR 22AWMvpZrO23ndJumdLfnh98HECT+qCUMh1och/DV4SQqUBZdpFMiGB3E3Jr9SlkOLb376 8yvs4t3RE8e5o3Znw/GsHgiStFq4WoY= X-MC-Unique: socnZL8lPYyLgNGkpjLShg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 28/40] virStorageBackendSheepdogAddVolume: Clean up memory handling Date: Sat, 6 Feb 2021 09:32:50 +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.16 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" 'cells' can be pushed into the loop removing the need for manual cleanup, the check whether 'line' is NULL inside of the loop is always false since the loop checks it right before and 'line' variable is unnecessary. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/storage/storage_backend_sheepdog.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index c5b7c568dd..178cfbae11 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -140,7 +140,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) size_t i; g_autofree char *output =3D NULL; g_auto(GStrv) lines =3D NULL; - g_auto(GStrv) cells =3D NULL; g_autoptr(virCommand) cmd =3D NULL; cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL); @@ -154,20 +153,15 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) return -1; for (i =3D 0; lines[i]; i++) { - const char *line =3D lines[i]; - if (line =3D=3D NULL) - break; + g_auto(GStrv) cells =3D NULL; - cells =3D virStringSplit(line, " ", 0); + cells =3D virStringSplit(lines[i], " ", 0); if (cells !=3D NULL && virStringListLength((const char * const *)cells) > 2) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) return -1; } - - g_strfreev(cells); - cells =3D NULL; } return 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600485; cv=none; d=zohomail.com; s=zohoarc; b=M5SPhy6owdYIG3Ymi2F61BQcsMvcztuU8qVE5w2KLzvJ70wXkg42Fyj4uRBt9N1xg798vl5lAL7HkMSEVsz7GY9tad8CumY6TQT2UdcYGE3qldgWU2na8Pne961/2y8MPbILSTFU1QuA/ESA4A8BC/q83MbS2bg4spZqd5RkdKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600485; 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=ieI5FPrCxFI+X5CwoEsSiRyzUruiXfRufabRZ0Z7DHY=; b=iMneI234v8M7vIe7IiM6K/cZ+XSv0dWYKOYsctQIGiA51OxrZxy0cx2UrQ6b+UWxRCFYWNJ5oZvnhr/fZr5gpRHsJ883njeQJj0UdYq+ugCyJQfRhlwOOngwhZC9SnjvvCa1Fnmj84716J2GDuG2edbIhzuaFgDvQ/thJGj478U= 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 1612600485976892.4476318643182; Sat, 6 Feb 2021 00:34:45 -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-558-rL1Xl5K5O5KIFA_6iidZyA-1; Sat, 06 Feb 2021 03:34:42 -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 99961107ACC7; Sat, 6 Feb 2021 08:34:36 +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 750556F983; Sat, 6 Feb 2021 08:34:36 +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 0A14458077; Sat, 6 Feb 2021 08:34:36 +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 1168YYfR005419 for ; Sat, 6 Feb 2021 03:34:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id B35C160C79; Sat, 6 Feb 2021 08:34:34 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E9F960C93 for ; Sat, 6 Feb 2021 08:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600485; 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=ieI5FPrCxFI+X5CwoEsSiRyzUruiXfRufabRZ0Z7DHY=; b=Ty/yCEdpbyK/3kmluwV9EiPMRlrZDOueVXuOfRHJ6g3TWYKa46f/ED3KQ+I7YTQ020ZxVC WBA9MiLYddyQd5WdflmqDgKtjMh9XDrPyLzR6KU/HyAI1u3gEke6BoakKET3/MYfpEz06n HN9qZa8J2l0W3FFIspZIM/eUwELsxOc= X-MC-Unique: rL1Xl5K5O5KIFA_6iidZyA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 29/40] qemufirmwaretest: Base iteration on string lists Date: Sat, 6 Feb 2021 09:32:51 +0100 Message-Id: <2eb191c1be0db46996ad560f3e6186c86e53158d.1612599659.git.pkrempa@redhat.com> 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" Remove the need to calculate list lengths. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/qemufirmwaretest.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c index ced9d53260..b59b002c3b 100644 --- a/tests/qemufirmwaretest.c +++ b/tests/qemufirmwaretest.c @@ -57,16 +57,16 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED) { g_autofree char *fakehome =3D NULL; g_auto(GStrv) fwList =3D NULL; - size_t nfwList; - size_t i; const char *expected[] =3D { PREFIX "/share/qemu/firmware/40-bios.json", SYSCONFDIR "/qemu/firmware/40-ovmf-sb-keys.json", PREFIX "/share/qemu/firmware/50-ovmf-sb-keys.json", PREFIX "/share/qemu/firmware/61-ovmf.json", PREFIX "/share/qemu/firmware/70-aavmf.json", + NULL }; - const size_t nexpected =3D G_N_ELEMENTS(expected); + GStrv e; + GStrv f; fakehome =3D g_strdup(abs_srcdir "/qemufirmwaredata/home/user/.config"= ); @@ -80,18 +80,18 @@ testFWPrecedence(const void *opaque G_GNUC_UNUSED) return -1; } - nfwList =3D virStringListLength((const char **)fwList); - - for (i =3D 0; i < MAX(nfwList, nexpected); i++) { - const char *e =3D i < nexpected ? expected[i] : NULL; - const char *f =3D i < nfwList ? fwList[i] : NULL; - - if (STRNEQ_NULLABLE(e, f)) { + for (e =3D (char **) expected, f =3D fwList; *f || *e;) { + if (STRNEQ_NULLABLE(*f, *e)) { fprintf(stderr, - "Unexpected path (i=3D%zu). Expected %s got %s \n", - i, NULLSTR(e), NULLSTR(f)); + "Unexpected path. Expected %s got %s \n", + NULLSTR(*e), NULLSTR(*f)); return -1; } + + if (*f) + f++; + if (*e) + e++; } return 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600489; cv=none; d=zohomail.com; s=zohoarc; b=gMzinRJw8ffTfJjPu02rUFi2O+uwR2ODiwyhkfQNWwlCjiuQgRHqBkwCNtJ2UkFHA6KAaMUPqAOKfShx7Q8dyH00JcJ080VymUR9qi362OUJErDINITvefJdH7anwOcTqqV7G+d6yIlvpBww0QLgOEBAZ66JlFDcP4zVkeXlbRM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600489; 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=KW8c2MRJbTptAiUBD4clLf9vSHem0CV3Cxiyv5Ts/pI=; b=QwqjaDcK5FjkwoahU8lVMSLWt7FK8OKtsm3Cydn8vsGkHnuhJlF73C3XfNcBfgep8ZzI8kVSJ/oRwKt8qygjab+zXPo36+tgh54Z8bWQ7L6iV1hD2nXBhDQtvjBQ40I3ODo99VvYxQydOHSIlrmv3ynYYJH5FQY3GaC7QWNO0/0= 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) header.from= 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 1612600489428868.425736262923; Sat, 6 Feb 2021 00:34:49 -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-169-aoGO2EvUMKiFj2LnIP3ZQg-1; Sat, 06 Feb 2021 03:34:46 -0500 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 20C4C801976; Sat, 6 Feb 2021 08:34:40 +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 F16D15D9E4; Sat, 6 Feb 2021 08:34:39 +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 BBD4258080; Sat, 6 Feb 2021 08:34:39 +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 1168Yc6I005441 for ; Sat, 6 Feb 2021 03:34:38 -0500 Received: by smtp.corp.redhat.com (Postfix) id C483460C7B; Sat, 6 Feb 2021 08:34:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28F4660C79 for ; Sat, 6 Feb 2021 08:34:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600488; 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=KW8c2MRJbTptAiUBD4clLf9vSHem0CV3Cxiyv5Ts/pI=; b=NZDNAb2Ev5zxm5Ej/JsvYSXLoCCwuvuhruBRAEncc4fRNv0K6JLpxWmx1KYaa19XuAm7gs 7ph1ivTCWqhgIzqOJcZkV0wVTdBb/xY2VL+ZUtXtGZsprS3A57M5mAT1UMQB00G1e9xk+B 6sFAUN/VArpH0NixOxO04efCLZRedvI= X-MC-Unique: aoGO2EvUMKiFj2LnIP3ZQg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 30/40] qemuvhostusertest: Base iteration on string lists Date: Sat, 6 Feb 2021 09:32:52 +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.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) Content-Type: text/plain; charset="utf-8" Remove the need to calculate list lengths. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/qemuvhostusertest.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/qemuvhostusertest.c b/tests/qemuvhostusertest.c index 17e4e83b99..a34b60c7dd 100644 --- a/tests/qemuvhostusertest.c +++ b/tests/qemuvhostusertest.c @@ -57,14 +57,14 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED) { g_autofree char *fakehome =3D NULL; g_auto(GStrv) vuList =3D NULL; - size_t nvuList; - size_t i; const char *expected[] =3D { PREFIX "/share/qemu/vhost-user/30-gpu.json", SYSCONFDIR "/qemu/vhost-user/40-gpu.json", PREFIX "/share/qemu/vhost-user/60-gpu.json", + NULL }; - const size_t nexpected =3D G_N_ELEMENTS(expected); + GStrv e; + GStrv f; fakehome =3D g_strdup(abs_srcdir "/qemuvhostuserdata/home/user/.config= "); @@ -78,18 +78,18 @@ testVUPrecedence(const void *opaque G_GNUC_UNUSED) return -1; } - nvuList =3D virStringListLength((const char **)vuList); - - for (i =3D 0; i < MAX(nvuList, nexpected); i++) { - const char *e =3D i < nexpected ? expected[i] : NULL; - const char *f =3D i < nvuList ? vuList[i] : NULL; - - if (STRNEQ_NULLABLE(e, f)) { + for (e =3D (char **) expected, f =3D vuList; *f || *e;) { + if (STRNEQ_NULLABLE(*f, *e)) { fprintf(stderr, - "Unexpected path (i=3D%zu). Expected %s got %s \n", - i, NULLSTR(e), NULLSTR(f)); + "Unexpected path. Expected %s got %s \n", + NULLSTR(*e), NULLSTR(*f)); return -1; } + + if (*f) + f++; + if (*e) + e++; } return 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600573; cv=none; d=zohomail.com; s=zohoarc; b=XpYUGUV3F2m9ezqeN9A0fkhI0Sf58mc4u+6lsPgALa/3oSPMV8y+W9X7ViuN1f8jWznPWiOF9WuNNKG+BwRlQMeUg/jB60m6GEpCihmJJgAj4L2CkLrIaQO24RYDJMwF9vNwt9g3z3ONNnZ23o4mGIuWV7x9dA3DikuB76Ys5Ws= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600573; 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=Ib+6hiVcy1Ppm5y44mP/Ldc2SvgXogS/X2GY3y3oimE=; b=hn3eD7MjF+WA5albuENM5o0Lo5il+dIgcGMndtrD+PP9gPQH2eveTvkJYcP40vLTqpKKd4F1C1kU/5A/m1EXxLGK481ie1f4qegkUeMr8GcikTT1bFT7eJx/Mj/pEG1aKURubBkplAmmmQLPkZFEbg+Xy0ucyn+6LJdzlu6LouM= 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 1612600573613797.5980737305451; Sat, 6 Feb 2021 00:36:13 -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-109-TX-EOaB5OaKB8SISD5YdzQ-1; Sat, 06 Feb 2021 03:34:49 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D619E1DDE2; Sat, 6 Feb 2021 08:34:43 +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 B1F4F72FAB; Sat, 6 Feb 2021 08:34:43 +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 7A04F18089D1; Sat, 6 Feb 2021 08:34:43 +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 1168YgdP005461 for ; Sat, 6 Feb 2021 03:34:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 57EC960C8F; Sat, 6 Feb 2021 08:34:42 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB7D860C79 for ; Sat, 6 Feb 2021 08:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600572; 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=Ib+6hiVcy1Ppm5y44mP/Ldc2SvgXogS/X2GY3y3oimE=; b=b65uWZL3nXn3wi3QPF59/VKYe3nRiO21Tn5saDUHRnww8Ygst6zILy29H+szgHk24mQIEA Xjpu/KlcNrbeWLbdew7DPsVlpQxfuZO++y2GI5SbUv2986vBNVCDv/z7YXlRscU0HgyyJv qKXGZYdhvPRY1VB54RlaMjeBxDrqC+w= X-MC-Unique: TX-EOaB5OaKB8SISD5YdzQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 31/40] Replace virStringListLength where actual lenght is not needed Date: Sat, 6 Feb 2021 09:32:53 +0100 Message-Id: <98ad6657f01013763177136d9e96caf232667bcd.1612599659.git.pkrempa@redhat.com> 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.11 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" Some callers don't need to know the actual lenght of the list but only care whether the required element is present or the list is non-empty. Don't calculate the list length in those cases. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/lxc/lxc_native.c | 2 +- src/qemu/qemu_driver.c | 2 +- src/storage/storage_backend_sheepdog.c | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index e68977dd99..4229a9ca7a 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -568,7 +568,7 @@ lxcNetworkParseDataIPs(const char *name, family =3D AF_INET6; ipparts =3D virStringSplit(value->str, "/", 2); - if (virStringListLength((const char * const *)ipparts) !=3D 2 || + if (!ipparts || !ipparts[0] || !ipparts[1] || virSocketAddrParse(&ip->address, ipparts[0], family) < 0 || virStrToLong_ui(ipparts[1], NULL, 10, &ip->prefix) < 0) { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c34af6b7d1..80bd27696b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17737,7 +17737,7 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, return -1; } - if (virStringListLength((const char * const *)features) =3D=3D 0) + if (!features || !*features) return 0; for (i =3D 0; i < dom->def->nresctrls; i++) { diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 178cfbae11..2db2384e67 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -157,8 +157,7 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) cells =3D virStringSplit(lines[i], " ", 0); - if (cells !=3D NULL && - virStringListLength((const char * const *)cells) > 2) { + if (cells !=3D NULL && cells[0] && cells[1]) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) return -1; } --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600863; cv=none; d=zohomail.com; s=zohoarc; b=dZnI5RVaJT0mmnOVVgjxamdRxMbXbKYKODXX5tGf6NQ9Yl18XY+SH4vtSYfQkJ+KnU0Y4RFVeSiV/kNbk4RwgUZ/YlmN0Y+fkbVd/9b5ahzxGDxzfn5XsXs2H393OHRhyV6CPTUBBz3NSmC95ysxxjWIlhy+iwryd63B2/KsYRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600863; 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=fVLOuC4wmckNY8ICnfTPo+G5zKY2i9OEHqvHAtfMDKI=; b=CU24TeHCLunY9vwWz8zznZgzwmZJaWXD/dPIqm3q6PJyGVwnDyvg1dlk0DtLVVHASDllcxFXa1rEzSZj6nR/sc0qO30d6PMvfcR1xFP2d/u7ZH1/MWryxS968UnpJ1EysXnVQ9/LY1oPo8GYZAYMWakNsgQvjluXmpGZKOSvfMs= 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 1612600863921658.3974278590878; Sat, 6 Feb 2021 00:41:03 -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-312-dfJ96p45PESfOuszTEVcag-1; Sat, 06 Feb 2021 03:34:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9775D107ACED; Sat, 6 Feb 2021 08:34:49 +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 3981E72FAE; Sat, 6 Feb 2021 08:34:49 +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 005EE18077D0; Sat, 6 Feb 2021 08:34:48 +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 1168Yl89005492 for ; Sat, 6 Feb 2021 03:34:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id CBCD360C7B; Sat, 6 Feb 2021 08:34:47 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6B4F60C79 for ; Sat, 6 Feb 2021 08:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600862; 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=fVLOuC4wmckNY8ICnfTPo+G5zKY2i9OEHqvHAtfMDKI=; b=HLCB1Kd4XfaC4sDKVORxWoM0OvcUORc+HiRarA4LVM3TncGTR7Lk36tq8ZGi5yKmXDb00N 5N7J3Ic0364PJv1tZgEf57f1YNWT4xcudqV10SLqPuwF6Tccv+6cvqTIs6xtR9W/entGnx XDIVuxaVqSS64MFmFvAw0t249y0eu8A= X-MC-Unique: dfJ96p45PESfOuszTEVcag-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 32/40] virPolkitCheckAuth: Avoid virStringListLength in loop condition Date: Sat, 6 Feb 2021 09:32:54 +0100 Message-Id: <0890b42ce32dee472c175e384c3fbc2fa83c4169.1612599659.git.pkrempa@redhat.com> 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.11 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" Don't re-calculate the string list length on every iteration. Convert the loop to NULL-terminated iteration. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virpolkit.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/util/virpolkit.c b/src/util/virpolkit.c index 1d6be443f7..c657c45681 100644 --- a/src/util/virpolkit.c +++ b/src/util/virpolkit.c @@ -75,7 +75,7 @@ int virPolkitCheckAuth(const char *actionid, gboolean is_authorized; gboolean is_challenge; bool is_dismissed =3D false; - size_t i; + const char **next; if (!(sysbus =3D virGDBusGetSystemBus())) return -1; @@ -90,8 +90,15 @@ int virPolkitCheckAuth(const char *actionid, gprocess =3D g_variant_builder_end(&builder); g_variant_builder_init(&builder, G_VARIANT_TYPE("a{ss}")); - for (i =3D 0; i < virStringListLength(details); i +=3D 2) - g_variant_builder_add(&builder, "{ss}", details[i], details[i + 1]= ); + + if (details) { + for (next =3D details; *next; next++) { + const char *detail1 =3D *(next++); + const char *detail2 =3D *next; + g_variant_builder_add(&builder, "{ss}", detail1, detail2); + } + } + gdetails =3D g_variant_builder_end(&builder); message =3D g_variant_new("((s@a{sv})s@a{ss}us)", --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600564; cv=none; d=zohomail.com; s=zohoarc; b=XO1QkrA3ggbTsKw2AaXvk7wiigdpf5dJ3HmP7JT0P6JeesN2/CMRt2QNZcIRTCU8lw8ms0kkx2iIaVyycnoJfq6b+xfNDmWsJe/LwJ7P/2X/0vDba92LEKm9+ahgiQkbXe47wJWixqWMH+v4OZUDDxF3F2nlkcZVuKjGKLHde5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600564; 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=QN0OprPbbXSS5wnGxS1/lvf8nr4WJ/IwIyqr1WQv0pA=; b=jOrdDlYMkiU+h0813FweFPUi0CI3VeDj3yYd9gLWVDMgHCiVHrsbwAJ9hR+Hz1iyiyKEW3Varbnxb5lPPpCFMKggU9OZmA6BTfop8m1YWQZsDjZYckFKXgGRi2xl2+x93RzdtF5oBTUDAhe5/EiaiuP+eF6eydY8lb1t2AvS27Q= 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 16126005641771006.6457254808954; Sat, 6 Feb 2021 00:36:04 -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-10--MXyNSxLNtO2ZA_WU56UyA-1; Sat, 06 Feb 2021 03:34:56 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 40B0F100CCC0; Sat, 6 Feb 2021 08:34:51 +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 1B4B81017CD0; Sat, 6 Feb 2021 08:34:51 +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 D722918077D3; Sat, 6 Feb 2021 08:34:50 +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 1168Ynpt005513 for ; Sat, 6 Feb 2021 03:34:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDB3960C7B; Sat, 6 Feb 2021 08:34:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A366660C79 for ; Sat, 6 Feb 2021 08:34:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600563; 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=QN0OprPbbXSS5wnGxS1/lvf8nr4WJ/IwIyqr1WQv0pA=; b=Nf3WCR58fSeeBZ/z7Y/Yurj80Q95zxUNu5pAohRTx6QXM0C/uMwhiRAPCBLh5rMl4h6T18 AVDAIztPofvAmFbxuNpTx22KjbWlrOMnKntQYfdJb3LFz99w4Z4XI7accL6JxZDxgHrmJV nOtT8PZqEa8wMeVS521rauhfwVFl0RI= X-MC-Unique: -MXyNSxLNtO2ZA_WU56UyA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 33/40] Replace virStringListLength by g_strv_length Date: Sat, 6 Feb 2021 09:32:55 +0100 Message-Id: <8e5e91b97532c023c1d6e74a3e5d870a1f22e667.1612599659.git.pkrempa@redhat.com> 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.84 on 10.5.11.22 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" The glib implementation doesn't tolerate NULL but in most cases we check before anyways. The rest of the callers adds a NULL check. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/cpu/cpu_arm.c | 2 +- src/qemu/qemu_conf.c | 4 ++-- src/qemu/qemu_firmware.c | 5 ++++- src/qemu/qemu_vhost_user.c | 4 +++- src/util/virprocess.c | 3 ++- src/util/virstring.c | 4 ++-- tests/virconftest.c | 4 ++-- tests/virstringtest.c | 6 +++--- tools/virsh-completer.c | 2 +- tools/virsh-domain.c | 2 +- tools/virsh-host.c | 4 ++-- tools/virt-login-shell-helper.c | 2 +- tools/vsh.c | 2 +- 13 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c index 6ba5bf0724..a7aef29fe4 100644 --- a/src/cpu/cpu_arm.c +++ b/src/cpu/cpu_arm.c @@ -637,7 +637,7 @@ virCPUarmDecode(virCPUDefPtr cpu, cpu->vendor =3D g_strdup(vendor->name); if (cpuData->features) { - cpu->nfeatures =3D virStringListLength((const char **)cpuData->fea= tures); + cpu->nfeatures =3D g_strv_length(cpuData->features); cpu->features =3D g_new0(virCPUFeatureDef, cpu->nfeatures); for (i =3D 0; i < cpu->nfeatures; i++) { diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 35d0b6515c..2bbc75024c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -648,7 +648,7 @@ virQEMUDriverConfigLoadProcessEntry(virQEMUDriverConfig= Ptr cfg, } VIR_FREE(cfg->hugetlbfs); - cfg->nhugetlbfs =3D virStringListLength((const char *const *)huget= lbfs); + cfg->nhugetlbfs =3D g_strv_length(hugetlbfs); if (hugetlbfs[0]) cfg->hugetlbfs =3D g_new0(virHugeTLBFS, cfg->nhugetlbfs); @@ -847,7 +847,7 @@ virQEMUDriverConfigLoadNVRAMEntry(virQEMUDriverConfigPt= r cfg, return 0; } - cfg->nfirmwares =3D virStringListLength((const char *const *)nvram= ); + cfg->nfirmwares =3D g_strv_length(nvram); cfg->firmwares =3D g_new0(virFirmwarePtr, cfg->nfirmwares); for (i =3D 0; nvram[i] !=3D NULL; i++) { diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index e6541d505e..c571fdecf7 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1191,7 +1191,10 @@ qemuFirmwareFetchParsedConfigs(bool privileged, if (qemuFirmwareFetchConfigs(&paths, privileged) < 0) return -1; - npaths =3D virStringListLength((const char **)paths); + if (!paths) + return 0; + + npaths =3D g_strv_length(paths); firmwares =3D g_new0(qemuFirmwarePtr, npaths); diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c index 5ceefbe456..a9f6f3192d 100644 --- a/src/qemu/qemu_vhost_user.c +++ b/src/qemu/qemu_vhost_user.c @@ -250,8 +250,10 @@ qemuVhostUserFetchParsedConfigs(bool privileged, if (qemuVhostUserFetchConfigs(&paths, privileged) < 0) return -1; - npaths =3D virStringListLength((const char **)paths); + if (!paths) + return 0; + npaths =3D g_strv_length(paths); vus =3D g_new0(qemuVhostUserPtr, npaths); for (i =3D 0; i < npaths; i++) { diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 0523bf9afb..4c27f9d771 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1013,7 +1013,8 @@ int virProcessGetStartTime(pid_t pid, tokens =3D virStringSplit(tmp, " ", 0); - if (virStringListLength((const char * const *)tokens) < 20) { + if (!tokens || + g_strv_length(tokens) < 20) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find start time in %s"), filename); diff --git a/src/util/virstring.c b/src/util/virstring.c index c0393585e2..1fd61650be 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -182,8 +182,8 @@ virStringListMerge(char ***dst, if (!src || !*src) return 0; - dst_len =3D virStringListLength((const char **) *dst); - src_len =3D virStringListLength((const char **) *src); + dst_len =3D g_strv_length(*dst); + src_len =3D g_strv_length(*src); if (VIR_REALLOC_N(*dst, dst_len + src_len + 1) < 0) return -1; diff --git a/tests/virconftest.c b/tests/virconftest.c index 8269730662..7a759db014 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -394,7 +394,7 @@ static int testConfParseStringList(const void *opaque G= _GNUC_UNUSED) if (virConfGetValueStringList(conf, "string_list", false, &str) < 0) goto cleanup; - if (virStringListLength((const char *const*)str) !=3D 2) { + if (!str || g_strv_length(str) !=3D 2) { fprintf(stderr, "expected a 2 element list\n"); goto cleanup; } @@ -418,7 +418,7 @@ static int testConfParseStringList(const void *opaque G= _GNUC_UNUSED) if (virConfGetValueStringList(conf, "string", true, &str) < 0) goto cleanup; - if (virStringListLength((const char *const*)str) !=3D 1) { + if (!str || g_strv_length(str) !=3D 1) { fprintf(stderr, "expected a 1 element list\n"); goto cleanup; } diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 9eabb5b299..238cb9d79e 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -243,10 +243,10 @@ testStringSearch(const void *opaque) goto cleanup; } - if (virStringListLength((const char * const *)matches) !=3D nmatch= es) { - fprintf(stderr, "expected %zu matches on %s but got %zd matche= s\n", + if (g_strv_length(matches) !=3D nmatches) { + fprintf(stderr, "expected %zu matches on %s but got %u matches= \n", data->expectNMatches, data->str, - virStringListLength((const char * const *)matches)); + g_strv_length(matches)); goto cleanup; } diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index fb42358bd0..d3923c4bc7 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -87,7 +87,7 @@ char ** virshCommaStringListComplete(const char *input, const char **options) { - const size_t optionsLen =3D virStringListLength(options); + const size_t optionsLen =3D g_strv_length((char **) options); g_autofree char *inputCopy =3D NULL; g_auto(GStrv) inputList =3D NULL; g_auto(GStrv) ret =3D NULL; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 98a87dd43c..05d79a7843 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14391,7 +14391,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cm= d) if (!(keys =3D virStringSplit(buffer, "\n", -1))) goto cleanup; - nkeys =3D virStringListLength((const char **) keys); + nkeys =3D g_strv_length(keys); if (nkeys =3D=3D 0) { vshError(ctl, _("File %s contains no keys"), from); goto cleanup; diff --git a/tools/virsh-host.c b/tools/virsh-host.c index ba524523f5..747d355456 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1325,7 +1325,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd) return false; result =3D virConnectBaselineCPU(priv->conn, (const char **)list, - virStringListLength((const char **)list= ), + g_strv_length(list), flags); if (result) { @@ -1798,7 +1798,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl, result =3D virConnectBaselineHypervisorCPU(priv->conn, emulator, arch, machine, virttype, (const char **)list, - virStringListLength((const ch= ar **)list), + g_strv_length(list), flags); if (result) { diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helpe= r.c index 0522896eee..1ac02bed00 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -103,7 +103,7 @@ static int virLoginShellGetShellArgv(virConfPtr conf, (*shargv)[0] =3D g_strdup("/bin/sh"); *shargvlen =3D 1; } else { - *shargvlen =3D virStringListLength((const char *const *)*shargv); + *shargvlen =3D g_strv_length(*shargv); } return 0; } diff --git a/tools/vsh.c b/tools/vsh.c index 202bd564f7..4e76ad348a 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2704,7 +2704,7 @@ vshCompleterFilter(char ***list, if (!list || !*list) return -1; - list_len =3D virStringListLength((const char **) *list); + list_len =3D g_strv_length(*list); newList =3D g_new0(char *, list_len + 1); for (i =3D 0; i < list_len; i++) { --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600503; cv=none; d=zohomail.com; s=zohoarc; b=lRBCigqBISO6epmzrjWGAGOmuY/tV2T8mlTIr6rC674QEz14Fx7Y7fpjsWWC7E6bvuowHvlCUrv2BG4z2GY5PcN5UjhocTMXlKT/rizMVFcSCP2R4Tji0XdKNXW5TMggO6UN7MuAP0Ix1cI5o0eyVWRlpnEaJe8eNz05DxNovwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600503; 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=UlnMwUkpwjvHyXUwGsQDnSKDs158TScnezDZ3omA3GE=; b=f7LSvamk2NdLryai/q0IFg1/vfUapotAmNyU4q/qUrPgyZYizjUCh88WZRYkmDvOhTVjwncxJS3acnwc9VHvo/V+VVXA/ROlz62lZgPM3E4CBuvzGOBnQHaJ6RHze9VQMXl7mDpD2GhKYL+Vzi5lOU+t7QISv1Ef6qqWeX+ZbFI= 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) header.from= 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 1612600503416103.18822120348852; Sat, 6 Feb 2021 00:35:03 -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-5-fLaoIq8kNzmYB75gItAnQw-1; Sat, 06 Feb 2021 03:34:59 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 053CF107ACF3; Sat, 6 Feb 2021 08:34: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 D9EAF72F88; Sat, 6 Feb 2021 08:34: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 A1AEA18077D7; Sat, 6 Feb 2021 08:34:53 +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 1168YpBB005528 for ; Sat, 6 Feb 2021 03:34:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8322660C8F; Sat, 6 Feb 2021 08:34:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BE1260C79 for ; Sat, 6 Feb 2021 08:34:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600502; 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=UlnMwUkpwjvHyXUwGsQDnSKDs158TScnezDZ3omA3GE=; b=Eo7BjOUGo3Jmla8PEHAIES+spXD/0zmnjU0P1cyk9Zv9KFLd6Gg11KpXknuo01DcGZh1h+ g6yG1B5Ck0JQ0Fxk98tNiyZmNrOG27A5nBEuo8UPOiA3KCvYZ6GrqLQMkiCWnoSQkhuh1h Ddes39iyTjR0tNrGLytIHPJlY1Xx0pU= X-MC-Unique: fLaoIq8kNzmYB75gItAnQw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 34/40] util: virstring: Remove virStringListLength Date: Sat, 6 Feb 2021 09:32:56 +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.11 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" glib provides g_strv_length. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 - src/util/virstring.c | 11 ----------- src/util/virstring.h | 2 -- 3 files changed, 14 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ab8cf62552..535776166d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3242,7 +3242,6 @@ virStringIsEmpty; virStringIsPrintable; virStringListFreeCount; virStringListJoin; -virStringListLength; virStringListMerge; virStringMatch; virStringMatchesNameSuffix; diff --git a/src/util/virstring.c b/src/util/virstring.c index 1fd61650be..c7276fa7c4 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -747,17 +747,6 @@ virStringIsEmpty(const char *str) } -size_t virStringListLength(const char * const *strings) -{ - size_t i =3D 0; - - while (strings && strings[i]) - i++; - - return i; -} - - /** * virStringSortCompare: * diff --git a/src/util/virstring.h b/src/util/virstring.h index 1a15812307..db6f2d4795 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -112,8 +112,6 @@ int virStrcpy(char *dest, const char *src, size_t destb= ytes) G_GNUC_WARN_UNUSED_RESULT; #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) -size_t virStringListLength(const char * const *strings); - int virStringSortCompare(const void *a, const void *b); int virStringSortRevCompare(const void *a, const void *b); int virStringToUpper(char **dst, const char *src); --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600506; cv=none; d=zohomail.com; s=zohoarc; b=annTJSr1SyoCGAl9xpwlKJTN2sySi1AVB0t/vrdulJYjGek68wIZ3eSxH2aIdqeV6CyXbfKgcfp9B7DphQMGwHIIZxnTqrXW5sKOWYfYrIBqnP5mLXhjVdrRjsWge/P1PniRQergaH82TCe2iKHOf5QKESprUwLy+9ynqB7ZllM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600506; 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=6ikcgrK5It0JoZTErIX+3YcveSTPQf9dDF8GPq1qHWk=; b=nJATwynWnCE6/NpA0STosJSiKv8Dl86egY4E3sLIDvGcul/+nLDFJriKjULqJnRs+caq1Dva0k9yXZl1QVqDV5rafiEy2t1JFMod9DvRnxVRvErVqjEMQmp5RF4cWnpzW12D73MkoxyGUvCr7SY++xZBtFHjMCf7Y2uCCRjf+3A= 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 1612600506074241.74484089950442; Sat, 6 Feb 2021 00:35:06 -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-42-eEOw2q9GMT6ewkU2cUaZAg-1; Sat, 06 Feb 2021 03:35:02 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C21F71DDE2; Sat, 6 Feb 2021 08:34:56 +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 A0E1B72FB0; Sat, 6 Feb 2021 08:34:56 +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 6BCD058095; Sat, 6 Feb 2021 08:34:56 +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 1168Ys3I005555 for ; Sat, 6 Feb 2021 03:34:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5127A60C7B; Sat, 6 Feb 2021 08:34:54 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C1B860C79 for ; Sat, 6 Feb 2021 08:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600505; 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=6ikcgrK5It0JoZTErIX+3YcveSTPQf9dDF8GPq1qHWk=; b=IxEsB54H8zJAyMsWJMuk7EYlSfnla0eVnHu0wt0bhJIqPjFpl4CkNfnBZIgfhlnzsF8Nz4 RB0usDMVoOZwF3xJuK15b3IE81LLqz98bW8iMkmxiDWYayNLisykXPyEd47HVQAdaEcs1j nktWWWpI6tMebLqscMJtmmJBeMPTscc= X-MC-Unique: eEOw2q9GMT6ewkU2cUaZAg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 35/40] Replace virStringSplit with g_strsplit Date: Sat, 6 Feb 2021 09:32:57 +0100 Message-Id: <1ac4f5ce8c66c273b29d2ad7048e780be27ef245.1612599659.git.pkrempa@redhat.com> 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.11 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" Our implementation was heavily inspired by the glib version so it's a drop-in replacement. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/bhyve/bhyve_command.c | 2 +- src/conf/storage_conf.c | 2 +- src/libxl/libxl_conf.c | 8 ++++---- src/libxl/xen_common.c | 6 +++--- src/libxl/xen_xl.c | 4 ++-- src/lxc/lxc_native.c | 8 ++++---- src/qemu/qemu_driver.c | 2 +- src/qemu/qemu_qapi.c | 2 +- src/rpc/virnetsocket.c | 4 ++-- src/storage/storage_backend_sheepdog.c | 4 ++-- src/storage/storage_backend_zfs.c | 6 +++--- src/storage_file/storage_source_backingstore.c | 4 ++-- src/util/vircgroup.c | 6 +++--- src/util/vircgroupv2.c | 2 +- src/util/vircommand.c | 2 +- src/util/virdevmapper.c | 2 +- src/util/virfile.c | 2 +- src/util/virfirewall.c | 2 +- src/util/virfirmware.c | 4 ++-- src/util/virprocess.c | 2 +- src/vz/vz_sdk.c | 2 +- tests/qemuxml2argvtest.c | 2 +- tests/vboxsnapshotxmltest.c | 2 +- tools/virsh-completer.c | 2 +- tools/virsh-domain.c | 12 ++++++------ 25 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index daf313c9c1..a963338654 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -806,7 +806,7 @@ virAppendBootloaderArgs(virCommandPtr cmd, virDomainDef= Ptr def) char **blargs; /* XXX: Handle quoted? */ - blargs =3D virStringSplit(def->os.bootloaderArgs, " ", 0); + blargs =3D g_strsplit(def->os.bootloaderArgs, " ", 0); virCommandAddArgSet(cmd, (const char * const *)blargs); g_strfreev(blargs); } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 3f06fcaebf..0f515c7cbb 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1305,7 +1305,7 @@ virStorageCheckCompat(const char *compat) if (!compat) return 0; - version =3D virStringSplit(compat, ".", 2); + version =3D g_strsplit(compat, ".", 2); if (!version || !version[1] || virStrToLong_ui(version[0], NULL, 10, &result) < 0 || virStrToLong_ui(version[1], NULL, 10, &result) < 0) { diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 37a2c2e3cd..f8db118996 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -698,7 +698,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, b_info->bootloader =3D g_strdup(def->os.bootloader); if (def->os.bootloaderArgs) { if (!(b_info->bootloader_args =3D - virStringSplit(def->os.bootloaderArgs, " \t\n", 0))) + g_strsplit(def->os.bootloaderArgs, " \t\n", 0))) return -1; } #endif @@ -714,7 +714,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def, } if (def->os.bootloaderArgs) { if (!(b_info->u.pv.bootloader_args =3D - virStringSplit(def->os.bootloaderArgs, " \t\n", 0))) + g_strsplit(def->os.bootloaderArgs, " \t\n", 0))) return -1; } b_info->u.pv.cmdline =3D g_strdup(def->os.cmdline); @@ -1896,14 +1896,14 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfigPtr c= fg, int ret =3D -1; if (cfg->verInfo->commandline =3D=3D NULL || - !(cmd_tokens =3D virStringSplit(cfg->verInfo->commandline, " ", 0)= )) + !(cmd_tokens =3D g_strsplit(cfg->verInfo->commandline, " ", 0))) goto physmem; for (i =3D 0; cmd_tokens[i] !=3D NULL; i++) { if (!STRPREFIX(cmd_tokens[i], "dom0_mem=3D")) continue; - if (!(mem_tokens =3D virStringSplit(cmd_tokens[i], ",", 0))) + if (!(mem_tokens =3D g_strsplit(cmd_tokens[i], ",", 0))) break; for (j =3D 0; mem_tokens[j] !=3D NULL; j++) { if (STRPREFIX(mem_tokens[j], "max:")) { diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 2d1f5ea5f5..75c65a4135 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -420,7 +420,7 @@ xenParsePCI(char *entry) return NULL; str =3D nextstr; - if (str && (options =3D virStringSplit(str, ",", 0))) { + if (str && (options =3D g_strsplit(str, ",", 0))) { size_t i; for (i =3D 0; options[i] !=3D NULL; i++) { @@ -1051,7 +1051,7 @@ xenParseVifBridge(virDomainNetDefPtr net, char *bridg= e) /* 'bridge' string contains a bridge name and one or more vlan tru= nks */ size_t i; size_t nvlans =3D 0; - char **vlanstr_list =3D virStringSplit(bridge, ":", 0); + char **vlanstr_list =3D g_strsplit(bridge, ":", 0); if (!vlanstr_list) return -1; @@ -1258,7 +1258,7 @@ xenParseVif(char *entry, const char *vif_typename) goto cleanup; } if (ip[0]) { - char **ip_list =3D virStringSplit(ip, " ", 0); + char **ip_list =3D g_strsplit(ip, " ", 0); size_t i; if (!ip_list) diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index a8af54a845..a7036ba494 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -268,7 +268,7 @@ xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def) def->cpu->nfeatures_max =3D 0; } - cpuid_pairs =3D virStringSplit(cpuid_str, ",", 0); + cpuid_pairs =3D g_strsplit(cpuid_str, ",", 0); if (!cpuid_pairs) goto cleanup; @@ -285,7 +285,7 @@ xenParseXLCPUID(virConfPtr conf, virDomainDefPtr def) } for (i =3D 1; cpuid_pairs[i]; i++) { - name_and_value =3D virStringSplit(cpuid_pairs[i], "=3D", 2); + name_and_value =3D g_strsplit(cpuid_pairs[i], "=3D", 2); if (!name_and_value) goto cleanup; if (!name_and_value[0] || !name_and_value[1]) { diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 4229a9ca7a..b903dc91d6 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -119,7 +119,7 @@ static char ** lxcStringSplit(const char *string) tmp[i] =3D ' '; } - if (!(parts =3D virStringSplit(tmp, " ", 0))) + if (!(parts =3D g_strsplit(tmp, " ", 0))) goto error; /* Append NULL element */ @@ -257,7 +257,7 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab) { const char *src =3D NULL; g_autofree char *dst =3D NULL; - char **options =3D virStringSplit(fstab->options, ",", 0); + char **options =3D g_strsplit(fstab->options, ",", 0); bool readonly; int type =3D VIR_DOMAIN_FS_TYPE_MOUNT; unsigned long long usage =3D 0; @@ -567,7 +567,7 @@ lxcNetworkParseDataIPs(const char *name, if (STREQ(name, "ipv6") || STREQ(name, "ipv6.address")) family =3D AF_INET6; - ipparts =3D virStringSplit(value->str, "/", 2); + ipparts =3D g_strsplit(value->str, "/", 2); if (!ipparts || !ipparts[0] || !ipparts[1] || virSocketAddrParse(&ip->address, ipparts[0], family) < 0 || virStrToLong_ui(ipparts[1], NULL, 10, &ip->prefix) < 0) { @@ -1103,7 +1103,7 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr propert= ies) size_t i; if (virConfGetValueString(properties, "lxc.cap.drop", &value) > 0) - toDrop =3D virStringSplit(value, " ", 0); + toDrop =3D g_strsplit(value, " ", 0); for (i =3D 0; i < VIR_DOMAIN_PROCES_CAPS_FEATURE_LAST; i++) { capString =3D virDomainProcessCapsFeatureTypeToString(i); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 80bd27696b..ca4ba8071c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1365,7 +1365,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait, if (virFileReadAll(proc, (1<<16), &data) < 0) goto cleanup; - lines =3D virStringSplit(data, "\n", 0); + lines =3D g_strsplit(data, "\n", 0); if (!lines) goto cleanup; diff --git a/src/qemu/qemu_qapi.c b/src/qemu/qemu_qapi.c index b41016f7d8..f7e4ca9324 100644 --- a/src/qemu/qemu_qapi.c +++ b/src/qemu/qemu_qapi.c @@ -440,7 +440,7 @@ virQEMUQAPISchemaPathGet(const char *query, if (entry) *entry =3D NULL; - if (!(elems =3D virStringSplit(query, "/", 0))) + if (!(elems =3D g_strsplit(query, "/", 0))) return -1; if (!*elems) { diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index d0dc59c10c..17aaf86ce3 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -961,7 +961,7 @@ virNetSocketNewConnectLibSSH2(const char *host, virNetSSHSessionSetChannelCommand(sess, command); - if (!(authMethodList =3D virStringSplit(authMethods, ",", 0))) + if (!(authMethodList =3D g_strsplit(authMethods, ",", 0))) goto error; for (authMethodNext =3D authMethodList; *authMethodNext; authMethodNex= t++) { @@ -1092,7 +1092,7 @@ virNetSocketNewConnectLibssh(const char *host, virNetLibsshSessionSetChannelCommand(sess, command); - if (!(authMethodList =3D virStringSplit(authMethods, ",", 0))) + if (!(authMethodList =3D g_strsplit(authMethods, ",", 0))) goto error; for (authMethodNext =3D authMethodList; *authMethodNext; authMethodNex= t++) { diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_sheepdog.c index 2db2384e67..8c37947308 100644 --- a/src/storage/storage_backend_sheepdog.c +++ b/src/storage/storage_backend_sheepdog.c @@ -148,14 +148,14 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePool= ObjPtr pool) if (virCommandRun(cmd, NULL) < 0) return -1; - lines =3D virStringSplit(output, "\n", 0); + lines =3D g_strsplit(output, "\n", 0); if (lines =3D=3D NULL) return -1; for (i =3D 0; lines[i]; i++) { g_auto(GStrv) cells =3D NULL; - cells =3D virStringSplit(lines[i], " ", 0); + cells =3D g_strsplit(lines[i], " ", 0); if (cells !=3D NULL && cells[0] && cells[1]) { if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0) diff --git a/src/storage/storage_backend_zfs.c b/src/storage/storage_backen= d_zfs.c index 31ffcc6f15..e4ef06722f 100644 --- a/src/storage/storage_backend_zfs.c +++ b/src/storage/storage_backend_zfs.c @@ -195,7 +195,7 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, if (virCommandRun(cmd, NULL) < 0) return -1; - if (!(lines =3D virStringSplit(volumes_list, "\n", 0))) + if (!(lines =3D g_strsplit(volumes_list, "\n", 0))) return -1; for (i =3D 0; lines[i]; i++) { @@ -230,7 +230,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol G_GNUC_UNUSED) * * Here we just provide a list of properties we want to see */ - if (!(name_tokens =3D virStringSplit(def->source.name, "/", 0))) + if (!(name_tokens =3D g_strsplit(def->source.name, "/", 0))) goto cleanup; cmd =3D virCommandNewArgList(ZPOOL, @@ -242,7 +242,7 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol G_GNUC_UNUSED) if (virCommandRun(cmd, NULL) < 0) goto cleanup; - if (!(lines =3D virStringSplit(zpool_props, "\n", 0))) + if (!(lines =3D g_strsplit(zpool_props, "\n", 0))) goto cleanup; for (i =3D 0; lines[i]; i++) { diff --git a/src/storage_file/storage_source_backingstore.c b/src/storage_f= ile/storage_source_backingstore.c index bbcc720af1..8e1606a1fe 100644 --- a/src/storage_file/storage_source_backingstore.c +++ b/src/storage_file/storage_source_backingstore.c @@ -54,7 +54,7 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src, src->hosts =3D g_new0(virStorageNetHostDef, 1); src->nhosts =3D 1; - if (!(scheme =3D virStringSplit(uri->scheme, "+", 2))) + if (!(scheme =3D g_strsplit(uri->scheme, "+", 2))) return -1; if (!scheme[0] || @@ -165,7 +165,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, goto error; } - parts =3D virStringSplit(hostport, "\\:", 0); + parts =3D g_strsplit(hostport, "\\:", 0); if (!parts) goto error; src->hosts[src->nhosts-1].name =3D virStringListJoin((const char **)pa= rts, ":"); diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 2c418cd84d..a7e2728dd7 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -574,7 +574,7 @@ virCgroupGetValueForBlkDev(const char *str, if (!(prefix =3D virCgroupGetBlockDevString(path))) return -1; - if (!(lines =3D virStringSplit(str, "\n", -1))) + if (!(lines =3D g_strsplit(str, "\n", -1))) return -1; for (tmp =3D lines; *tmp; tmp++) { @@ -805,7 +805,7 @@ virCgroupSetPartitionSuffix(const char *path, char **re= s) size_t i; int ret =3D -1; - if (!(tokens =3D virStringSplit(path, "/", 0))) + if (!(tokens =3D g_strsplit(path, "/", 0))) return ret; for (i =3D 0; tokens[i] !=3D NULL; i++) { @@ -1140,7 +1140,7 @@ virCgroupEnableMissingControllers(char *path, virCgroupPtr *group) { g_autoptr(virCgroup) parent =3D NULL; - g_auto(GStrv) tokens =3D virStringSplit(path, "/", 0); + g_auto(GStrv) tokens =3D g_strsplit(path, "/", 0); size_t i; if (virCgroupNew("/", controllers, &parent) < 0) diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 4a239f067a..c9c3f5b76e 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -279,7 +279,7 @@ virCgroupV2ParseControllersFile(virCgroupPtr group, virTrimSpaces(contStr, NULL); - contList =3D virStringSplit(contStr, " ", 20); + contList =3D g_strsplit(contStr, " ", 20); if (!contList) return -1; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 87a60be201..323f841b98 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -3230,7 +3230,7 @@ virCommandRunRegex(virCommandPtr cmd, goto cleanup; } - if (!(lines =3D virStringSplit(outbuf, "\n", 0))) + if (!(lines =3D g_strsplit(outbuf, "\n", 0))) goto cleanup; for (k =3D 0; lines[k]; k++) { diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 15a7eb9fde..d97334bf67 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -63,7 +63,7 @@ virDevMapperGetMajor(unsigned int *major) if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0) return -1; - lines =3D virStringSplit(buf, "\n", 0); + lines =3D g_strsplit(buf, "\n", 0); if (!lines) return -1; diff --git a/src/util/virfile.c b/src/util/virfile.c index e25cbe797e..5710495bbf 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1711,7 +1711,7 @@ virFindFileInPath(const char *file) * it. return it if found. */ - if (!(paths =3D virStringSplit(origpath, ":", 0))) + if (!(paths =3D g_strsplit(origpath, ":", 0))) return NULL; for (pathiter =3D paths; *pathiter; pathiter++) { diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index 8b69a18ecc..6b04a8011f 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -719,7 +719,7 @@ virFirewallApplyRule(virFirewallPtr firewall, } if (rule->queryCB && output) { - if (!(lines =3D virStringSplit(output, "\n", -1))) + if (!(lines =3D g_strsplit(output, "\n", -1))) return -1; VIR_DEBUG("Invoking query %p with '%s'", rule->queryCB, output); diff --git a/src/util/virfirmware.c b/src/util/virfirmware.c index d49bea3a55..c0ffcb4392 100644 --- a/src/util/virfirmware.c +++ b/src/util/virfirmware.c @@ -61,7 +61,7 @@ virFirmwareParse(const char *str, virFirmwarePtr firmware) int ret =3D -1; char **token; - if (!(token =3D virStringSplit(str, ":", 0))) + if (!(token =3D g_strsplit(str, ":", 0))) goto cleanup; if (token[0]) { @@ -98,7 +98,7 @@ virFirmwareParseList(const char *list, char **token; size_t i, j; - if (!(token =3D virStringSplit(list, ":", 0))) + if (!(token =3D g_strsplit(list, ":", 0))) goto cleanup; for (i =3D 0; token[i]; i +=3D 2) { diff --git a/src/util/virprocess.c b/src/util/virprocess.c index 4c27f9d771..41c5678537 100644 --- a/src/util/virprocess.c +++ b/src/util/virprocess.c @@ -1011,7 +1011,7 @@ int virProcessGetStartTime(pid_t pid, return -1; } - tokens =3D virStringSplit(tmp, " ", 0); + tokens =3D g_strsplit(tmp, " ", 0); if (!tokens || g_strv_length(tokens) < 20) { diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 9ea0edaf97..f49cd983f0 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -745,7 +745,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk, goto cleanup; } - if (!(matches =3D virStringSplit(uri->path, "/", 0)) || + if (!(matches =3D g_strsplit(uri->path, "/", 0)) || !matches[0]) { virReportError(VIR_ERR_INTERNAL_ERROR, _("splitting StorageUrl failed %s"), uri->path); diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index faa71a7a16..d324921271 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -149,7 +149,7 @@ fakeStorageVolLookupByName(virStoragePoolPtr pool, if (!strchr(name, '+')) goto fallback; - if (!(volinfo =3D virStringSplit(name, "+", 2))) + if (!(volinfo =3D g_strsplit(name, "+", 2))) return NULL; if (!volinfo[1]) diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index d2beb7858d..9298bcb837 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -23,7 +23,7 @@ testFilterXML(char *xml) char **xmlLine; char *ret =3D NULL; - if (!(xmlLines =3D virStringSplit(xml, "\n", 0))) { + if (!(xmlLines =3D g_strsplit(xml, "\n", 0))) { VIR_FREE(xml); goto cleanup; } diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index d3923c4bc7..57e0c3905c 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -108,7 +108,7 @@ virshCommaStringListComplete(const char *input, g_clear_pointer(&inputCopy, g_free); } - if (inputCopy && !(inputList =3D virStringSplit(inputCopy, ",", 0))) + if (inputCopy && !(inputList =3D g_strsplit(inputCopy, ",", 0))) return NULL; ret =3D g_new0(char *, optionsLen + 1); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 05d79a7843..1c58c26d93 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4057,7 +4057,7 @@ cmdStartGetFDs(vshControl *ctl, if (vshCommandOptStringQuiet(ctl, cmd, "pass-fds", &fdopt) <=3D 0) return 0; - if (!(fdlist =3D virStringSplit(fdopt, ",", -1))) { + if (!(fdlist =3D g_strsplit(fdopt, ",", -1))) { vshError(ctl, _("Unable to split FD list '%s'"), fdopt); return -1; } @@ -5929,7 +5929,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0) return false; - if (mode && !(modes =3D virStringSplit(mode, ",", 0))) { + if (mode && !(modes =3D g_strsplit(mode, ",", 0))) { vshError(ctl, "%s", _("Cannot parse mode string")); return false; } @@ -6013,7 +6013,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0) return false; - if (mode && !(modes =3D virStringSplit(mode, ",", 0))) { + if (mode && !(modes =3D g_strsplit(mode, ",", 0))) { vshError(ctl, "%s", _("Cannot parse mode string")); return false; } @@ -10784,7 +10784,7 @@ doMigrate(void *opaque) if (opt) { char **val =3D NULL; - val =3D virStringSplit(opt, ",", 0); + val =3D g_strsplit(opt, ",", 0); if (virTypedParamsAddStringList(¶ms, &nparams, @@ -10801,7 +10801,7 @@ doMigrate(void *opaque) if (vshCommandOptStringReq(ctl, cmd, "comp-methods", &opt) < 0) goto out; if (opt) { - char **val =3D virStringSplit(opt, ",", 0); + char **val =3D g_strsplit(opt, ",", 0); if (virTypedParamsAddStringList(¶ms, &nparams, @@ -14388,7 +14388,7 @@ cmdSetUserSSHKeys(vshControl *ctl, const vshCmd *cm= d) goto cleanup; } - if (!(keys =3D virStringSplit(buffer, "\n", -1))) + if (!(keys =3D g_strsplit(buffer, "\n", -1))) goto cleanup; nkeys =3D g_strv_length(keys); --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600510; cv=none; d=zohomail.com; s=zohoarc; b=DmzIqoqQCVXsw1fs8aSWYeNZH8hD9P/5HoW9ZbdrzLgmX1UF6jJW4mVbdUXxn3muhNW0CFpkbfO1HD6FYLd1XxFUjDgKdTg/I6eePrsEHoIwIyavnS4l0kYZnTht5fm0P1s+ukcP38rNaOxh/V3aNTOQP6n7IdEsysWCt/0Im2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600510; 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=MrXz1cGAul4aKlzAsTfCFMGF4aawdHzOao1HjXaJz+U=; b=kdUNtZYEI1FOlSYxMPKjrzsORzniD23nK8gpHJGbqqUvl8K8Uf9rzVUDutVM8EJIKOmJmucSFrUYs1dd+ZYHR2eFRm5lzQAJy+V9a2mKV6cA/mHs9DdqzTyQgzVcz/6RSvKovAUPX7AD5ahGHsEIoKyN1M++kkC5Z42CQ4qD+bQ= 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 1612600510241985.6370362471453; Sat, 6 Feb 2021 00:35:10 -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-42-Fhvv-9UsMuauEukv59wxGg-1; Sat, 06 Feb 2021 03:35:02 -0500 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 EA8F9100CCC1; Sat, 6 Feb 2021 08:34:56 +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 C7A145D9D2; Sat, 6 Feb 2021 08:34:56 +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 9459758096; Sat, 6 Feb 2021 08:34:56 +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 1168YuuR005577 for ; Sat, 6 Feb 2021 03:34:56 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0406660C7B; Sat, 6 Feb 2021 08:34:56 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02FE460C79 for ; Sat, 6 Feb 2021 08:34:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600509; 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=MrXz1cGAul4aKlzAsTfCFMGF4aawdHzOao1HjXaJz+U=; b=iUSVm0totSH4kF0HU026HZr/nR1lJqezSxmqsntWfmE9kCYLGd/OPpba9uQc+XssjrXd23 GcEopoxgCXaoONojyEvFHx/RvPe0/fhW0sf9xA0LunJbaMxdRu00RRAVUkKY+rmZhtzLMv 6LZTBCqSmUG/APHXDkCsQyG+8afFQRQ= X-MC-Unique: Fhvv-9UsMuauEukv59wxGg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 36/40] util: virstring: Remove virStringSplit Date: Sat, 6 Feb 2021 09:32:58 +0100 Message-Id: <15bc5d02e46b5d4a2c78c6223d513b0a525d6549.1612599659.git.pkrempa@redhat.com> 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.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) Content-Type: text/plain; charset="utf-8" Callers were replaced by g_strsplit. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 - src/util/virstring.c | 9 --------- src/util/virstring.h | 5 ----- 3 files changed, 15 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 535776166d..7d05d25106 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3251,7 +3251,6 @@ virStringReplace; virStringSearch; virStringSortCompare; virStringSortRevCompare; -virStringSplit; virStringSplitCount; virStringStripControlChars; virStringStripIPv6Brackets; diff --git a/src/util/virstring.c b/src/util/virstring.c index c7276fa7c4..fa12b7dcd7 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -123,15 +123,6 @@ virStringSplitCount(const char *string, } -char ** -virStringSplit(const char *string, - const char *delim, - size_t max_tokens) -{ - return virStringSplitCount(string, delim, max_tokens, NULL); -} - - /** * virStringListJoin: * @strings: a NULL-terminated array of strings to join diff --git a/src/util/virstring.h b/src/util/virstring.h index db6f2d4795..18793a34b4 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -28,11 +28,6 @@ char **virStringSplitCount(const char *string, size_t *tokcount) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); -char **virStringSplit(const char *string, - const char *delim, - size_t max_tokens) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - char *virStringListJoin(const char **strings, const char *delim) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600509; cv=none; d=zohomail.com; s=zohoarc; b=Q6fOnovOZGqqQDRts3rwIZkUjiD6/fgy0xEvDx9O+F7IJMu6rQSHMn+/1rkZqyhR8CRud79qRH7kfFOonKYDAoQD6j3ZZcHkZ2Z/m2hqiY3/fAhGQyRA5+ljPtcVEOWKLHC17X1lGGljxjbsE1a5O/7C0OcaWeOhnZWTG8S7y1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600509; 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=snaH0PaRyqano4XIcmyL0YLImDn4Ko0L+NEVaQ+QVCA=; b=nwuvgHJt8lzQl8/VGk1rYjqAiCIoClMZvnEWw+e41iBqo4VPNKLlWrAiW+iRrzf+KUwUXuSeATaLi80KThqNyngts0x0CDx88e1cLiTsQsqW+0B5PtlIZ2ha0R1xVHq7y8LiJZmK+z8oQmIIEduX4bmS5l3/iOJokm3sHt2Uua8= 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 1612600509349293.31895642938025; Sat, 6 Feb 2021 00:35:09 -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-484-wy0KVtrNOsyPxe32MmxndA-1; Sat, 06 Feb 2021 03:35:05 -0500 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 5046C107AFD3; Sat, 6 Feb 2021 08:35: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 274B41A873; Sat, 6 Feb 2021 08:35: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 E2E0B18095CD; Sat, 6 Feb 2021 08:34:59 +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 1168Yw0p005597 for ; Sat, 6 Feb 2021 03:34:58 -0500 Received: by smtp.corp.redhat.com (Postfix) id B215D60C7B; Sat, 6 Feb 2021 08:34:58 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1AB160C79 for ; Sat, 6 Feb 2021 08:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600508; 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=snaH0PaRyqano4XIcmyL0YLImDn4Ko0L+NEVaQ+QVCA=; b=AaiU4sTd0JHeU9K5tcIQA+dIvm7wt9Jgd4g1mnyYReZNq3uizdc7w+IimG/gJA4Q/Qf7nw IKQK4csokEduQAcp1huZOOUjtsw1+SSL9Uaorwy4rePeGngoBsAz6bTxPdbIqL5QWBX/u3 zYrZmJpzfdvyLfTllmchl40M409CZKE= X-MC-Unique: wy0KVtrNOsyPxe32MmxndA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 37/40] virStringSplitCount: Reimplement using g_strsplit and g_strv_length Date: Sat, 6 Feb 2021 09:32:59 +0100 Message-Id: <5d697ad1754a3674dcda7861a8c1166586ab1c85.1612599659.git.pkrempa@redhat.com> 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.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) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virstring.c | 72 +++----------------------------------------- src/util/virstring.h | 2 +- 2 files changed, 6 insertions(+), 68 deletions(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index fa12b7dcd7..89d9ba4a13 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -43,28 +43,9 @@ VIR_LOG_INIT("util.string"); /** * virStringSplitCount: - * @string: a string to split - * @delim: a string which specifies the places at which to split - * the string. The delimiter is not included in any of the resulting - * strings, unless @max_tokens is reached. - * @max_tokens: the maximum number of pieces to split @string into. - * If this is 0, the string is split completely. - * @tokcount: If provided, the value is set to the count of pieces the str= ing - * was split to excluding the terminating NULL element. * - * Splits a string into a maximum of @max_tokens pieces, using the given - * @delim. If @max_tokens is reached, the remainder of @string is - * appended to the last token. - * - * As a special case, the result of splitting the empty string "" is an em= pty - * vector, not a vector containing a single string. The reason for this - * special case is that being able to represent an empty vector is typical= ly - * more useful than consistent handling of empty elements. If you do need - * to represent empty elements, you'll need to check for the empty string - * before calling virStringSplit(). - * - * Return value: a newly-allocated NULL-terminated array of strings. Use - * g_strfreev() to free it. + * A wrapper for g_strsplit which provides number of elements of the split + * string. */ char ** virStringSplitCount(const char *string, @@ -72,54 +53,11 @@ virStringSplitCount(const char *string, size_t max_tokens, size_t *tokcount) { - char **tokens =3D NULL; - size_t ntokens =3D 0; - size_t maxtokens =3D 0; - const char *remainder =3D string; - char *tmp; - size_t i; - - if (max_tokens =3D=3D 0) - max_tokens =3D INT_MAX; - - tmp =3D strstr(remainder, delim); - if (tmp) { - size_t delimlen =3D strlen(delim); - - while (--max_tokens && tmp) { - size_t len =3D tmp - remainder; - - if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto error; + GStrv ret =3D g_strsplit(string, delim, max_tokens); - tokens[ntokens] =3D g_strndup(remainder, len); - ntokens++; - remainder =3D tmp + delimlen; - tmp =3D strstr(remainder, delim); - } - } - if (*string) { - if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto error; - - tokens[ntokens] =3D g_strdup(remainder); - ntokens++; - } + *tokcount =3D g_strv_length(ret); - if (VIR_RESIZE_N(tokens, maxtokens, ntokens, 1) < 0) - goto error; - tokens[ntokens++] =3D NULL; - - if (tokcount) - *tokcount =3D ntokens - 1; - - return tokens; - - error: - for (i =3D 0; i < ntokens; i++) - VIR_FREE(tokens[i]); - VIR_FREE(tokens); - return NULL; + return ret; } diff --git a/src/util/virstring.h b/src/util/virstring.h index 18793a34b4..48b20f5c7d 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -26,7 +26,7 @@ char **virStringSplitCount(const char *string, const char *delim, size_t max_tokens, size_t *tokcount) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); char *virStringListJoin(const char **strings, const char *delim) --=20 2.29.2 From nobody Sun May 19 00:47:33 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=1612600512; cv=none; d=zohomail.com; s=zohoarc; b=mjkK1RYxC2MzeNgBghQ2lWFaOg/T589mzo0Z9RwzlSl02K7QvZ/WpBZv7ULITpsrn/m+z6/gJPwtT8a2QmiNAX9ap+hpSo5dIvwO4W769G0X1FiSXUoqI45uTrRrU3X1pNP/fyiy2QupphXzdaDsW74bmEig3rBprbyZPqhJD3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600512; 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=Gros9bI4NXLKqLUprBdvrrv79O4kD4lQOEC0SuGH3cA=; b=O4Ye4cVx9Q82BAnaIfxp+V5S+mOAqgGRPRolk/zqxWwHZz2AUI2CWZ5R5muOOOwO8368zMYTDj9phCjJ7P/l63+7rLEfOXXKzrtT1Sw3yZDaFRBukgEw9vH57DkkFD5w8ZPFPQt1O1AsRMjQefczDNKqh7UrlcVC2eokyKOPBzY= 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) header.from= 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 1612600512584682.432670638844; Sat, 6 Feb 2021 00:35:12 -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-525-VcBLNDrqNVq89IAWr9X4yg-1; Sat, 06 Feb 2021 03:35:09 -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 8DC08100CCC0; Sat, 6 Feb 2021 08:35: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 677D260C9C; Sat, 6 Feb 2021 08:35: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 24F635809A; Sat, 6 Feb 2021 08:35:03 +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 1168Z1oc005625 for ; Sat, 6 Feb 2021 03:35:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 93D8B60C93; Sat, 6 Feb 2021 08:35:01 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5328E60C79 for ; Sat, 6 Feb 2021 08:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600511; 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=Gros9bI4NXLKqLUprBdvrrv79O4kD4lQOEC0SuGH3cA=; b=gwDodi/rqC59YKp8aHDkS0bpOhpPWkDNenbqDyuV5vht1EN8Yb35sKU86mQHPp0q60eMLs UnDmu9i9oNz8N39NbSkI05lVPtjd4yvgYhlfmaa/ZR8I0NiducmEB36iqgoyOIl8uS+J+p 1C+v6+6K0CSV95XxjN/CnaKeyOIyfSk= X-MC-Unique: VcBLNDrqNVq89IAWr9X4yg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 38/40] Replace virStringListJoin by g_strjoinv Date: Sat, 6 Feb 2021 09:33:00 +0100 Message-Id: <9a07d2adbbca1f941384b07cb77e32419d7fda3f.1612599659.git.pkrempa@redhat.com> 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" Our implementation was inspired by glib anyways. The difference is only the order of arguments. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/bhyve/bhyve_parse_command.c | 4 ++-- src/libxl/xen_common.c | 2 +- src/libxl/xen_xl.c | 4 +--- src/qemu/qemu_process.c | 2 +- src/storage_file/storage_source_backingstore.c | 4 +--- src/util/vircgroup.c | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_comman= d.c index 4f1d384da1..2762b7e921 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -923,7 +923,7 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def, /* Set os.bootloader since virDomainDefFormatInternal will only fo= rmat * the bootloader arguments if os->bootloader is set. */ def->os.bootloader =3D g_strdup(argv[0]); - def->os.bootloaderArgs =3D virStringListJoin((const char**) &argv[= 1], " "); + def->os.bootloaderArgs =3D g_strjoinv(" ", &argv[1]); } if (def->name =3D=3D NULL) { @@ -950,7 +950,7 @@ bhyveParseCustomLoaderCommandLine(virDomainDefPtr def, return -1; def->os.bootloader =3D g_strdup(argv[0]); - def->os.bootloaderArgs =3D virStringListJoin((const char**) &argv[1], = " "); + def->os.bootloaderArgs =3D g_strjoinv(" ", &argv[1]); return 0; } diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 75c65a4135..f852032d8a 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1659,7 +1659,7 @@ xenMakeIPList(virNetDevIPInfoPtr guestIP) if (!address_array[i]) goto cleanup; } - ret =3D virStringListJoin((const char**)address_array, " "); + ret =3D g_strjoinv(" ", address_array); cleanup: g_strfreev(address_array); diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index a7036ba494..3d44dd1c59 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1421,9 +1421,7 @@ xenFormatXLCPUID(virConfPtr conf, virDomainDefPtr def) cpuid_pairs[j] =3D NULL; if (j > 1) { - cpuid_string =3D virStringListJoin((const char **)cpuid_pairs, ","= ); - if (!cpuid_string) - goto cleanup; + cpuid_string =3D g_strjoinv(",", cpuid_pairs); if (xenConfigSetString(conf, "cpuid", cpuid_string) < 0) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d24ef789ab..13231ed0de 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5489,7 +5489,7 @@ qemuProcessStartValidate(virQEMUDriverPtr driver, if (n > 0) { g_autofree char *str =3D NULL; - str =3D virStringListJoin((const char **)features, ", "); + str =3D g_strjoinv(", ", features); virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Some features cannot be reliably used " "with this QEMU: %s"), str); diff --git a/src/storage_file/storage_source_backingstore.c b/src/storage_f= ile/storage_source_backingstore.c index 8e1606a1fe..5e2db3d390 100644 --- a/src/storage_file/storage_source_backingstore.c +++ b/src/storage_file/storage_source_backingstore.c @@ -168,9 +168,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, parts =3D g_strsplit(hostport, "\\:", 0); if (!parts) goto error; - src->hosts[src->nhosts-1].name =3D virStringListJoin((const char **)pa= rts, ":"); - if (!src->hosts[src->nhosts-1].name) - goto error; + src->hosts[src->nhosts-1].name =3D g_strjoinv(":", parts); src->hosts[src->nhosts-1].transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; src->hosts[src->nhosts-1].socket =3D NULL; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index a7e2728dd7..abaf1c98f7 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -831,7 +831,7 @@ virCgroupSetPartitionSuffix(const char *path, char **re= s) goto cleanup; } - if (!(*res =3D virStringListJoin((const char **)tokens, "/"))) + if (!(*res =3D g_strjoinv("/", tokens))) goto cleanup; ret =3D 0; --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600629; cv=none; d=zohomail.com; s=zohoarc; b=luhIv+/PhSC5KDdxaHVBAJrKE0hIq3m74428PeOr9OFxLoQaaSYux6frJB9Sz2i4oLoIR2dM7n26UhE7c2hxvHOVsTM4OlqREDisiib9Cf/j3yPzuCp/r9sZCu9z8AVrxci/gshD22psr8FI2ICisWREgDUhU0M5RRlGYZoNX60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600629; 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=V6bYAUd2A7hDxrHUq98FCaX+kRmyMWGFM7UCQ3t1YBU=; b=i3+8CT0vaqF5zxV6CuHZX6XQM7ANw/pE5pVlIV1Bg/M0LhOHT8hlKW1J5z2sG4vIMcv2v02NOB9oZJJZDCmUJryR0obgOvgdqPTH2Bbdp2j4WKshnBrJdR+Fz90CWq/DYsGQk84vJyFVdNhPn36Kb66oqgkoHOPea6LeJJE3pGE= 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 1612600629823245.0970861926006; Sat, 6 Feb 2021 00:37:09 -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-189-OyvtoKSKO9KJyXRkd-hB-w-1; Sat, 06 Feb 2021 03:35:15 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AD2AD1DDE4; Sat, 6 Feb 2021 08:35:09 +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 8974360C79; Sat, 6 Feb 2021 08:35:09 +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 26FC85809D; Sat, 6 Feb 2021 08:35:09 +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 1168Z72n005765 for ; Sat, 6 Feb 2021 03:35:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id B836460C8F; Sat, 6 Feb 2021 08:35:07 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6D0B60C79 for ; Sat, 6 Feb 2021 08:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600628; 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=V6bYAUd2A7hDxrHUq98FCaX+kRmyMWGFM7UCQ3t1YBU=; b=g0I9g3HdVIaaEifCc+2QdaP85oPQ2zyFdGv8e42ZF9CZVB37zmPQvDlFAHkAsen8Il4Xh7 WFCM3C6pKvD9HaEWZswObVSKMpwswu/ZwnSzKbyMSDlmB992e/gubXwNc8QnTiaf8RhNuO cl8pXUbPDF/RrYJHNnDOIvdlm9xTmco= X-MC-Unique: OyvtoKSKO9KJyXRkd-hB-w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 39/40] util: virstring: Remove virStringListJoin Date: Sat, 6 Feb 2021 09:33:01 +0100 Message-Id: <88bc1c7c3306bae2f14ed86558925279be01aa28.1612599659.git.pkrempa@redhat.com> 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.12 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" The glib alternative is now used everywhere. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 - src/util/virstring.c | 36 ------------------------------------ src/util/virstring.h | 4 ---- tests/virstringtest.c | 36 ------------------------------------ 4 files changed, 77 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 7d05d25106..63c2b2bfc3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3241,7 +3241,6 @@ virStringHasSuffix; virStringIsEmpty; virStringIsPrintable; virStringListFreeCount; -virStringListJoin; virStringListMerge; virStringMatch; virStringMatchesNameSuffix; diff --git a/src/util/virstring.c b/src/util/virstring.c index 89d9ba4a13..c98435388a 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -35,12 +35,6 @@ VIR_LOG_INIT("util.string"); -/* - * The following virStringSplit & virStringListJoin methods - * are derived from g_strsplit / g_strjoin in glib2, - * also available under the LGPLv2+ license terms - */ - /** * virStringSplitCount: * @@ -61,36 +55,6 @@ virStringSplitCount(const char *string, } -/** - * virStringListJoin: - * @strings: a NULL-terminated array of strings to join - * @delim: a string to insert between each of the strings - * - * Joins a number of strings together to form one long string, with the - * @delim inserted between each of them. The returned string - * should be freed with VIR_FREE(). - * - * Returns: a newly-allocated string containing all of the strings joined - * together, with @delim between them - */ -char *virStringListJoin(const char **strings, - const char *delim) -{ - char *ret; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - while (*strings) { - virBufferAdd(&buf, *strings, -1); - if (*(strings+1)) - virBufferAdd(&buf, delim, -1); - strings++; - } - ret =3D virBufferContentAndReset(&buf); - if (!ret) - ret =3D g_strdup(""); - return ret; -} - - /** * virStringListMerge: * @dst: a NULL-terminated array of strings to expand diff --git a/src/util/virstring.h b/src/util/virstring.h index 48b20f5c7d..45aead1838 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -28,10 +28,6 @@ char **virStringSplitCount(const char *string, size_t *tokcount) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); -char *virStringListJoin(const char **strings, - const char *delim) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); - int virStringListMerge(char ***dst, char ***src); diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 238cb9d79e..3bd9b97db7 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -82,12 +82,6 @@ struct testSplitData { }; -struct testJoinData { - const char *string; - const char *delim; - const char **tokens; -}; - static int testSplit(const void *args) { const struct testSplitData *data =3D args; @@ -140,29 +134,6 @@ static int testSplit(const void *args) } -static int testJoin(const void *args) -{ - const struct testJoinData *data =3D args; - char *got; - int ret =3D -1; - - if (!(got =3D virStringListJoin(data->tokens, data->delim))) { - VIR_DEBUG("Got no result"); - return -1; - } - if (STRNEQ(got, data->string)) { - fprintf(stderr, "Mismatch '%s' vs '%s'\n", got, data->string); - goto cleanup; - } - - ret =3D 0; - cleanup: - VIR_FREE(got); - - return ret; -} - - static int testStringSortCompare(const void *opaque G_GNUC_UNUSED) { @@ -606,15 +577,8 @@ mymain(void) .max_tokens =3D max, \ .tokens =3D toks, \ }; \ - struct testJoinData joinData =3D { \ - .string =3D str, \ - .delim =3D del, \ - .tokens =3D toks, \ - }; \ if (virTestRun("Split " #str, testSplit, &splitData) < 0) \ ret =3D -1; \ - if (virTestRun("Join " #str, testJoin, &joinData) < 0) \ - ret =3D -1; \ } while (0) VIR_WARNINGS_NO_DECLARATION_AFTER_STATEMENT --=20 2.29.2 From nobody Sun May 19 00:47:33 2024 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=1612600567; cv=none; d=zohomail.com; s=zohoarc; b=WiqvxsFRL+o8FKUhMtEDUMU8/pVc/qjWzHG2uUccvdCm+ppMqC933laMIueHyu4dyZWogkGOSXzgoNoSg/YjLiK1ZBTVHlmgCUrOQpIFeRGMWJU7UAaS8O4CPNPYXyIAWJz9lxlKtcTN7/ogW9uL7DHrnkKcXKcfu01Qy8MN5vo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612600567; 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=AloT79haZs1FGdGsLgJ+t/ClPr5zWtpo8lq9MNCIUAg=; b=YYpGE2sxDjKOHsljOkUDF6dhkOVb2PLgV9/3L3Ua7euhFpLQ28IdxlnEcZggUUTig41pwV9Vm7XiPMQ2U8VX5VDJlQ6ZLpg49SOg0ILD8mlsgZev4XfZcDCFFtvcu44ZLwOXgJC+hUkKTSDy2Jl7q4b9sLVRACeRmBxp5mS8zI8= 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 1612600567300534.8945087117678; Sat, 6 Feb 2021 00:36:07 -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-401-HeLaYXraN_OAmJ1ltfQE2w-1; Sat, 06 Feb 2021 03:35:16 -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 1F1871DDE8; Sat, 6 Feb 2021 08:35:11 +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 F1B796F999; Sat, 6 Feb 2021 08:35:10 +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 B82A31800822; Sat, 6 Feb 2021 08:35:10 +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 1168Z91D005801 for ; Sat, 6 Feb 2021 03:35:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69EEC60C79; Sat, 6 Feb 2021 08:35:09 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F52860C8F for ; Sat, 6 Feb 2021 08:35:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612600566; 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=AloT79haZs1FGdGsLgJ+t/ClPr5zWtpo8lq9MNCIUAg=; b=ZfqEoc/MmRjAO8SLzAsoeqJ5maGdxzu3BLhDA7pnwfKBiA5YoUKBU9thoQreHSKdAAJfCe g1Rxe4/Z093j2ZrdhEJ0qUW3OTGRNsmq69BDk1DpV2mO38daE4CYWPw3RRV3Qzh5dCAme7 PodQ5VXf0db89mil3Nn7cq7u+mvN7CI= X-MC-Unique: HeLaYXraN_OAmJ1ltfQE2w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 40/40] virstringtest: Remove testing of virStringSplitCount Date: Sat, 6 Feb 2021 09:33:02 +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" The function is a wrapper on top of glibs g_strsplit, so is covered by glibs testing. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- tests/virstringtest.c | 97 ------------------------------------------- 1 file changed, 97 deletions(-) diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 3bd9b97db7..82e8e2106f 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -74,65 +74,6 @@ static int testStreq(const void *args) return 0; } -struct testSplitData { - const char *string; - const char *delim; - size_t max_tokens; - const char **tokens; -}; - - -static int testSplit(const void *args) -{ - const struct testSplitData *data =3D args; - char **got; - size_t ntokens; - size_t exptokens =3D 0; - char **tmp1; - const char **tmp2; - int ret =3D -1; - - if (!(got =3D virStringSplitCount(data->string, data->delim, - data->max_tokens, &ntokens))) { - VIR_DEBUG("Got no tokens at all"); - return -1; - } - - tmp1 =3D got; - tmp2 =3D data->tokens; - while (*tmp1 && *tmp2) { - if (STRNEQ(*tmp1, *tmp2)) { - fprintf(stderr, "Mismatch '%s' vs '%s'\n", *tmp1, *tmp2); - goto cleanup; - } - tmp1++; - tmp2++; - exptokens++; - } - if (*tmp1) { - fprintf(stderr, "Too many pieces returned\n"); - goto cleanup; - } - if (*tmp2) { - fprintf(stderr, "Too few pieces returned\n"); - goto cleanup; - } - - if (ntokens !=3D exptokens) { - fprintf(stderr, - "Returned token count (%zu) doesn't match " - "expected count (%zu)", - ntokens, exptokens); - goto cleanup; - } - - ret =3D 0; - cleanup: - g_strfreev(got); - - return ret; -} - static int testStringSortCompare(const void *opaque G_GNUC_UNUSED) @@ -569,44 +510,6 @@ mymain(void) TEST_STREQ("", ""); TEST_STREQ("hello", "hello"); -#define TEST_SPLIT(str, del, max, toks) \ - do { \ - struct testSplitData splitData =3D { \ - .string =3D str, \ - .delim =3D del, \ - .max_tokens =3D max, \ - .tokens =3D toks, \ - }; \ - if (virTestRun("Split " #str, testSplit, &splitData) < 0) \ - ret =3D -1; \ - } while (0) - - VIR_WARNINGS_NO_DECLARATION_AFTER_STATEMENT - const char *tokens1[] =3D { NULL }; - TEST_SPLIT("", " ", 0, tokens1); - - const char *tokens2[] =3D { "", "", NULL }; - TEST_SPLIT(" ", " ", 0, tokens2); - - const char *tokens3[] =3D { "", "", "", NULL }; - TEST_SPLIT(" ", " ", 0, tokens3); - - const char *tokens4[] =3D { "The", "quick", "brown", "fox", NULL }; - TEST_SPLIT("The quick brown fox", " ", 0, tokens4); - - const char *tokens5[] =3D { "The quick ", " fox", NULL }; - TEST_SPLIT("The quick brown fox", "brown", 0, tokens5); - - const char *tokens6[] =3D { "", "The", "quick", "brown", "fox", NULL }; - TEST_SPLIT(" The quick brown fox", " ", 0, tokens6); - - const char *tokens7[] =3D { "The", "quick", "brown", "fox", "", NULL }; - TEST_SPLIT("The quick brown fox ", " ", 0, tokens7); - - const char *tokens8[] =3D { "gluster", "rdma", NULL }; - TEST_SPLIT("gluster+rdma", "+", 2, tokens8); - VIR_WARNINGS_RESET - if (virTestRun("virStringSortCompare", testStringSortCompare, NULL) < = 0) ret =3D -1; --=20 2.29.2