diff mbox

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

Message ID 1269185633-31750-1-git-send-email-nsprei@redhat.com
State New
Headers show

Commit Message

Naphtali Sprei March 21, 2010, 3:33 p.m. UTC
Signed-off-by: Naphtali Sprei <nsprei@redhat.com>
---
 vl.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

Comments

Richard Henderson March 21, 2010, 5:29 p.m. UTC | #1
On 03/21/2010 08:33 AM, Naphtali Sprei wrote:
> -    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~
diff mbox

Patch

diff --git a/vl.c b/vl.c
index 2e38b77..d3863d7 100644
--- a/vl.c
+++ b/vl.c
@@ -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) {