From nobody Mon Feb 9 03:46:26 2026 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=1617808372; cv=none; d=zohomail.com; s=zohoarc; b=nd49FPa+Tk/f5RYmnQ2DfT78lfb/DY7xySZs/ZPCMkGTNBcc2ix0I7Zqd/EsoHngKMcy1J5+mb+br1L2mn5U3LUDQkA2hm+n2cngpHBfs5MtZNaQMFB7OfArTf4YSSgWRe/wA4iOAvKAkwpi1bW09bGR68tm+NmUPR9uZ+twuWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1617808372; 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=dBPxDFD10rzxwRDU9l+lgiujBM/G4bkTCq5nQq3s0nM=; b=a6/VQVoWT+lqBDcoWRZM2tDFEZNyf94fgjqujLV+YLMSN/zgT8TP6W2Lq/iax/87+6+6TF63omWKJrNkFzTG+6IJK3/RC6q1u7fRa+AfZvWc9VPAanxzJmQGz+9a7gdww0QJL1UP0HE3IUZ0jj2sUtSf4pETpFEkjxpRMaGFUzY= 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 1617808372885814.7042314208888; Wed, 7 Apr 2021 08:12:52 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-561-KzLNlHhwM8SaiwPNB1wAew-1; Wed, 07 Apr 2021 11:12:49 -0400 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 2DEBCCC628; Wed, 7 Apr 2021 15:12: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 056FA18811; Wed, 7 Apr 2021 15:12: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 B5611180B653; Wed, 7 Apr 2021 15:12:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 137FA2SX031820 for ; Wed, 7 Apr 2021 11:10:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 782BE19D7D; Wed, 7 Apr 2021 15:10:02 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC20819C78 for ; Wed, 7 Apr 2021 15:10:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617808371; 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=dBPxDFD10rzxwRDU9l+lgiujBM/G4bkTCq5nQq3s0nM=; b=DEhq6hiOquikA65XBTwnH6HDPwGxj7Irc5625T+wh/al4VQdKj+AK2deXuJt4droqVp3gl 3j29MzqOKwJYP22J+xbDT8G1sUVgHKa0w/YIM3TMTYOI7Tjuj2KuGS/msi2dMca3O9VhBc fW2afVV51wlt43NllFNH8MVnfgaJ8Ck= X-MC-Unique: KzLNlHhwM8SaiwPNB1wAew-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/24] virCommandSetDryRun: Rework resetting of the dry run data Date: Wed, 7 Apr 2021 17:09:30 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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" While virCommandSetDryRun is used in tests only, there were some cases when error paths would not call the function with NULL arguments to reset the dry run infrastructure. Introduce VIR_COMMAND_DRY_RUN_TOKEN macro which declares a variable called 'dryRunToken' which must be passed to virCommandSetDryRun. This way we can use automatic variable cleaning to trigger the cleanup of virCommandSetDryRun parameters and also the use of the token variable ensures that all callers of virCommandSetDryRun clean up after themselves and also that VIR_COMMAND_DRY_RUN_TOKEN isn't left unused in the code. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/vircommand.c | 13 ++++++++++- src/util/vircommandpriv.h | 10 +++++++- tests/networkxml2firewalltest.c | 4 ++-- tests/nodedevmdevctltest.c | 8 +++---- tests/nwfilterebiptablestest.c | 28 +++++++++++----------- tests/nwfilterxml2firewalltest.c | 4 ++-- tests/sysinfotest.c | 4 ++-- tests/virfirewalltest.c | 40 ++++++++++++++++---------------- tests/viriscsitest.c | 12 +++++----- tests/virkmodtest.c | 8 +++---- tests/virnetdevbandwidthtest.c | 4 ++-- 12 files changed, 78 insertions(+), 58 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index caa0fd18f8..e32088badb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1983,6 +1983,7 @@ virCommandAllowCap; virCommandClearCaps; virCommandDaemonize; virCommandDoAsyncIO; +virCommandDryRunResetHelper; virCommandExec; virCommandFree; virCommandGetArgList; diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 8ae5badf0f..7b2588f5c8 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -3132,7 +3132,8 @@ virCommandDoAsyncIO(virCommandPtr cmd) * To cancel this effect pass NULL for @buf and @callback. */ void -virCommandSetDryRun(virBufferPtr buf, +virCommandSetDryRun(virCommandDryRunToken tok G_GNUC_UNUSED, + virBufferPtr buf, virCommandDryRunCallback cb, void *opaque) { @@ -3141,6 +3142,16 @@ virCommandSetDryRun(virBufferPtr buf, dryRunOpaque =3D opaque; } + +void +virCommandDryRunResetHelper(virCommandDryRunToken *tok G_GNUC_UNUSED) +{ + dryRunBuffer =3D NULL; + dryRunCallback =3D NULL; + dryRunOpaque =3D NULL; +} + + #ifndef WIN32 /** * virCommandRunRegex: diff --git a/src/util/vircommandpriv.h b/src/util/vircommandpriv.h index 80f1d1376c..8a47a6d5e3 100644 --- a/src/util/vircommandpriv.h +++ b/src/util/vircommandpriv.h @@ -35,6 +35,14 @@ typedef void (*virCommandDryRunCallback)(const char *con= st*args, int *status, void *opaque); -void virCommandSetDryRun(virBufferPtr buf, +typedef int virCommandDryRunToken; + +void virCommandSetDryRun(virCommandDryRunToken tok, + virBufferPtr buf, virCommandDryRunCallback cb, void *opaque); + +void +virCommandDryRunResetHelper(virCommandDryRunToken *tok); + +#define VIR_COMMAND_DRY_RUN_TOKEN __attribute__((cleanup(virCommandDryRunR= esetHelper))) virCommandDryRunToken dryRunToken =3D 0 diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltes= t.c index d358f12897..574b553fa6 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -96,8 +96,9 @@ static int testCompareXMLToArgvFiles(const char *xml, virNetworkDefPtr def =3D NULL; int ret =3D -1; char *actual; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, testCommandDryRun, NULL); + virCommandSetDryRun(dryRunToken, &buf, testCommandDryRun, NULL); if (!(def =3D virNetworkDefParseFile(xml, NULL))) goto cleanup; @@ -107,7 +108,6 @@ static int testCompareXMLToArgvFiles(const char *xml, actual =3D actualargv =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); - virCommandSetDryRun(NULL, NULL, NULL); /* The first network to be created populates the * libvirt global chains. We must skip args for diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 1bad65549b..ce8e5e85f6 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -60,6 +60,7 @@ testMdevctlStart(const char *virt_type, g_autofree char *uuid =3D NULL; g_autofree char *stdinbuf =3D NULL; g_autoptr(virCommand) cmd =3D NULL; + VIR_COMMAND_DRY_RUN_TOKEN; if (!(def =3D virNodeDeviceDefParseFile(mdevxml, create, virt_type))) goto cleanup; @@ -71,7 +72,7 @@ testMdevctlStart(const char *virt_type, if (!cmd) goto cleanup; - virCommandSetDryRun(&buf, testCommandDryRunCallback, &stdinbuf); + virCommandSetDryRun(dryRunToken, &buf, testCommandDryRunCallback, &std= inbuf); if (virCommandRun(cmd, NULL) < 0) goto cleanup; @@ -87,7 +88,6 @@ testMdevctlStart(const char *virt_type, ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); virNodeDeviceObjEndAPI(&obj); return ret; } @@ -120,13 +120,14 @@ testMdevctlStop(const void *data) g_autofree char *cmdlinefile =3D g_strdup_printf("%s/nodedevmdevctldata/mdevctl-stop.argv", abs_srcdir); + VIR_COMMAND_DRY_RUN_TOKEN; cmd =3D nodeDeviceGetMdevctlStopCommand(uuid); if (!cmd) goto cleanup; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (virCommandRun(cmd, NULL) < 0) goto cleanup; @@ -139,7 +140,6 @@ testMdevctlStop(const void *data) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); return ret; } diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c index f47b4f1dfd..0893548c0a 100644 --- a/tests/nwfilterebiptablestest.c +++ b/tests/nwfilterebiptablestest.c @@ -103,8 +103,9 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_= GNUC_UNUSED) "ebtables --concurrent -t nat -X libvirt-O-vnet0\n"; char *actual =3D NULL; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.allTeardown("vnet0") < 0) goto cleanup; @@ -119,7 +120,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_= GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } @@ -170,8 +170,9 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G= _GNUC_UNUSED) "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n= "; char *actual =3D NULL; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.tearOldRules("vnet0") < 0) goto cleanup; @@ -186,7 +187,6 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G= _GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } @@ -215,8 +215,9 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaq= ue G_GNUC_UNUSED) "ebtables --concurrent -t nat -X libvirt-P-vnet0\n"; char *actual =3D NULL; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.removeBasicRules("vnet0") < 0) goto cleanup; @@ -231,7 +232,6 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaq= ue G_GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } @@ -245,8 +245,9 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G= _GNUC_UNUSED) VIR_NWFILTER_NEW_RULES_TEARDOWN; char *actual =3D NULL; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.tearNewRules("vnet0") < 0) goto cleanup; @@ -261,7 +262,6 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G= _GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } @@ -313,8 +313,9 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaqu= e G_GNUC_UNUSED) char *actual =3D NULL; int ret =3D -1; virMacAddr mac =3D { .addr =3D { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 } = }; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.applyBasicRules("vnet0", &mac) < 0) goto cleanup; @@ -329,7 +330,6 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaqu= e G_GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } @@ -399,8 +399,9 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *op= aque G_GNUC_UNUSED) } } }; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.applyDHCPOnlyRules("vnet0", &mac, &val, false) <= 0) goto cleanup; @@ -415,7 +416,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *op= aque G_GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } @@ -468,8 +468,9 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opa= que G_GNUC_UNUSED) "ebtables --concurrent -t nat -E libvirt-P-vnet0 libvirt-O-vnet0\n= "; char *actual =3D NULL; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (ebiptables_driver.applyDropAllRules("vnet0") < 0) goto cleanup; @@ -484,7 +485,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opa= que G_GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual); return ret; } diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewallt= est.c index 3e2ab0b0ba..a3b8ae70c1 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -371,10 +371,11 @@ static int testCompareXMLToArgvFiles(const char *xml, GHashTable *vars =3D virHashNew(virNWFilterVarValueHashFree); virNWFilterInst inst; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; memset(&inst, 0, sizeof(inst)); - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (!vars) goto cleanup; @@ -392,7 +393,6 @@ static int testCompareXMLToArgvFiles(const char *xml, actualargv =3D virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); - virCommandSetDryRun(NULL, NULL, NULL); testRemoveCommonRules(actualargv); diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c index e40a4564a7..85687e995a 100644 --- a/tests/sysinfotest.c +++ b/tests/sysinfotest.c @@ -96,17 +96,17 @@ testSysinfo(const void *data) g_autofree char *sysinfo =3D NULL; g_autofree char *cpuinfo =3D NULL; g_autofree char *expected =3D NULL; + VIR_COMMAND_DRY_RUN_TOKEN; sysinfo =3D g_strdup_printf("%s/sysinfodata/%ssysinfo.data", abs_srcdi= r, testdata->name); cpuinfo =3D g_strdup_printf("%s/sysinfodata/%scpuinfo.data", abs_srcdi= r, testdata->name); expected =3D g_strdup_printf("%s/sysinfodata/%ssysinfo.expect", abs_sr= cdir, testdata->name); - virCommandSetDryRun(NULL, testDMIDecodeDryRun, sysinfo); + virCommandSetDryRun(dryRunToken, NULL, testDMIDecodeDryRun, sysinfo); virSysinfoSetup(sysinfo, cpuinfo); ret =3D testdata->func(); - virCommandSetDryRun(NULL, NULL, NULL); if (!ret) return -1; diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index 8bd73311fd..c442aca9da 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -189,6 +189,7 @@ testFirewallSingleGroup(const void *opaque) IPTABLES_PATH " -w -A INPUT --source 192.168.122.1 --jump ACCEPT\n" IPTABLES_PATH " -w -A INPUT --source '!192.168.122.1' --jump REJEC= T\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -196,7 +197,7 @@ testFirewallSingleGroup(const void *opaque) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) - virCommandSetDryRun(&cmdbuf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, NULL, NULL); else fwBuf =3D &cmdbuf; @@ -226,7 +227,6 @@ testFirewallSingleGroup(const void *opaque) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -243,6 +243,7 @@ testFirewallRemoveRule(const void *opaque) IPTABLES_PATH " -w -A INPUT --source '!192.168.122.1' --jump REJEC= T\n"; const struct testFirewallData *data =3D opaque; virFirewallRulePtr fwrule; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -250,7 +251,7 @@ testFirewallRemoveRule(const void *opaque) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) - virCommandSetDryRun(&cmdbuf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, NULL, NULL); else fwBuf =3D &cmdbuf; @@ -286,7 +287,6 @@ testFirewallRemoveRule(const void *opaque) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -304,6 +304,7 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED) IPTABLES_PATH " -w -A OUTPUT --source 192.168.122.1 --jump ACCEPT\= n" IPTABLES_PATH " -w -A OUTPUT --jump DROP\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -311,7 +312,7 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) - virCommandSetDryRun(&cmdbuf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, NULL, NULL); else fwBuf =3D &cmdbuf; @@ -353,7 +354,6 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -392,6 +392,7 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_U= NUSED) IPTABLES_PATH " -w -A OUTPUT --source 192.168.122.1 --jump ACCEPT\= n" IPTABLES_PATH " -w -A OUTPUT --jump DROP\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -399,7 +400,7 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_U= NUSED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallRollbackHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallRollbackHook= , NULL); } else { fwBuf =3D &cmdbuf; fwError =3D true; @@ -443,7 +444,6 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_U= NUSED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -461,6 +461,7 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UN= USED) IPTABLES_PATH " -w -A OUTPUT --source 192.168.122.1 --jump ACCEPT\= n" IPTABLES_PATH " -w -A OUTPUT --jump DROP\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -468,7 +469,7 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UN= USED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallRollbackHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallRollbackHook= , NULL); } else { fwBuf =3D &cmdbuf; fwError =3D true; @@ -511,7 +512,6 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UN= USED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -527,6 +527,7 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED) IPTABLES_PATH " -w -A INPUT --source 192.168.122.1 --jump ACCEPT\n" IPTABLES_PATH " -w -A INPUT --source 192.168.122.255 --jump REJECT= \n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -534,7 +535,7 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallRollbackHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallRollbackHook= , NULL); } else { fwBuf =3D &cmdbuf; fwError =3D true; @@ -573,7 +574,6 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -591,6 +591,7 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UN= USED) IPTABLES_PATH " -w -D INPUT --source 192.168.122.255 --jump REJECT= \n" IPTABLES_PATH " -w -D INPUT --source '!192.168.122.1' --jump REJEC= T\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -598,7 +599,7 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UN= USED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallRollbackHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallRollbackHook= , NULL); } else { fwError =3D true; fwBuf =3D &cmdbuf; @@ -654,7 +655,6 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UN= USED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -671,6 +671,7 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUS= ED) IPTABLES_PATH " -w -D INPUT --source 192.168.122.255 --jump REJECT= \n" IPTABLES_PATH " -w -D INPUT --source '!192.168.122.1' --jump REJEC= T\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -678,7 +679,7 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUS= ED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallRollbackHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallRollbackHook= , NULL); } else { fwBuf =3D &cmdbuf; fwError =3D true; @@ -738,7 +739,6 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUS= ED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -759,6 +759,7 @@ testFirewallChainedRollback(const void *opaque G_GNUC_U= NUSED) IPTABLES_PATH " -w -D INPUT --source 192.168.122.255 --jump REJECT= \n" IPTABLES_PATH " -w -D INPUT --source '!192.168.122.1' --jump REJEC= T\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; fwDisabled =3D data->fwDisabled; if (virFirewallSetBackend(data->tryBackend) < 0) @@ -766,7 +767,7 @@ testFirewallChainedRollback(const void *opaque G_GNUC_U= NUSED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallRollbackHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallRollbackHook= , NULL); } else { fwBuf =3D &cmdbuf; fwError =3D true; @@ -852,7 +853,6 @@ testFirewallChainedRollback(const void *opaque G_GNUC_U= NUSED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } @@ -953,6 +953,7 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED) IPTABLES_PATH " -w -A INPUT --source 192.168.122.128 --jump REJECT= \n" IPTABLES_PATH " -w -A INPUT --source '!192.168.122.1' --jump REJEC= T\n"; const struct testFirewallData *data =3D opaque; + VIR_COMMAND_DRY_RUN_TOKEN; expectedLineNum =3D 0; expectedLineError =3D false; @@ -962,7 +963,7 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED) if (data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_DIRECT || data->expectBackend =3D=3D VIR_FIREWALL_BACKEND_FIREWALLD) { - virCommandSetDryRun(&cmdbuf, testFirewallQueryHook, NULL); + virCommandSetDryRun(dryRunToken, &cmdbuf, testFirewallQueryHook, N= ULL); } else { fwBuf =3D &cmdbuf; fwError =3D true; @@ -1030,7 +1031,6 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: fwBuf =3D NULL; - virCommandSetDryRun(NULL, NULL, NULL); return ret; } diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index e86d3970b6..2927e235cd 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -212,10 +212,11 @@ testISCSIGetSession(const void *data) struct testIscsiadmCbData cbData =3D { 0 }; char *actual_session =3D NULL; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; cbData.output_version =3D info->output_version; - virCommandSetDryRun(NULL, testIscsiadmCb, &cbData); + virCommandSetDryRun(dryRunToken, NULL, testIscsiadmCb, &cbData); actual_session =3D virISCSIGetSession(info->device_path, true); @@ -230,7 +231,6 @@ testISCSIGetSession(const void *data) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual_session); return ret; } @@ -250,8 +250,9 @@ testISCSIScanTargets(const void *data) char **targets =3D NULL; int ret =3D -1; size_t i; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(NULL, testIscsiadmCb, NULL); + virCommandSetDryRun(dryRunToken, NULL, testIscsiadmCb, NULL); if (virISCSIScanTargets(info->portal, NULL, false, &ntargets, &targets) < 0) @@ -276,7 +277,6 @@ testISCSIScanTargets(const void *data) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); for (i =3D 0; i < ntargets; i++) VIR_FREE(targets[i]); VIR_FREE(targets); @@ -297,15 +297,15 @@ testISCSIConnectionLogin(const void *data) const struct testConnectionInfoLogin *info =3D data; struct testIscsiadmCbData cbData =3D { 0 }; int ret =3D -1; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(NULL, testIscsiadmCb, &cbData); + virCommandSetDryRun(dryRunToken, NULL, testIscsiadmCb, &cbData); if (virISCSIConnectionLogin(info->portal, info->initiatoriqn, info->ta= rget) < 0) goto cleanup; ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); return ret; } diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c index 369eb8baca..725c204667 100644 --- a/tests/virkmodtest.c +++ b/tests/virkmodtest.c @@ -61,8 +61,9 @@ testKModLoad(const void *args G_GNUC_UNUSED) int ret =3D -1; char *errbuf =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); errbuf =3D virKModLoad(MODNAME); if (errbuf) { @@ -76,7 +77,6 @@ testKModLoad(const void *args G_GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(errbuf); return ret; } @@ -88,8 +88,9 @@ testKModUnload(const void *args G_GNUC_UNUSED) int ret =3D -1; char *errbuf =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + VIR_COMMAND_DRY_RUN_TOKEN; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); errbuf =3D virKModUnload(MODNAME); if (errbuf) { @@ -103,7 +104,6 @@ testKModUnload(const void *args G_GNUC_UNUSED) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(errbuf); return ret; } diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 6f3cab27be..5233fc47d3 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -72,13 +72,14 @@ testVirNetDevBandwidthSet(const void *data) g_autoptr(virNetDevBandwidth) band =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; char *actual_cmd =3D NULL; + VIR_COMMAND_DRY_RUN_TOKEN; PARSE(info->band, band); if (!iface) iface =3D "eth0"; - virCommandSetDryRun(&buf, NULL, NULL); + virCommandSetDryRun(dryRunToken, &buf, NULL, NULL); if (virNetDevBandwidthSet(iface, band, info->hierarchical_class, true)= < 0) goto cleanup; @@ -97,7 +98,6 @@ testVirNetDevBandwidthSet(const void *data) ret =3D 0; cleanup: - virCommandSetDryRun(NULL, NULL, NULL); VIR_FREE(actual_cmd); return ret; } --=20 2.30.2