From nobody Sat May 4 14:00:15 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com 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 1625021730636230.28289591978626; Tue, 29 Jun 2021 19:55:30 -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-214-TKHT11ZPPhWebZueAUvFAA-1; Tue, 29 Jun 2021 22:55:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D5D41084F55; Wed, 30 Jun 2021 02:55:22 +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 D689060862; Wed, 30 Jun 2021 02:55:21 +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 39D534EA2A; Wed, 30 Jun 2021 02:55:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15U2s4XE021055 for ; Tue, 29 Jun 2021 22:54:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 830172044709; Wed, 30 Jun 2021 02:54:04 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DF1320341B9 for ; Wed, 30 Jun 2021 02:54:01 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 935F8185A79C for ; Wed, 30 Jun 2021 02:54:01 +0000 (UTC) Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-193-F-Z3iX3NPmCZJDa6ZFpgVA-1; Tue, 29 Jun 2021 22:53:59 -0400 Received: by mail-pf1-f179.google.com with SMTP id 17so847210pfz.4 for ; Tue, 29 Jun 2021 19:53:58 -0700 (PDT) Received: from localhost ([38.94.109.214]) by smtp.gmail.com with ESMTPSA id 202sm78380pfu.113.2021.06.29.19.53.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 19:53:57 -0700 (PDT) X-MC-Unique: TKHT11ZPPhWebZueAUvFAA-1 X-MC-Unique: F-Z3iX3NPmCZJDa6ZFpgVA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6WEIaBUa8umCPFkxU4XtJxdhzcQeGlOm/cx2peEV48M=; b=s4w4X8bzA+HKgNVxkcw+DmHKjjfv8mVxdf88Dtgn0IaJV4m7F6slTqWB9yTzua9o/8 U+ECbSOz/KybjPgWuQzmk9zRsSPY5AVrXQx2SCrC8R7/aFhAuQ9qHS+MLN/DHD5AcS96 XXOg2mIRKBmMhH2oyUWDhIHGNuEhOvSI6akWl176dAdiCwA1NKB9QMd641fgSAYy2BH2 63U0Bfh/OL4rrH+2ekjQSHNByu0EZzUjx4rNxwnTzDwBa+g7OzPLrmfOPcmkjzCGWOV3 JZIoPdDTZaEmPt2GW8yqZgrTt9b1p3ZA8A6u6FwIW4ag9wJo+DA3uiEyRylNCcWZUloS i3yQ== X-Gm-Message-State: AOAM530BQMcsV3Xdpy0GcXvxCUdxkdxhhz7p7jxlkOyGzs5Vg2IEugR4 exJdw6t1ja5hcHOWeeO8yBiR1cn9mvTvSjP3 X-Google-Smtp-Source: ABdhPJzEEFjGmN8vDF6dMriiRFewS6ASuFkyAD3loxbXkeRyWia4A5kxDTAD+EVL5pNwoY7EXw36+Q== X-Received: by 2002:a63:f20a:: with SMTP id v10mr19538220pgh.415.1625021637749; Tue, 29 Jun 2021 19:53:57 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v3 1/3] test_driver: Implement virDomainGetMessages Date: Wed, 30 Jun 2021 10:53:44 +0800 Message-Id: <20210630025346.180353-2-lukedyue@gmail.com> In-Reply-To: <20210630025346.180353-1-lukedyue@gmail.com> References: <20210630025346.180353-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 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 Content-Type: text/plain; charset="utf-8" Signed-off-by: Luke Yue --- src/test/test_driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ef0ddab54d..35742fcde3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9291,6 +9291,58 @@ testDomainCheckpointDelete(virDomainCheckpointPtr ch= eckpoint, return ret; } =20 +static int +testDomainGetMessages(virDomainPtr dom, + char ***msgs, + unsigned int flags) +{ + virDomainObj *vm =3D NULL; + int rv =3D -1; + size_t i, n; + int nmsgs; + + virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION | + VIR_DOMAIN_MESSAGE_TAINTING, -1); + + if (!(vm =3D testDomObjFromDomain(dom))) + return -1; + + *msgs =3D NULL; + nmsgs =3D 0; + n =3D 0; + + if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { + nmsgs +=3D __builtin_popcount(vm->taint); + *msgs =3D g_renew(char *, *msgs, nmsgs+1); + + for (i =3D 0; i < VIR_DOMAIN_TAINT_LAST; i++) { + if (vm->taint & (1 << i)) { + (*msgs)[n++] =3D g_strdup_printf( + _("tainted: %s"), + _(virDomainTaintMessageTypeToString(i))); + } + } + } + + if (!flags || (flags & VIR_DOMAIN_MESSAGE_DEPRECATION)) { + nmsgs +=3D vm->ndeprecations; + *msgs =3D g_renew(char *, *msgs, nmsgs+1); + + for (i =3D 0; i < vm->ndeprecations; i++) { + (*msgs)[n++] =3D g_strdup_printf( + _("deprecated configuration: %s"), + vm->deprecations[i]); + } + } + + (*msgs)[nmsgs] =3D NULL; + + rv =3D nmsgs; + + virDomainObjEndAPI(&vm); + return rv; +} + /* * Test driver */ @@ -9448,6 +9500,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainCheckpointLookupByName =3D testDomainCheckpointLookupByName, /*= 5.6.0 */ .domainCheckpointGetParent =3D testDomainCheckpointGetParent, /* 5.6.0= */ .domainCheckpointDelete =3D testDomainCheckpointDelete, /* 5.6.0 */ + .domainGetMessages =3D testDomainGetMessages, /* 7.6.0 */ }; =20 static virNetworkDriver testNetworkDriver =3D { --=20 2.32.0 From nobody Sat May 4 14:00:15 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; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com 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 1625021738320509.7098545332424; Tue, 29 Jun 2021 19:55:38 -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-473-i0eMLjgdMkWwJYsN56KFcg-1; Tue, 29 Jun 2021 22:55:35 -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 40C7C1084F54; Wed, 30 Jun 2021 02:55:30 +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 204755C1D1; Wed, 30 Jun 2021 02:55:30 +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 E007D1809C99; Wed, 30 Jun 2021 02:55:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15U2s6bq021066 for ; Tue, 29 Jun 2021 22:54:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA8D6101312F; Wed, 30 Jun 2021 02:54:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A67A11013120 for ; Wed, 30 Jun 2021 02:54:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 516F5802700 for ; Wed, 30 Jun 2021 02:54:04 +0000 (UTC) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-67-r_0pBF_KNDemdY3annYH6g-1; Tue, 29 Jun 2021 22:54:01 -0400 Received: by mail-pj1-f46.google.com with SMTP id z3-20020a17090a3983b029016bc232e40bso386450pjb.4 for ; Tue, 29 Jun 2021 19:54:01 -0700 (PDT) Received: from localhost ([38.94.109.214]) by smtp.gmail.com with ESMTPSA id c2sm19819783pjv.10.2021.06.29.19.53.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 19:53:59 -0700 (PDT) X-MC-Unique: i0eMLjgdMkWwJYsN56KFcg-1 X-MC-Unique: r_0pBF_KNDemdY3annYH6g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JnOiNKQIHlauRD4U5rPR2AEKNIPyax0EMdgCNjVF6/g=; b=JsRF9URfNdA01mep340MKSwYnHgNmNRBgbD3PlkmcZ/N2JqWd+VdUA52+H7giy9TvD I5tmjYHw/GQUsyuAPdr6Bt/GaE9chOyVh2EJjXOUDLwMxyet9ceXTewVFxvZmog5+H2d G9muJd664TqkycYYDAQ9YUBFY5xTeUZ0++S8fQdOas+Tw39ZbFCZ1eeFThikF3aoQ2Dt KklweakykQQviurkqwMz3/mc4tgkUwlM8RNdChyUgNS9KhbbBFG5T0YeY4hQmE5KHV23 CwI9iLvsjHlkFpS6SjF0zz9yuRB8kVJXMHv13og4gQG3MttW69AstkN1O4cqK3gwpdpn xPwA== X-Gm-Message-State: AOAM531TLB5pWne3m0qCMJMBViTjCJr9H3jFpbwwPWLbijRIYOL9075U DtUFa8Jh01E97KxkvsVn8iUquCrzumX/CwpL X-Google-Smtp-Source: ABdhPJxdcPFFndd7PExz376FOMSlOWYgdaAWCpGPr8J6kx1IXTN8li7IFq1p60DV+qGzoePSWtwBUA== X-Received: by 2002:a17:903:304e:b029:11d:41c:fa73 with SMTP id u14-20020a170903304eb029011d041cfa73mr30210076pla.82.1625021640161; Tue, 29 Jun 2021 19:54:00 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v3 2/3] test_driver: Introduce testDomainObjCheckTaint Date: Wed, 30 Jun 2021 10:53:45 +0800 Message-Id: <20210630025346.180353-3-lukedyue@gmail.com> In-Reply-To: <20210630025346.180353-1-lukedyue@gmail.com> References: <20210630025346.180353-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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 Content-Type: text/plain; charset="utf-8" In order to test the virDomainGetMessages for test driver, we need to check some taints or deprecations, so introduce testDomainObjCheckTaint for checking taints. As we introduced testDomainObjCheckTaint for test driver, the `dominfo` command in virshtest will now print tainting messages, so add them for test. Signed-off-by: Luke Yue --- src/test/test_driver.c | 57 ++++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 59 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 35742fcde3..06ba7c4cd2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9291,6 +9291,61 @@ testDomainCheckpointDelete(virDomainCheckpointPtr ch= eckpoint, return ret; } =20 +static void +testDomainObjCheckDiskTaint(virDomainObj *obj, + virDomainDiskDef *disk) +{ + if (disk->rawio =3D=3D VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); + + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM && + virStorageSourceGetActualType(disk->src) =3D=3D VIR_STORAGE_TYPE_B= LOCK && + disk->src->path && virFileIsCDROM(disk->src->path) =3D=3D 1) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CDROM_PASSTHROUGH); +} + +static void +testDomainObjCheckHostdevTaint(virDomainObj *obj, + virDomainHostdevDef *hostdev) +{ + if (!virHostdevIsSCSIDevice(hostdev)) + return; + + if (hostdev->source.subsys.u.scsi.rawio =3D=3D VIR_TRISTATE_BOOL_YES) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_HIGH_PRIVILEGES); +} + +static void +testDomainObjCheckNetTaint(virDomainObj *obj, + virDomainNetDef *net) +{ + /* script is only useful for NET_TYPE_ETHERNET (qemu) and + * NET_TYPE_BRIDGE (xen), but could be (incorrectly) specified for + * any interface type. In any case, it's adding user sauce into + * the soup, so it should taint the domain. + */ + if (net->script !=3D NULL) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_SHELL_SCRIPTS); +} + +static void +testDomainObjCheckTaint(virDomainObj *obj) +{ + size_t i; + + for (i =3D 0; i < obj->def->ndisks; i++) + testDomainObjCheckDiskTaint(obj, obj->def->disks[i]); + + for (i =3D 0; i < obj->def->nhostdevs; i++) + testDomainObjCheckHostdevTaint(obj, obj->def->hostdevs[i]); + + for (i =3D 0; i < obj->def->nnets; i++) + testDomainObjCheckNetTaint(obj, obj->def->nets[i]); + + if (obj->def->os.dtb) + virDomainObjTaint(obj, VIR_DOMAIN_TAINT_CUSTOM_DTB); +} + static int testDomainGetMessages(virDomainPtr dom, char ***msgs, @@ -9311,6 +9366,8 @@ testDomainGetMessages(virDomainPtr dom, nmsgs =3D 0; n =3D 0; =20 + testDomainObjCheckTaint(vm); + if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { nmsgs +=3D __builtin_popcount(vm->taint); *msgs =3D g_renew(char *, *msgs, nmsgs+1); diff --git a/tests/virshtest.c b/tests/virshtest.c index c1974c46cb..937448cefc 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -22,6 +22,7 @@ main(void) =20 # define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" # define SECURITY_LABEL "libvirt-test (enforcing)" +# define MESSAGES "tainted: network configuration using opaque shell scrip= ts" =20 static const char *dominfo_fc4 =3D "\ Id: 2\n\ @@ -38,6 +39,7 @@ Managed save: no\n\ Security model: testSecurity\n\ Security DOI: \n\ Security label: " SECURITY_LABEL "\n\ +Messages: " MESSAGES "\n\ \n"; static const char *domuuid_fc4 =3D DOM_UUID "\n\n"; static const char *domid_fc4 =3D "2\n\n"; --=20 2.32.0 From nobody Sat May 4 14:00:15 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; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com 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 1625021846473477.6562573501029; Tue, 29 Jun 2021 19:57:26 -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-74-ybRlGBZ0OK2NlfpCfG0Mdg-1; Tue, 29 Jun 2021 22:57:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34735802E64; Wed, 30 Jun 2021 02:57:17 +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 75A9F5DAA5; Wed, 30 Jun 2021 02:57: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 99D7A1809C99; Wed, 30 Jun 2021 02:57:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15U2sAHi021092 for ; Tue, 29 Jun 2021 22:54:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 319B1200ACFE; Wed, 30 Jun 2021 02:54:10 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CEBA200E572 for ; Wed, 30 Jun 2021 02:54:07 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50FDA866DF1 for ; Wed, 30 Jun 2021 02:54:07 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-410-L6fE1NTEPr2J3vcQd6kkqA-1; Tue, 29 Jun 2021 22:54:04 -0400 Received: by mail-pg1-f180.google.com with SMTP id o18so143287pgu.10 for ; Tue, 29 Jun 2021 19:54:03 -0700 (PDT) Received: from localhost ([38.94.109.214]) by smtp.gmail.com with ESMTPSA id d13sm4820090pjr.49.2021.06.29.19.54.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 19:54:02 -0700 (PDT) X-MC-Unique: ybRlGBZ0OK2NlfpCfG0Mdg-1 X-MC-Unique: L6fE1NTEPr2J3vcQd6kkqA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7q3KS0QVfVEosQy3O6JtO3m7iRTAU+lXwpwSVdOU8TM=; b=E05tyRLyQM7+KdOYAsCn5MEHPi//yiEdh+/TRZrk378O+VlolXk5VNVtk40P2XcNuC rq7lFuS0sOcZzA6V0al0aN9+iUartDshYcyM0+GIiCvqSZCkz6q+SrcCe6Wy3Eztx705 gOhT8fj217TBk/ACsEzR6R//PdQ00XOTPCGTdXbCtiKYvhJys31CsYXQ3L/APlke8dHw AGjE2p+7sbG4JdxdpLttZ3MmJ1GtVK/zoMnZxS1FOoGm+HVVkvssT4Qb0+zAClvkOYIB UaMp6ffXZL6DGRgxKG8EyFyzZ8bus0kFld/BgbhL4cadwfMemNOmrybpgMItkGvVevPA ZWZw== X-Gm-Message-State: AOAM5305zOiQaWw/nPA+Ct6BbnCdvnE3/flGTRdI7geZOUdu5gPlIC6M Br4buAkUI8GFz5pTGe986gVN9DffYtXG10pv X-Google-Smtp-Source: ABdhPJye9QQz3ddyf5za2OpEn+lFj+BwEgoFK2Pf9+KUucfbss3gZ1ZvzBVoY8MpbN2sqfNYZ1+X5Q== X-Received: by 2002:a62:dd83:0:b029:30f:d69:895f with SMTP id w125-20020a62dd830000b029030f0d69895fmr4092921pff.17.1625021642597; Tue, 29 Jun 2021 19:54:02 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v3 3/3] conf: domain: Introduce and use virDomainObjGetMessages() Date: Wed, 30 Jun 2021 10:53:46 +0800 Message-Id: <20210630025346.180353-4-lukedyue@gmail.com> In-Reply-To: <20210630025346.180353-1-lukedyue@gmail.com> References: <20210630025346.180353-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 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 Content-Type: text/plain; charset="utf-8" The test driver and qemu driver share the same code in virDomainGetMessages(), so extract it to a function. Signed-off-by: Luke Yue --- src/conf/domain_conf.c | 53 ++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 5 ++++ src/libvirt_private.syms | 1 + src/qemu/qemu_driver.c | 34 +------------------------- src/test/test_driver.c | 34 +------------------------- 5 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d78f846a52..f5b7cc8dc4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -31153,3 +31153,56 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *= hostdev) hostdev->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_= PCI && hostdev->source.subsys.u.pci.backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI= _BACKEND_VFIO; } + + +/** + * virDomainObjGetMessages + * @vm: domain object + * @msgs: pointer to a variable to store messages + * @flags: zero or more virDomainMessageType flags + * + * Returns number of messages stored in @msgs, -1 otherwise. + */ +int +virDomainObjGetMessages(virDomainObj *vm, + char ***msgs, + unsigned int flags) +{ + size_t i, n; + int nmsgs; + int rv =3D -1; + + *msgs =3D NULL; + nmsgs =3D 0; + n =3D 0; + + if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { + nmsgs +=3D __builtin_popcount(vm->taint); + *msgs =3D g_renew(char *, *msgs, nmsgs+1); + + for (i =3D 0; i < VIR_DOMAIN_TAINT_LAST; i++) { + if (vm->taint & (1 << i)) { + (*msgs)[n++] =3D g_strdup_printf( + _("tainted: %s"), + _(virDomainTaintMessageTypeToString(i))); + } + } + } + + if (!flags || (flags & VIR_DOMAIN_MESSAGE_DEPRECATION)) { + nmsgs +=3D vm->ndeprecations; + *msgs =3D g_renew(char *, *msgs, nmsgs+1); + + for (i =3D 0; i < vm->ndeprecations; i++) { + (*msgs)[n++] =3D g_strdup_printf( + _("deprecated configuration: %s"), + vm->deprecations[i]); + } + } + + (*msgs)[nmsgs] =3D NULL; + + rv =3D nmsgs; + + return rv; +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f706c498ff..71b9c69e2c 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -4138,3 +4138,8 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hos= tdev) bool virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev) ATTRIBUTE_NONNULL(1); + +int +virDomainObjGetMessages(virDomainObj *vm, + char ***msgs, + unsigned int flags); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 68e4b6aab8..17d2cfbdbe 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -562,6 +562,7 @@ virDomainObjDeprecation; virDomainObjEndAPI; virDomainObjFormat; virDomainObjGetDefs; +virDomainObjGetMessages; virDomainObjGetMetadata; virDomainObjGetOneDef; virDomainObjGetOneDefState; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 235f575901..592e1236e7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20319,8 +20319,6 @@ qemuDomainGetMessages(virDomainPtr dom, { virDomainObj *vm =3D NULL; int rv =3D -1; - size_t i, n; - int nmsgs; =20 virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION | VIR_DOMAIN_MESSAGE_TAINTING, -1); @@ -20331,37 +20329,7 @@ qemuDomainGetMessages(virDomainPtr dom, if (virDomainGetMessagesEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - *msgs =3D NULL; - nmsgs =3D 0; - n =3D 0; - - if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { - nmsgs +=3D __builtin_popcount(vm->taint); - *msgs =3D g_renew(char *, *msgs, nmsgs+1); - - for (i =3D 0; i < VIR_DOMAIN_TAINT_LAST; i++) { - if (vm->taint & (1 << i)) { - (*msgs)[n++] =3D g_strdup_printf( - _("tainted: %s"), - _(virDomainTaintMessageTypeToString(i))); - } - } - } - - if (!flags || (flags & VIR_DOMAIN_MESSAGE_DEPRECATION)) { - nmsgs +=3D vm->ndeprecations; - *msgs =3D g_renew(char *, *msgs, nmsgs+1); - - for (i =3D 0; i < vm->ndeprecations; i++) { - (*msgs)[n++] =3D g_strdup_printf( - _("deprecated configuration: %s"), - vm->deprecations[i]); - } - } - - (*msgs)[nmsgs] =3D NULL; - - rv =3D nmsgs; + rv =3D virDomainObjGetMessages(vm, msgs, flags); =20 cleanup: virDomainObjEndAPI(&vm); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 06ba7c4cd2..b389e3412b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9353,8 +9353,6 @@ testDomainGetMessages(virDomainPtr dom, { virDomainObj *vm =3D NULL; int rv =3D -1; - size_t i, n; - int nmsgs; =20 virCheckFlags(VIR_DOMAIN_MESSAGE_DEPRECATION | VIR_DOMAIN_MESSAGE_TAINTING, -1); @@ -9362,39 +9360,9 @@ testDomainGetMessages(virDomainPtr dom, if (!(vm =3D testDomObjFromDomain(dom))) return -1; =20 - *msgs =3D NULL; - nmsgs =3D 0; - n =3D 0; - testDomainObjCheckTaint(vm); =20 - if (!flags || (flags & VIR_DOMAIN_MESSAGE_TAINTING)) { - nmsgs +=3D __builtin_popcount(vm->taint); - *msgs =3D g_renew(char *, *msgs, nmsgs+1); - - for (i =3D 0; i < VIR_DOMAIN_TAINT_LAST; i++) { - if (vm->taint & (1 << i)) { - (*msgs)[n++] =3D g_strdup_printf( - _("tainted: %s"), - _(virDomainTaintMessageTypeToString(i))); - } - } - } - - if (!flags || (flags & VIR_DOMAIN_MESSAGE_DEPRECATION)) { - nmsgs +=3D vm->ndeprecations; - *msgs =3D g_renew(char *, *msgs, nmsgs+1); - - for (i =3D 0; i < vm->ndeprecations; i++) { - (*msgs)[n++] =3D g_strdup_printf( - _("deprecated configuration: %s"), - vm->deprecations[i]); - } - } - - (*msgs)[nmsgs] =3D NULL; - - rv =3D nmsgs; + rv =3D virDomainObjGetMessages(vm, msgs, flags); =20 virDomainObjEndAPI(&vm); return rv; --=20 2.32.0