[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/32] qemu-img: Allow target be aligned to sector size
From: |
Hanna Reitz |
Subject: |
[PULL 21/32] qemu-img: Allow target be aligned to sector size |
Date: |
Wed, 15 Sep 2021 19:53:07 +0200 |
We cannot write to images opened with O_DIRECT unless we allow them to
be resized so they are aligned to the sector size: Since 9c60a5d1978,
bdrv_node_refresh_perm() ensures that for nodes whose length is not
aligned to the request alignment and where someone has taken a WRITE
permission, the RESIZE permission is taken, too).
Let qemu-img convert pass the BDRV_O_RESIZE flag (which causes
blk_new_open() to take the RESIZE permission) when using cache=none for
the target, so that when writing to it, it can be aligned to the target
sector size.
Without this patch, an error is returned:
$ qemu-img convert -f raw -O raw -t none foo.img /mnt/tmp/foo.img
qemu-img: Could not open '/mnt/tmp/foo.img': Cannot get 'write'
permission without 'resize': Image size is not a multiple of request
alignment
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1994266
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20210819101200.64235-1-hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
qemu-img.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/qemu-img.c b/qemu-img.c
index d77f3e76a9..e43a71a794 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2628,6 +2628,14 @@ static int img_convert(int argc, char **argv)
goto out;
}
+ if (flags & BDRV_O_NOCACHE) {
+ /*
+ * If we open the target with O_DIRECT, it may be necessary to
+ * extend its size to align to the physical sector size.
+ */
+ flags |= BDRV_O_RESIZE;
+ }
+
if (skip_create) {
s.target = img_open(tgt_image_opts, out_filename, out_fmt,
flags, writethrough, s.quiet, false);
--
2.31.1
- [PULL 15/32] block/mirror: fix NULL pointer dereference in mirror_wait_on_conflicts(), (continued)
- [PULL 15/32] block/mirror: fix NULL pointer dereference in mirror_wait_on_conflicts(), Hanna Reitz, 2021/09/15
- [PULL 17/32] block: bdrv_inactivate_recurse(): check for permissions and fix crash, Hanna Reitz, 2021/09/15
- [PULL 09/32] iotests: Fix use-{list,dict}-literal warnings, Hanna Reitz, 2021/09/15
- [PULL 11/32] migrate-bitmaps-postcopy-test: Fix pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 12/32] migrate-bitmaps-test: Fix pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 16/32] tests: add migrate-during-backup, Hanna Reitz, 2021/09/15
- [PULL 14/32] iotests/297: Cover tests/, Hanna Reitz, 2021/09/15
- [PULL 08/32] iotests: Fix unspecified-encoding pylint warnings, Hanna Reitz, 2021/09/15
- [PULL 19/32] qcow2: refactor handle_dependencies() loop body, Hanna Reitz, 2021/09/15
- [PULL 18/32] simplebench: add img_bench_templater.py, Hanna Reitz, 2021/09/15
- [PULL 21/32] qemu-img: Allow target be aligned to sector size,
Hanna Reitz <=
- [PULL 20/32] qcow2: handle_dependencies(): relax conflict detection, Hanna Reitz, 2021/09/15
- [PULL 22/32] qcow2-refcount: improve style of check_refcounts_l2(), Hanna Reitz, 2021/09/15
- [PULL 23/32] qcow2: compressed read: simplify cluster descriptor passing, Hanna Reitz, 2021/09/15
- [PULL 24/32] qcow2: introduce qcow2_parse_compressed_l2_entry() helper, Hanna Reitz, 2021/09/15
- [PULL 25/32] qcow2-refcount: introduce fix_l2_entry_by_zero(), Hanna Reitz, 2021/09/15
- [PULL 26/32] qcow2-refcount: fix_l2_entry_by_zero(): also zero L2 entry bitmap, Hanna Reitz, 2021/09/15
- [PULL 27/32] qcow2-refcount: check_refcounts_l2(): check l2_bitmap, Hanna Reitz, 2021/09/15
- [PULL 28/32] qcow2-refcount: check_refcounts_l2(): check reserved bits, Hanna Reitz, 2021/09/15
- [PULL 29/32] qcow2-refcount: improve style of check_refcounts_l1(), Hanna Reitz, 2021/09/15
- [PULL 30/32] qcow2-refcount: check_refcounts_l1(): check reserved bits, Hanna Reitz, 2021/09/15