Skip to contentSkip to conversation

read-only: allow read-only CDROM with any interface

PATCH Superseded Naphtali Sprei 2 participants 3 messages Mar 21, 2010 – Mar 23, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 read-only: allow read-only CDROM with any interface

---
 vl.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
vl.c +5 -8
index 2e38b77..d3863d7 100644
@@ -1255,19 +1255,16 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
         bdrv_flags &= ~BDRV_O_NATIVE_AIO;
     }
 
-    if (ro == 1) {
+    if (media == MEDIA_CDROM) {
+        ro = 1;
+    }
+    if (ro == 1 &&
+        media != MEDIA_CDROM) { /* CDROM is fine for any interface, don't check */
         if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY) {
             fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n");
             return NULL;
         }
     }
-    /* 
-     * cdrom is read-only. Set it now, after above interface checking
-     * since readonly attribute not explicitly required, so no error.
-     */
-    if (media == MEDIA_CDROM) {
-        ro = 1;
-    }
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
 
     if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
Signature · 1 line
1.6.3.3
#1 lore raw

vl.c DriveInfo *drive_init(QemuOpts *opts, void *opaque,

Quoted 7 lines · Naphtali Sprei
vl.c +5 -1
-    if (ro == 1) {
+    if (media == MEDIA_CDROM) {
+        ro = 1;
+    }
+    if (ro == 1&&
+        media != MEDIA_CDROM) { /* CDROM is fine for any interface, don't check */
          if (type != IF_SCSI&&  type != IF_VIRTIO&&  type != IF_FLOPPY) {

Ug. How about formatting this as

    if (media == MEDIA_CDROM) {
        /* CDROM is fine for any interface, don't check.  */
        ro = 1;
    } else if (ro == 1) {
        if (type != IF_SCSI ...)
    }

duplicating the MEDIA_CDROM test makes the logic harder to follow.

r~

#2 lore raw

PATCH v2 1/1 read-only: allow read-only CDROM with any interface

In reply to Naphtali Sprei

v1 -> v2
cosmetic change of if block arrangement

---
 vl.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
vl.c +5 -8
index d69250c..11c68f2 100644
@@ -1222,19 +1222,16 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
         bdrv_flags &= ~BDRV_O_NATIVE_AIO;
     }
 
-    if (ro == 1) {
+    if (media == MEDIA_CDROM) {
+        /* CDROM is fine for any interface, don't check.  */
+        ro = 1;
+    } else if (ro == 1) {
         if (type != IF_SCSI && type != IF_VIRTIO && type != IF_FLOPPY) {
             fprintf(stderr, "qemu: readonly flag not supported for drive with this interface\n");
             return NULL;
         }
     }
-    /* 
-     * cdrom is read-only. Set it now, after above interface checking
-     * since readonly attribute not explicitly required, so no error.
-     */
-    if (media == MEDIA_CDROM) {
-        ro = 1;
-    }
+
     bdrv_flags |= ro ? 0 : BDRV_O_RDWR;
 
     if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
Signature · 1 line
1.6.3.3