From nobody Sat Jan 4 23:44:19 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 173375111531647.07926735437104; Mon, 9 Dec 2024 05:31:55 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id DF776B24; Mon, 9 Dec 2024 08:28:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D354811E5; Mon, 9 Dec 2024 08:20:15 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2CA2D11CC; Mon, 9 Dec 2024 07:42:47 -0500 (EST) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 4B1F011BE for ; Mon, 9 Dec 2024 07:42:46 -0500 (EST) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-21628b3fe7dso18901385ad.3 for ; Mon, 09 Dec 2024 04:42:46 -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.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 09 Dec 2024 04:42:44 -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=1733748165; x=1734352965; 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=0SuqAboSe4y8YVJiA3nCOtTsdr1EJdCPWOpF2FhaaU4=; b=L7p4xB4SHfx5CzRDVyoNfZpiofwpmWZ9Ng78UtcS16oBi02lBHX4DQeW7xTf7qHynN qkY/WhPUTHucKxTubgLecbta5K9xn07CEjaU3wz6M9QbBO4NdoddsCVm7q4/Y+H80YFW XSDs7B8Lg9OAKWjUXkeBL0SDCRKAqPnSzeR6vppEBHtXr6AxsZC0u/iC9CDy0Yyo878o EcE18581UkNkb3btJyFIi3WGAuLSmTNR8F9u1KzqOre2GIpBY7w83+vdPy2KvJgOYHL/ nnBH0Ga7okQIQaxPDutcYcMJxRods+/H1iAPHGcEv3WrqAI2Reu3ug8WuIOa1kI6HdAk pDYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733748165; x=1734352965; 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=0SuqAboSe4y8YVJiA3nCOtTsdr1EJdCPWOpF2FhaaU4=; b=ZhJzhHOtquInrEifH5x0P/FulaUAwzOcm6EVQ26lsokw2FQbvd6bf0BjC0h4camv9D e0br1aJmkuawvxQJggxvfsmqfFl3z1YBMWkT/b4XqsS0bLWonl6OC6vgGiUGU6uiv8D0 9Gxn+aA3ssA4fk5BQCa33c099FNUsPxD7X3/xb5ZipwO4LEpEg1ZPHmpPHz5ywJFWqb+ 1ZEVpxRiJ5mV8FdmRoyM/1srHNXoMhDSkMq1tsaW70bzBdORbSDPbBAc/XpRoWQF0LfZ 7qvFP/mIdSewjh5lzCnhhbLdUsBhn5xdNnfqw5NBZFnS+gulz2hDEE40zoqzgQ2zSVZu B0Bg== X-Gm-Message-State: AOJu0Yx01xuU2El4rlhyfFNonz8XkBZ8UaLNTj3yX8MSC5s2tharJogm Q+YLMC5SQrAJKIPMtzC1mVwKRynjFt3Ga5/oNID8NDjxmBtBOYnsOORmKkvL X-Gm-Gg: ASbGncvLXD0tF3FFdIg3dz4rdL1dIEM7TMK3bjSbDgM6yaUDDlgfxgVhVwPfw4t2gR3 aAQeD80pyuFokv7XvQvgdKtCsNJxrw6S168t2hl8tp5i3gu6wWxf9WG14u/pVFpxsc3Va4B+z1Q 2G624US5vMScwO85kO/u1MRR9GTA/xABKJiqmpZo0NgHkdLmIpE9OJMLIRV6VDbBxFC6wEtEped BtsC/G4FET15hoHhf9XshvkC2ogvGs2CWoC+fuWR2i/7leLWUxT75gVYrAlMWPMyE/NWW4229K8 NwZ6Cg== X-Google-Smtp-Source: AGHT+IGBmKzM3YZM0316hE9jgxBV4RyitLQuc+8eRpjzDZATFCFpOBXI9GUelbW8+ELvX7R4VASN+g== X-Received: by 2002:a17:902:e5d0:b0:216:48f4:4f1a with SMTP id d9443c01a7336-21648f450e1mr66589905ad.16.1733748164776; Mon, 09 Dec 2024 04:42:44 -0800 (PST) From: Harikumar R To: devel@lists.libvirt.org Subject: [PATCH v6 11/18] qemu: block: Support block disk along with throttle filters Date: Mon, 9 Dec 2024 18:11:11 +0530 Message-Id: <20241209124118.39471-12-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: RVJ3KD44J6VX7SBZK5JQ2WPN2NUUWYCK X-Message-ID-Hash: RVJ3KD44J6VX7SBZK5JQ2WPN2NUUWYCK X-Mailman-Approved-At: Mon, 09 Dec 2024 13:19:48 -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: 1733751117757116600 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 a209452594..92363c64e9 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)) @@ -10440,6 +10536,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 3c18af6b0c..855ce9ca44 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); @@ -4653,6 +4669,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; @@ -4691,6 +4708,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)