From nobody Sat Nov 23 12:06:41 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 1731939408196654.2126135504832; Mon, 18 Nov 2024 06:16:48 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 26A641AC6; Mon, 18 Nov 2024 09:16:47 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D563A1B92; Mon, 18 Nov 2024 09:10:41 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 497C71A01; Mon, 18 Nov 2024 08:55:12 -0500 (EST) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (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 6DDB619FF for ; Mon, 18 Nov 2024 08:55:10 -0500 (EST) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-72483f6e2fbso1572701b3a.2 for ; Mon, 18 Nov 2024 05:55:10 -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.06 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 05:55:08 -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_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=1731938109; x=1732542909; 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=2GTdHq0EGQGm/8oyBtDos9kpsFU1U/+ja47GCUhm+Lk=; b=mB/tJ8iZrykCKlk1e4VEgJdwk7APBWe/mJCwGk8nAS6kEyDURtIgzlcQn6261Z/1my JX7ReCYw+WF5rx+m1md6g0jJyLAwne8sZma8eV9QbEvQ4hjG4YjjUncjFLWoh58zhhet lYJRdTBJXfgrLuTVuInuZeTS0+HXIa3O0kNF6SqINHgLWqvo1zoGhYHB33m070NAIVXO /6tVP2dghXDqCDvqR95W7ZS48XnkM25sKa9zx5N4++QmREKQbppD+rQZ7M6WmYqnTUET 3fmEIhanX8pXoj8RL8ElU4L9X4/2+hxpwG/pP5EszNgC82UIlzt/nZ2BaUZbM7owLvfT SwaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731938109; x=1732542909; 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=2GTdHq0EGQGm/8oyBtDos9kpsFU1U/+ja47GCUhm+Lk=; b=uGyEDHhGEpK5Mt2rzcJws7+TAnUGr2VwbHZS4ez9uPNz9ARypGt20vHsVXft9CHxRM j4ufp/fmXQa8GiUYlvBgnTds4WqIVDth6/oPLnycG1GAmrDUIWYGwNuxzJnRD2A8CnWb FBjg7h5Y+cHW8PBtucxhhie1WreLm6zzSLaAZSqwnkh2gB+HgpCDZJJdTxHY4A2+KWy+ Bl5kdh2VHP5DOoXPfmvGNuLXuGAVva8ayn2R9PRJyIPbwW9+gFXRabrzETX4zBjKAZzG dBGDWGVZfemCHn97N31xT39PowOI/Wmirab7e334Yjw2qnLu4uVbbqU0ibFVS3RFbIvI uXzw== X-Gm-Message-State: AOJu0YxZVEvDfH75EVLA2P5/euH/1cHy33koyuGwmbgn+LZwLAdbY4mO 29rcnXV1wEAR7QrGp/OM0pDvU+nJo6SwS2PN79Q4X42KzBIJUnJarAn0Voj6 X-Google-Smtp-Source: AGHT+IFJux2XLOrJinltqfZqW3PwSGMIPiyb0enJkdtsyaZHVcDu6H/Pw7pAooaAV+qOKYIHCWj4kA== X-Received: by 2002:a05:6a00:b82:b0:724:6b02:61b8 with SMTP id d2e1a72fcca58-72476b9680dmr13968755b3a.7.1731938108900; Mon, 18 Nov 2024 05:55:08 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v5 09/18] qemu: Implement qemu driver for throttle API Date: Mon, 18 Nov 2024 19:24:17 +0530 Message-Id: <20241118135426.37643-10-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: 2CLDNI2VH5QJNN5VUNEUS5KUWODPVJCA X-Message-ID-Hash: 2CLDNI2VH5QJNN5VUNEUS5KUWODPVJCA 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: 1731939408848116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu ThrottleGroup lifecycle implementation, note, in QOM, throttlegroup name is= prefixed with "throttle-" to clearly separate throttle group objects into their own names= pace. * "qemuDomainSetThrottleGroup", this method is to add("object-add") or upda= te("qom-set") throttlegroup in QOM and update corresponding objects in DOM * "qemuDomainGetThrottleGroup", this method queries throttlegroup info by g= roupname * "qemuDomainDelThrottleGroup", this method checks if group is referenced b= y any throttle in disks and delete it if it's not used anymore * Check flag "QEMU_CAPS_OBJECT_JSON" during qemuDomainSetThrottleGroup when= vm is active, throttle group feature requries such flag * "objectAddNoWrap"("props") check is done by reusing qemuMonitorAddObject = in qemuDomainSetThrottleGroup Signed-off-by: Chun Feng Wu --- src/qemu/qemu_driver.c | 388 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 388 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e80e5fc511..d65d5fd2ff 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20111,6 +20111,390 @@ qemuDomainGraphicsReload(virDomainPtr domain, return ret; } =20 + +/** + * qemuDomainCheckThrottleGroupAllZero: + * @newiotune: Pointer to iotune, which contains detailed items + * + * Check if params within @newiotune contain all zero values, if yes, + * return failure since it's meaningless to set all zero values in @newiot= une + * + * Returns -1 on failure, or 0 on success. + */ +static int +qemuDomainCheckThrottleGroupAllZero(virDomainBlockIoTuneInfo *newiotune) +{ + if (virDomainBlockIoTuneInfoHasAny(newiotune)) + return 0; + + VIR_FREE(newiotune->group_name); + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("creating a new group/updating existing with all para= meters zero is not supported")); + return -1; +} + + +static int +qemuDomainSetThrottleGroup(virDomainPtr dom, + const char *groupname, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virQEMUDriver *driver =3D dom->conn->privateData; + virDomainObj *vm =3D NULL; + virDomainDef *def =3D NULL; + virDomainDef *persistentDef =3D NULL; + virDomainThrottleGroupDef info =3D { 0 }; + virDomainThrottleGroupDef conf_info =3D { 0 }; + int ret =3D -1; + 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; + virDomainThrottleGroupDef *cur_info; + virDomainThrottleGroupDef *conf_cur_info; + int rc =3D 0; + g_autoptr(virJSONValue) props =3D NULL; + g_autoptr(virJSONValue) limits =3D virJSONValueNewObject(); + qemuDomainObjPrivate *priv =3D NULL; + virQEMUCaps *qemuCaps =3D NULL; + + + 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 (virDomainSetThrottleGroupEnsureACL(dom->conn, vm->def, flags) < 0) + goto cleanup; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxpara= ms, + VIR_DOMAIN_TUNABLE_BLKDEV_GROUP_NAME, grou= pname) < 0) + goto endjob; + + if (qemuDomainSetBlockIoTuneFields(&info, + params, + nparams, + &set_fields, + &eventParams, + &eventNparams, + &eventMaxparams) < 0) + goto endjob; + + if (qemuDomainCheckBlockIoTuneMutualExclusion(&info) < 0) + goto endjob; + + virDomainThrottleGroupDefCopy(&info, &conf_info); + + priv =3D vm->privateData; + qemuCaps =3D priv->qemuCaps; + /* this throttle group feature requires "QEMU_CAPS_OBJECT_JSON" + * when starting domain later, so check such flag here as well */ + if (virDomainObjIsActive(vm)) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_JSON)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("This QEMU doesn't support throttle group cre= ation")); + return -1; + } + } + + if (def) { + if (qemuDomainCheckThrottleGroupAllZero(&info) < 0) + goto endjob; + + if (qemuDomainCheckBlockIoTuneMax(&info) < 0) + goto endjob; + + cur_info =3D virDomainThrottleGroupByName(def, groupname); + /* Update existing group. */ + if (cur_info !=3D NULL) { + if (qemuDomainSetBlockIoTuneDefaults(&info, cur_info, set_fiel= ds) < 0) + goto endjob; + qemuDomainObjEnterMonitor(vm); + rc =3D qemuMonitorUpdateThrottleGroup(qemuDomainGetMonitor(vm), + groupname, + &info); + qemuDomainObjExitMonitor(vm); + if (rc < 0) + goto endjob; + virDomainThrottleGroupUpdate(def, &info); + } else { + /* prefix group name with "throttle-" in QOM */ + g_autofree char *prefixed_group_name =3D g_strdup_printf("thro= ttle-%s", groupname); + + if (qemuMonitorThrottleGroupLimits(limits, &info)<0) + goto endjob; + if (qemuMonitorCreateObjectProps(&props, + "throttle-group", prefixed_gr= oup_name, + "a:limits", &limits, + NULL) < 0) + goto endjob; + qemuDomainObjEnterMonitor(vm); + rc =3D qemuMonitorAddObject(qemuDomainGetMonitor(vm), &props, = NULL); + qemuDomainObjExitMonitor(vm); + if (rc < 0) + goto endjob; + virDomainThrottleGroupAdd(def, &info); + } + + qemuDomainSaveStatus(vm); + + if (eventNparams) { + event =3D virDomainEventTunableNewFromDom(dom, &eventParams, e= ventNparams); + virObjectEventStateQueue(driver->domainEventState, event); + } + } + + if (persistentDef) { + conf_cur_info =3D virDomainThrottleGroupByName(persistentDef, grou= pname); + + if (qemuDomainCheckThrottleGroupAllZero(&conf_info) < 0) + goto endjob; + + if (conf_cur_info !=3D NULL) { + if (qemuDomainSetBlockIoTuneDefaults(&conf_info, conf_cur_info, + set_fields) < 0) + goto endjob; + virDomainThrottleGroupUpdate(persistentDef, &conf_info); + } else { + virDomainThrottleGroupAdd(persistentDef, &conf_info); + } + + + if (virDomainDefSave(persistentDef, driver->xmlopt, + cfg->configDir) < 0) + goto endjob; + } + + ret =3D 0; + endjob: + virDomainObjEndJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + virTypedParamsFree(eventParams, eventNparams); + return ret; +} + + +static int +qemuDomainGetThrottleGroup(virDomainPtr dom, + const char *groupname, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + virDomainObj *vm =3D NULL; + virDomainDef *def =3D NULL; + virDomainDef *persistentDef =3D NULL; + virDomainThrottleGroupDef groupDef =3D { 0 }; + virDomainThrottleGroupDef *reply =3D &groupDef; + int ret =3D -1; + int maxparams =3D 0; + int rc =3D 0; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + if (virDomainGetThrottleGroupEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginJob(vm, VIR_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + if (def) { + if (virDomainThrottleGroupByName(def, groupname) =3D=3D NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("throttle group '%1$s' was not found in the d= omain config"), + groupname); + goto endjob; + } + qemuDomainObjEnterMonitor(vm); + rc =3D qemuMonitorGetThrottleGroup(qemuDomainGetMonitor(vm), group= name, reply); + qemuDomainObjExitMonitor(vm); + + if (rc < 0) + goto endjob; + } + + if (persistentDef) { + reply =3D virDomainThrottleGroupByName(persistentDef, groupname); + if (reply =3D=3D NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("throttle group '%1$s' was not found in the d= omain config"), + groupname); + goto endjob; + } + reply->group_name =3D g_strdup(groupname); + } + + *nparams =3D 0; + +#define THROTTLE_GROUP_ASSIGN(name, var) \ + if (virTypedParamsAddULLong(params, \ + nparams, \ + &maxparams, \ + VIR_DOMAIN_BLOCK_IOTUNE_ ## name, \ + reply->var) < 0) \ + goto endjob; + + + if (virTypedParamsAddString(params, nparams, &maxparams, + VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME, + reply->group_name) < 0) + goto endjob; + + THROTTLE_GROUP_ASSIGN(TOTAL_BYTES_SEC, total_bytes_sec); + THROTTLE_GROUP_ASSIGN(READ_BYTES_SEC, read_bytes_sec); + THROTTLE_GROUP_ASSIGN(WRITE_BYTES_SEC, write_bytes_sec); + + THROTTLE_GROUP_ASSIGN(TOTAL_IOPS_SEC, total_iops_sec); + THROTTLE_GROUP_ASSIGN(READ_IOPS_SEC, read_iops_sec); + THROTTLE_GROUP_ASSIGN(WRITE_IOPS_SEC, write_iops_sec); + + THROTTLE_GROUP_ASSIGN(TOTAL_BYTES_SEC_MAX, total_bytes_sec_max); + THROTTLE_GROUP_ASSIGN(READ_BYTES_SEC_MAX, read_bytes_sec_max); + THROTTLE_GROUP_ASSIGN(WRITE_BYTES_SEC_MAX, write_bytes_sec_max); + + THROTTLE_GROUP_ASSIGN(TOTAL_IOPS_SEC_MAX, total_iops_sec_max); + THROTTLE_GROUP_ASSIGN(READ_IOPS_SEC_MAX, read_iops_sec_max); + THROTTLE_GROUP_ASSIGN(WRITE_IOPS_SEC_MAX, write_iops_sec_max); + + THROTTLE_GROUP_ASSIGN(SIZE_IOPS_SEC, size_iops_sec); + + THROTTLE_GROUP_ASSIGN(TOTAL_BYTES_SEC_MAX_LENGTH, total_bytes_sec_max_= length); + THROTTLE_GROUP_ASSIGN(READ_BYTES_SEC_MAX_LENGTH, read_bytes_sec_max_le= ngth); + THROTTLE_GROUP_ASSIGN(WRITE_BYTES_SEC_MAX_LENGTH, write_bytes_sec_max_= length); + + THROTTLE_GROUP_ASSIGN(TOTAL_IOPS_SEC_MAX_LENGTH, total_iops_sec_max_le= ngth); + THROTTLE_GROUP_ASSIGN(READ_IOPS_SEC_MAX_LENGTH, read_iops_sec_max_leng= th); + THROTTLE_GROUP_ASSIGN(WRITE_IOPS_SEC_MAX_LENGTH, write_iops_sec_max_le= ngth); +#undef THROTTLE_GROUP_ASSIGN + + ret =3D 0; + + endjob: + virDomainObjEndJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +static int +qemuDomainCheckThrottleGroupRef(virDomainDef *def, + const char *group_name) +{ + size_t i; + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + if (virDomainThrottleFilterFind(disk, group_name)) { + virReportError(VIR_ERR_INVALID_ARG, + _("throttle group '%1$s' is still being used b= y disk %2$s"), + group_name, disk->dst); + return -1; + } + } + return 0; +} + + +static int +qemuDomainDelThrottleGroup(virDomainPtr dom, + const char *groupname, + unsigned int flags) +{ + virQEMUDriver *driver =3D dom->conn->privateData; + virDomainObj *vm =3D NULL; + virDomainDef *def =3D NULL; + virDomainDef *persistentDef =3D NULL; + g_autoptr(virQEMUDriverConfig) cfg =3D NULL; + int ret =3D -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return -1; + + if (virDomainDelThrottleGroupEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjBeginJob(vm, VIR_JOB_MODIFY) < 0) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto endjob; + + /* check if this group is still being used by disks, catch errors upfr= ont and + * avoid a partial success with error reported */ + if (def) { + if (qemuDomainCheckThrottleGroupRef(def, groupname) < 0) + goto endjob; + } + if (persistentDef) { + if (qemuDomainCheckThrottleGroupRef(persistentDef, groupname) < 0) + goto endjob; + } + + if (def) { + int rc =3D 0; + /* prefix group name with "throttle-" in QOM */ + g_autofree char *prefixed_group_name =3D g_strdup_printf("throttle= -%s", groupname); + + qemuDomainObjEnterMonitor(vm); + rc =3D qemuMonitorDelObject(qemuDomainGetMonitor(vm), prefixed_gro= up_name, true); + qemuDomainObjExitMonitor(vm); + + if (rc < 0) + goto endjob; + + virDomainThrottleGroupDel(def, groupname); + qemuDomainSaveStatus(vm); + } + + if (persistentDef) { + cfg =3D virQEMUDriverGetConfig(driver); + virDomainThrottleGroupDel(persistentDef, groupname); + if (virDomainDefSave(persistentDef, driver->xmlopt, + cfg->configDir) < 0) + goto endjob; + } + + ret =3D 0; + + endjob: + virDomainObjEndJob(vm); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static virHypervisorDriver qemuHypervisorDriver =3D { .name =3D QEMU_DRIVER_NAME, .connectURIProbe =3D qemuConnectURIProbe, @@ -20361,6 +20745,10 @@ static virHypervisorDriver qemuHypervisorDriver = =3D { .domainSetLaunchSecurityState =3D qemuDomainSetLaunchSecurityState, /*= 8.0.0 */ .domainFDAssociate =3D qemuDomainFDAssociate, /* 9.0.0 */ .domainGraphicsReload =3D qemuDomainGraphicsReload, /* 10.2.0 */ + .domainSetThrottleGroup =3D qemuDomainSetThrottleGroup, /* 10.7.0 */ + .domainGetThrottleGroup =3D qemuDomainGetThrottleGroup, /* 10.7.0 */ + .domainDelThrottleGroup =3D qemuDomainDelThrottleGroup, /* 10.7.0 */ + }; =20 =20 --=20 2.39.5 (Apple Git-154)