block/vvfat: Fix ro shared folder
PATCH 1/1 block/vvfat: Fix ro shared folder
QEMU exits in error when passing a vfat shared folder in read-only mode.
To fix this issue, this patch removes any potential write permission from cumulative_perms, when a read-only block device is in use.
---
This is an attempt to fix this behavior, but it feels a bit hacky to me since this patch checks for the vvfat format in a generic function.
However, I'd be glad to have some advice to make it better. Anyway, I ran the block tests to ensure this does not introduce any regression.
To add some context: I know that this can be worked around by setting the shared folder in rw mode. But our use-case requires using both shared and VM snapshots, and QEMU prevents using snapshot with a rw shared folder.
block.c | 6 ++++++ 1 file changed, 6 insertions(+)
block.c +6 -0
@@ -2383,6 +2383,12 @@ void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, cumulative_shared_perms &= c->shared_perm; } +/* Discard write permission if vvfat block device is read-only */ +const char *format =bdrv_get_format_name (bs); +if (format !=NULL &&strncmp (format,"vvfat" ,5 ) ==0 &&bdrv_is_read_only (bs)) { + cumulative_perms &= ~BLK_PERM_WRITE ; + } + *perm = cumulative_perms; *shared_perm = cumulative_shared_perms; }
Signature · 1 line
2.31.1
Hi Guillaume,
Quoted 11 lines · Guillaume Roche
QEMU exits in error when passing a vfat shared folder in read-only mode.
To fix this issue, this patch removes any potential write permission from
cumulative_perms, when a read-only block device is in use.Signed-off-by Guillaume Roche <[email protected]>---
This is an attempt to fix this behavior, but it feels a bit hacky to me since this patch checks for the vvfat format in a generic function.
What about implementing bdrv_vvfat::bdrv_check_perm()?
Quoted 29 lines
However, I'd be glad to have some advice to make it better. Anyway, I ran the block tests to ensure this does not introduce any regression.
To add some context: I know that this can be worked around by setting the shared folder in rw mode. But our use-case requires using both shared and VM snapshots, and QEMU prevents using snapshot with a rw shared folder.
block.c | 6 ++++++ 1 file changed, 6 insertions(+)block.c +6
-0@@ -2383,6 +2383,12 @@ void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, cumulative_shared_perms &= c->shared_perm; } +/* Discard write permission if vvfat block device is read-only */ +const char *format =bdrv_get_format_name (bs); +if (format !=NULL &&strncmp (format,"vvfat" ,5 ) ==0 &&bdrv_is_read_only (bs)) { + cumulative_perms &= ~BLK_PERM_WRITE ; + } + *perm = cumulative_perms; *shared_perm = cumulative_shared_perms; }
Hi Philippe,
Quoted 9 lines · Philippe Mathieu-Daudé
Hi Guillaume,
Quoted 5 lines · Guillaume Roche
QEMU exits in error when passing a vfat shared folder in read-only mode.
To fix this issue, this patch removes any potential write permission from
cumulative_perms, when a read-only block device is in use.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Guillaume Roche <[email protected]>---
This is an attempt to fix this behavior, but it feels a bit hacky to me since this patch checks for the vvfat format in a generic function.What about implementing
bdrv_vvfat::bdrv_check_perm()?
Thanks for this feedback. I had a look at your suggestion, but I'm a bit confused.
As I understand it, bdrv_node_refresh_perm() calls bdrv_get_cumulative_perm() (which I patched to remove the write permission) then it checks the permissions.
Afterwards, it calls bdrv_drv_set_perm() that in turn calls bs->drv->bdrv_check_perm(). So even if I implement bdrv_vvfat::bdrv_check_perm(), I will get the permission error before it is called.
Could you elaborate a bit on what you have in mind please?
Regards,
Guillaume
Quoted 31 lines
Quoted 30 lines
However, I'd be glad to have some advice to make it better. Anyway, I ran the block tests to ensure this does not introduce any regression.
To add some context: I know that this can be worked around by setting the shared folder in rw mode. But our use-case requires using both shared and VM snapshots, and QEMU prevents using snapshot with a rw shared folder.
block.c | 6 ++++++ 1 file changed, 6 insertions(+)block.c +6
-0@@ -2383,6 +2383,12 @@ void bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm, cumulative_shared_perms &= c->shared_perm; } +/* Discard write permission if vvfat block device is read-only */ +const char *format =bdrv_get_format_name (bs); +if (format !=NULL &&strncmp (format,"vvfat" ,5 ) ==0 &&bdrv_is_read_only (bs)) { + cumulative_perms &= ~BLK_PERM_WRITE ; + } + *perm = cumulative_perms; *shared_perm = cumulative_shared_perms; }
Am 31.08.2021 um 16:17 hat Guillaume Roche geschrieben:
Quoted 12 lines
QEMU exits in error when passing a vfat shared folder in read-only mode.
To fix this issue, this patch removes any potential write permission from
cumulative_perms, when a read-only block device is in use.Signed-off-by Guillaume Roche <[email protected]>---
This is an attempt to fix this behavior, but it feels a bit hacky to me since this patch checks for the vvfat format in a generic function.
Quoted 7 lines
However, I'd be glad to have some advice to make it better. Anyway, I ran the block tests to ensure this does not introduce any regression.
To add some context: I know that this can be worked around by setting the shared folder in rw mode. But our use-case requires using both shared and VM snapshots, and QEMU prevents using snapshot with a rw shared folder.
I don't think the behaviour is actually a bug: ide-hd requires a writable backend, so attaching a read-only vvfat node is a real error.
You can either specify -drive read-only=on and use a device that can accept read-only backends (such as virtio-blk or ide-cd), or add a temporary writable qcow2 overlay with -snapshot or -drive snapshot=on so that the ide-hd device actually does get the writable backend it needs.
Kevin