Skip to contentSkip to conversation

block: read-only: open cdrom as read-only when using monitor's change command

PATCH Applied Naphtali Sprei 2 participants 2 messages Apr 25, 2010 – May 3, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: read-only: open cdrom as read-only when using monitor's change command

Current code of monitor command: 'change', used to open file for read-write uncoditionally. Change to open it as read-only for CDROM, and read-write for all others.

---
 monitor.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
monitor.c +3 -1
index c25d551..df5a15d 100644
@@ -1083,6 +1083,7 @@ static int do_change_block(Monitor *mon, const char *device,
 {
     BlockDriverState *bs;
     BlockDriver *drv = NULL;
+    int bdrv_flags;
 
     bs = bdrv_find(device);
     if (!bs) {
@@ -1099,7 +1100,8 @@ static int do_change_block(Monitor *mon, const char *device,
     if (eject_device(mon, bs, 0) < 0) {
         return -1;
     }
-    if (bdrv_open(bs, filename, BDRV_O_RDWR, drv) < 0) {
+    bdrv_flags = bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM ? 0 : BDRV_O_RDWR;
+    if (bdrv_open(bs, filename, bdrv_flags, drv) < 0) {
         qerror_report(QERR_OPEN_FILE_FAILED, filename);
         return -1;
     }
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 5 lines · Naphtali Sprei

Current code of monitor command: 'change', used to open file for read-write uncoditionally. Change to open it as read-only for CDROM, and read-write for all others.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 27 lines
---
  monitor.c |    4 +++-
  1 files changed, 3 insertions(+), 1 deletions(-)
monitor.c +3 -1
index c25d551..df5a15d 100644
@@ -1083,6 +1083,7 @@ static int do_change_block(Monitor *mon, const char *device,
  {
      BlockDriverState *bs;
      BlockDriver *drv = NULL;
+    int bdrv_flags;
 
      bs = bdrv_find(device);
      if (!bs) {
@@ -1099,7 +1100,8 @@ static int do_change_block(Monitor *mon, const char *device,
      if (eject_device(mon, bs, 0)<  0) {
          return -1;
      }
-    if (bdrv_open(bs, filename, BDRV_O_RDWR, drv)<  0) {
+    bdrv_flags = bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM ? 0 : BDRV_O_RDWR;
+    if (bdrv_open(bs, filename, bdrv_flags, drv)<  0) {
          qerror_report(QERR_OPEN_FILE_FAILED, filename);
          return -1;
      }