From nobody Mon Feb 9 00:01:11 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; 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 1629112822014217.40012960325953; Mon, 16 Aug 2021 04:20:22 -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-125-cOc2L_dbNrqf20Nns4FcUw-1; Mon, 16 Aug 2021 07:20:20 -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 8FF8D801AEB; Mon, 16 Aug 2021 11:20: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 6E0765FC25; Mon, 16 Aug 2021 11:20: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 34FA3181A1CE; Mon, 16 Aug 2021 11:20:14 +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 17GBK2h3022137 for ; Mon, 16 Aug 2021 07:20:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 39FB02157F57; Mon, 16 Aug 2021 11:20:02 +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 334FD21602BE for ; Mon, 16 Aug 2021 11:19:58 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 AD0C5188142E for ; Mon, 16 Aug 2021 11:19:58 +0000 (UTC) Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-cAPfaD3lM2CTE0hH53_NzA-1; Mon, 16 Aug 2021 07:19:56 -0400 Received: by mail-pj1-f50.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so31821149pjr.1 for ; Mon, 16 Aug 2021 04:19:56 -0700 (PDT) Received: from localhost ([103.138.53.99]) by smtp.gmail.com with ESMTPSA id g13sm9873675pfo.53.2021.08.16.04.19.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Aug 2021 04:19:54 -0700 (PDT) X-MC-Unique: cOc2L_dbNrqf20Nns4FcUw-1 X-MC-Unique: cAPfaD3lM2CTE0hH53_NzA-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=LofKkANC+A48Y2lTKeTGfT5MzQd8PsmhZ+KbksHmkoU=; b=Zuy3tvxuOuuvHxEuUpmEJJjfg9fNnWBihkWBRFthecW8zWOR22znDm0nRNI2VLAa5V RAztNIBdCiPqiWmoBz9jYJy6wHN9kLrm9Xw5EqtzVDcisK9EtH0yHDyGGwAXvxFbGKc8 Ush1SdixNpzS8XE4VdbBHqFGme0i4X6GI03yZjYWeV79C+fxhKZt2ewOjR2FJfVxgM33 o2A9gBaYFR6k+KlHM4S3FT76LHljXaF24o5UJCbYTLG4d9W7bybVopN3DGyLVazWGSeK yK9uLgZsCPrlJJVcnX5o+sY7KkDJIC3fdxzJLL0elPjLspWGdA/y7DfdSoonY2UpBYmv tlJw== X-Gm-Message-State: AOAM530uSrrA3lg7+JonG6fdr6Y8nR/BywZwjZjITpE3LBtQX8+hEF4q Gr08pYzqmqmDYmOA9O+jcHV1HBeaFc3BznEPhZQ= X-Google-Smtp-Source: ABdhPJyYt8KYLLj+c90aAbJcJqewUV2fh93kKQ+NIEEc7dl5KeHojVb31FQ40oXPqRDP6iX7M6GKHw== X-Received: by 2002:a63:1b53:: with SMTP id b19mr15624270pgm.160.1629112795307; Mon, 16 Aug 2021 04:19:55 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH 1/5] test_driver: Implement virDomainDetachDeviceFlags Date: Mon, 16 Aug 2021 19:19:45 +0800 Message-Id: <20210816111949.125013-2-lukedyue@gmail.com> In-Reply-To: <20210816111949.125013-1-lukedyue@gmail.com> References: <20210816111949.125013-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.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-ZM-MESSAGEID: 1629112824053100001 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. Signed-off-by: Luke Yue --- src/test/test_driver.c | 270 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 00cc13511a..2ebdbaa604 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9452,6 +9452,275 @@ testDomainGetMessages(virDomainPtr dom, return rv; } =20 +static int +testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef, + virDomainDeviceDef *dev) +{ + virDomainDiskDef *disk; + virDomainDiskDef *det_disk; + virDomainNetDef *net; + virDomainSoundDef *sound; + virDomainHostdevDef *hostdev; + virDomainHostdevDef *det_hostdev; + virDomainLeaseDef *lease; + virDomainLeaseDef *det_lease; + virDomainControllerDef *cont; + virDomainControllerDef *det_cont; + virDomainFSDef *fs; + virDomainMemoryDef *mem; + int idx; + + switch (dev->type) { + case VIR_DOMAIN_DEVICE_DISK: + disk =3D dev->data.disk; + if (!(det_disk =3D virDomainDiskRemoveByName(vmdef, disk->dst))) { + virReportError(VIR_ERR_DEVICE_MISSING, + _("no target device %s"), disk->dst); + return -1; + } + virDomainDiskDefFree(det_disk); + break; + + case VIR_DOMAIN_DEVICE_NET: + net =3D dev->data.net; + if ((idx =3D virDomainNetFindIdx(vmdef, net)) < 0) + return -1; + + /* this is guaranteed to succeed */ + virDomainNetDefFree(virDomainNetRemove(vmdef, idx)); + break; + + case VIR_DOMAIN_DEVICE_SOUND: + sound =3D dev->data.sound; + if ((idx =3D virDomainSoundDefFind(vmdef, sound)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("device not present in domain configuration")= ); + return -1; + } + virDomainSoundDefFree(virDomainSoundDefRemove(vmdef, idx)); + break; + + case VIR_DOMAIN_DEVICE_HOSTDEV: { + hostdev =3D dev->data.hostdev; + if ((idx =3D virDomainHostdevFind(vmdef, hostdev, &det_hostdev)) <= 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("device not present in domain configuration")= ); + return -1; + } + virDomainHostdevRemove(vmdef, idx); + virDomainHostdevDefFree(det_hostdev); + break; + } + + case VIR_DOMAIN_DEVICE_LEASE: + lease =3D dev->data.lease; + if (!(det_lease =3D virDomainLeaseRemove(vmdef, lease))) { + virReportError(VIR_ERR_DEVICE_MISSING, + _("Lease %s in lockspace %s does not exist"), + lease->key, NULLSTR(lease->lockspace)); + return -1; + } + virDomainLeaseDefFree(det_lease); + break; + + case VIR_DOMAIN_DEVICE_CONTROLLER: + cont =3D dev->data.controller; + if ((idx =3D virDomainControllerFind(vmdef, cont->type, + cont->idx)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("device not present in domain configuration")= ); + return -1; + } + det_cont =3D virDomainControllerRemove(vmdef, idx); + virDomainControllerDefFree(det_cont); + + break; + + case VIR_DOMAIN_DEVICE_FS: + fs =3D dev->data.fs; + idx =3D virDomainFSIndexByName(vmdef, fs->dst); + if (idx < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("no matching filesystem device was found")); + return -1; + } + + fs =3D virDomainFSRemove(vmdef, idx); + virDomainFSDefFree(fs); + break; + + case VIR_DOMAIN_DEVICE_RNG: + if ((idx =3D virDomainRNGFind(vmdef, dev->data.rng)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("no matching RNG device was found")); + return -1; + } + + virDomainRNGDefFree(virDomainRNGRemove(vmdef, idx)); + break; + + case VIR_DOMAIN_DEVICE_MEMORY: + if ((idx =3D virDomainMemoryFindInactiveByDef(vmdef, + dev->data.memory)) < 0= ) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("matching memory device was not found")); + return -1; + } + mem =3D virDomainMemoryRemove(vmdef, idx); + vmdef->mem.cur_balloon -=3D mem->size; + virDomainMemoryDefFree(mem); + break; + + case VIR_DOMAIN_DEVICE_REDIRDEV: + if ((idx =3D virDomainRedirdevDefFind(vmdef, + dev->data.redirdev)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("no matching redirdev was not found")); + return -1; + } + + virDomainRedirdevDefFree(virDomainRedirdevDefRemove(vmdef, idx)); + break; + + case VIR_DOMAIN_DEVICE_SHMEM: + if ((idx =3D virDomainShmemDefFind(vmdef, dev->data.shmem)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("matching shmem device was not found")); + return -1; + } + + virDomainShmemDefFree(virDomainShmemDefRemove(vmdef, idx)); + break; + + + case VIR_DOMAIN_DEVICE_WATCHDOG: + if (!vmdef->watchdog) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("domain has no watchdog")); + return -1; + } + virDomainWatchdogDefFree(vmdef->watchdog); + vmdef->watchdog =3D NULL; + break; + + case VIR_DOMAIN_DEVICE_INPUT: + if ((idx =3D virDomainInputDefFind(vmdef, dev->data.input)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("matching input device not found")); + return -1; + } + virDomainInputDefFree(vmdef->inputs[idx]); + VIR_DELETE_ELEMENT(vmdef->inputs, idx, vmdef->ninputs); + break; + + case VIR_DOMAIN_DEVICE_VSOCK: + if (!vmdef->vsock || + !virDomainVsockDefEquals(dev->data.vsock, vmdef->vsock)) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("matching vsock device not found")); + return -1; + } + virDomainVsockDefFree(vmdef->vsock); + vmdef->vsock =3D NULL; + break; + + case VIR_DOMAIN_DEVICE_CHR: + case VIR_DOMAIN_DEVICE_VIDEO: + case VIR_DOMAIN_DEVICE_GRAPHICS: + case VIR_DOMAIN_DEVICE_HUB: + case VIR_DOMAIN_DEVICE_SMARTCARD: + case VIR_DOMAIN_DEVICE_MEMBALLOON: + case VIR_DOMAIN_DEVICE_NVRAM: + case VIR_DOMAIN_DEVICE_NONE: + case VIR_DOMAIN_DEVICE_TPM: + case VIR_DOMAIN_DEVICE_PANIC: + case VIR_DOMAIN_DEVICE_IOMMU: + case VIR_DOMAIN_DEVICE_AUDIO: + case VIR_DOMAIN_DEVICE_LAST: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("persistent detach of device '%s' is not supporte= d"), + virDomainDeviceTypeToString(dev->type)); + return -1; + } + + return 0; +} + +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; + virDomainDeviceDef *dev =3D NULL; + unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE; + 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 (!(def =3D virDomainObjGetOneDef(vm, flags))) + goto cleanup; + + 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: + break; + + case VIR_DOMAIN_DEVICE_ACTION_DETACH: + if (testDomainDetachDeviceLiveAndConfig(def, dev) < 0) + goto cleanup; + break; + + case VIR_DOMAIN_DEVICE_ACTION_UPDATE: + break; + } + + ret =3D 0; + + cleanup: + if (xml) { + virDomainDeviceDefFree(dev); + } else { + g_free(dev); + } + 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); +} /* * Test driver */ @@ -9541,6 +9810,7 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainFSFreeze =3D testDomainFSFreeze, /* 5.7.0 */ .domainFSThaw =3D testDomainFSThaw, /* 5.7.0 */ .domainFSTrim =3D testDomainFSTrim, /* 5.7.0 */ + .domainDetachDeviceFlags =3D testDomainDetachDeviceFlags, /* 7.7.0 */ .domainGetAutostart =3D testDomainGetAutostart, /* 0.3.2 */ .domainSetAutostart =3D testDomainSetAutostart, /* 0.3.2 */ .domainGetDiskErrors =3D testDomainGetDiskErrors, /* 5.4.0 */ --=20 2.32.0