From c79662f7f765a0e6cb7aa26902cc8d61f9022dd5 Mon Sep 17 00:00:00 2001 From: Naphtali Sprei Date: Thu, 29 Oct 2009 11:42:11 +0200 Subject: [PATCH] Pass the drive's readonly attribute to the guest OS Implemented for virtio-blk and for scsi Signed-off-by: Naphtali Sprei Signed-off-by: Anthony Liguori --- hw/scsi-disk.c | 3 ++- hw/virtio-blk.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2a9268aa63..5da573d59e 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -633,7 +633,8 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, memset(p, 0, 4); outbuf[1] = 0; /* Default media type. */ outbuf[3] = 0; /* Block descriptor length. */ - if (bdrv_get_type_hint(s->dinfo->bdrv) == BDRV_TYPE_CDROM) { + if (bdrv_get_type_hint(s->dinfo->bdrv) == BDRV_TYPE_CDROM || + bdrv_is_read_only(s->dinfo->bdrv)) { outbuf[2] = 0x80; /* Readonly. */ } p += 4; diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 2630b99304..e6df9f2619 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -444,6 +444,9 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev) #endif if (strcmp(s->serial_str, "0")) features |= 1 << VIRTIO_BLK_F_IDENTIFY; + + if (bdrv_is_read_only(s->bs)) + features |= 1 << VIRTIO_BLK_F_RO; return features; }