Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1B2BAC25B78 for ; Wed, 29 May 2024 02:34:24 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sC98B-00075i-QU; Tue, 28 May 2024 22:33:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sC98A-00075W-81; Tue, 28 May 2024 22:33:34 -0400 Received: from mgamail.intel.com ([192.198.163.15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sC988-000184-1J; Tue, 28 May 2024 22:33:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716950012; x=1748486012; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=JgDlSwe1FXWB1FK6idf15AhPLY2bmiRr1vnduoZmYrM=; b=lBWi5p2TcCxVEdYbtI1FxSS89mAm/vPwX2fOrKKUHHbANyHDtbUCkf9L RjlP4FKvKAOE+KAgo9lGkjoiWmYg6WnBvN9P16PRR9bpC8mWY1W5AdVIx 8MzrDE1JcTXU4TnDJPRu2ynHS4FyHkQnnO72FSK+HsGtbJ4oxLSQ4MEvv ff1rDUKpwDYsQTO0DPU08jRcD8sJeWsaG8EVr2Y3ARhXC9OT6FkbkYbxd TevEJjWjmxILTc5GvHZN4aO6oY0+VWhxczULl4YEUhJkr75JVvtHFchvq vIzglu8ygEnEI5oVJayXsDR7+iXkfejFOn9WZL2sDACtQmVxPPK6YBkXi g==; X-CSE-ConnectionGUID: GE6dMSkaT/ud98oDPl0vwQ== X-CSE-MsgGUID: atNOhtGxRIWYiYrzcHhnWA== X-IronPort-AV: E=McAfee;i="6600,9927,11085"; a="13515322" X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="13515322" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 19:33:26 -0700 X-CSE-ConnectionGUID: ///mfHj7SsW6JMYEKmDRJw== X-CSE-MsgGUID: eW7do7QATG64ow+PS9vkDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,197,1712646000"; d="scan'208";a="35356223" Received: from leiwang7-mobl.ccr.corp.intel.com (HELO [10.124.244.145]) ([10.124.244.145]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2024 19:33:24 -0700 Message-ID: <02a0f82a-9681-4a44-97d7-6b2cc77342da@intel.com> Date: Wed, 29 May 2024 10:33:21 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] prealloc: add truncate mode for prealloc filter To: "Denis V. Lunev" , qemu-block@nongnu.org, qemu-devel@nongnu.org Cc: Alexander Ivanov , Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy References: <20240430170510.148812-1-den@openvz.org> From: "Wang, Lei" Content-Language: en-US In-Reply-To: <20240430170510.148812-1-den@openvz.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=192.198.163.15; envelope-from=lei4.wang@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 5/1/2024 1:05, Denis V. Lunev via wrote: > Preallocate filter allows to implement really interesting setups. > > Assume that we have > * shared block device, f.e. iSCSI LUN, implemented with some HW device > * clustered LVM on top of it > * QCOW2 image stored inside LVM volume > > This allows very cheap clustered setups with all QCOW2 features intact. > Currently supported setups using QCOW2 with data_file option are not > so cool as snapshots are not allowed, QCOW2 should be placed into some > additional distributed storage and so on. > > Though QCOW2 inside LVM volume has a drawback. The image is growing and > in order to accomodate that image LVM volume is to be resized. This > could be done externally using ENOSPACE event/condition but this is > cumbersome. > > This patch introduces native implementation for such a setup. We should > just put prealloc filter in between QCOW2 format and file nodes. In that > case LVM will be resized at proper moment and that is done effectively > as resizing is done in chinks. > > The patch adds allocation mode for this purpose in order to distinguish > 'fallocate' for ordinary file system and 'truncate'. > > Signed-off-by: Denis V. Lunev > CC: Alexander Ivanov > CC: Kevin Wolf > CC: Hanna Reitz > CC: Vladimir Sementsov-Ogievskiy > --- > block/preallocate.c | 50 +++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 48 insertions(+), 2 deletions(-) > > diff --git a/block/preallocate.c b/block/preallocate.c > index 4d82125036..6d31627325 100644 > --- a/block/preallocate.c > +++ b/block/preallocate.c > @@ -33,10 +33,24 @@ > #include "block/block-io.h" > #include "block/block_int.h" > > +typedef enum PreallocateMode { > + PREALLOCATE_MODE_FALLOCATE = 0, > + PREALLOCATE_MODE_TRUNCATE = 1, > + PREALLOCATE_MODE__MAX = 2, > +} PreallocateMode; > + > +static QEnumLookup prealloc_mode_lookup = { > + .array = (const char *const[]) { > + "falloc", > + "truncate", > + }, > + .size = PREALLOCATE_MODE__MAX, > +}; > > typedef struct PreallocateOpts { > int64_t prealloc_size; > int64_t prealloc_align; > + PreallocateMode prealloc_mode; > } PreallocateOpts; > > typedef struct BDRVPreallocateState { > @@ -79,6 +93,7 @@ typedef struct BDRVPreallocateState { > > #define PREALLOCATE_OPT_PREALLOC_ALIGN "prealloc-align" > #define PREALLOCATE_OPT_PREALLOC_SIZE "prealloc-size" > +#define PREALLOCATE_OPT_MODE "mode" Why not keeping the names consistent, I mean: #define PREALLOCATE_OPT_PREALLOC_MODE "prealloc-mode" > static QemuOptsList runtime_opts = { > .name = "preallocate", > .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head), > @@ -94,7 +109,14 @@ static QemuOptsList runtime_opts = { > .type = QEMU_OPT_SIZE, > .help = "how much to preallocate, default 128M", > }, > - { /* end of list */ } > + { > + .name = PREALLOCATE_OPT_MODE, > + .type = QEMU_OPT_STRING, > + .help = "Preallocation mode on image expansion " > + "(allowed values: falloc, truncate)", > + .def_value_str = "falloc", > + }, > + { /* end of list */ }, > }, > }; > > @@ -102,6 +124,8 @@ static bool preallocate_absorb_opts(PreallocateOpts *dest, QDict *options, > BlockDriverState *child_bs, Error **errp) > { > QemuOpts *opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort); > + Error *local_err = NULL; > + char *buf; > > if (!qemu_opts_absorb_qdict(opts, options, errp)) { > return false; > @@ -112,6 +136,17 @@ static bool preallocate_absorb_opts(PreallocateOpts *dest, QDict *options, > dest->prealloc_size = > qemu_opt_get_size(opts, PREALLOCATE_OPT_PREALLOC_SIZE, 128 * MiB); > > + buf = qemu_opt_get_del(opts, PREALLOCATE_OPT_MODE); > + /* prealloc_mode can be downgraded later during allocate_clusters */ > + dest->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf, > + PREALLOCATE_MODE_FALLOCATE, > + &local_err); > + g_free(buf); > + if (local_err != NULL) { > + error_propagate(errp, local_err); > + return false; > + } > + > qemu_opts_del(opts); > > if (!QEMU_IS_ALIGNED(dest->prealloc_align, BDRV_SECTOR_SIZE)) { > @@ -335,9 +370,20 @@ handle_write(BlockDriverState *bs, int64_t offset, int64_t bytes, > > want_merge_zero = want_merge_zero && (prealloc_start <= offset); > > - ret = bdrv_co_pwrite_zeroes( > + switch (s->opts.prealloc_mode) { > + case PREALLOCATE_MODE_FALLOCATE: > + ret = bdrv_co_pwrite_zeroes( > bs->file, prealloc_start, prealloc_end - prealloc_start, > BDRV_REQ_NO_FALLBACK | BDRV_REQ_SERIALISING | BDRV_REQ_NO_WAIT); > + break; > + case PREALLOCATE_MODE_TRUNCATE: > + ret = bdrv_co_truncate(bs->file, prealloc_end, false, > + PREALLOC_MODE_OFF, 0, NULL); > + break; > + default: > + return false; > + } > + > if (ret < 0) { > s->file_end = ret; > return false;