From nobody Sun Feb 8 14:56:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=git.sr.ht ARC-Seal: i=1; a=rsa-sha256; t=1689657157; cv=none; d=zohomail.com; s=zohoarc; b=iZY91nuv6gUStA+xm45mjIViHTmQcLWxmug2a0667xCNqJgx62SxfCjImetpZQHhJKJ1OhmOrbHtoytaf44fJcoADCBMwSnnGc7g1D5HvHI7yTTZhh7hAutNs2c18iDBrqCfv8TX99iAD17d/iA/IcFYQdQVpYkmcZkXJcu+/YY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689657157; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=8xxoY5hC7F+CC2/48HHtjENXZF2W+vHmK+E12or4hWk=; b=JhWtey8d6Bsgwf91+yXxwLPUnn+q1YGzAatDSvPWXHzO9fTR7wjQNIoYCVjdF5X5Ceu9+MeskNDuNsimEmLflho9ch/TebocAnPPUps6Srqd9zu1qiLcSHU2B26Ad7xVb18NcDl3jXoZB8ywa/BvaGQQXbsFj3qCEPcR3ppoYnI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1689657157789286.55230058565155; Mon, 17 Jul 2023 22:12:37 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-166-_lgn1ASAPZqJjYl8FBb-RQ-1; Tue, 18 Jul 2023 01:12:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CBE971044599; Tue, 18 Jul 2023 05:12:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55A2C1121314; Tue, 18 Jul 2023 05:12:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B981C1946A43; Tue, 18 Jul 2023 05:12:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F3406194658D for ; Tue, 18 Jul 2023 05:12:24 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E7B0FF66A0; Tue, 18 Jul 2023 05:12:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast10.extmail.prod.ext.rdu2.redhat.com [10.11.55.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFAD7F6CCA for ; Tue, 18 Jul 2023 05:12:23 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4E161C05155 for ; Tue, 18 Jul 2023 05:12:23 +0000 (UTC) Received: from mail-b.sr.ht (mail-b.sr.ht [173.195.146.151]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92-9GcnpaDnNYGL0zOE6Zu_OA-1; Tue, 18 Jul 2023 01:12:20 -0400 Received: from git.sr.ht (unknown [173.195.146.142]) by mail-b.sr.ht (Postfix) with ESMTPSA id C80E811EEF9 for ; Tue, 18 Jul 2023 05:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689657156; h=from:from:sender:sender:reply-to: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: in-reply-to:in-reply-to:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=8xxoY5hC7F+CC2/48HHtjENXZF2W+vHmK+E12or4hWk=; b=WiIWPQoQAobeQOOcGR3e+s2FxFHwHpv6gz6YYFTE8E02URNGAYWxIivguNNuehA9NOCj86 4IDeWh31KlDnfalZtJk44x098TSogd6KZ7C9gszAT+YsSQmxyGcxRj3Ymt7859wEplJ63V 9AoGxijHGslVMWBWHuzGb9N+G1bnjck= X-MC-Unique: _lgn1ASAPZqJjYl8FBb-RQ-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 9GcnpaDnNYGL0zOE6Zu_OA-1 From: ~hyman Date: Sun, 16 Jul 2023 22:36:21 +0800 Subject: [PATCH Libvirt v2 1/3] conf: Add 'virtio_discard' and 'virtio_write_zeroes' attributes MIME-Version: 1.0 Message-ID: <168965713958.6380.15816724194528301257-1@git.sr.ht> In-Reply-To: <168965713958.6380.15816724194528301257-0@git.sr.ht> To: libvir-list@redhat.com X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ~hyman Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: git.sr.ht Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1689657160106100001 From: Hyman Huang(=E9=BB=84=E5=8B=87) Add 'virtio_discard' and 'virtio_write_zeroes' attribute to control whether discard and write-zeroes requests are handled by the virtio-blk device. To distinguish the attributes in block drive layer, use the 'virtio' prefix to indicate that these attributes are specific for virtio-blk. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- docs/formatdomain.rst | 8 ++++++++ src/conf/domain_conf.c | 16 ++++++++++++++++ src/conf/domain_conf.h | 2 ++ src/conf/schemas/domaincommon.rng | 10 ++++++++++ src/conf/storage_source_conf.c | 2 ++ src/conf/storage_source_conf.h | 2 ++ src/qemu/qemu_domain.c | 2 ++ src/qemu/qemu_driver.c | 4 +++- src/vz/vz_utils.c | 12 ++++++++++++ 9 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 4af0b82569..7be12ff08e 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3259,6 +3259,14 @@ paravirtualized driver is specified via the ``disk``= element. value can be either "unmap" (allow the discard request to be passed)= or "ignore" (ignore the discard request). :since:`Since 1.0.6 (QEMU and= KVM only)` + - The optional ``virtio_discard`` and ``virtio_write_zeroes`` are attr= ibutes + that control whether discard and write-zeroes requests are handled b= y the + virtio-blk device. The feature is based on DISCARD and WRITE_ZEROES + commands introduced in virtio-blk protocol to improve performance wh= en + using SSD backend. The value can be either 'on' or 'off'. Note that + ``discard`` and ``write_zeroes`` implementations in the block drive = layer + are parts of the feature logically and should be turned on when enab= ling + the feature. :since:`Since 9.6.0 (QEMU and KVM only)` - The optional ``detect_zeroes`` attribute controls whether to detect = zero write requests. The value can be "off", "on" or "unmap". First two v= alues turn the detection off and on, respectively. The third value ("unmap= ") diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5ac5c0b771..0f82b489f4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7813,6 +7813,14 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, VIR_XML_PROP_NONZERO, &def->discard) < 0) return -1; =20 + if (virXMLPropTristateSwitch(cur, "virtio_discard", VIR_XML_PROP_NONE, + &def->virtio_discard) < 0) + return -1; + + if (virXMLPropTristateSwitch(cur, "virtio_write_zeroes", VIR_XML_PROP_= NONE, + &def->virtio_write_zeroes) < 0) + return -1; + if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONZERO, &def->io= thread) < 0) return -1; =20 @@ -22514,6 +22522,14 @@ virDomainDiskDefFormatDriver(virBuffer *buf, virBufferAsprintf(&attrBuf, " discard=3D'%s'", virDomainDiskDiscardTypeToString(disk->discard)); =20 + if (disk->virtio_discard) + virBufferAsprintf(&attrBuf, " virtio_discard=3D'%s'", + virTristateSwitchTypeToString(disk->virtio_disca= rd)); + + if (disk->virtio_write_zeroes) + virBufferAsprintf(&attrBuf, " virtio_write_zeroes=3D'%s'", + virTristateSwitchTypeToString(disk->virtio_write= _zeroes)); + if (disk->iothread) virBufferAsprintf(&attrBuf, " iothread=3D'%u'", disk->iothread); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c857ba556f..86e955333e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -607,6 +607,8 @@ struct _virDomainDiskDef { unsigned int iothread; /* unused =3D 0, > 0 specific thread # */ virDomainDiskDetectZeroes detect_zeroes; virTristateSwitch discard_no_unref; + virTristateSwitch virtio_discard; + virTristateSwitch virtio_write_zeroes; char *domain_name; /* backend domain name */ unsigned int queues; unsigned int queue_size; diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index c2f56b0490..c3a59aeb15 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -2510,6 +2510,16 @@ + + + + + + + + + + diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index dcac3a8ff6..c2fee652f3 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -810,6 +810,8 @@ virStorageSourceCopy(const virStorageSource *src, def->discard =3D src->discard; def->detect_zeroes =3D src->detect_zeroes; def->discard_no_unref =3D src->discard_no_unref; + def->virtio_discard =3D src->virtio_discard; + def->virtio_write_zeroes =3D src->virtio_write_zeroes; def->sslverify =3D src->sslverify; def->readahead =3D src->readahead; def->timeout =3D src->timeout; diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index f13e7c756a..5e7f093fc0 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -400,6 +400,8 @@ struct _virStorageSource { int discard; /* enum virDomainDiskDiscard */ int detect_zeroes; /* enum virDomainDiskDetectZeroes */ virTristateSwitch discard_no_unref; + virTristateSwitch virtio_discard; + virTristateSwitch virtio_write_zeroes; =20 bool floppyimg; /* set to true if the storage source is going to be us= ed as a source for floppy drive */ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 3700b3e711..634d8699d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11031,6 +11031,8 @@ qemuDomainPrepareDiskSourceData(virDomainDiskDef *d= isk, src->cachemode =3D disk->cachemode; src->discard =3D disk->discard; src->discard_no_unref =3D disk->discard_no_unref; + src->virtio_discard =3D disk->virtio_discard; + src->virtio_write_zeroes =3D disk->virtio_write_zeroes; =20 if (disk->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY) src->floppyimg =3D true; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f20544590d..43e157da68 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14243,9 +14243,11 @@ qemuDomainBlockCopyCommon(virDomainObj *vm, * Since 'mirror' has the ambition to replace it we need to propagate * it into the mirror too. We do it directly as otherwise we'd need * to modify all callers of 'qemuDomainPrepareStorageSourceBlockdev' - * Same for discard_no_unref */ + * Same for discard_no_unref,virtio_discard and virtio_write_zeroes */ mirror->detect_zeroes =3D disk->detect_zeroes; mirror->discard_no_unref =3D disk->discard_no_unref; + mirror->virtio_discard =3D disk->virtio_discard; + mirror->virtio_write_zeroes =3D disk->virtio_write_zeroes; =20 /* If reusing an external image that includes a backing file but the u= ser * did not enumerate the chain in the XML we need to detect the chain = */ diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c index 7db7dbd419..1d824a9d2b 100644 --- a/src/vz/vz_utils.c +++ b/src/vz/vz_utils.c @@ -353,6 +353,18 @@ vzCheckDiskUnsupportedParams(virDomainDiskDef *disk) return -1; } =20 + if (disk->virtio_discard) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Disk virtio_discard is not supported by vz drive= r.")); + return -1; + } + + if (disk->virtio_write_zeroes) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Disk virtio_write_zeroes is not supported by vz = driver.")); + return -1; + } + if (disk->startupPolicy !=3D VIR_DOMAIN_STARTUP_POLICY_DEFAULT) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Setting up disk startup policy is not " --=20 2.38.5 From nobody Sun Feb 8 14:56:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=git.sr.ht ARC-Seal: i=1; a=rsa-sha256; t=1689657162; cv=none; d=zohomail.com; s=zohoarc; b=XgWUpmSn3X5Po/smkMwyCeCA0xQptnCnYcHNt60OSH7fGJz5uGxgIxcqnza4cOCEU7rCLNBvvEztnsUPcP0rtX+Nq2RxGTXdtTMlsBFp6tMli/ACp/0xx7DpH6Jv07vEiQPCEreLRtAXmvGWKw1HeFDv/IPruQxxZJxNrPRkoUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1689657162; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Z8iOz1HDQTY1NaUfvTTvCp1zQBPvDeYwznW6b8GdUK0=; b=GNUl6ECp4YDbPQcgmh3V6B9+Tcl16b3aAwn21ZK4iSYPnw9M4os2XPzFf2NcW7LFwp2zi3bUB5vKW9H74yS9ZHBEgDHJdg6tBJsGkeXueZvAoJhLPSLmEXdiOTg9JvO208NO4CPuSn097MOnA7Rh8oQ7epGch8txy0nL9dii1aI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1689657162362911.0738061351435; Mon, 17 Jul 2023 22:12:42 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-543-UcFy71OiNXiqM1WYlvVnwA-1; Tue, 18 Jul 2023 01:12:35 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D04C38D1698; Tue, 18 Jul 2023 05:12:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFAB3200C0F2; Tue, 18 Jul 2023 05:12:28 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 741D8194658F; Tue, 18 Jul 2023 05:12:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id EECFE1946588 for ; Tue, 18 Jul 2023 05:12:26 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8F5BEF6CCD; Tue, 18 Jul 2023 05:12:26 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast08.extmail.prod.ext.rdu2.redhat.com [10.11.55.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4D0ED7D552 for ; Tue, 18 Jul 2023 05:12:26 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F8413815EE2 for ; Tue, 18 Jul 2023 05:12:26 +0000 (UTC) Received: from mail-b.sr.ht (mail-b.sr.ht [173.195.146.151]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-270-cYK2n3gCOryaOnvH0L-ahA-1; Tue, 18 Jul 2023 01:12:20 -0400 Received: from git.sr.ht (unknown [173.195.146.142]) by mail-b.sr.ht (Postfix) with ESMTPSA id ECE4711EFF7 for ; Tue, 18 Jul 2023 05:12:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689657161; h=from:from:sender:sender:reply-to: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: in-reply-to:in-reply-to:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=Z8iOz1HDQTY1NaUfvTTvCp1zQBPvDeYwznW6b8GdUK0=; b=JfUyq2YeUjXU5WF+Fr/HUtnO6KI4prN2wSmz6wCJ9LOgQOO5f3ZSxHfmPJoHP9vvoIsEfN 9Z3lXouFSIWCwtnuQ/Uhbkk19RrewNMVwECH4IQqKqD2VyP587fqwgLuLzlW8a/E/LaFvg 3oSoJdVV/T+ALTbb7nz+z3w118PsGyo= X-MC-Unique: UcFy71OiNXiqM1WYlvVnwA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: cYK2n3gCOryaOnvH0L-ahA-1 From: ~hyman Date: Mon, 17 Jul 2023 00:19:45 +0800 Subject: [PATCH Libvirt v2 2/3] qemu_command: Generate cmd line for discard and write-zeroes properties MIME-Version: 1.0 Message-ID: <168965713958.6380.15816724194528301257-2@git.sr.ht> In-Reply-To: <168965713958.6380.15816724194528301257-0@git.sr.ht> To: libvir-list@redhat.com X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: ~hyman Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: git.sr.ht Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1689657164012100003 From: Hyman Huang(=E9=BB=84=E5=8B=87) Generate cmd line for virtio-blk.discard and virtio-blk.write-zeroes properties. Also, validate that the requested feature is supported by QEMU. Signed-off-by: Hyman Huang(=E9=BB=84=E5=8B=87) --- src/qemu/qemu_command.c | 2 + src/qemu/qemu_validate.c | 9 +++ .../disk-virtio-discard.x86_64-latest.args | 45 ++++++++++++++ .../qemuxml2argvdata/disk-virtio-discard.xml | 45 ++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../disk-virtio-discard.x86_64-latest.xml | 58 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 7 files changed, 161 insertions(+) create mode 100644 tests/qemuxml2argvdata/disk-virtio-discard.x86_64-lates= t.args create mode 100644 tests/qemuxml2argvdata/disk-virtio-discard.xml create mode 100644 tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-lat= est.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ad224571f3..6954fc5d75 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1834,6 +1834,8 @@ qemuBuildDiskDeviceProps(const virDomainDef *def, "T:scsi", scsi, "p:num-queues", disk->queues, "p:queue-size", disk->queue_size, + "T:discard", disk->virtio_discard, + "T:write-zeroes", disk->virtio_write_zer= oes, NULL) < 0) return NULL; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 7e09e2c52f..499b49ce74 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2949,6 +2949,15 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDom= ainDiskDef *disk, } } =20 + if (disk->virtio_discard || disk->virtio_write_zeroes) { + if (disk->bus !=3D VIR_DOMAIN_DISK_BUS_VIRTIO) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("virtio_discard and virtio_write_zeroes optio= ns are " + "only valid for VIRTIO bus")); + return -1; + } + } + switch (disk->bus) { case VIR_DOMAIN_DISK_BUS_SCSI: if (disk->info.type !=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { diff --git a/tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args = b/tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args new file mode 100644 index 0000000000..ee7a7edc9c --- /dev/null +++ b/tests/qemuxml2argvdata/disk-virtio-discard.x86_64-latest.args @@ -0,0 +1,45 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=3DQEMUGuest1,debug-threads=3Don \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/va= r/lib/libvirt/qemu/domain--1-QEMUGuest1/master-key.aes"}' \ +-machine pc,usb=3Doff,dump-guest-core=3Doff,memory-backend=3Dpc.ram,acpi= =3Doff \ +-accel tcg \ +-cpu qemu64 \ +-m size=3D219136k \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}'= \ +-overcommit mem-lock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,fd=3D1729,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-boot strict=3Don \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0= x2"}' \ +-blockdev '{"driver":"file","filename":"/tmp/data.img","node-name":"libvir= t-4-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-4-format","read-only":false,"driver":"raw= ","file":"libvirt-4-storage"}' \ +-device '{"driver":"virtio-blk-pci","discard":true,"write-zeroes":true,"bu= s":"pci.0","addr":"0x2","drive":"libvirt-4-format","id":"virtio-disk0","boo= tindex":1}' \ +-blockdev '{"driver":"file","filename":"/tmp/data1.img","node-name":"libvi= rt-3-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-3-format","read-only":false,"driver":"raw= ","file":"libvirt-3-storage"}' \ +-device '{"driver":"virtio-blk-pci","discard":true,"write-zeroes":false,"b= us":"pci.0","addr":"0x3","drive":"libvirt-3-format","id":"virtio-disk1"}' \ +-blockdev '{"driver":"file","filename":"/tmp/data2.img","node-name":"libvi= rt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,"driver":"raw= ","file":"libvirt-2-storage"}' \ +-device '{"driver":"virtio-blk-pci","discard":false,"write-zeroes":true,"b= us":"pci.0","addr":"0x4","drive":"libvirt-2-format","id":"virtio-disk2"}' \ +-blockdev '{"driver":"file","filename":"/tmp/data3.img","node-name":"libvi= rt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw= ","file":"libvirt-1-storage"}' \ +-device '{"driver":"virtio-blk-pci","discard":false,"write-zeroes":false,"= bus":"pci.0","addr":"0x5","drive":"libvirt-1-format","id":"virtio-disk3"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","add= r":"0x6"}' \ +-sandbox on,obsolete=3Ddeny,elevateprivileges=3Ddeny,spawn=3Ddeny,resource= control=3Ddeny \ +-msg timestamp=3Don diff --git a/tests/qemuxml2argvdata/disk-virtio-discard.xml b/tests/qemuxml= 2argvdata/disk-virtio-discard.xml new file mode 100644 index 0000000000..cd6ec6a51d --- /dev/null +++ b/tests/qemuxml2argvdata/disk-virtio-discard.xml @@ -0,0 +1,45 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 534eb9e699..9c7ff63ff1 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1420,6 +1420,7 @@ mymain(void) DO_TEST_CAPS_LATEST("net-vdpa"); DO_TEST_CAPS_LATEST("net-vdpa-multiqueue"); DO_TEST_CAPS_LATEST("net-virtio-rss"); + DO_TEST_CAPS_LATEST("disk-virtio-discard"); =20 DO_TEST("hostdev-pci-multifunction", QEMU_CAPS_KVM, diff --git a/tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml= b/tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml new file mode 100644 index 0000000000..9895fe13fb --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-virtio-discard.x86_64-latest.xml @@ -0,0 +1,58 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + qemu64 + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + + +
+ + + + + +
+ + + + + +
+ + + + + +
+ + +
+ + +
+ + + + +