From nobody Sun Dec 7 13:20:57 2025 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 1739985014861933.4748073795165; Wed, 19 Feb 2025 09:10:14 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id BD5021EBB; Wed, 19 Feb 2025 12:10:13 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CDD531C60; Wed, 19 Feb 2025 12:02:35 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3C30C1C30; Wed, 19 Feb 2025 12:02:30 -0500 (EST) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (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 899C81D86 for ; Wed, 19 Feb 2025 12:02:08 -0500 (EST) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-21f2339dcfdso679125ad.1 for ; Wed, 19 Feb 2025 09:02:08 -0800 (PST) Received: from localhost.localdomain ([2001:4490:4ea9:8374:8512:e327:fdaf:a56e]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-220d558fe3asm106651545ad.234.2025.02.19.09.02.04 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 09:02:06 -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.8 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_H3,RCVD_IN_MSPIKE_WL,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=1739984527; x=1740589327; 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=Hy0al22nm0hCWXrNkhJUxP03xI7ps+bkMDWGqjLg4iA=; b=XnTqyxjzFs6RPcO5wGKE6DhTSYHRBjkyx7B1JTYiR6aKJVIzrMwXnMn9tx50fC3Xt+ befcWjXkI+nXR9lIQTe7hnVrItJkMfI+DuP7Sp9J08ioZ0zU/FKba/RrGcMH1xEYwreq xiZPfWK8aRjWQgyTdGI37fD80iaiiSfBA8ItbMZUNaqSQIu1GIglcLRaRgRX16o35KUn 0D0c+VIHHQTHUGZt66UbtCQfHiFWX8/8EUHPBq4IIeYxczl+7cPCozeAo4abaZViSAq1 MpChrXNAe7fKaeKEtlnaniEHoReyV3fPxHODa80JP4Y1mxV8Z6EDi78CfCxb/b7bIYqC hogw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739984527; x=1740589327; 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=Hy0al22nm0hCWXrNkhJUxP03xI7ps+bkMDWGqjLg4iA=; b=cTu3Js4EQxZDYxJSVNE3422UxHeX/LFHm5oZCnKpz46EAx4s0kPsDxdT5U0k7pvqAf jOSAWH4RbVzHy0RwReEhDspEebs88vfv4GgyAxDqQLK/urRG8harxyS4SZkFg1zvXhhI YTC1d2PbddIDACtHAMXo0tWpL1sBmAfxrFWgTzuLUJueaQxK6xa3ir6PMNYFiUwx20SK 37FJtnMe0R7ziKeof73IrNC7COHTNwpVELCG14FGBvpAi/HkEkPcX4zeArGNZP3D4N/K omqA3gJgjLObzt76e/T4pYjmquUSr+vGWcQ14BzIAkLzydKFYx/2XzXnLO3QWqp3I08w 3CMA== X-Gm-Message-State: AOJu0Yz9i5xvcABEiM5P9xiAR1n1ugdZGY5+FdBiJ/NF7m3MXUlMEedi KW5yE10DVDYyrBb3yycRpnwNzIGlJ8xhc8/jFt/Y3pAhiLkI+y/WThQTygg3 X-Gm-Gg: ASbGncsU34KDAGvpQATBJ79gccdBoDE3qW/W1W5SWQzpWefjIvDZLKxwD8t4HO4ywC5 0xqN6YB2cDC63HPBnn5rDFvkn53AQTGGMeRY2LrtA7UYGQIvpE9sHLB36oYMOptkBOnMhb3VRiF lgq9lnEiHyjqz7eCB/oVXAfaUJ2SYUnhAFjhFfq5I1dStDMLZjtgOxTvCr5dx9XFMDJjAmE1B3P mstCH9enFDeEwRpaAzU4ssz84A1ZQskmiSdKyvSl9MYEl4qBk16RUxVkbBIPhdvXfdjal2ATJkF ow2ypSJYnK1x+KqfgK6DjTkFXeg6s1smFfqRGPrCgv5OfjeMcvjwGYvssQ== X-Google-Smtp-Source: AGHT+IHZTjPMsX10l3QTzriYavpu9dDHrMZlUxYp98yfm3Zu0JP3kpM88rgWVUBrCk1oYY/4HTOnXA== X-Received: by 2002:a17:902:f712:b0:21f:7078:4074 with SMTP id d9443c01a7336-2216ee9ca60mr73795925ad.7.1739984526992; Wed, 19 Feb 2025 09:02:06 -0800 (PST) From: Harikumar Rajkumar To: devel@lists.libvirt.org Subject: [PATCH v8 12/18] config: validate: Verify iotune, throttle group and filter Date: Wed, 19 Feb 2025 22:27:16 +0530 Message-Id: <20250219165722.26348-13-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250219165722.26348-1-harirajkumar230@gmail.com> References: <20250219165722.26348-1-harirajkumar230@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ILG6YIIUBLYZQ2AWQNLCXY5MQ63XRPCD X-Message-ID-Hash: ILG6YIIUBLYZQ2AWQNLCXY5MQ63XRPCD X-MailFrom: harirajkumar230@gmail.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: sanjeev.ranjan@ibm.com, harikumar.rajkumar@ibm.com, earulana@in.ibm.com, Chun Feng Wu , Harikumar Rajkumar 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: 1739985016610019100 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 * Update of code documentation comments. Signed-off-by: Harikumar Rajkumar --- src/conf/domain_conf.c | 8 +++ src/conf/domain_validate.c | 118 ++++++++++++++++++++++++++----------- src/qemu/qemu_driver.c | 13 ++++ src/qemu/qemu_hotplug.c | 8 +++ 4 files changed, 113 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 303aa7d1ae..0cc318d1f9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8008,6 +8008,14 @@ virDomainDiskDefThrottleFiltersParse(virDomainDiskDe= f *def, if ((n =3D virXPathNodeSet("./throttlefilters/throttlefilter", ctxt, &= nodes)) < 0) return -1; =20 + if (def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { + if (n > 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cdrom device with throttle filters isn't sup= ported")); + return -1; + } + } + if (n) def->throttlefilters =3D g_new0(virDomainThrottleFilterDef *, n); =20 diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 563558d920..d51682d155 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -685,11 +685,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) { @@ -739,41 +783,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 @@ -974,6 +985,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 @@ -1874,6 +1905,22 @@ 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= ]; + + if (virDomainDiskIoTuneValidate(*throttleGroup) < 0) + return -1; + } + + return 0; +} + + static int virDomainDefValidateInternal(const virDomainDef *def, virDomainXMLOption *xmlopt) @@ -1932,6 +1979,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 afb41a4c89..6b1e8d01e0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6703,6 +6703,13 @@ qemuDomainAttachDeviceConfig(virDomainDef *vmdef, _("target %1$s already exists"), disk->dst); return -1; } + 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= supported")); + return -1; + } + } if (virDomainDiskTranslateSourcePool(disk) < 0) return -1; if (qemuCheckDiskConfigAgainstDomain(vmdef, disk) < 0) @@ -14861,6 +14868,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 75437164ca..ff29cd55f4 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -985,6 +985,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)