From nobody Sat Jan 4 23:09:08 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 17337507626041014.3586174080533; Mon, 9 Dec 2024 05:26:02 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0593013C9; Mon, 9 Dec 2024 08:26:00 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 034001249; Mon, 9 Dec 2024 08:20:09 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D24D011CF; Mon, 9 Dec 2024 07:42:39 -0500 (EST) Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 E0D7D11BE for ; Mon, 9 Dec 2024 07:42:38 -0500 (EST) Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-216401de828so9750535ad.3 for ; Mon, 09 Dec 2024 04:42:38 -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.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 04:42:36 -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.6 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=1733748157; x=1734352957; 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=ThUom6yY0BHMEykxVI2dwyrimA1KWKCO1kYWJhAKMAU=; b=HnFdRfc8ZAmCPgcVwmshE7FFzNlOxASKwBUuDY/pmTSPHLuKnO28evi0c7kuUAbXOj xpZMA+LJp/t3dcDxHPZAQaU8CCbqqc4MB7E8QyCCxyxlm4KwyxcGwwJbP/S+TCvVaO5w 8rZMIwdbODgZG4QRHbRZUxeCYKx9G9zn/V7EJlcP1HFWP14bwt7Ajx51QzUc5rnGiaB+ Aj1eM/5VK1V1Dy52AvIp2eKHMr4Er9DksphgVrBkf/Skkgt8oR5ULoSSz8lewwVJvttZ eHnP8tKwD1z8P5IITn6BP+/DpwEJMKOpW4QyqeLiMjlwnNBm9+KrqaP7RGvo/OAbHIwH c9/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733748157; x=1734352957; 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=ThUom6yY0BHMEykxVI2dwyrimA1KWKCO1kYWJhAKMAU=; b=JlvClSjpAE1n1QCMi5WCnWdf60TATZUJuUpw9w+wa4uBBa2UlyBaz1a6QPcmpCp3vR M/8wiRjwL7+0Ivexyj+karjXxHz/ODZUw2FJ73tkRHH5HYRiEom09dsiHkt/8NOpTfv2 qaE6ZKSSn+xc8n0TooP23VQPrKNSTatd9mAnEXxIZeuZ7Nqj2V8uyWLX4i5omjW8WyMj A+cKaGOVQyw05yfGfHep0UM1eyrbjTZurKtUQ8xmlnoYxdRNPTUq05ztjj3NMeVz4yhL dQjmNoJJPenCs0gRWj+FaaKo6UA6qoi/h9A0/qbS0OuIwd9saPupbmS8HQTbtB1P/mwQ k+LQ== X-Gm-Message-State: AOJu0YyPwsvInG31OKPzBCDdccm35d/TzRJEdfhb5XhZPReat4Ja2Alb +bBPRzy7rP2HGk9elywbG7U2wULAjKxIIkp+H4H4xc6/781+eoW97DxsIY0z X-Gm-Gg: ASbGnctAObmmOaMMuE+xO541JCo1v4HmwCw1jWwKdPCZMjES1aakzI7I/ymuLF/AggW zzu7mlJck7oieN6+BFJKwVMAQ73ndZdP9rhopbelaYzPO8H57Eh0MZ8G9v/wLmDjxNNa99eY8lX bHzb6itRAdOIEzWM+jLyujqu5nty9vYUcXW+hwmB7fdDmwaTOc934qvkhIA8CaiPNUrTap4s8At eZXq89bUrP/BfsSBFCXKUfD3BIdgYp6/Q8qxMQKHGrVZV3VaHtvAYLBBbZkealsTqwXC+aWD8Jm k7ehgQ== X-Google-Smtp-Source: AGHT+IHl4nXRj+ulk9NL4ofWe/tNPKmgqOCSfN6i0A2rkmcnfAW28jEF6jqVdyLJdDdgpq0gk/deAw== X-Received: by 2002:a17:902:e84d:b0:215:a3e4:d251 with SMTP id d9443c01a7336-21669fa3664mr4281875ad.6.1733748157432; Mon, 09 Dec 2024 04:42:37 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v6 08/18] qemu: Refactor qemuDomainSetBlockIoTune to extract common methods Date: Mon, 9 Dec 2024 18:11:08 +0530 Message-Id: <20241209124118.39471-9-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: APKFOS7QJQSUNILBCKBCOXFILD5XN4Q6 X-Message-ID-Hash: APKFOS7QJQSUNILBCKBCOXFILD5XN4Q6 X-Mailman-Approved-At: Mon, 09 Dec 2024 13:19:47 -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: 1733750763472116600 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 09f7edda7d..ab2d40e85f 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14990,35 +14990,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, @@ -15063,32 +15036,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; \ @@ -15128,10 +15097,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; @@ -15154,56 +15123,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"), \ @@ -15215,7 +15184,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); \ @@ -15233,6 +15202,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)