From nobody Mon Sep 8 17:04:31 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1752758293; cv=none; d=zohomail.com; s=zohoarc; b=kQxSl10Mo0wem9IDuErb/Tc+ioHso0uIE7XRHZGnJzVsF4PWhUWAZtFZn5QgeH9GFZmLfa8kMMUUhGSoPJwwXI5YfzjXmsMcGxrQ9YnSxSDWYk6XL7SS01FJr4/HwI9Do2kyxW0XwNGqPxsNCchQNgCXdW2cN6FBmqoQEXtndpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752758293; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id:Cc; bh=F22nOT+hDvrA24rp/orVKCAfiue4EdVRuM1V3jbBukc=; b=W8I4Ebqn+LdwCvdtVXRF5+IX+X017asWoR/gI7SyI7iOO3LnXqyoAYIcUIr+aVgS8G1eNELfYePVB9CFK30mxYV1K0rBJ5ufxTXDyd9j/3qmxbuJVRgamQ2j17C+vcyJbbolqc5OXIAwzNYQLCQ+VDw9muOFoQmkwBh93X/Lmfs= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1752758293855685.8233603622757; Thu, 17 Jul 2025 06:18:13 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C5620E31; Thu, 17 Jul 2025 09:18:12 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5FF6DE00; Thu, 17 Jul 2025 09:17:46 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7CB45A5C; Thu, 17 Jul 2025 09:17:43 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 D6669AE2 for ; Thu, 17 Jul 2025 09:17:42 -0400 (EDT) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-Y_WZIej9MPqTP6mlAGpSAw-1; Thu, 17 Jul 2025 09:17:41 -0400 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4562985ac6aso10128515e9.3 for ; Thu, 17 Jul 2025 06:17:40 -0700 (PDT) Received: from wheatley.localdomain ([85.93.96.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4562e7f2d4fsm52533625e9.4.2025.07.17.06.17.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Jul 2025 06:17:38 -0700 (PDT) Received: from wheatley.pinto-pinecone.ts.net (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 0FE15C3E1A13 for ; Thu, 17 Jul 2025 15:17:38 +0200 (CEST) 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_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752758262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=U40jUUwroXJmabUK5q0s6kuI5qJiIUkX5uNktdR3oX4=; b=co0XT+kOQzKZA2mzAab91mkkZXzBw+yCd7RAqOJTatihWdmHX8x66dPJTU7Rq90ExFqZx2 uGfG2Q7R8UVIiI6jBXmillKUe4zuNn+vvQF6mIB2dW+I+3oTLtkBLRBVLf1YrYDfgrJByI 6PTnAxAmg7XGdQmlMauy6jodGZmv7es= X-MC-Unique: Y_WZIej9MPqTP6mlAGpSAw-1 X-Mimecast-MFC-AGG-ID: Y_WZIej9MPqTP6mlAGpSAw_1752758260 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752758260; x=1753363060; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U40jUUwroXJmabUK5q0s6kuI5qJiIUkX5uNktdR3oX4=; b=ZwQdSV/kD02uftofWwy+WI0JzyV7+h4V1RTCszTN8anFqmoj9M2obbAQ++14QtvH/Y q2BDDfoQlrq5XMmezzvoTejrjHx8zYY7p/Q1M1mATr03dEiwvQ2zR24+knZIF2C4jQzN 0LrFWBHgIBE4GgbgEjnHzNbdDQWbDoTScuoIFfvoKx+Er9UwPNet0r0NpzvZVixjXT2F GkJEYwvBLI0twX0XcOll22fZuIUOAl4rCWg9+e3Xz0LzjjvECT0zSVcEvTt4fJZ2WD+V UVLnwKqYhhRFy2X9/gG2x3aWYT5kuweDWhCv3/pQyJ4WbnZlY416FWuUgqhmBmBy+2E8 lDvw== X-Gm-Message-State: AOJu0Yzh5XxK0x6FOZdEawgBeW2yzzFlWyAVM9ZYuu899CQi0gD1fakU LvEYPtFkgzwA+XIC9ux7xikYcUimBv1/XEksiQ5bbwrNL7AmFwbG9j88Il5GiRmOcyxojO8HIvm sU+YPhv92J/P8hwGXvzXgnDULmyzTj70+2TnSQyiJDtXtGcnsp7Net1ibuNOJiuGXICAf8Q/mZv 4glR+C7mF5kLYBvDL3b/EVwYkoNhcU3I7Wd7NyXcfaD3I= X-Gm-Gg: ASbGncugaN0Xq1LU+5zJT8fq6kJCIqzmEedcxqTlgfKPOgIG0pk7rTdrUyDK1KlaiQ2 KfqsCm5ygepqxpLCW6H/9kxTclJGrmEcIBT78mAfjzJCqCSaCwMJJtoxH4Sc0Q9+I/5x9vUUHQs rqelTmaf8tV7l0yKgr7w3leRym5FirDAGqhKgETgGYSL9ndVUg0dZ1mx8nuOquX0DGoxu6x0oRc zHsvFxn36UOhK2iaTC3xg3tm9NmDrwdIaiTERAfDnPBD4eCYuGdUhefekL3PNUBp5hNciwr7IrB ZHcaPPNvpYPThGXSC53zqvRrPMv4bXqqq5lc+CY4OMUu3XZe X-Received: by 2002:a5d:588f:0:b0:3a4:d64a:3df6 with SMTP id ffacd0b85a97d-3b60e4c914amr5490108f8f.3.1752758259699; Thu, 17 Jul 2025 06:17:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGsJVUUD/Mp887fIdvscdY56xwGB84Kr2DcSkAwkGkQUwp7W7xyteT6GS8NvWIMsmU7vHRZHw== X-Received: by 2002:a5d:588f:0:b0:3a4:d64a:3df6 with SMTP id ffacd0b85a97d-3b60e4c914amr5490072f8f.3.1752758259072; Thu, 17 Jul 2025 06:17:39 -0700 (PDT) To: devel@lists.libvirt.org Subject: [PATCH] Allow specifying zero discard granularity for block devices Date: Thu, 17 Jul 2025 15:14:36 +0200 Message-ID: X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lt36lD2tfxQLLjySwoqG3Lm_AxuJw-Hv6mu1ny3pvTk_1752758260 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: L3CSDUPJ7HS4SI3VQ7RVEHR4PBRVMOSG X-Message-ID-Hash: L3CSDUPJ7HS4SI3VQ7RVEHR4PBRVMOSG X-MailFrom: mkletzan@redhat.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 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: From: Martin Kletzander via Devel Reply-To: Martin Kletzander X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1752758295946116600 Content-Type: text/plain; charset="utf-8"; x-default="true" From: Martin Kletzander That allows for disabling discard in a way that some guest OSes (e.g. Windows) understand and do not try to trim the disk. Resolves: https://issues.redhat.com/browse/RHEL-72006 Signed-off-by: Martin Kletzander Reviewed-by: Peter Krempa --- Out of all the approaches for allowing previously default value 100% of the= m are ugly. This one is maybe slightly more error-prone. src/conf/domain_conf.c | 12 ++++++++---- src/conf/domain_conf.h | 1 + src/conf/domain_validate.c | 2 +- src/qemu/qemu_command.c | 7 ++++++- tests/qemuxmlconftest.c | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bfc62b62705f..ba0d4a7b128c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8554,6 +8554,8 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, } =20 if ((blockioNode =3D virXPathNode("./blockio", ctxt))) { + int tmp =3D 0; + if (virXMLPropUInt(blockioNode, "logical_block_size", 10, VIR_XML_= PROP_NONE, &def->blockio.logical_block_size) < 0) return NULL; @@ -8562,9 +8564,11 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, &def->blockio.physical_block_size) < 0) return NULL; =20 - if (virXMLPropUInt(blockioNode, "discard_granularity", 10, VIR_XML= _PROP_NONE, - &def->blockio.discard_granularity) < 0) + if ((tmp =3D virXMLPropUInt(blockioNode, "discard_granularity", 10= , VIR_XML_PROP_NONE, + &def->blockio.discard_granularity)) < 0) return NULL; + if (tmp > 0) + def->blockio.discard_granularity_specified =3D true; } =20 if ((driverNode =3D virXPathNode("./driver", ctxt))) { @@ -23102,7 +23106,7 @@ virDomainDiskBlockIoDefFormat(virBuffer *buf, { if (def->blockio.logical_block_size > 0 || def->blockio.physical_block_size > 0 || - def->blockio.discard_granularity > 0) { + def->blockio.discard_granularity_specified) { virBufferAddLit(buf, "blockio.logical_block_size > 0) { virBufferAsprintf(buf, @@ -23114,7 +23118,7 @@ virDomainDiskBlockIoDefFormat(virBuffer *buf, " physical_block_size=3D'%u'", def->blockio.physical_block_size); } - if (def->blockio.discard_granularity > 0) { + if (def->blockio.discard_granularity_specified) { virBufferAsprintf(buf, " discard_granularity=3D'%u'", def->blockio.discard_granularity); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6997cf7c09be..6008ec66d3fe 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -560,6 +560,7 @@ struct _virDomainDiskDef { unsigned int logical_block_size; unsigned int physical_block_size; unsigned int discard_granularity; + bool discard_granularity_specified; } blockio; =20 virDomainBlockIoTuneInfo blkdeviotune; diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b28af7fa5618..8f7259a0e1ed 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -462,7 +462,7 @@ virDomainDiskVhostUserValidate(const virDomainDiskDef *= disk) =20 if (disk->blockio.logical_block_size > 0 || disk->blockio.physical_block_size > 0 || - disk->blockio.discard_granularity > 0) { + disk->blockio.discard_granularity_specified) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("blockio is not supported with vhostuser disk")); return -1; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7658cc4d395a..fc6ce4dd9143 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1899,7 +1899,6 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, "S:loadparm", bootLoadparm, "p:logical_block_size", logical_block_size, "p:physical_block_size", physical_block_size, - "p:discard_granularity", discard_granularity, "A:wwn", &wwn, "p:rotation_rate", disk->rotation_rate, "S:vendor", disk->vendor, @@ -1917,6 +1916,12 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, NULL) < 0) return NULL; =20 + if (disk->blockio.discard_granularity_specified && + virJSONValueObjectAdd(&props, + "u:discard_granularity", discard_granularity, + NULL) < 0) + return NULL; + return g_steal_pointer(&props); } =20 diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index 9fba98429019..ae8efd58f8ac 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -1694,6 +1694,7 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-ide-wwn"); DO_TEST_CAPS_LATEST("disk-geometry"); DO_TEST_CAPS_LATEST("disk-blockio"); + DO_TEST_CAPS_LATEST("disk-blockio-no-discard"); =20 driver.config->storageUseNbdkit =3D 1; DO_TEST_CAPS_LATEST_NBDKIT("disk-cdrom-network-nbdkit", QEMU_NBDKIT_CA= PS_PLUGIN_CURL); --=20 2.50.1