From nobody Sat Feb 7 15:09:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1595266431; cv=none; d=zohomail.com; s=zohoarc; b=PcB9pIJoPNopEvZPjOKRCOsmRwSR8IAUNG3XWZX9F0v2VGa5iUo1JziWfAFiRX6CJC11/99ntJ09Zz+QXj9sathfs8cLC/yi07MYfoVbnia+npAEa7sYbS2Zur0f90ltgy2qMeeV6uZ7s4dX81hS0TyPPXQBILDde0DwCOOn5g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595266431; 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:References:Sender:Subject:To; bh=4MxUvDrvd2dZUrlFcj+QuX23NT4LcpDf896ljvEhnEM=; b=kl78WEoyhoyFUU6GJfT8ZTTysWunQjHtfloeVq5mX8Xqcdhu3tN6VD8qbEbQnTkN+MxSocJkGGXeK3qRH7sKmDhATKCgqU/t5mc8PTfmNe7dcW7WjMGr8UAmaLKWrwXv9zXesLV/mKTFCFgg3GsmqPI3joiHEyBeETISDPbKipA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1595266431291312.85408667823447; Mon, 20 Jul 2020 10:33:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-395-r3ADK_0rPFSVNmj44CDsMQ-1; Mon, 20 Jul 2020 13:33:47 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 420301923761; Mon, 20 Jul 2020 17:33:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E1331002391; Mon, 20 Jul 2020 17:33:42 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DFE2C1806B0C; Mon, 20 Jul 2020 17:33:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06KHXV3a020471 for ; Mon, 20 Jul 2020 13:33:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9AD62DE81; Mon, 20 Jul 2020 17:33:31 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08DD919C66; Mon, 20 Jul 2020 17:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595266430; h=from:from:sender:sender: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:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4MxUvDrvd2dZUrlFcj+QuX23NT4LcpDf896ljvEhnEM=; b=fWlfAmyooUaWYeeqtpVv74vmgSXF7Uu2/WWVZdULlwPtg082+rlVZqOucwcX77VJZ2Vt1i VyjSTLpqO3HM12RcNuKKySY87LyTlwowyjD7r6cwQ/JiKLs4FtEmYhi2mzecUa5YbfYBTG 4QFeBsRfVvwQJYKyXQk2YKm6/9oNP5Y= X-MC-Unique: r3ADK_0rPFSVNmj44CDsMQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/4] conf: add control over COW for storage pool directories Date: Mon, 20 Jul 2020 18:33:22 +0100 Message-Id: <20200720173322.839717-5-berrange@redhat.com> In-Reply-To: <20200720173322.839717-1-berrange@redhat.com> References: <20200720173322.839717-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The storage pool code now attempts to disable COW by default on btrfs, but management applications may wish to override this behaviour. Thus we introduce a concept of storage pool features: If the feature policy is set, it will be enforced. It will always return an hard error if COW cannot be explicitly set or unset. Signed-off-by: Daniel P. Berrang=C3=A9 --- docs/formatstorage.html.in | 25 ++++++++++ docs/schemas/storagepool.rng | 30 ++++++++++++ src/conf/storage_conf.c | 49 ++++++++++++++++++++ src/conf/storage_conf.h | 8 ++++ src/storage/storage_util.c | 2 +- tests/storagepoolxml2xmlin/pool-dir-cow.xml | 10 ++++ tests/storagepoolxml2xmlout/pool-dir-cow.xml | 15 ++++++ tests/storagepoolxml2xmltest.c | 1 + 8 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2xmlin/pool-dir-cow.xml create mode 100644 tests/storagepoolxml2xmlout/pool-dir-cow.xml diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index 2a7604d136..7493714c5c 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -67,6 +67,31 @@ pool. Since 0.4.1 =20 +

Features

+ +

+ Some pools support optional features: +

+ +
+...
+<features>
+  <cow state=3D'no'>
+</features>
+...
+ +

+ Valid features are: +

+
    +
    cow
    +
    Controls whether the filesystem performs copy-on-write (COW) for + images in the pool. This may only be set for directory / filesystem + pools on the btrfs filesystem. If not set then libvirt + will attempt to disable COW on any btrfs filesystems. + Since 6.6.0.
    +
+

Source elements

=20

diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index ff0d3c836c..f5cf6769c8 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -37,6 +37,7 @@ + @@ -49,6 +50,7 @@ + @@ -64,6 +66,7 @@ + @@ -79,6 +82,7 @@ + @@ -91,6 +95,7 @@ + @@ -103,6 +108,7 @@ + @@ -117,6 +123,7 @@ + @@ -128,6 +135,7 @@ + @@ -140,6 +148,7 @@ + @@ -154,6 +163,7 @@ + @@ -169,6 +179,7 @@ + @@ -180,6 +191,7 @@ + @@ -191,6 +203,7 @@ + @@ -205,6 +218,7 @@ + @@ -277,6 +291,22 @@ =20 + + + + + + + + + + + + + + + + diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 65d9b33049..4e63865b39 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -839,6 +839,33 @@ virStoragePoolDefRefreshFormat(virBufferPtr buf, } =20 =20 +static int +virStoragePoolDefParseFeatures(virStoragePoolDefPtr def, + xmlXPathContextPtr ctxt) +{ + g_autofree char *cow =3D virXPathString("string(./features/cow/@state)= ", ctxt); + + if (cow) { + int val; + if (def->type !=3D VIR_STORAGE_POOL_FS && + def->type !=3D VIR_STORAGE_POOL_DIR) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("cow feature may only be used for 'fs' and 'd= ir' pools")); + return -1; + } + if ((val =3D virTristateBoolTypeFromString(cow)) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid storage pool cow feature state '%s'"= ), + cow); + return -1; + } + def->features.cow =3D val; + } + + return 0; +} + + virStoragePoolDefPtr virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) { @@ -910,6 +937,9 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) } } =20 + if (virStoragePoolDefParseFeatures(def, ctxt) < 0) + return NULL; + if (options->flags & VIR_STORAGE_POOL_SOURCE_HOST) { if (!def->source.nhost) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -1131,6 +1161,23 @@ virStoragePoolSourceFormat(virBufferPtr buf, } =20 =20 +static void +virStoragePoolDefFormatFeatures(virBufferPtr buf, + virStoragePoolDefPtr def) +{ + if (!def->features.cow) + return; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + if (def->features.cow) + virBufferAsprintf(buf, "\n", + virTristateBoolTypeToString(def->features.cow)); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); +} + + static int virStoragePoolDefFormatBuf(virBufferPtr buf, virStoragePoolDefPtr def) @@ -1166,6 +1213,8 @@ virStoragePoolDefFormatBuf(virBufferPtr buf, virBufferAsprintf(buf, "%llu\n", def->available); =20 + virStoragePoolDefFormatFeatures(buf, def); + if (virStoragePoolSourceFormat(buf, options, &def->source) < 0) return -1; =20 diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index daa21a127b..ffd406e093 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -180,6 +180,13 @@ struct _virStoragePoolSourceDevice { } geometry; }; =20 +typedef struct _virStoragePoolFeatures virStoragePoolFeatures; +typedef virStoragePoolFeatures *virStoragePoolFeaturesPtr; +struct _virStoragePoolFeatures { + virTristateBool cow; +}; + + typedef struct _virStoragePoolSource virStoragePoolSource; typedef virStoragePoolSource *virStoragePoolSourcePtr; struct _virStoragePoolSource { @@ -256,6 +263,7 @@ struct _virStoragePoolDef { unsigned long long capacity; /* bytes */ unsigned long long available; /* bytes */ =20 + virStoragePoolFeatures features; virStoragePoolSource source; virStoragePoolTarget target; =20 diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 80b49bd1cf..f7c09e3375 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2755,7 +2755,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) return -1; =20 if (virFileSetCOW(def->target.path, - VIR_TRISTATE_BOOL_ABSENT) < 0) + def->features.cow) < 0) return -1; =20 return 0; diff --git a/tests/storagepoolxml2xmlin/pool-dir-cow.xml b/tests/storagepoo= lxml2xmlin/pool-dir-cow.xml new file mode 100644 index 0000000000..2217f2b8e3 --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-dir-cow.xml @@ -0,0 +1,10 @@ + + vms + 751f8e7e-d2e9-463d-8ffe-d38f5e13a19b + + + + + /i/cant/believe/its/not/btrfs + + diff --git a/tests/storagepoolxml2xmlout/pool-dir-cow.xml b/tests/storagepo= olxml2xmlout/pool-dir-cow.xml new file mode 100644 index 0000000000..2f3fe1f909 --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-dir-cow.xml @@ -0,0 +1,15 @@ + + vms + 751f8e7e-d2e9-463d-8ffe-d38f5e13a19b + 0 + 0 + 0 + + + + + + + /i/cant/believe/its/not/btrfs + + diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 382a7c659f..f21f20357a 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -62,6 +62,7 @@ mymain(void) =20 DO_TEST("pool-dir"); DO_TEST("pool-dir-naming"); + DO_TEST("pool-dir-cow"); DO_TEST("pool-fs"); DO_TEST("pool-logical"); DO_TEST("pool-logical-nopath"); --=20 2.26.2