From nobody Sun May 5 06:12:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1595266424; cv=none; d=zohomail.com; s=zohoarc; b=PAaf3ZkESJwgDA75Z3ZXIwjtxLyPSctogzc2d2/Y5aQLrA2Chg1FyNu6yN1eYZe8bXaygaoogiShYEJzO4P99lGhpmmbZNCnNdLQu52oma9RLSLzLkTNbsgmT2BvpUXkyBPplcHbid11Jkxc8Jo61hF1FjlWZXoVcVtkIyUTDqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595266424; 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=efbkjVnkCO4s0Oekw9m8N1nJWWG1H3VDQc1dt63po/M=; b=Ovxzy8g/+lYJeWd5uexPfQCxtJ8Yjl4mY6JDf3UoE6bym2wezXApyFI5sVp+CBQMZjWti9IMSwaqT25UEm4VQ5m7nbds4mXXTA+hP/rUNg79e7Bn0ipy+hkMQQVIwJPePkbzw2iolAOMleqyJM6tVurT2tg04TVfqQEpKz88lZI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1595266424270778.1922089666065; Mon, 20 Jul 2020 10:33:44 -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-400-NjkgrNykO0u_Z3WPnqs1dA-1; Mon, 20 Jul 2020 13:33:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0851210059AA; Mon, 20 Jul 2020 17:33:35 +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 DA3F960F8D; Mon, 20 Jul 2020 17:33:34 +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 AA7681809563; Mon, 20 Jul 2020 17:33:34 +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 06KHXSbN020443 for ; Mon, 20 Jul 2020 13:33:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E7A02B6E2; Mon, 20 Jul 2020 17:33:28 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E56F19C66; Mon, 20 Jul 2020 17:33:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595266423; 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=efbkjVnkCO4s0Oekw9m8N1nJWWG1H3VDQc1dt63po/M=; b=BGOZU+Fe+5nfCzhvBBNzb16GZhso+2jumoMEmUWqEr3Pmhie/F/SOGVLq66NJh/vt+8a6u le8hszzvKUtyPW4oLI71B4VgaFqa4Oim5LRtlsP7ua245Wp8V1bTV+weUNvkx7p323TjhP BX5peH7rJ7yVVZsN3QCkDSB5XZIz4rI= X-MC-Unique: NjkgrNykO0u_Z3WPnqs1dA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/4] util: add a helper method for controlling the COW flag on btrfs Date: Mon, 20 Jul 2020 18:33:19 +0100 Message-Id: <20200720173322.839717-2-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.79 on 10.5.11.12 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) btrfs defaults to performing copy-on-write for files. This is often undesirable for VM images, so we need to be able to control whether this behaviour is used. The virFileSetCOW() will allow for this. We use a tristate, since out of the box, we want the default behaviour attempt to disable cow, but only on btrfs, silently do nothing on non-btrfs. If someone explicitly asks to disable/enable cow, then we want to raise a hard error on non-btrfs. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik Reviewed-by: Neal Gompa Reviewed-by: Peter Krempa --- src/libvirt_private.syms | 1 + src/util/virfile.c | 76 ++++++++++++++++++++++++++++++++++++++++ src/util/virfile.h | 3 ++ 3 files changed, 80 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 73b72c9e10..eea31a736d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2125,6 +2125,7 @@ virFileRewrite; virFileRewriteStr; virFileSanitizePath; virFileSetACLs; +virFileSetCOW; virFileSetupDev; virFileSetXAttr; virFileTouch; diff --git a/src/util/virfile.c b/src/util/virfile.c index 213acdbcaa..5b169b3d11 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -71,6 +71,7 @@ # endif # include # include +# include #endif =20 #if HAVE_LIBATTR @@ -4504,3 +4505,78 @@ virFileDataSync(int fd) return fdatasync(fd); #endif } + + +int +virFileSetCOW(const char *path, + virTristateBool state) +{ +#if __linux__ + int val =3D 0; + struct statfs buf; + VIR_AUTOCLOSE fd =3D -1; + + VIR_DEBUG("Setting COW flag on '%s' to '%s'", + path, virTristateBoolTypeToString(state)); + + fd =3D open(path, O_RDONLY|O_NONBLOCK|O_LARGEFILE); + if (fd < 0) { + virReportSystemError(errno, _("unable to open '%s'"), + path); + return -1; + } + + if (fstatfs(fd, &buf) < 0) { + virReportSystemError(errno, _("unable query filesystem type on '%s= '"), + path); + return -1; + } + + if (buf.f_type !=3D BTRFS_SUPER_MAGIC) { + if (state =3D=3D VIR_TRISTATE_BOOL_ABSENT) { + virReportSystemError(ENOSYS, + _("unable to control COW flag on '%s', no= t btrfs"), + path); + return -1; + } + return 0; + } + + if (ioctl(fd, FS_IOC_GETFLAGS, &val) < 0) { + virReportSystemError(errno, _("unable get directory flags on '%s'"= ), + path); + return -1; + } + + VIR_DEBUG("Current flags on '%s' are 0x%x", path, val); + if (state =3D=3D VIR_TRISTATE_BOOL_YES) { + val &=3D ~FS_NOCOW_FL; + } else { + val |=3D FS_NOCOW_FL; + } + + VIR_DEBUG("New flags on '%s' will be 0x%x", path, val); + if (ioctl(fd, FS_IOC_SETFLAGS, &val) < 0) { + int saved_err =3D errno; + VIR_DEBUG("Failed to set flags on '%s': %s", path, g_strerror(save= d_err)); + if (state !=3D VIR_TRISTATE_BOOL_ABSENT) { + virReportSystemError(saved_err, + _("unable control COW flag on '%s'"), + path); + return -1; + } else { + VIR_DEBUG("Ignoring failure to set COW"); + } + } + + return 0; +#else /* ! __linux__ */ + if (state !=3D VIR_TRISTATE_BOOL_ABSENT) { + virReportSystemError(ENOSYS, + _("Unable to set copy-on-write state on '%s' = to '%s'"), + path, virTristateBoolTypeToString(state)); + return -1; + } + return 0; +#endif /* ! __linux__ */ +} diff --git a/src/util/virfile.h b/src/util/virfile.h index 7a92364a5c..cb0e586a7d 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -374,3 +374,6 @@ int virFileRemoveXAttr(const char *path, G_GNUC_NO_INLINE; =20 int virFileDataSync(int fd); + +int virFileSetCOW(const char *path, + virTristateBool state); --=20 2.26.2 From nobody Sun May 5 06:12:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1595266427; cv=none; d=zohomail.com; s=zohoarc; b=a/dKl9jvVVO4eu3/lSKVxlSj57faqyW2LmzH6jUucWFE2S90Hmq8XoyHgO3rX2cmJIOSB37kT9lsFy9ZceXLwUcL3u47YqlUiGQeNd26/9oMYLs0cQJ3PUcvf9JMPwpQCAPUl/EGVb7VN7Mx5AqEm4wChrezKOcgVz4Pvr0xK0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595266427; 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=XqVLjOGmYjN1eOqkFzALC7oQZcg/9KzRnebAhlwcy9c=; b=WSbU5afs6z+4eKosbSpwVgzPlNuATuxO13ytmZLU6NSp3MZ3BOhd2mwtTXu45T4lTmarL/54ai5pQof0/op1qUCqeP0ZK2/0pCwo3r4/OWJI3ygcktqKxAwjU11huJaMRasi9sO7KFbjhVeCnV5DifVtia1W4j7KxjCUOd2co5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1595266427387752.5095125243778; Mon, 20 Jul 2020 10:33:47 -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-227-qnrRD8JaPq-pGdfJV3nKZQ-1; Mon, 20 Jul 2020 13:33:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6FEF4E91B; Mon, 20 Jul 2020 17:33:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4EF318730A; Mon, 20 Jul 2020 17:33:37 +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 1F5B89A135; Mon, 20 Jul 2020 17:33:37 +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 06KHXTmK020453 for ; Mon, 20 Jul 2020 13:33:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9CF7219C66; Mon, 20 Jul 2020 17:33:29 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id D61682DE89; Mon, 20 Jul 2020 17:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595266426; 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=XqVLjOGmYjN1eOqkFzALC7oQZcg/9KzRnebAhlwcy9c=; b=aiwG2o7fPY7K2UosysPspUl70nvS4vZDszY23rYzvVZCTVdn3f8NxnmgbN0AAME4QoUB7A YKmg5R+ZdDcqxmk5rAwdEW1mJgMf2P4R6Or/+Owj6lQQ69YsSvZ1J2Gkw4HU+MdaAH+ZHe 7QYZ54qBNs/LYhMuzUyNjlwIMYOIQKM= X-MC-Unique: qnrRD8JaPq-pGdfJV3nKZQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] storage: convert to use virFileSetCOW Date: Mon, 20 Jul 2020 18:33:20 +0100 Message-Id: <20200720173322.839717-3-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.79 on 10.5.11.13 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) When disabling COW on individual files, we now use the virFileSetCOW method. Note that this change has a slight semantic difference to the old implementation. The original code reported errors but returned success when disabling COW failed. With this new code, we will always report an error if the user requested disabling of COW and we could not honour it, either because btrfs returned an error, or because the filesystem is not btrfs. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik Reviewed-by: Neal Gompa Reviewed-by: Peter Krempa --- src/storage/storage_util.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index ee048f02fe..2595162a61 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -28,9 +28,6 @@ #ifdef __linux__ # include # include -# ifndef FS_NOCOW_FL -# define FS_NOCOW_FL 0x00800000 /* Do not cow file */ -# endif # define default_mount_opts "nodev,nosuid,noexec" #elif defined(__FreeBSD__) # define default_mount_opts "nosuid,noexec" @@ -456,25 +453,11 @@ storageBackendCreateRaw(virStoragePoolObjPtr pool, } created =3D true; =20 - if (vol->target.nocow) { -#ifdef __linux__ - int attr; - - /* Set NOCOW flag. This is an optimisation for btrfs. - * The FS_IOC_SETFLAGS ioctl return value will be ignored since any - * failure of this operation should not block the volume creation. - */ - if (ioctl(fd, FS_IOC_GETFLAGS, &attr) < 0) { - virReportSystemError(errno, "%s", _("Failed to get fs flags")); - } else { - attr |=3D FS_NOCOW_FL; - if (ioctl(fd, FS_IOC_SETFLAGS, &attr) < 0) { - virReportSystemError(errno, "%s", - _("Failed to set NOCOW flag")); - } - } -#endif - } + /* NB, COW flag can only be toggled when the file is zero-size, + * so must go before the createRawFile call allocates payload */ + if (vol->target.nocow && + virFileSetCOW(vol->target.path, VIR_TRISTATE_BOOL_NO) < 0) + goto cleanup; =20 if ((ret =3D createRawFile(fd, vol, inputvol, reflink_copy)) < 0) /* createRawFile already reported the exact error. */ --=20 2.26.2 From nobody Sun May 5 06:12:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1595266430; cv=none; d=zohomail.com; s=zohoarc; b=bae236GiFIoqQdl2gxwHIxugedUycnS89e54Nb9i0WkA+WXHFhyfk34py5MlkDkHIa4iHPzX9ZofAIudfxkOK2RaPWAiR/vyiBBBzLpHvyY1TSb16oVeSbTKQjOd4wIUV2gBN0fDg5Hh+2IG0ZNp9NMKrt02IgajQTd3iIlS+qY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595266430; 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=nZ7aXzU/OBeJ2CdiCsD/NHNd6baEGjfXBSw/xaNybYE=; b=H4wW3kr5O9M0kDDoF1zeXyfPrQg3lJmNzWbZ80nwvd8KQQhSc8le+Ri+alN8CQa/Prm/nKg3dhXH36SyKbAWfbrdFqKWlEBK91vd0B8yhidKHBf1pvVLNP8/Z2nvYMHw/QWcv8nrO0eZz1KKD87Zr/CNpJnV5aWUHgEsg2JKJjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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 [205.139.110.61]) by mx.zohomail.com with SMTPS id 1595266430735431.37457824823537; Mon, 20 Jul 2020 10:33:50 -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-58-iTMB2RuFOPGxGAu28LLGZQ-1; Mon, 20 Jul 2020 13:33:46 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D63ED800468; Mon, 20 Jul 2020 17:33:39 +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 B82C95C298; Mon, 20 Jul 2020 17:33:39 +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 869E91800FDD; Mon, 20 Jul 2020 17:33:39 +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 06KHXUin020461 for ; Mon, 20 Jul 2020 13:33:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id A1F8B2B6E2; Mon, 20 Jul 2020 17:33:30 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.36.110.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id F309B19C66; Mon, 20 Jul 2020 17:33:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595266429; 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=nZ7aXzU/OBeJ2CdiCsD/NHNd6baEGjfXBSw/xaNybYE=; b=JS1v5Z44oj4NzxDftLYKjaJ0numEQbbf8zHxaxnLHPiolwXPMtMO18Bs4TzOocWfrj1vyu fK64BECryiCIT+dwZEFNAlNQZG4Eq0P0mWuAz4nOL1dQRrFschKiHCxCDEPiEsLk/IaIes ErGa0T2STEkTyoFcaEWl5ZeeO255XFs= X-MC-Unique: iTMB2RuFOPGxGAu28LLGZQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/4] storage: attempt to disable COW by default Date: Mon, 20 Jul 2020 18:33:21 +0100 Message-Id: <20200720173322.839717-4-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.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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) This calls virFileSetCOW when building a pool with a request to attempt, but not require, COW to be disabled. The effect is that nothing changes on non-btrfs filesystems, but btrfs will get COW disabled on the directory. This setting is then inherited by all newly created files in the pool, avoiding the need for mgmt app to set "nocow" on a per-volume basis. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Michal Privoznik Reviewed-by: Neal Gompa Reviewed-by: Peter Krempa --- src/storage/storage_util.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 2595162a61..80b49bd1cf 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2712,6 +2712,7 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr pool) bool needs_create_as_uid; unsigned int dir_create_flags; g_autofree char *parent =3D NULL; + int ret; =20 parent =3D g_strdup(def->target.path); if (!(p =3D strrchr(parent, '/'))) { @@ -2745,11 +2746,19 @@ virStorageBackendBuildLocal(virStoragePoolObjPtr po= ol) /* Now create the final dir in the path with the uid/gid/mode * requested in the config. If the dir already exists, just set * the perms. */ - return virDirCreate(def->target.path, - mode, - def->target.perms.uid, - def->target.perms.gid, - dir_create_flags); + ret =3D virDirCreate(def->target.path, + mode, + def->target.perms.uid, + def->target.perms.gid, + dir_create_flags); + if (ret < 0) + return -1; + + if (virFileSetCOW(def->target.path, + VIR_TRISTATE_BOOL_ABSENT) < 0) + return -1; + + return 0; } =20 =20 --=20 2.26.2 From nobody Sun May 5 06:12:31 2024 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 Reviewed-by: Michal Privoznik Reviewed-by: Neal Gompa Reviewed-by: Peter Krempa --- 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