aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNaphtali Sprei <nsprei@redhat.com>2010-04-25 19:30:37 +0300
committerAnthony Liguori <aliguori@us.ibm.com>2010-05-03 12:39:53 -0500
commitcb4e5f8ed1b648c451491b10dc92b1af1e324535 (patch)
treedf59ad6308bb8a33649f853035c189cde6dc256e
parent288e7bccf1719df4d05abc872e75d544089aa139 (diff)
downloadqemu-cb4e5f8ed1b648c451491b10dc92b1af1e324535.zip
qemu-cb4e5f8ed1b648c451491b10dc92b1af1e324535.tar.gz
qemu-cb4e5f8ed1b648c451491b10dc92b1af1e324535.tar.bz2
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. Signed-off-by: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r--monitor.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/monitor.c b/monitor.c
index bb87479..46d0b47 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1087,6 +1087,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) {
@@ -1103,7 +1104,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;
}