From nobody Thu Nov 21 16:25:25 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 1731939493291818.6273966420167; Mon, 18 Nov 2024 06:18:13 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3840A1AC6; Mon, 18 Nov 2024 09:18:12 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5736D1AAF; Mon, 18 Nov 2024 09:10:44 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id A2AF719F9; Mon, 18 Nov 2024 08:55:16 -0500 (EST) Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) (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 CC1C41A06 for ; Mon, 18 Nov 2024 08:55:15 -0500 (EST) Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-7ae3d7222d4so2456230a12.3 for ; Mon, 18 Nov 2024 05:55:15 -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.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 18 Nov 2024 05:55:13 -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=1731938114; x=1732542914; 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=INPmrj1SDVUtiKjmFXN6nNhccLkrLMZ2WTGqX0s5Yzs=; b=lGhpAJMRjvYj35IPcdD5LUfW98WHj/7F+66GQ9r+kmFZu2lVDeXA1HsAenQnaRBLFy 5BqHcwtNNatXZpE930mYl2ocCn4GYMsUv2ToKk0E2geUyB7kBeffIDDXIm9Axdv8c4S+ 652K6RejIJc4W7yd7TOzKH6o4t/3Ylit/bw4sPfpc8NgzVM1b9GimNMDI4dGLsLqoPUK sFfx2V6TVebTj/WCUY2VJDv1s8Oun30gRjEjRjUJNy3Hr7sXkQbuhuoGcKWyMWr/IYI0 h/oZ98/xbUg7rXdRrnIk9QEfw0huqB2tUhtG9MoW4ydBGZC54kBPpJcw85JMOkjE9ZBy 23aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731938114; x=1732542914; 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=INPmrj1SDVUtiKjmFXN6nNhccLkrLMZ2WTGqX0s5Yzs=; b=aD4oodQb9BO1TUzBZzMTiKhHYBzjo398XwjJKRV6SxIaXddxL8iwacEF8lkEao4Ipu 1QWG7JlrJ0lID++Y6GE9a7mvaQNtOcBGNRWSVbGSry8sT1pPPWdz2T8STwFVj0eguvqG 4c1VnZQf1cpA1KmNtnW1S1BXMLAC1DGwXCsr/o3Y4B4LW1bQocQFtI7AYSFHbWk7XdPT qegVYeVMJlpdF+LNkYpLnU1HIw7QNv1uNBBk986fEAp8WFxYmV6QoudXUMPumHSTRYLj D54yL7f1FNzB/GHE2hrXm0zLA4zW2mXNYgQPhU8Ccx8080toUBRUbBBbq41liE+qx7a0 NPwQ== X-Gm-Message-State: AOJu0YzhyTgWeH7pSj9VCu7oIezTuUKdyZx1H8I+Q4v9b0eSw2xGMnR0 ipqggEFci75rZywLner4UEfNbVVTIoGMU9w/nJp4QCXsZJnAKUgvAMX6bPAf X-Google-Smtp-Source: AGHT+IHH/NlYHB05ZyMdbKcnMaJPnNX7m5IFrdl92ADZvr+kQ8JMwHs+SEZCEc7wGN1foWfZ/jhmww== X-Received: by 2002:a05:6a20:a104:b0:1db:de89:5d18 with SMTP id adf61e73a8af0-1dc90b0350bmr16144878637.1.1731938114297; Mon, 18 Nov 2024 05:55:14 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v5 11/18] qemu: block: Support block disk along with throttle filters Date: Mon, 18 Nov 2024 19:24:19 +0530 Message-Id: <20241118135426.37643-12-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: P6X34L7AUNYZERDTWAEXD2E65ONN5T7B X-Message-ID-Hash: P6X34L7AUNYZERDTWAEXD2E65ONN5T7B X-Mailman-Approved-At: Mon, 18 Nov 2024 14:10:18 -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: 1731939495238116600 Content-Type: text/plain; charset="utf-8" From: Chun Feng Wu For hot attaching/detaching * Leverage qemuBlockThrottleFiltersData to prepare attaching/detaching throttle filter data for qemuMonitorBlockdevAdd and qemuMonitorBlockdevDel * For hot attaching, within qemuDomainAttachDiskGeneric,prepare throttle filters json data, and create corresponding blockdev for QMP request ("blockdev-add" with "driver":"throttle") * Each filter has a nodename, and those filters are chained up, create them in sequence, and delete them reversely * Delete filters by "qemuBlockThrottleFiltersDetach"("blockdev-del") when detaching device For throttle group commandline * Add qemuBuildThrottleGroupCommandLine in qemuBuildCommandLine to add "object" of throttle-group * Verify throttle group definition when lauching vm * Check QEMU_CAPS_OBJECT_JSON before "qemuBuildObjectCommandlineFromJSON", which is to build "-object" option For throttle filter commandline * Add qemuBuildDiskThrottleFiltersCommandLine in qemuBuildDiskCommandLine to add "blockdev" Signed-off-by: Chun Feng Wu --- src/qemu/qemu_command.c | 99 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.c | 25 +++++++++++ 2 files changed, 124 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0c119c8827..19c8ab1b7f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2022,6 +2022,99 @@ qemuBuildBlockStorageSourceAttachDataCommandline(vir= Command *cmd, } =20 =20 +static bool +qemuDiskConfigThrottleGroupEnabled(const virDomainThrottleGroupDef *group) +{ + return !!group->group_name && + virDomainBlockIoTuneInfoHasAny(group); +} + + +/** + * qemuBuildThrottleGroupCommandLine: + * @cmd: the command to modify + * @def: domain definition + * @qemuCaps: qemu capabilities object + * + * build throttle group object in json format + */ +static int +qemuBuildThrottleGroupCommandLine(virCommand *cmd, + const virDomainDef *def, + virQEMUCaps *qemuCaps) +{ + size_t i; + + for (i =3D 0; i < def->nthrottlegroups; i++) { + g_autoptr(virJSONValue) props =3D NULL; + g_autoptr(virJSONValue) limits =3D virJSONValueNewObject(); + virDomainThrottleGroupDef *group =3D def->throttlegroups[i]; + /* prefix group name with "throttle-" in QOM */ + g_autofree char *prefixed_group_name =3D g_strdup_printf("throttle= -%s", group->group_name); + + if (!qemuDiskConfigThrottleGroupEnabled(group)) { + continue; + } + + if (qemuMonitorThrottleGroupLimits(limits, group) < 0) + return -1; + + if (qemuMonitorCreateObjectProps(&props, "throttle-group", prefixe= d_group_name, + "a:limits", &limits, + NULL) < 0) + return -1; + + /* this throttle group feature requires "QEMU_CAPS_OBJECT_JSON" */ + 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 (qemuBuildObjectCommandlineFromJSON(cmd, props, qemuCaps) < 0) + return -1; + } + + return 0; +} + + +static int +qemuBuildBlockThrottleFilterCommandline(virCommand *cmd, + qemuBlockThrottleFilterAttachData = *data) +{ + if (data->filterProps) { + g_autofree char *tmp =3D NULL; + if (!(tmp =3D virJSONValueToString(data->filterProps, false))) + return -1; + + virCommandAddArgList(cmd, "-blockdev", tmp, NULL); + } + + return 0; +} + + +static int +qemuBuildDiskThrottleFiltersCommandLine(virCommand *cmd, + virDomainDiskDef *disk) +{ + g_autoptr(qemuBlockThrottleFiltersData) data =3D NULL; + size_t i; + + data =3D qemuBuildThrottleFiltersAttachPrepareBlockdev(disk); + if (!data) + return -1; + + for (i =3D 0; i < data->nfilterdata; i++) { + if (qemuBuildBlockThrottleFilterCommandline(cmd, + data->filterdata[i]) <= 0) + return -1; + } + + return 0; +} + + static int qemuBuildDiskSourceCommandLine(virCommand *cmd, virDomainDiskDef *disk, @@ -2079,6 +2172,9 @@ qemuBuildDiskCommandLine(virCommand *cmd, if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0) return -1; =20 + if (qemuBuildDiskThrottleFiltersCommandLine(cmd, disk) < 0) + return -1; + /* SD cards are currently instantiated via -drive if=3Dsd, so the -dev= ice * part must be skipped */ if (qemuDiskBusIsSD(disk->bus)) @@ -10435,6 +10531,9 @@ qemuBuildCommandLine(virDomainObj *vm, if (qemuBuildIOThreadCommandLine(cmd, def, qemuCaps) < 0) return NULL; =20 + if (qemuBuildThrottleGroupCommandLine(cmd, def, qemuCaps) < 0) + return NULL; + if (virDomainNumaGetNodeCount(def->numa) && qemuBuildNumaCommandLine(cfg, def, cmd, priv) < 0) return NULL; diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index bddd553c88..bf001aa902 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -708,6 +708,7 @@ qemuDomainAttachDiskGeneric(virDomainObj *vm, virDomainAsyncJob asyncJob) { g_autoptr(qemuBlockStorageSourceChainData) data =3D NULL; + g_autoptr(qemuBlockThrottleFiltersData) filterData =3D NULL; qemuDomainObjPrivate *priv =3D vm->privateData; g_autoptr(virJSONValue) devprops =3D NULL; bool extensionDeviceAttached =3D false; @@ -746,6 +747,19 @@ qemuDomainAttachDiskGeneric(virDomainObj *vm, if (rc < 0) goto rollback; =20 + /* Setup throttling filters + * add additional "blockdev-add"(throttle filter) between "blockde= v-add" (qemuBlockStorageSourceChainAttach) and "device_add" (qemuDomainAtta= chExtensionDevice) + */ + if ((filterData =3D qemuBuildThrottleFiltersAttachPrepareBlockdev(= disk))) { + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + /* QMP requests("blockdev-add" with "driver":"throttle") to QE= MU */ + rc =3D qemuBlockThrottleFiltersAttach(priv->mon, filterData); + qemuDomainObjExitMonitor(vm); + if (rc < 0) + goto rollback; + } + if (disk->transient) { g_autoptr(qemuBlockStorageSourceAttachData) backend =3D NULL; g_autoptr(GHashTable) blockNamedNodeData =3D NULL; @@ -817,6 +831,8 @@ qemuDomainAttachDiskGeneric(virDomainObj *vm, if (extensionDeviceAttached) ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &disk->inf= o)); =20 + qemuBlockThrottleFiltersDetach(priv->mon, filterData); + qemuBlockStorageSourceChainDetach(priv->mon, data); =20 qemuDomainObjExitMonitor(vm); @@ -4642,6 +4658,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver, { qemuDomainDiskPrivate *diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); g_autoptr(qemuBlockStorageSourceChainData) diskBackend =3D NULL; + g_autoptr(qemuBlockThrottleFiltersData) filterData =3D NULL; size_t i; qemuDomainObjPrivate *priv =3D vm->privateData; int ret =3D -1; @@ -4680,6 +4697,14 @@ qemuDomainRemoveDiskDevice(virQEMUDriver *driver, } } =20 + qemuDomainObjEnterMonitor(vm); + /* QMP request("blockdev-del") to QEMU to delete throttle filter*/ + if ((filterData =3D qemuBuildThrottleFiltersDetachPrepareBlockdev(disk= ))) { + /* "qemuBlockThrottleFiltersDetach" is used in rollback within "qe= muDomainAttachDiskGeneric" as well */ + qemuBlockThrottleFiltersDetach(priv->mon, filterData); + } + qemuDomainObjExitMonitor(vm); + qemuDomainObjEnterMonitor(vm); =20 if (diskBackend) --=20 2.39.5 (Apple Git-154)