From nobody Tue Feb 10 19:14:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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.129.124]) by mx.zohomail.com with SMTPS id 1638535575615327.67372388117144; Fri, 3 Dec 2021 04:46:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-519-0PeqBSZwO3-VNFLR5p18mA-1; Fri, 03 Dec 2021 07:46:13 -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 CD5571927806; Fri, 3 Dec 2021 12:46:07 +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 98D1A22DF9; Fri, 3 Dec 2021 12:46: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 5F2491806D03; Fri, 3 Dec 2021 12:46:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B3Cjq4I017095 for ; Fri, 3 Dec 2021 07:45:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 16503492C3B; Fri, 3 Dec 2021 12:45:52 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 117C1492C38 for ; Fri, 3 Dec 2021 12:45:51 +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 890FA805B0A for ; Fri, 3 Dec 2021 12:45:51 +0000 (UTC) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-oiT8YCReO-2IMrjnVttF5g-1; Fri, 03 Dec 2021 07:45:50 -0500 Received: by mail-pj1-f54.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so5157416pjj.0 for ; Fri, 03 Dec 2021 04:45:49 -0800 (PST) Received: from localhost ([2400:ddc0:1000::b373:390c]) by smtp.gmail.com with ESMTPSA id j6sm3201818pfu.205.2021.12.03.04.45.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 04:45:48 -0800 (PST) X-MC-Unique: 0PeqBSZwO3-VNFLR5p18mA-1 X-MC-Unique: oiT8YCReO-2IMrjnVttF5g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v6fuzdS7t/7ihgT0yEh86FiRshQRUxSPZJeOINf1naA=; b=HLBaSp1RQZ0ZZn30iE98k925AUrJeRaZnqrRSqkPOXrVHHcTs0FXEY+MKkVfLtvfd0 hDwQtrLoHoXloAWt5AGK8OURWPh0An7XhRlFyp8CkGTUILk7DgSpz6QyTknuyrT6maH2 oygrFytgf5tSudA+JLjbzgwfjcSxqhM5hrYxwKmQjMLWrhLrq2v+M7vctSWIU6VExe69 s3YpZPSpqiX26ux9dd53IYNILtRkDzLlSbLC8H0UOz0acb4YmCd975dqC2kb9unUHBcr MlhD7dtbrIUqclz2PhRQXQnTNK8UyBdn+s3Uth3nPmliNa0M8SP7LSdZWg7yXR/R9R4T uJTQ== X-Gm-Message-State: AOAM531zRrAmg77XYKWo9+W1aERIrZa6YJvxQqC5f2PpO3/naDdwVij3 ds3bUKaLffuSdj7X50s+JssCcS4PEJsDoEiN X-Google-Smtp-Source: ABdhPJzU8qekqHxYPxpKvWzXrtDSHjwKhTTJv6DBWFMZ9fNc2C0v6waPw16sWmvHhYF+s6kRVqSWmQ== X-Received: by 2002:a17:90a:4142:: with SMTP id m2mr13964540pjg.80.1638535548405; Fri, 03 Dec 2021 04:45:48 -0800 (PST) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v4 6/8] test_driver: Implement virDomainDetachDeviceFlags Date: Fri, 3 Dec 2021 20:45:15 +0800 Message-Id: <20211203124517.571524-7-lukedyue@gmail.com> In-Reply-To: <20211203124517.571524-1-lukedyue@gmail.com> References: <20211203124517.571524-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.85 on 10.11.54.9 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-ZM-MESSAGEID: 1638535576931100002 Content-Type: text/plain; charset="utf-8" Introduce testDomainChgDevice for further development (just like what we did for IOThread). And introduce testDomainDetachDeviceLiveAndConfig for detaching devices. Also as we implement testDomainChgDevice for both DetachDeviceFlags and DetachDeviceAlias, we could easily implement virDomainDetachDeviceAlias and virDomainDetachDevice. Signed-off-by: Luke Yue --- src/test/test_driver.c | 149 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 21caa83be7..6cd1e75771 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -10022,6 +10022,152 @@ testConnectGetAllDomainStats(virConnectPtr conn, return ret; } =20 + +static int +testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef, + virDomainDeviceDef *dev, + unsigned int flags, + unsigned int parse_flags, + virDomainXMLOption *xmlopt) +{ + /* Though the function called virDomainDetachDeviceConfig, for + test driver, it could be for both live and config */ + return virDomainDetachDeviceConfig(vmdef, dev, NULL, flags, + parse_flags, xmlopt); +} + +static int +testDomainDoChgDevice(testDriver *driver, + virDomainDeviceAction action, + const char *xml, + const char *alias, + virDomainDef *def, + unsigned int flags) +{ + virDomainDeviceDef *dev =3D NULL; + unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + int ret =3D -1; + + if (action =3D=3D VIR_DOMAIN_DEVICE_ACTION_DETACH) + parse_flags |=3D VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; + + if (xml) { + if (!(dev =3D virDomainDeviceDefParse(xml, def, driver->xmlopt, + driver->caps, parse_flags))) + goto cleanup; + } else if (alias) { + dev =3D g_new0(virDomainDeviceDef, 1); + if (virDomainDefFindDevice(def, alias, dev, true) < 0) + goto cleanup; + } + + if (dev =3D=3D NULL) + goto cleanup; + + switch (action) { + case VIR_DOMAIN_DEVICE_ACTION_ATTACH: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("attaching devices is not supported")); + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ACTION_DETACH: + if (testDomainDetachDeviceLiveAndConfig(def, dev, flags, parse_fla= gs, + driver->xmlopt) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ACTION_UPDATE: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("updating devices is not supported")); + goto cleanup; + break; + } + + ret =3D 0; + + cleanup: + if (xml) { + virDomainDeviceDefFree(dev); + } else { + g_free(dev); + } + return ret; +} + +static int +testDomainChgDevice(virDomainPtr dom, + virDomainDeviceAction action, + const char *xml, + const char *alias, + unsigned int flags) +{ + testDriver *driver =3D dom->conn->privateData; + virDomainObj *vm =3D NULL; + virDomainDef *def; + virDomainDef *persistentDef; + + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(vm =3D testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjUpdateModificationImpact(vm, &flags) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto cleanup; + + if (def) { + if (testDomainDoChgDevice(driver, action, xml, + alias, def, flags) < 0) { + goto cleanup; + } + } + + if (persistentDef) { + if (testDomainDoChgDevice(driver, action, xml, + alias, persistentDef, flags) < 0) { + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +static int +testDomainDetachDeviceFlags(virDomainPtr dom, + const char *xml, + unsigned int flags) +{ + return testDomainChgDevice(dom, VIR_DOMAIN_DEVICE_ACTION_DETACH, + xml, NULL, flags); +} + +static int +testDomainDetachDeviceAlias(virDomainPtr dom, + const char *alias, + unsigned int flags) +{ + return testDomainChgDevice(dom, VIR_DOMAIN_DEVICE_ACTION_DETACH, + NULL, alias, flags); +} + +static int +testDomainDetachDevice(virDomainPtr dom, + const char *xml) +{ + return testDomainDetachDeviceFlags(dom, xml, + VIR_DOMAIN_AFFECT_LIVE); +} + /* * Test driver */ @@ -10119,6 +10265,9 @@ static virHypervisorDriver testHypervisorDriver =3D= { .domainFSFreeze =3D testDomainFSFreeze, /* 5.7.0 */ .domainFSThaw =3D testDomainFSThaw, /* 5.7.0 */ .domainFSTrim =3D testDomainFSTrim, /* 5.7.0 */ + .domainDetachDevice =3D testDomainDetachDevice, /* 8.0.0 */ + .domainDetachDeviceAlias =3D testDomainDetachDeviceAlias, /* 8.0.0 */ + .domainDetachDeviceFlags =3D testDomainDetachDeviceFlags, /* 8.0.0 */ .domainGetAutostart =3D testDomainGetAutostart, /* 0.3.2 */ .domainSetAutostart =3D testDomainSetAutostart, /* 0.3.2 */ .domainGetDiskErrors =3D testDomainGetDiskErrors, /* 5.4.0 */ --=20 2.34.1