From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 0/3] block/file-posix: File locking during creation
Date: Sat, 21 Apr 2018 00:09:10 +0200 [thread overview]
Message-ID: <20180420220913.27000-1-mreitz@redhat.com> (raw)
Currently we do not take permissions on a file while it is being
created. That is a bit sad. The simplest way to test this is the
following:
$ qemu-img create -f qcow2 foo.qcow2 64M
Formatting 'foo.qcow2', fmt=qcow2 size=67108864 cluster_size=65536 lazy_refcounts=off refcount_bits=16
$ qemu-img convert -f qcow2 -O qcow2 foo.qcow2 foo.qcow2
qemu-img: foo.qcow2: error while converting qcow2: Failed to get "write" lock
Is another process using the image?
$ qemu-img info foo.qcow2
image: foo.qcow2
file format: raw
virtual size: 0 (0 bytes)
disk size: 0
(See also https://bugzilla.redhat.com/show_bug.cgi?id=1519144)
Here is what's happening: file-posix opens the file with
O_CREAT | O_TRUNC, thus truncating the file to 0. Then qcow2 tries to
format it, but fails because it needs the WRITE permission to do so. So
it cannot format it and the file stays empty.
We should actually take a WRITE and a RESIZE permission before we
truncate the file, and this is what this series does.
I personally consider the solution taken here a bit of a hack, but it
works and we don't have any locking in any drivers but file-posix
anyway, so it isn't lacking anything in that regard. Integrating it in
blockdev-create might be possible, but there are two issues:
(1) It would be harder.
(2) What would we do anyway? We'd advise protocol drivers to take WRITE
and RESIZE permissions before they truncate a file to be empty...
Well, and then they'd do exactly what file-posix is made to do in
this series.
So basically what I consider a hack could be seen as exactly the right
way to tackle the issue: Protocol drivers have to ensure the correct
permissions (and they have to choose what those are) are applied before
changing any file -- which is what this series implements.
Max Reitz (3):
block/file-posix: Pass FD to locking helpers
block/file-posix: File locking during creation
iotests: Add creation test to 153
block/file-posix.c | 68 ++++++++++++++++++++++++++++++++++++----------
tests/qemu-iotests/153 | 18 ++++++++++++
tests/qemu-iotests/153.out | 13 +++++++++
3 files changed, 84 insertions(+), 15 deletions(-)
--
2.14.3
next reply other threads:[~2018-04-20 22:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 22:09 Max Reitz [this message]
2018-04-20 22:09 ` [Qemu-devel] [PATCH 1/3] block/file-posix: Pass FD to locking helpers Max Reitz
2018-04-27 6:24 ` Fam Zheng
2018-04-20 22:09 ` [Qemu-devel] [PATCH 2/3] block/file-posix: File locking during creation Max Reitz
2018-04-27 6:22 ` Fam Zheng
2018-04-28 11:03 ` Max Reitz
2018-05-03 6:45 ` Fam Zheng
2018-05-04 13:45 ` Max Reitz
2018-05-07 7:23 ` Fam Zheng
2018-04-20 22:09 ` [Qemu-devel] [PATCH 3/3] iotests: Add creation test to 153 Max Reitz
2018-04-27 6:24 ` Fam Zheng
2018-04-23 13:19 ` [Qemu-devel] [Qemu-block] [PATCH 0/3] block/file-posix: File locking during creation Alberto Garcia
2018-04-23 15:56 ` Max Reitz
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=20180420220913.27000-1-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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.