From nobody Sun Dec 7 13:35:52 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 173998485498287.56254829426177; Wed, 19 Feb 2025 09:07:34 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D860C1CA0; Wed, 19 Feb 2025 12:07:33 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C5F9A1DFB; Wed, 19 Feb 2025 12:02:26 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4052E1C59; Wed, 19 Feb 2025 12:02:19 -0500 (EST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 1316B1BE5 for ; Wed, 19 Feb 2025 12:01:58 -0500 (EST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-22101839807so100028585ad.3 for ; Wed, 19 Feb 2025 09:01:58 -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.01.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 19 Feb 2025 09:01:55 -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=1739984516; x=1740589316; 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=h3YMT3YYzMAypkSrTWEnkYbKWHqmk1ivf58kCPdE7k0=; b=F25HHxM45BdIBiwJf2rbEi1g8ZMVnLH/xVcStVvrcxUFCFmiTxvuzG0CXAhVQeJ1to bUhM1aahyr67z2BAlT9dR5G/d0kFmZb8ia+9iV00ABBU/3+CBfUWbpsTvQ72sTFpInZL /bbuIAlBzIyDoVH15zu4B2JTtvtr80L4JA9oZDtyJJk8LfiM3z1TjNLh5QKB/2rKRZLE dRRsUzm+xNZSiiRpNEjeqeWzuyExJB/8cMZTJDCFfMpsiHVJJwqGLLEPAtMtC7/xvra/ 7Ons8zuh7LBjd9Gf73KO4wo1UCIYjXkO1wkp6WOgkQOrofSvGB8TKxyWINOg1b8WuhHO bTIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739984516; x=1740589316; 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=h3YMT3YYzMAypkSrTWEnkYbKWHqmk1ivf58kCPdE7k0=; b=AtatCAMG4qvR+LxsX0T/nPBUhySBAOOX7/siuutvsg1YK/EuyUqQRotLMmkCYCULWZ TMxbsqaySvRGnEV6Q3zLFM5piHUsEhj2bxfjvnoUItYZ7trOcNOzC2Aol1MIwKihYad6 clTiyG/JdShQd6itUV3yQ6XZFim+Qfl5Av9wIEH5NKVWWaDEqJ5XAffl60491FEvQyym lTdSYdvxuPoXBDffnWt3mFa1SFKxfUs/o8hvOB6XqQCeUoYcrpGlNQJlFjtLAiohVkuX pMBnqvDG8XZqcdSUoUB3hAqbxXUWVwtigorFBNQZ/xyDiT3OcMty6FVAv+fYuguhbBet u20w== X-Gm-Message-State: AOJu0YzaPKIc4lrVM2JyMJrP9KEMIkEKO7eR5n4jCoak3wseb4PmzG+h QbuBMh2ia+l3LHMAeZ73q1WnIKiz0w23j2Q+Vhz2i8BrrDftbexFH0LECp1f X-Gm-Gg: ASbGncuCi3Yd5KD9Bxo4knUSy+AkNdV6m5JFVvEjWeVd40c+YmSPHrgMcFVdeIVQk29 LvgQ5yKR7KoWbZdHVsdnVxrInbKvpBK3LwiOc9nTgh+/Klty1Q9b9+cA9x+nTOiIb+XvnDDCwER LX0ymmyd+2tT5y5oX8z8rmW/6MtYlFveiyrxtIaTzXoclMQfnoTSMIW3+P+sSC3FHuBl7om5sET Ky3KuxTH0lKcD/Yfw894XaobprCa1SuSsaxIoaG9TiniA+qElBtC9qOO81hqO1hM1iOLUIWMtTj MnypsTaNMcPr+3J7mdEZjHz7UtTza6bxj5q5iIyJcPAUYZLftJbwBooMMA== X-Google-Smtp-Source: AGHT+IHXc7k2GRDEXJjfR6/FCRUHD/nvuOkbI0tYq/uk17Ad8sA9nRgYbp6mvhHDRRLzrLr9ptcRpg== X-Received: by 2002:a17:903:22cb:b0:216:73f0:ef63 with SMTP id d9443c01a7336-221711bbd57mr76136445ad.49.1739984516070; Wed, 19 Feb 2025 09:01:56 -0800 (PST) From: Harikumar Rajkumar To: devel@lists.libvirt.org Subject: [PATCH v8 08/18] qemu: Refactor qemuDomainSetBlockIoTune to extract common methods Date: Wed, 19 Feb 2025 22:27:12 +0530 Message-Id: <20250219165722.26348-9-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: ASRQPE65QLYLARBH2EGXQWRS6ZNEJNYK X-Message-ID-Hash: ASRQPE65QLYLARBH2EGXQWRS6ZNEJNYK 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: 1739984860564019100 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 * Apply suggested coding style changes. Signed-off-by: Harikumar Rajkumar Reviewed-by: Peter Krempa --- src/qemu/qemu_driver.c | 229 +++++++++++++++++++++++++---------------- 1 file changed, 141 insertions(+), 88 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1d0da1028f..31c543175f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14988,35 +14988,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, @@ -15061,35 +15034,30 @@ 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; + return 0; +} =20 - priv =3D vm->privateData; =20 - if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) - goto endjob; - - 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; =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; \ + return -1; \ continue; \ } =20 @@ -15100,7 +15068,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, _("block I/O throttle limit value must be no mo= re than %1$llu"), QEMU_BLOCK_IOTUNE_MAX); - goto endjob; + return -1; } =20 SET_IOTUNE_FIELD(total_bytes_sec, BYTES, TOTAL_BYTES_SEC); @@ -15126,13 +15094,13 @@ 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; + return -1; continue; } =20 @@ -15152,56 +15120,53 @@ 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)) { + return 0; +} + + +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) +{ =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"), \ @@ -15211,13 +15176,13 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, _("value '%1$s' cannot be set if '%= 2$s' is not set"), \ #val "_max", #val); \ } \ - goto endjob; \ + return -1; \ } \ - 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); \ - goto endjob; \ + return -1; \ } \ } \ } while (false) @@ -15231,6 +15196,94 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, =20 #undef CHECK_MAX =20 + return 0; +} + + +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)