Pass the drive's readonly attribute to the guest OS
authorNaphtali Sprei <nsprei@redhat.com>
Thu, 29 Oct 2009 09:42:11 +0000 (11:42 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 9 Nov 2009 14:43:01 +0000 (08:43 -0600)
Implemented for virtio-blk and for scsi

Signed-off-by: Naphtali Sprei <nsprei@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/scsi-disk.c
hw/virtio-blk.c

index 2a9268aa6326d8db92ec1ea51abbf405e46d05fc..5da573d59e0cf85dcbae2cf2829af222b553100e 100644 (file)
@@ -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;
index 2630b99304928045be1b7949223b50d873c67a34..e6df9f2619da793c92b10a943bcc6465bf670a0e 100644 (file)
@@ -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;
 }