file-posix: Fix check_hdev_writable() with auto-read-only
authorKevin Wolf <kwolf@redhat.com>
Fri, 17 Jul 2020 10:54:25 +0000 (12:54 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 17 Jul 2020 12:20:57 +0000 (14:20 +0200)
commitbca5283bd4a086bcbfaddc024491a400cc9b2fa9
tree38fd2929ac16434c9c3e9cfa835f2d4e7ea6cb8a
parent20eaf1bf6ef1df916cb7ea2d06d1e868f238835f
file-posix: Fix check_hdev_writable() with auto-read-only

For Linux block devices, being able to open the device read-write
doesn't necessarily mean that the device is actually writable (one
example is a read-only LV, as you get with lvchange -pr <device>). We
have check_hdev_writable() to check this condition and fail opening the
image read-write if it's not actually writable.

However, this check doesn't take auto-read-only into account, but
results in a hard failure instead of downgrading to read-only where
possible.

Fix this and do the writable check not based on BDRV_O_RDWR, but only
when this actually results in opening the file read-write. A second
check is inserted in raw_reconfigure_getfd() to have the same check when
dynamic auto-read-only upgrades an image file from read-only to
read-write.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20200717105426.51134-3-kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/file-posix.c