Hello Rusty, sometimes it is useful to share a disk (e.g. usr). To avoid file system corruption, the disk should be mounted read-only in that case. This patch adds a new feature flag, that allows the host to specify, if the disk should be considered read-only. Signed-off-by: Christian Borntraeger <borntraeger at de.ibm.com> --- drivers/block/virtio_blk.c | 6 +++++- include/linux/virtio_blk.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) Index: kvm/drivers/block/virtio_blk.c ==================================================================--- kvm.orig/drivers/block/virtio_blk.c +++ kvm/drivers/block/virtio_blk.c @@ -260,6 +260,10 @@ static int virtblk_probe(struct virtio_d if (virtio_has_feature(vdev, VIRTIO_BLK_F_BARRIER)) blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL); + /* If disk is read-only in the host, the guest should obey */ + if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO)) + set_disk_ro(vblk->disk, 1); + /* Host must always specify the capacity. */ vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity), &cap, sizeof(cap)); @@ -325,7 +329,7 @@ static struct virtio_device_id id_table[ static unsigned int features[] = { VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, - VIRTIO_BLK_F_GEOMETRY, + VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, }; static struct virtio_driver virtio_blk = { Index: kvm/include/linux/virtio_blk.h ==================================================================--- kvm.orig/include/linux/virtio_blk.h +++ kvm/include/linux/virtio_blk.h @@ -10,6 +10,7 @@ #define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */ #define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */ #define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ +#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ struct virtio_blk_config {
Tomasz Chmielewski
2008-May-16 09:28 UTC
[kvm-devel] [PATCH] virtio_blk: allow read-only disks
Christian Borntraeger schrieb:> Hello Rusty, > > sometimes it is useful to share a disk (e.g. usr). To avoid file system > corruption, the disk should be mounted read-only in that case.Although it is done at a different level here, I wanted to note that mounting a filesystem read-only does not necessarily mean the system will not try to write to it. This is the case for ext3, for example - when mounted ro, system will still reply the journal and do some writes etc. The patch, however, should take care of that, too, as it is completely different place it is made ro. -- Tomasz Chmielewski http://wpkg.org
On Friday 16 May 2008 19:17:03 Christian Borntraeger wrote:> Hello Rusty, > > sometimes it is useful to share a disk (e.g. usr). To avoid file system > corruption, the disk should be mounted read-only in that case. This patch > adds a new feature flag, that allows the host to specify, if the disk > should be considered read-only.Applied, thanks. Rusty.
Seemingly Similar Threads
- [PATCH/RFC] virtio_blk: check for hardsector size from host
- [PATCH/RFC] virtio_blk: check for hardsector size from host
- [PATCH v2] virtio_blk: VIRTIO_BLK_F_WCE->VIRTIO_BLK_F_FLUSH
- [PATCH v2] virtio_blk: VIRTIO_BLK_F_WCE->VIRTIO_BLK_F_FLUSH
- [PATCH] virtio_blk: VIRTIO_BLK_F_WCE->VIRTIO_BLK_F_FLUSH