From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com, eblake@redhat.com,
eesposit@redhat.com, pbonzini@redhat.com,
vsementsov@yandex-team.ru, qemu-devel@nongnu.org
Subject: [PATCH v2 02/21] preallocate: Factor out preallocate_truncate_to_real_size()
Date: Mon, 11 Sep 2023 11:46:01 +0200 [thread overview]
Message-ID: <20230911094620.45040-3-kwolf@redhat.com> (raw)
In-Reply-To: <20230911094620.45040-1-kwolf@redhat.com>
It's essentially the same code in preallocate_check_perm() and
preallocate_close(), except that the latter ignores errors.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
block/preallocate.c | 48 +++++++++++++++++++++------------------------
1 file changed, 22 insertions(+), 26 deletions(-)
diff --git a/block/preallocate.c b/block/preallocate.c
index 3d0f621003..3173d80534 100644
--- a/block/preallocate.c
+++ b/block/preallocate.c
@@ -162,26 +162,39 @@ static int preallocate_open(BlockDriverState *bs, QDict *options, int flags,
return 0;
}
-static void preallocate_close(BlockDriverState *bs)
+static int preallocate_truncate_to_real_size(BlockDriverState *bs, Error **errp)
{
- int ret;
BDRVPreallocateState *s = bs->opaque;
-
- if (s->data_end < 0) {
- return;
- }
+ int ret;
if (s->file_end < 0) {
s->file_end = bdrv_getlength(bs->file->bs);
if (s->file_end < 0) {
- return;
+ error_setg_errno(errp, -s->file_end, "Failed to get file length");
+ return s->file_end;
}
}
if (s->data_end < s->file_end) {
ret = bdrv_truncate(bs->file, s->data_end, true, PREALLOC_MODE_OFF, 0,
NULL);
- s->file_end = ret < 0 ? ret : s->data_end;
+ if (ret < 0) {
+ error_setg_errno(errp, -ret, "Failed to drop preallocation");
+ s->file_end = ret;
+ return ret;
+ }
+ s->file_end = s->data_end;
+ }
+
+ return 0;
+}
+
+static void preallocate_close(BlockDriverState *bs)
+{
+ BDRVPreallocateState *s = bs->opaque;
+
+ if (s->data_end >= 0) {
+ preallocate_truncate_to_real_size(bs, NULL);
}
}
@@ -473,24 +486,7 @@ static int preallocate_check_perm(BlockDriverState *bs,
* We should truncate in check_perm, as in set_perm bs->file->perm will
* be already changed, and we should not violate it.
*/
- if (s->file_end < 0) {
- s->file_end = bdrv_getlength(bs->file->bs);
- if (s->file_end < 0) {
- error_setg(errp, "Failed to get file length");
- return s->file_end;
- }
- }
-
- if (s->data_end < s->file_end) {
- int ret = bdrv_truncate(bs->file, s->data_end, true,
- PREALLOC_MODE_OFF, 0, NULL);
- if (ret < 0) {
- error_setg(errp, "Failed to drop preallocation");
- s->file_end = ret;
- return ret;
- }
- s->file_end = s->data_end;
- }
+ return preallocate_truncate_to_real_size(bs, errp);
}
return 0;
--
2.41.0
next prev parent reply other threads:[~2023-09-11 9:49 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-11 9:45 [PATCH v2 00/21] Graph locking part 4 (node management) Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 01/21] block: Remove unused BlockReopenQueueEntry.perms_checked Kevin Wolf
2023-09-11 9:46 ` Kevin Wolf [this message]
2023-09-11 9:46 ` [PATCH v2 03/21] preallocate: Don't poll during permission updates Kevin Wolf
2023-10-05 19:55 ` Vladimir Sementsov-Ogievskiy
2023-10-06 8:56 ` Kevin Wolf
2023-10-06 18:10 ` Vladimir Sementsov-Ogievskiy
2023-10-09 9:28 ` Denis V. Lunev
2023-09-11 9:46 ` [PATCH v2 04/21] block: Take AioContext lock for bdrv_append() more consistently Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 05/21] block: Introduce bdrv_schedule_unref() Kevin Wolf
2023-09-12 16:49 ` Stefan Hajnoczi
2023-09-11 9:46 ` [PATCH v2 06/21] block-coroutine-wrapper: Add no_co_wrapper_bdrv_wrlock functions Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 07/21] block-coroutine-wrapper: Allow arbitrary parameter names Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 08/21] block: Mark bdrv_replace_child_noperm() GRAPH_WRLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 09/21] block: Mark bdrv_replace_child_tran() GRAPH_WRLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 10/21] block: Mark bdrv_attach_child_common() GRAPH_WRLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 11/21] block: Call transaction callbacks with lock held Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 12/21] block: Mark bdrv_attach_child() GRAPH_WRLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 13/21] block: Mark bdrv_parent_perms_conflict() and callers GRAPH_RDLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 14/21] block: Mark bdrv_get_cumulative_perm() " Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 15/21] block: Mark bdrv_child_perm() GRAPH_RDLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 16/21] block: Mark bdrv_parent_cb_change_media() GRAPH_RDLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 17/21] block: Take graph rdlock in bdrv_drop_intermediate() Kevin Wolf
2023-09-12 16:49 ` Stefan Hajnoczi
2023-09-11 9:46 ` [PATCH v2 18/21] block: Take graph rdlock in bdrv_change_aio_context() Kevin Wolf
2023-09-12 16:49 ` Stefan Hajnoczi
2023-09-11 9:46 ` [PATCH v2 19/21] block: Mark bdrv_root_unref_child() GRAPH_WRLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 20/21] block: Mark bdrv_unref_child() GRAPH_WRLOCK Kevin Wolf
2023-09-11 9:46 ` [PATCH v2 21/21] block: Mark bdrv_add/del_child() and caller GRAPH_WRLOCK Kevin Wolf
2023-09-12 16:49 ` [PATCH v2 00/21] Graph locking part 4 (node management) Stefan Hajnoczi
2023-09-14 13:12 ` Kevin Wolf
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=20230911094620.45040-3-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=eblake@redhat.com \
--cc=eesposit@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).