From nobody Thu Nov 21 16:29:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 173193952261281.97036192500593; Mon, 18 Nov 2024 06:18:42 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8951BCB3; Mon, 18 Nov 2024 09:18:41 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8A92A1BF3; Mon, 18 Nov 2024 09:10:47 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 24DB719F5; Mon, 18 Nov 2024 08:55:19 -0500 (EST) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 621BC19F5 for ; Mon, 18 Nov 2024 08:55:18 -0500 (EST) Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7f3da2c2cb5so3004707a12.2 for ; Mon, 18 Nov 2024 05:55:18 -0800 (PST) Received: from localhost.localdomain ([2409:40f4:9:7d39:e991:fcfb:15ab:ce58]) by smtp.googlemail.com with ESMTPSA id d2e1a72fcca58-72477135ecbsm6113482b3a.84.2024.11.18.05.55.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 05:55:16 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731938117; x=1732542917; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nzbZfTBsXCBMXMtTr5VbW6pbP3sFeEZS56DUeMutVDU=; b=JHzz5Ywa1ksC8hoFCKK8d9iu+PczgB70UIL56xIqAnTE8VEIrQeyi6SL2BojrLDLX9 jh0DwQvDYBdL1vuhaW5BiEu2Ta+zt8VHg/HivMXRZuyHbM3sP1lUd1XN2/5/V7yS5AZ7 gbB/zdZc81FSrAejBtiBl9TtM5wsf41+xyvtV/h436GvYWpVNXn/0sZIRxDdE/6b9SHJ WYDJJKEzUC7TGMrda6Ic9K3WFYCP0a9HITlPODivwr7e/2nZuO0CLU7ubmB/fhzyQvJB jaoKbPsrS7++RH2R/43RgKDl/cpqYvSnCSCsdg+tGqg1N0TBZVmgI+qyo5xYTY5i7BOf 36OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731938117; x=1732542917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nzbZfTBsXCBMXMtTr5VbW6pbP3sFeEZS56DUeMutVDU=; b=WSv9b4YdzuIWP2cuH3eYPsNwILe/LTQ4ttpzpQsqioDCFtzfnT8Yh9ONglOMT9FRoo plTPIXq4uyQPMoaFazXXzbI7SciLatX+sKM062Q+qdJd6kdC7bW7LI/AhMyWsEiRs4BS CQYzPS1IPFSJb8yYoEmPxvUihmE29YUGa6XQeG82Z49A9wkUUBsrC0qdsLy9aSP+NtA9 tCgckpf1NDOcS9jfpEoSEu0IMVXgWm17LpEhmNJ8NwdsTf1t13J7MmzLjAP4DAE1yQKn rLQsLc8Cglbum2Bdyzk0/6wNVD30ZedEKWjI0xH/qrR15aXBLtS5FpGv8OKvMeFjXIn8 ZQ1g== X-Gm-Message-State: AOJu0Yzwqzg7R03CsVaGV/P9vsT/iabq9dFhOsii+b28+ts29fKE+jrR Zkcby4O7YNXQXymBFiUfJ+kb3ELHZ1GBkPPVKTv3GZBkafZAtuHAPpXS8DdR X-Google-Smtp-Source: AGHT+IECwLaeWiIs2ih0amgQ6QzmKNn9qZQ+BERclCX4gegtVlC8OCCGdtOiR8UaP6hJVnUTGXDy6w== X-Received: by 2002:a05:6a21:7e06:b0:1d9:2694:44df with SMTP id adf61e73a8af0-1dc90c15588mr14731228637.43.1731938116943; Mon, 18 Nov 2024 05:55:16 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v5 12/18] config: validate: Verify iotune, throttle group and filter Date: Mon, 18 Nov 2024 19:24:20 +0530 Message-Id: <20241118135426.37643-13-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241118135426.37643-1-harirajkumar230@gmail.com> References: <20241118135426.37643-1-harirajkumar230@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MailFrom: harirajkumar230@gmail.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: YSEBXB7JTUDB6XG7VQEDMD573J7ALRIS X-Message-ID-Hash: YSEBXB7JTUDB6XG7VQEDMD573J7ALRIS X-Mailman-Approved-At: Mon, 18 Nov 2024 14:10:18 -0500 CC: harikumar.rajkumar@ibm.com, sanjeev.ranjan@ibm.com, earulana@in.ibm.com, Chun Feng Wu X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1731939523402116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu Refactor iotune verification, and verify some rules * Disk iotune validation can be reused for throttle group validation, refactor it into common method "virDomainDiskIoTuneValidate" * Add "virDomainDefValidateThrottleGroups" to validate throttle groups, which in turn calls "virDomainDiskIoTuneValidate" * Make sure referenced throttle group exists * Use "iotune" and "throttlefilters" exclusively for specific disk * Throttle filters cannot be used together with CDROM Signed-off-by: Chun Feng Wu --- src/conf/domain_validate.c | 119 ++++++++++++++++++++++++++----------- src/qemu/qemu_driver.c | 6 ++ src/qemu/qemu_hotplug.c | 8 +++ 3 files changed, 99 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b352cd874a..916d5c9986 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -659,11 +659,55 @@ virDomainDiskDefValidateStartupPolicy(const virDomain= DiskDef *disk) } =20 =20 +static int +virDomainDiskIoTuneValidate(const virDomainBlockIoTuneInfo blkdeviotune) +{ + if ((blkdeviotune.total_bytes_sec && + blkdeviotune.read_bytes_sec) || + (blkdeviotune.total_bytes_sec && + blkdeviotune.write_bytes_sec)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("total and read/write bytes_sec cannot be set at = the same time")); + return -1; + } + + if ((blkdeviotune.total_iops_sec && + blkdeviotune.read_iops_sec) || + (blkdeviotune.total_iops_sec && + blkdeviotune.write_iops_sec)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("total and read/write iops_sec cannot be set at t= he same time")); + return -1; + } + + if ((blkdeviotune.total_bytes_sec_max && + blkdeviotune.read_bytes_sec_max) || + (blkdeviotune.total_bytes_sec_max && + blkdeviotune.write_bytes_sec_max)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("total and read/write bytes_sec_max cannot be set= at the same time")); + return -1; + } + + if ((blkdeviotune.total_iops_sec_max && + blkdeviotune.read_iops_sec_max) || + (blkdeviotune.total_iops_sec_max && + blkdeviotune.write_iops_sec_max)) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("total and read/write iops_sec_max cannot be set = at the same time")); + return -1; + } + + return 0; +} + + static int virDomainDiskDefValidate(const virDomainDef *def, const virDomainDiskDef *disk) { virStorageSource *next; + size_t i; =20 /* disk target is used widely in other code so it must be validated fi= rst */ if (!disk->dst) { @@ -713,41 +757,8 @@ virDomainDiskDefValidate(const virDomainDef *def, } =20 /* Validate IotuneParse */ - if ((disk->blkdeviotune.total_bytes_sec && - disk->blkdeviotune.read_bytes_sec) || - (disk->blkdeviotune.total_bytes_sec && - disk->blkdeviotune.write_bytes_sec)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("total and read/write bytes_sec cannot be set at = the same time")); + if (virDomainDiskIoTuneValidate(disk->blkdeviotune) < 0) return -1; - } - - if ((disk->blkdeviotune.total_iops_sec && - disk->blkdeviotune.read_iops_sec) || - (disk->blkdeviotune.total_iops_sec && - disk->blkdeviotune.write_iops_sec)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("total and read/write iops_sec cannot be set at t= he same time")); - return -1; - } - - if ((disk->blkdeviotune.total_bytes_sec_max && - disk->blkdeviotune.read_bytes_sec_max) || - (disk->blkdeviotune.total_bytes_sec_max && - disk->blkdeviotune.write_bytes_sec_max)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("total and read/write bytes_sec_max cannot be set= at the same time")); - return -1; - } - - if ((disk->blkdeviotune.total_iops_sec_max && - disk->blkdeviotune.read_iops_sec_max) || - (disk->blkdeviotune.total_iops_sec_max && - disk->blkdeviotune.write_iops_sec_max)) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("total and read/write iops_sec_max cannot be set = at the same time")); - return -1; - } =20 /* Reject disks with a bus type that is not compatible with the * given address type. The function considers only buses that are @@ -943,6 +954,26 @@ virDomainDiskDefValidate(const virDomainDef *def, return -1; } =20 + /* referenced group should be defined */ + for (i =3D 0; i < disk->nthrottlefilters; i++) { + virDomainThrottleFilterDef *filter =3D disk->throttlefilters[i]; + if (!virDomainThrottleGroupByName(def, filter->group_name)) { + virReportError(VIR_ERR_XML_ERROR, + _("throttle group '%1$s' not found"), + filter->group_name); + return -1; + } + } + + if (disk->throttlefilters && + (disk->blkdeviotune.group_name || + virDomainBlockIoTuneInfoHasAny(&disk->blkdeviotune))) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("block 'throttlefilters' can't be used together w= ith 'iotune' for disk '%1$s'"), + disk->dst); + return -1; + } + return 0; } =20 @@ -1843,6 +1874,23 @@ virDomainDefLaunchSecurityValidate(const virDomainDe= f *def) =20 #undef CHECK_BASE64_LEN =20 +static int +virDomainDefValidateThrottleGroups(const virDomainDef *def) +{ + size_t i; + + for (i =3D 0; i < def->nthrottlegroups; i++) { + virDomainThrottleGroupDef *throttleGroup =3D def->throttlegroups[i= ]; + + /* Validate Throttle Group */ + if (virDomainDiskIoTuneValidate(*throttleGroup) < 0) + return -1; + } + + return 0; +} + + static int virDomainDefValidateInternal(const virDomainDef *def, virDomainXMLOption *xmlopt) @@ -1901,6 +1949,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefLaunchSecurityValidate(def) < 0) return -1; =20 + if (virDomainDefValidateThrottleGroups(def) < 0) + return -1; + return 0; } =20 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d65d5fd2ff..2a5f58635c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14862,6 +14862,12 @@ qemuDomainDiskBlockIoTuneIsSupported(virDomainDisk= Def *disk) return false; } =20 + if (disk->throttlefilters) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("block 'iotune' can't be used together with 'thro= ttlefilters' for disk '%1$s'"), disk->dst); + return false; + } + return true; } =20 diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bf001aa902..8c41d27704 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -988,6 +988,14 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *= driver, bool releaseSeclabel =3D false; int ret =3D -1; =20 + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { + if (disk->nthrottlefilters > 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cdrom device with throttle filters isn't suppor= ted")); + return -1; + } + } + if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("floppy device hotplug isn't supported")); --=20 2.39.5 (Apple Git-154)