From nobody Sat Jan 4 23:16:34 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 1733750929440822.7505802228526; Mon, 9 Dec 2024 05:28:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0334B1235; Mon, 9 Dec 2024 08:28:47 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EB9BF12A2; Mon, 9 Dec 2024 08:20:17 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id B67DD11CC; Mon, 9 Dec 2024 07:42:49 -0500 (EST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.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 E2D5111C7 for ; Mon, 9 Dec 2024 07:42:48 -0500 (EST) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2161eb95317so23054935ad.1 for ; Mon, 09 Dec 2024 04:42:48 -0800 (PST) Received: from localhost.localdomain ([120.60.110.156]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-2164d103993sm18113195ad.193.2024.12.09.04.42.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 04:42:46 -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=1733748167; x=1734352967; 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=lTQ9S13cnR+6jk66kNCHkhQKKLdgxo7jpFpY1+f4xpQ=; b=le0x9PLrMBrDj5BkLTqmvTEPAoeHOeZAHq8fIaErDMG6vw9ItwZetjXrZ4xP978nAV 4LVOe1kkMTRbAtXMvMexgSlwo2GK/NTHITvTA0DLglCcgXW2B5VB6/LEloWMrk26/liK BPleyIlwV5IPV1IMQL5lda3z+B14jP5o4oeSxf0SZPxFaScCf2LOkXUKi8YNAeWbWy9Y 9sZDpg7tAUv+CmavXHcSNnNKcqmkO30Xn7q2Gz5epaEnaK8/skNN8itupiLX2SWtJKut 30JxTyjUydIDmKTPKG6V/bvnFsuBoi7ZqbKFNXPBcZjhNnZGsmD9pcedqJVpqP/S+f4r /psg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733748167; x=1734352967; 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=lTQ9S13cnR+6jk66kNCHkhQKKLdgxo7jpFpY1+f4xpQ=; b=HVB0vIroRIlQ28DGsqjZzBfozZFsYCRvgbuf4GwTmHm4zdf480IFeehRjcEnz7IWCF FThYb4zlu64xEqMZ4vzk0yPVv4KJswzF6pEuioDVdq3I0KqI48SEfocu75SMet9cgSlN Y9fm6XSCPO3c7xehbg7PC3yKxG1TMwApiuzb6GVI7KG8UrRoZyC/Ze5s7t69/qH/Pcsl 2vUo6BCcfVgdqwuAUaHWmNFsGJ5pZlQ0XA+bx2D2agH18R3ttzO+F9MmMcNNAHZDbx3x VX8CBm6Nc44e8C3FRrSMIhPkwxjRjDCXoAR9cu+3GLitavbg5I8o6GfUAerPP0Y/JrAy REzA== X-Gm-Message-State: AOJu0YyvjgHRMmwjpfKHlMCxRFhZp9yke9JNhFM3yCc+Czjur7frr4K8 qra6VLIAfYP+/3UbYjeQKAyPF6NebaCDFyXdn9iqLy3C/h7wK4rjH/rP9LcI X-Gm-Gg: ASbGncu3yqwqf8vkee126QJ7msal88+ppE6ir2/ZZeIxVQ5x6vqSnkjYtALK1RjdwEn g4EnqpqIZtuOhY1dbuODFZjGazS7oANlCFMyxXJl+TdXxTivAkwZsjVbVJjnAhkkitAcF2erpbw DarQhIcoGpcgjjNa68d7gtexRkqbzMGgmdeSmF/W1K9FjQExXNw2fdqN14gY0TYbtDdG5oiIVoT VXJF9dXEG15GJgpauf6GEhHcRe1ubcbBA+BdwYXbSt/nKUg8SyvBSGFyRDBScZGipIBg6/kz0bN W97oEg== X-Google-Smtp-Source: AGHT+IFEiZdeWSWE1idtSKznfzL7pTwVqE+atprmFl968DTugAIeVK8Z20ZBlLupiVguPs4d4ClG3A== X-Received: by 2002:a17:902:fc8f:b0:215:8270:77e2 with SMTP id d9443c01a7336-21669eb689bmr6458055ad.0.1733748167462; Mon, 09 Dec 2024 04:42:47 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v6 12/18] config: validate: Verify iotune, throttle group and filter Date: Mon, 9 Dec 2024 18:11:12 +0530 Message-Id: <20241209124118.39471-13-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241209124118.39471-1-harirajkumar230@gmail.com> References: <20241209124118.39471-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: UDF24H4RMOMJRC3LBJYHET73WM4K32IC X-Message-ID-Hash: UDF24H4RMOMJRC3LBJYHET73WM4K32IC X-Mailman-Approved-At: Mon, 09 Dec 2024 13:19:48 -0500 CC: earulana@in.ibm.com, sanjeev.ranjan@ibm.com, harikumar.rajkumar@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: 1733750930341116600 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 1034bb57f5..03dfff93c0 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 @@ -969,6 +980,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 @@ -1869,6 +1900,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) @@ -1927,6 +1975,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 7217e4d881..78d1d83770 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14863,6 +14863,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 855ce9ca44..e341cac80c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -989,6 +989,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)