Skip to contentSkip to conversation

blockdev: fix cdrom read_only flag

PATCH Superseded Fam Zheng 2 participants 3 messages Oct 15, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 blockdev: fix cdrom read_only flag

Since 0ebd24e0, cdrom doesn't have read-only on by default, which will error out when using an read only image. Fix it by setting the default value when parsing opts.

---
 blockdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
blockdev.c +4 -3
index 4f76e28..7f5ef4a 100644
@@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     int cyls, heads, secs, translation;
     int max_devs, bus_id, unit_id, index;
     const char *devaddr;
-    bool read_only, copy_on_read;
+    bool read_only = false;
+    bool copy_on_read;
     Error *local_err = NULL;
 
     /* Change legacy command line options into QMP ones */
@@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
             media = MEDIA_DISK;
         } else if (!strcmp(value, "cdrom")) {
             media = MEDIA_CDROM;
-            qdict_put(bs_opts, "read-only", qstring_from_str("on"));
+            read_only = true;
         } else {
             error_report("'%s' invalid media", value);
             goto fail;
@@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* copy-on-read is disabled with a warning for read-only devices */
-    read_only = qemu_opt_get_bool(legacy_opts, "read-only", false);
+    read_only = qemu_opt_get_bool(legacy_opts, "read-only", read_only);
     copy_on_read = qemu_opt_get_bool(legacy_opts, "copy-on-read", false);
 
     if (read_only && copy_on_read) {
Signature · 1 line
1.8.3.1
#1 lore raw

Am 15.10.2013 um 03:27 hat Fam Zheng geschrieben:

Quoted 34 lines

Since 0ebd24e0, cdrom doesn't have read-only on by default, which will error out when using an read only image. Fix it by setting the default value when parsing opts.

---
 blockdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
blockdev.c +3 -2
index 4f76e28..7f5ef4a 100644
@@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     int cyls, heads, secs, translation;
     int max_devs, bus_id, unit_id, index;
     const char *devaddr;
-    bool read_only, copy_on_read;
+    bool read_only = false;
+    bool copy_on_read;
     Error *local_err = NULL;
 
     /* Change legacy command line options into QMP ones */
@@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
             media = MEDIA_DISK;
         } else if (!strcmp(value, "cdrom")) {
             media = MEDIA_CDROM;
-            qdict_put(bs_opts, "read-only", qstring_from_str("on"));
+            read_only = true;
         } else {
             error_report("'%s' invalid media", value);
             goto fail;

blockdev.c DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 713

Quoted 5 lines
blockdev.c +1 -1
@@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* copy-on-read is disabled with a warning for read-only devices */
-    read_only = qemu_opt_get_bool(legacy_opts, "read-only", false);
+    read_only = qemu_opt_get_bool(legacy_opts, "read-only", read_only);

I believe we must move this line to above the media=... handling for compatibility with old versions. Or actually, using |= instead of = may be enough.

The reason is this command line:

-drive file=test.iso,media=cdrom,readonly=off

Which, "obviously", means that a read-only CD-ROM device should be created.

Kevin

author
#2 lore raw
Quoted 45 lines · Kevin Wolf

Am 15.10.2013 um 03:27 hat Fam Zheng geschrieben:

Quoted 34 lines

Since 0ebd24e0, cdrom doesn't have read-only on by default, which will error out when using an read only image. Fix it by setting the default value when parsing opts.

---
 blockdev.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
blockdev.c +3 -2
index 4f76e28..7f5ef4a 100644
@@ -625,7 +625,8 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     int cyls, heads, secs, translation;
     int max_devs, bus_id, unit_id, index;
     const char *devaddr;
-    bool read_only, copy_on_read;
+    bool read_only = false;
+    bool copy_on_read;
     Error *local_err = NULL;
 
     /* Change legacy command line options into QMP ones */
@@ -701,7 +702,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
             media = MEDIA_DISK;
         } else if (!strcmp(value, "cdrom")) {
             media = MEDIA_CDROM;
-            qdict_put(bs_opts, "read-only", qstring_from_str("on"));
+            read_only = true;
         } else {
             error_report("'%s' invalid media", value);
             goto fail;

blockdev.c DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type) · line 713

Quoted 5 lines
blockdev.c +1 -1
@@ -709,7 +710,7 @@ DriveInfo *drive_init(QemuOpts *all_opts, BlockInterfaceType block_default_type)
     }
 
     /* copy-on-read is disabled with a warning for read-only devices */
-    read_only = qemu_opt_get_bool(legacy_opts, "read-only", false);
+    read_only = qemu_opt_get_bool(legacy_opts, "read-only", read_only);

I believe we must move this line to above the media=... handling for compatibility with old versions. Or actually, using |= instead of = may be enough.

Quoted 7 lines

The reason is this command line:

-drive file=test.iso,media=cdrom,readonly=off

Which, "obviously", means that a read-only CD-ROM device should be created.

Oh, I didn't notice readony=off means a read-only CD-ROM before...

Fam