From nobody Wed Dec 4 08:41:37 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 1731939349678877.7515585397451; Mon, 18 Nov 2024 06:15:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 93B4A140C; Mon, 18 Nov 2024 09:15:48 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 79A691B5C; Mon, 18 Nov 2024 09:10:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id BF4031A09; Mon, 18 Nov 2024 08:55:08 -0500 (EST) Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.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 CC37D19FF for ; Mon, 18 Nov 2024 08:55:07 -0500 (EST) Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-720d5ada03cso2807002b3a.1 for ; Mon, 18 Nov 2024 05:55:07 -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.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 05:55:05 -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=1731938106; x=1732542906; 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=8/XRQbSqyqb/Q9AYlsknAei8oCbutB1GWkuVWGKHE9s=; b=Cb1QjkFwbXcFdeHXrPQrORbK+t50pAkeMGkQIRClOY/+VM3yDDLtrN7oJngaZ6TGl4 gRhlteDfZh7AS/EGebSF8WgkDdP8x0mpCFR60Llh6tA5oi/5Lbk0DtNLkyfH1ptKcdu2 vrMPi+8COe2hBgDiAYj92qP1Jpkxy/JEYD8E7WilrfLQhXnUasKVTTTPnvN8EGI7/fnq SzBMtP0/KrBaxSiUksNyXpQXC4ivw5IMfZtvltudP3KjMQ9KqPO+v7Sz3KUTInDuSPTT n/lmbsvLYdBc0S6JbwAx21aqnimuwW5qn3EAgUjprF7ssgB4bCLYtcDqxJ3MaVTWXfn7 2tWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731938106; x=1732542906; 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=8/XRQbSqyqb/Q9AYlsknAei8oCbutB1GWkuVWGKHE9s=; b=EbbKlOolxYUxfe9K9XoNPGc5JIb7XMP3KAZ9CIKN1YEMRN4KVS/T6AsllHgE0sx5/W P4mdTmw/p+7ivkhhK++CWDBWrXvZ+opkREArPbf2yhvuHqM2uazPHEAmv/8VoFg39OtD gv9iJzKcRbEAHRCUj/9vh+ER2rvl3LulinHKCd+P194jIhZHDqEc7Agc6HL6j99TCpit rAGLMizk28TPMbc1iiqQDqdTrx1GwgPxINnvhi/cPcPC9PF/7YTIFmxjO5lv1i2nSGhZ FhZ+mk+At65zahMqCOaJhLxV4EJhWQBIMMeQ9UbHlYIrrXEe+FFwbu1mGUiaPtXZB8HE rCJQ== X-Gm-Message-State: AOJu0YwRgLJvCNxwIDEr7eRhHAkfq9MH4JvqJLWtqsGJE72wTzcmg7fJ Rqv3xRucsGXkju+Djj35A8KI65ZlABHzAZrr93myXEI+qUR5ESkQ6pfxe1hm X-Google-Smtp-Source: AGHT+IHuqsMUHvrIm57Mq+/c6iEtYt+3iJZvOKXkNJpDqB1cdSzu0P9KLh7LbZ2XUjhcG5HkDjkSwQ== X-Received: by 2002:a05:6a00:4fd0:b0:71e:64fe:965f with SMTP id d2e1a72fcca58-72476ccbc21mr17745810b3a.20.1731938106218; Mon, 18 Nov 2024 05:55:06 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v5 08/18] qemu: Refactor qemuDomainSetBlockIoTune to extract common methods Date: Mon, 18 Nov 2024 19:24:16 +0530 Message-Id: <20241118135426.37643-9-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: S7WF2K347CXCJ53JWIOVXBMX6HKINHOO X-Message-ID-Hash: S7WF2K347CXCJ53JWIOVXBMX6HKINHOO X-Mailman-Approved-At: Mon, 18 Nov 2024 14:10:14 -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: 1731939350548116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu extract common methods from "qemuDomainSetBlockIoTune" to be reused by throttle handling later, common methods include: * "qemuDomainValidateBlockIoTune", which is to validate that PARAMS contains only recognized parameter names with correct types * "qemuDomainSetBlockIoTuneFields", which is to load parameters into internal object virDomainBlockIoTuneInfo * "qemuDomainCheckBlockIoTuneMutualExclusion", which is to check rules like "total and read/write of bytes_sec cannot be set at the same time" * "qemuDomainCheckBlockIoTuneMax", which is to check "max" rules within iot= une Signed-off-by: Chun Feng Wu --- src/qemu/qemu_driver.c | 225 ++++++++++++++++++++++++++--------------- 1 file changed, 142 insertions(+), 83 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index aa8a78da69..e80e5fc511 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14989,35 +14989,8 @@ qemuDomainCheckBlockIoTuneReset(virDomainDiskDef *= disk, =20 =20 static int -qemuDomainSetBlockIoTune(virDomainPtr dom, - const char *path, - virTypedParameterPtr params, - int nparams, - unsigned int flags) +qemuDomainValidateBlockIoTune(virTypedParameterPtr params, int nparams) { - virQEMUDriver *driver =3D dom->conn->privateData; - virDomainObj *vm =3D NULL; - qemuDomainObjPrivate *priv; - virDomainDef *def =3D NULL; - virDomainDef *persistentDef =3D NULL; - virDomainBlockIoTuneInfo info =3D { 0 }; - virDomainBlockIoTuneInfo conf_info =3D { 0 }; - int ret =3D -1; - size_t i; - virDomainDiskDef *conf_disk =3D NULL; - virDomainDiskDef *disk; - qemuBlockIoTuneSetFlags set_fields =3D 0; - g_autoptr(virQEMUDriverConfig) cfg =3D NULL; - virObjectEvent *event =3D NULL; - virTypedParameterPtr eventParams =3D NULL; - int eventNparams =3D 0; - int eventMaxparams =3D 0; - virDomainBlockIoTuneInfo *cur_info; - virDomainBlockIoTuneInfo *conf_cur_info; - - - virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | - VIR_DOMAIN_AFFECT_CONFIG, -1); if (virTypedParamsValidate(params, nparams, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, VIR_TYPED_PARAM_ULLONG, @@ -15062,32 +15035,28 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, NULL) < 0) return -1; =20 - if (!(vm =3D qemuDomainObjFromDomain(dom))) - return -1; - - if (virDomainSetBlockIoTuneEnsureACL(dom->conn, vm->def, flags) < 0) - goto cleanup; - - cfg =3D virQEMUDriverGetConfig(driver); - - if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) - goto cleanup; - - priv =3D vm->privateData; + return 0; +} =20 - if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) - goto endjob; =20 - if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxpara= ms, - VIR_DOMAIN_TUNABLE_BLKDEV_DISK, path) < 0) - goto endjob; +static int +qemuDomainSetBlockIoTuneFields(virDomainBlockIoTuneInfo *info, + virTypedParameterPtr params, + int nparams, + qemuBlockIoTuneSetFlags *set_fields, + virTypedParameterPtr *eventParams, + int *eventNparams, + int *eventMaxparams) +{ + size_t i; + int ret =3D -1; =20 #define SET_IOTUNE_FIELD(FIELD, BOOL, CONST) \ if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_##CONST)) { \ - info.FIELD =3D param->value.ul; \ - set_fields |=3D QEMU_BLOCK_IOTUNE_SET_##BOOL; \ - if (virTypedParamsAddULLong(&eventParams, &eventNparams, \ - &eventMaxparams, \ + info->FIELD =3D param->value.ul; \ + *set_fields |=3D QEMU_BLOCK_IOTUNE_SET_##BOOL; \ + if (virTypedParamsAddULLong(eventParams, eventNparams, \ + eventMaxparams, \ VIR_DOMAIN_TUNABLE_BLKDEV_##CONST, \ param->value.ul) < 0) \ goto endjob; \ @@ -15127,10 +15096,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, =20 /* NB: Cannot use macro since this is a value.s not a value.ul */ if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME)) { - info.group_name =3D g_strdup(param->value.s); - set_fields |=3D QEMU_BLOCK_IOTUNE_SET_GROUP_NAME; - if (virTypedParamsAddString(&eventParams, &eventNparams, - &eventMaxparams, + info->group_name =3D g_strdup(param->value.s); + *set_fields |=3D QEMU_BLOCK_IOTUNE_SET_GROUP_NAME; + if (virTypedParamsAddString(eventParams, eventNparams, + eventMaxparams, VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NA= ME, param->value.s) < 0) goto endjob; @@ -15153,56 +15122,56 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, =20 #undef SET_IOTUNE_FIELD =20 - if ((info.total_bytes_sec && info.read_bytes_sec) || - (info.total_bytes_sec && info.write_bytes_sec)) { + ret =3D 0; + endjob: + return ret; +} + + +static int +qemuDomainCheckBlockIoTuneMutualExclusion(virDomainBlockIoTuneInfo *info) +{ + if ((info->total_bytes_sec && info->read_bytes_sec) || + (info->total_bytes_sec && info->write_bytes_sec)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("total and read/write of bytes_sec cannot be set = at the same time")); - goto endjob; + return -1; } =20 - if ((info.total_iops_sec && info.read_iops_sec) || - (info.total_iops_sec && info.write_iops_sec)) { + if ((info->total_iops_sec && info->read_iops_sec) || + (info->total_iops_sec && info->write_iops_sec)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("total and read/write of iops_sec cannot be set a= t the same time")); - goto endjob; + return -1; } =20 - if ((info.total_bytes_sec_max && info.read_bytes_sec_max) || - (info.total_bytes_sec_max && info.write_bytes_sec_max)) { + if ((info->total_bytes_sec_max && info->read_bytes_sec_max) || + (info->total_bytes_sec_max && info->write_bytes_sec_max)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("total and read/write of bytes_sec_max cannot be = set at the same time")); - goto endjob; + return -1; } =20 - if ((info.total_iops_sec_max && info.read_iops_sec_max) || - (info.total_iops_sec_max && info.write_iops_sec_max)) { + if ((info->total_iops_sec_max && info->read_iops_sec_max) || + (info->total_iops_sec_max && info->write_iops_sec_max)) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("total and read/write of iops_sec_max cannot be s= et at the same time")); - goto endjob; + return -1; } =20 - virDomainBlockIoTuneInfoCopy(&info, &conf_info); - - if (def) { - if (!(disk =3D qemuDomainDiskByName(def, path))) - goto endjob; - - if (!qemuDomainDiskBlockIoTuneIsSupported(disk)) - goto endjob; - - cur_info =3D qemuDomainFindGroupBlockIoTune(def, disk, &info); + return 0; +} =20 - if (qemuDomainSetBlockIoTuneDefaults(&info, cur_info, - set_fields) < 0) - goto endjob; =20 - if (qemuDomainCheckBlockIoTuneReset(disk, &info) < 0) - goto endjob; +static int +qemuDomainCheckBlockIoTuneMax(virDomainBlockIoTuneInfo *info) +{ + int ret =3D -1; =20 #define CHECK_MAX(val, _bool) \ do { \ - if (info.val##_max) { \ - if (!info.val) { \ + if (info->val##_max) { \ + if (!info->val) { \ if (QEMU_BLOCK_IOTUNE_SET_##_bool) { \ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \ _("cannot reset '%1$s' when '%2$s' = is set"), \ @@ -15214,7 +15183,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, } \ goto endjob; \ } \ - if (info.val##_max < info.val) { \ + if (info->val##_max < info->val) { \ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \ _("value '%1$s' cannot be smaller than = '%2$s'"), \ #val "_max", #val); \ @@ -15232,6 +15201,96 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, =20 #undef CHECK_MAX =20 + ret =3D 0; + endjob: + return ret; +} + + +static int +qemuDomainSetBlockIoTune(virDomainPtr dom, + const char *path, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virQEMUDriver *driver =3D dom->conn->privateData; + virDomainObj *vm =3D NULL; + qemuDomainObjPrivate *priv; + virDomainDef *def =3D NULL; + virDomainDef *persistentDef =3D NULL; + virDomainBlockIoTuneInfo info =3D { 0 }; + virDomainBlockIoTuneInfo conf_info =3D { 0 }; + int ret =3D -1; + virDomainDiskDef *conf_disk =3D NULL; + virDomainDiskDef *disk; + qemuBlockIoTuneSetFlags set_fields =3D 0; + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + virObjectEvent *event =3D NULL; + virTypedParameterPtr eventParams =3D NULL; + int eventNparams =3D 0; + int eventMaxparams =3D 0; + virDomainBlockIoTuneInfo *cur_info; + virDomainBlockIoTuneInfo *conf_cur_info; + + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + if (qemuDomainValidateBlockIoTune(params, nparams) < 0) + return -1; + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + if (virDomainSetBlockIoTuneEnsureACL(dom->conn, vm->def, flags) < 0) + goto cleanup; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + priv =3D vm->privateData; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxpara= ms, + VIR_DOMAIN_TUNABLE_BLKDEV_DISK, path) < 0) + goto endjob; + + if (qemuDomainSetBlockIoTuneFields(&info, + params, + nparams, + &set_fields, + &eventParams, + &eventNparams, + &eventMaxparams) < 0) + goto endjob; + + if (qemuDomainCheckBlockIoTuneMutualExclusion(&info) < 0) + goto endjob; + + virDomainBlockIoTuneInfoCopy(&info, &conf_info); + + if (def) { + if (!(disk =3D qemuDomainDiskByName(def, path))) + goto endjob; + + if (!qemuDomainDiskBlockIoTuneIsSupported(disk)) + goto endjob; + + cur_info =3D qemuDomainFindGroupBlockIoTune(def, disk, &info); + + if (qemuDomainSetBlockIoTuneDefaults(&info, cur_info, set_fields) = < 0) + goto endjob; + + if (qemuDomainCheckBlockIoTuneReset(disk, &info) < 0) + goto endjob; + + if (qemuDomainCheckBlockIoTuneMax(&info) < 0) + goto endjob; + /* blockdev-based qemu doesn't want to set the throttling when a c= drom * is empty. Skip the monitor call here since we will set the thro= ttling * once new media is inserted */ --=20 2.39.5 (Apple Git-154)