From nobody Mon Feb 9 05:40:21 2026 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 1627560684474707.0405003608429; Thu, 29 Jul 2021 05:11:24 -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-300-ftuEqzAPO2aj7wdXXY8H3g-1; Thu, 29 Jul 2021 08:11:21 -0400 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 A8E858799E0; Thu, 29 Jul 2021 12:11:15 +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 176962657B; Thu, 29 Jul 2021 12:11:15 +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 21E25180084A; Thu, 29 Jul 2021 12:11:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16TCBBjf014569 for ; Thu, 29 Jul 2021 08:11:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F670113B5F; Thu, 29 Jul 2021 12:11:11 +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 7A007113B55 for ; Thu, 29 Jul 2021 12:11:08 +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 C8E74811E78 for ; Thu, 29 Jul 2021 12:11:08 +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-216-tXktSKkQPKipXZAZgRkXEQ-1; Thu, 29 Jul 2021 08:11:06 -0400 Received: by mail-pj1-f50.google.com with SMTP id m2-20020a17090a71c2b0290175cf22899cso9002916pjs.2 for ; Thu, 29 Jul 2021 05:11:06 -0700 (PDT) Received: from localhost ([103.138.53.99]) by smtp.gmail.com with ESMTPSA id j3sm3353871pfc.10.2021.07.29.05.11.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Jul 2021 05:11:04 -0700 (PDT) X-MC-Unique: ftuEqzAPO2aj7wdXXY8H3g-1 X-MC-Unique: tXktSKkQPKipXZAZgRkXEQ-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=lxnsSkF4SpZyquITdZQFLImJvfrmAXTfdGKhXI9Ywa4=; b=XWIDfY/nONf9ozX6klMDKJgisedh4oXUwmBpncgDjVrxNIr5nGR3tSISxR0K9KXHRQ PWqUgQlNXuA2qkIjw31AwvZlbz1DLihPOKJ5I8ZB8Mew3R3zOqNnMuwWnzdFk3JBhbIZ s8VMku4ZLsfP7hx7nrd5z45aqyQjK3P5hYoBvPmlWbqUMGPLByeVmbd+f3P2iy1m1ElD jG2xwQby8WmTQ+mn2S77KpvO7bhenXH76fAXJwCPE7X6ww6XQvS8G6Gq1AiVtWgTFEqf o0jCtY2FKy5l7WrZjb+aC0QXJV1zTcgHXlUKWtzzH4CRi+iqKOJq5VilkZJ5GWJiGdHK MqnA== X-Gm-Message-State: AOAM530CYig2pqJJUdlYp+KPIzNzseCz/HTG6rYRxeFV3ELgoeyviTed /9gtoKjaiHFcI/xupvOiFgeC20BmiBJMRBGJ2bws0g== X-Google-Smtp-Source: ABdhPJxyKT9UHfhftGu1FyiljSMC0WSDmjQNIjlkdyKSFLcmUhhZw8BqtEwf/M26RdpZbmym6iCNCA== X-Received: by 2002:a65:6a4c:: with SMTP id o12mr3625603pgu.108.1627560665282; Thu, 29 Jul 2021 05:11:05 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v2 01/11] domain_driver.c: Introduce and use virDomainDriverAddIOThreadCheck() Date: Thu, 29 Jul 2021 20:10:48 +0800 Message-Id: <20210729121058.454431-2-lukedyue@gmail.com> In-Reply-To: <20210729121058.454431-1-lukedyue@gmail.com> References: <20210729121058.454431-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.79 on 10.11.54.5 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: 1627560684944100003 Content-Type: text/plain; charset="utf-8" The test driver can share the same code with qemu driver when implement testDomainAddIOThreadCheck and testDomainDelIOThreadCheck, so extract them for test driver to use. Signed-off-by: Luke Yue --- src/hypervisor/domain_driver.c | 64 ++++++++++++++++++++++++++++++++++ src/hypervisor/domain_driver.h | 6 ++++ src/libvirt_private.syms | 2 ++ src/qemu/qemu_driver.c | 60 +++---------------------------- 4 files changed, 76 insertions(+), 56 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 29e11c0447..0d4d9ae5de 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -511,3 +511,67 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr = dev, =20 return virHostdevPCINodeDeviceDetach(hostdevMgr, pci); } + +/** + * virDomainDriverAddIOThreadCheck: + * @def: domain definition + * @iothread_id: iothread id + * + * Returns -1 if an IOThread is already using the given iothread id + */ +int +virDomainDriverAddIOThreadCheck(virDomainDef *def, + unsigned int iothread_id) +{ + if (virDomainIOThreadIDFind(def, iothread_id)) { + virReportError(VIR_ERR_INVALID_ARG, + _("an IOThread is already using iothread_id '%u'"), + iothread_id); + return -1; + } + + return 0; +} + +/** + * virDomainDriverDelIOThreadCheck: + * @def: domain definition + * @iothread_id: iothread id + * + * Returns -1 if there is no IOThread using the given iothread id + */ +int +virDomainDriverDelIOThreadCheck(virDomainDef *def, + unsigned int iothread_id) +{ + size_t i; + + if (!virDomainIOThreadIDFind(def, iothread_id)) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot find IOThread '%u' in iothreadids list"), + iothread_id); + return -1; + } + + for (i =3D 0; i < def->ndisks; i++) { + if (def->disks[i]->iothread =3D=3D iothread_id) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot remove IOThread %u since it " + "is being used by disk '%s'"), + iothread_id, def->disks[i]->dst); + return -1; + } + } + + for (i =3D 0; i < def->ncontrollers; i++) { + if (def->controllers[i]->iothread =3D=3D iothread_id) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot remove IOThread '%u' since it " + "is being used by controller"), + iothread_id); + return -1; + } + } + + return 0; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 5970eef082..d91d21bc91 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -60,3 +60,9 @@ int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr de= v, int virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev, virHostdevManager *hostdevMgr, const char *driverName); + +int virDomainDriverAddIOThreadCheck(virDomainDef *def, + unsigned int iothread_id); + +int virDomainDriverDelIOThreadCheck(virDomainDef *def, + unsigned int iothread_id); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 43493ea76e..fa2412c0dc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1531,6 +1531,8 @@ virDomainCgroupSetupMemtune; =20 =20 # hypervisor/domain_driver.h +virDomainDriverAddIOThreadCheck; +virDomainDriverDelIOThreadCheck; virDomainDriverGenerateMachineName; virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0b35bbc15c..b96ac985bf 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5477,58 +5477,6 @@ qemuDomainHotplugDelIOThread(virQEMUDriver *driver, } =20 =20 -static int -qemuDomainAddIOThreadCheck(virDomainDef *def, - unsigned int iothread_id) -{ - if (virDomainIOThreadIDFind(def, iothread_id)) { - virReportError(VIR_ERR_INVALID_ARG, - _("an IOThread is already using iothread_id '%u'"), - iothread_id); - return -1; - } - - return 0; -} - - -static int -qemuDomainDelIOThreadCheck(virDomainDef *def, - unsigned int iothread_id) -{ - size_t i; - - if (!virDomainIOThreadIDFind(def, iothread_id)) { - virReportError(VIR_ERR_INVALID_ARG, - _("cannot find IOThread '%u' in iothreadids list"), - iothread_id); - return -1; - } - - for (i =3D 0; i < def->ndisks; i++) { - if (def->disks[i]->iothread =3D=3D iothread_id) { - virReportError(VIR_ERR_INVALID_ARG, - _("cannot remove IOThread %u since it " - "is being used by disk '%s'"), - iothread_id, def->disks[i]->dst); - return -1; - } - } - - for (i =3D 0; i < def->ncontrollers; i++) { - if (def->controllers[i]->iothread =3D=3D iothread_id) { - virReportError(VIR_ERR_INVALID_ARG, - _("cannot remove IOThread '%u' since it " - "is being used by controller"), - iothread_id); - return -1; - } - } - - return 0; -} - - /** * @params: Pointer to params list * @nparams: Number of params to be parsed @@ -5662,7 +5610,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver, =20 switch (action) { case VIR_DOMAIN_IOTHREAD_ACTION_ADD: - if (qemuDomainAddIOThreadCheck(def, iothread.iothread_id) < 0) + if (virDomainDriverAddIOThreadCheck(def, iothread.iothread_id)= < 0) goto endjob; =20 if (qemuDomainHotplugAddIOThread(driver, vm, iothread.iothread= _id) < 0) @@ -5671,7 +5619,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver, break; =20 case VIR_DOMAIN_IOTHREAD_ACTION_DEL: - if (qemuDomainDelIOThreadCheck(def, iothread.iothread_id) < 0) + if (virDomainDriverDelIOThreadCheck(def, iothread.iothread_id)= < 0) goto endjob; =20 if (qemuDomainHotplugDelIOThread(driver, vm, iothread.iothread= _id) < 0) @@ -5701,7 +5649,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver, if (persistentDef) { switch (action) { case VIR_DOMAIN_IOTHREAD_ACTION_ADD: - if (qemuDomainAddIOThreadCheck(persistentDef, iothread.iothrea= d_id) < 0) + if (virDomainDriverAddIOThreadCheck(persistentDef, iothread.io= thread_id) < 0) goto endjob; =20 if (!virDomainIOThreadIDAdd(persistentDef, iothread.iothread_i= d)) @@ -5710,7 +5658,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver, break; =20 case VIR_DOMAIN_IOTHREAD_ACTION_DEL: - if (qemuDomainDelIOThreadCheck(persistentDef, iothread.iothrea= d_id) < 0) + if (virDomainDriverDelIOThreadCheck(persistentDef, iothread.io= thread_id) < 0) goto endjob; =20 virDomainIOThreadIDDel(persistentDef, iothread.iothread_id); --=20 2.32.0