From nobody Wed Dec 17 08:52:28 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 1739356898749327.90738786285726; Wed, 12 Feb 2025 02:41:38 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 15B09644; Wed, 12 Feb 2025 05:41:38 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id DDE101DED; Wed, 12 Feb 2025 05:36:38 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6C8F61AEC; Wed, 12 Feb 2025 05:36:29 -0500 (EST) Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 85A0C1ADA for ; Wed, 12 Feb 2025 05:36:10 -0500 (EST) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2f9d627b5fbso12444290a91.2 for ; Wed, 12 Feb 2025 02:36:10 -0800 (PST) Received: from localhost.localdomain ([117.251.37.46]) by smtp.googlemail.com with ESMTPSA id 98e67ed59e1d1-2fbf98b3277sm1147688a91.7.2025.02.12.02.36.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 12 Feb 2025 02:36:07 -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=1739356569; x=1739961369; 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=2b0M+BOvl89eonByg0AQXhHRZVjoj/Mi4ogCPtHKN0M=; b=RY3iK6Q7SoSqCPgSvY9UuBey0a2vG3MdsZRdrIjNQ4TUo289bFAahSaOJZGGo226Ip q1jtDt4Qwmd7abI7DqghfDTKbHgYmda/3P3R7l/ZaWbgXmgh7VobYDp2qfzlyjQ1IaA4 9lzPONQdl4KE9w4SmLVIZVT4KQvfNBK8tBPVy6PzQDFNyHKGwJR4AIn6OhGqqUBERI2y z8ERvRc1lPoJuwAnPTkdMHX+D8obsq8P/wmKSsX3LUXsVCneDFXXeLy8sxWC3+e1EemX qgjbrbMawEVrncK2SVou5H//1boOyjeIk3T8mx+G7shfirvF5WQHSTRblKueSbn7Lx2Q pxXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739356569; x=1739961369; 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=2b0M+BOvl89eonByg0AQXhHRZVjoj/Mi4ogCPtHKN0M=; b=gUOYNmlA0zOsyijmv5TvI4qVM+bY3Qo9+pvo7yKmv95FJ1DV8fijT9CB7xGZRfjphC Uzhs2ufDJgJ8gnG7tdUFkqOprl5jDT7iWYBk3Wh8F7fUqo02qU9mx73EL3heiBGCv18b 5fyJPAyrdmt8SrNlf0uaU+Zef+yvZi1JQ8bftRMdy5FHLOLaHF7DV2HeOCRr+hr1bG6w 6b7/8DbaIItJ4syU35fTrkT41eUqqIHos+dyexpzuy3J2LpaUnoPiaI0oFZR0mIMCD4j Nr3wnrvUgwFzgTbH8GjCq69xHaMtZusHBapE8Dswj1ue8sA4aeRhawBXUkGBkpVMCQX5 zaFQ== X-Gm-Message-State: AOJu0YybNpDlXXTF1Tn8ViuTELrwM/vpwByShbZicVxXtx2o4AE2PRLw VxIavZf9jzu0nATL/PEfgwHY1le+n1C2v+jlztkPeVeq9+3TJIplZly7Mw== X-Gm-Gg: ASbGncvprNjLvcfZYV43FN7FQ+xzLGmCqZENiWmegQHRpX4HkiNUZ+/PnxROiv2SrA6 kD8rtNnsT0RAooAjToW38kLSkoyQ6ExadFzNPfz712tR5LSY0MY160jLTwTmWCz1jxauXFqcWh0 GN/YBSfop7o9Di67OuqcyyctdXQy2Ho4gVEebb04Xgp7DX7z6SX49iy3LNhm2EaOkuahs3BX/um tMBYVrJyza5DOvTU58K66GZ79bbdnPSlaBTkFHjv9ORa2ttBJI721KYrbwB2R/xiylDhSuImfem AcfD9fLxOpYvYjIOTtbHCGwiLppN+Cz0ZCEiifh+Z9fzeA== X-Google-Smtp-Source: AGHT+IHK46JZ9rNcIQAdTl15o1iNEu3P9/QSF43plXyd+6uu+XKfE6XITjkOx+0WyLTKaB9ax02w1w== X-Received: by 2002:a17:90b:524b:b0:2fa:229f:d03a with SMTP id 98e67ed59e1d1-2fbf5c57bf5mr3658287a91.26.1739356568698; Wed, 12 Feb 2025 02:36:08 -0800 (PST) From: Harikumar Rajkumar To: devel@lists.libvirt.org Subject: [PATCH v7 08/18] qemu: Refactor qemuDomainSetBlockIoTune to extract common methods Date: Wed, 12 Feb 2025 16:05:27 +0530 Message-Id: <20250212103537.26352-9-harirajkumar230@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250212103537.26352-1-harirajkumar230@gmail.com> References: <20250212103537.26352-1-harirajkumar230@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WF5QOTKKLZ3WL7BRYZRZPM5QF5UGYVGR X-Message-ID-Hash: WF5QOTKKLZ3WL7BRYZRZPM5QF5UGYVGR 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: harikumar.rajkumar@ibm.com, sanjeev.ranjan@ibm.com, earulana@in.ibm.com, 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: 1739356899482019000 Content-Type: text/plain; charset="utf-8" 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 iotune Signed-off-by: Harikumar Rajkumar --- 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 78bfaa5b3a..8720ea0a4c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15010,35 +15010,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, @@ -15083,35 +15056,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 @@ -15122,7 +15090,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); @@ -15148,13 +15116,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 @@ -15174,56 +15142,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"), \ @@ -15233,13 +15198,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) @@ -15253,6 +15218,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)