All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, qemu-block@nongnu.org, qemu-stable@nongnu.org,
	Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>,
	Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>,
	Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Subject: [PATCH 03/13] block/preallocate: collect the state assignments in one place
Date: Wed, 30 Sep 2026 18:49:49 +0200	[thread overview]
Message-ID: <20260930165000.303236-4-den@openvz.org> (raw)
In-Reply-To: <20260930165000.303236-1-den@openvz.org>

From: Denis V. Lunev <den@openvz.org>

The filter invalidates or re-establishes data_end, zero_start and
file_end together in six places, each spelling out the same chained
assignment. Put them in one function, so that a change to what the
state consists of is one edit rather than six.

No functional change.

Signed-off-by: Denis V. Lunev <den@openvz.org>
Cc: qemu-stable@nongnu.org
CC: Kevin Wolf <kwolf@redhat.com>
CC: Hanna Reitz <hreitz@redhat.com>
CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
CC: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
 block/preallocate.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/block/preallocate.c b/block/preallocate.c
index 99bd6b1ae7..8cd98684f4 100644
--- a/block/preallocate.c
+++ b/block/preallocate.c
@@ -104,6 +104,11 @@ static QemuOptsList runtime_opts = {
     },
 };
 
+static void preallocate_set_state(BDRVPreallocateState *s, int64_t v)
+{
+    s->file_end = s->zero_start = s->data_end = v;
+}
+
 static bool preallocate_absorb_opts(PreallocateOpts *dest, QDict *options,
                                     BlockDriverState *child_bs, Error **errp)
 {
@@ -149,7 +154,7 @@ static int preallocate_open(BlockDriverState *bs, QDict *options, int flags,
      * s->data_end and friends should be initialized on permission update.
      * For this to work, mark them invalid.
      */
-    s->file_end = s->zero_start = s->data_end = -EINVAL;
+    preallocate_set_state(s, -EINVAL);
     s->drop_resize_bh = qemu_bh_new(preallocate_drop_resize_bh, bs);
 
     ret = bdrv_open_file_child(NULL, options, "file", bs, errp);
@@ -480,12 +485,12 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t offset,
 
     ret = bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp);
     if (ret < 0) {
-        s->file_end = s->zero_start = s->data_end = ret;
+        preallocate_set_state(s, ret);
         return ret;
     }
 
     if (has_prealloc_perms(bs)) {
-        s->file_end = s->zero_start = s->data_end = offset;
+        preallocate_set_state(s, offset);
     }
     return 0;
 }
@@ -508,7 +513,7 @@ preallocate_co_getlength(BlockDriverState *bs)
     ret = bdrv_co_getlength(bs->file->bs);
 
     if (has_prealloc_perms(bs)) {
-        s->file_end = s->zero_start = s->data_end = ret;
+        preallocate_set_state(s, ret);
     }
 
     return ret;
@@ -539,7 +544,7 @@ preallocate_drop_resize(BlockDriverState *bs, Error **errp)
      * change the child, so mark all states invalid. We'll regain control if a
      * parent requests write access again.
      */
-    s->data_end = s->file_end = s->zero_start = -EINVAL;
+    preallocate_set_state(s, -EINVAL);
 
     bdrv_child_refresh_perms(bs, bs->file, NULL);
 
@@ -566,8 +571,8 @@ preallocate_set_perm(BlockDriverState *bs, uint64_t perm, uint64_t shared)
     if (can_write_resize(perm)) {
         qemu_bh_cancel(s->drop_resize_bh);
         if (s->data_end < 0) {
-            s->data_end = s->file_end = s->zero_start =
-                bs->file->bs->total_sectors * BDRV_SECTOR_SIZE;
+            preallocate_set_state(s,
+                    bs->file->bs->total_sectors * BDRV_SECTOR_SIZE);
         }
     } else {
         qemu_bh_schedule(s->drop_resize_bh);
-- 
2.53.0



  parent reply	other threads:[~2026-09-30 16:51 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30 16:49 [PATCH 00/13] block: fix data loss in the preallocate filter Denis V. Lunev
2026-09-30 16:49 ` [PATCH 01/13] block/file-posix: drop the XFS workaround for post-EOF fallocate Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 02/13] block/preallocate: keep zero_start above written data Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` Denis V. Lunev [this message]
2026-10-02 16:16   ` [PATCH 03/13] block/preallocate: collect the state assignments in one place Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 04/13] block/preallocate: serialise the filter state Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 05/13] block/preallocate: hold back writes into a preallocation in flight Denis V. Lunev
2026-10-02 16:16   ` Andrey Drobyshev
2026-09-30 16:49 ` [PATCH 06/13] iotests/298: add testcase for async writes with preallocation filter Denis V. Lunev
2026-09-30 16:49 ` [PATCH 07/13] tests/unit: prefix the iothread test helper Denis V. Lunev
2026-10-05 20:06   ` Eric Blake
2026-09-30 16:49 ` [PATCH 08/13] qemu-io: accept --object iothread Denis V. Lunev
2026-10-05 20:11   ` Eric Blake
2026-09-30 16:49 ` [PATCH 09/13] qemu-io: add -t to run an aio request in a named iothread Denis V. Lunev
2026-10-05 20:28   ` Eric Blake
2026-09-30 16:49 ` [PATCH 10/13] qemu-io: add -g to write past the end of the image Denis V. Lunev
2026-10-05 20:36   ` Eric Blake
2026-09-30 16:49 ` [PATCH 11/13] block/blkdebug: make a breakpoint work across AioContexts Denis V. Lunev
2026-10-05 20:42   ` Eric Blake
2026-09-30 16:49 ` [PATCH 12/13] block: add blkdebug events for a write before it is tracked Denis V. Lunev
2026-10-05 20:45   ` Eric Blake
2026-09-30 16:49 ` [PATCH 13/13] iotests/298: cover the preallocation races Denis V. Lunev
2026-10-05 21:06   ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930165000.303236-4-den@openvz.org \
    --to=den@openvz.org \
    --cc=andrey.drobyshev@virtuozzo.com \
    --cc=hreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --cc=vsementsov@yandex-team.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.