提交 cb4e5f8e 编写于 作者: N Naphtali Sprei 提交者: Anthony Liguori

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: NNaphtali Sprei <nsprei@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 288e7bcc
...@@ -1087,6 +1087,7 @@ static int do_change_block(Monitor *mon, const char *device, ...@@ -1087,6 +1087,7 @@ static int do_change_block(Monitor *mon, const char *device,
{ {
BlockDriverState *bs; BlockDriverState *bs;
BlockDriver *drv = NULL; BlockDriver *drv = NULL;
int bdrv_flags;
bs = bdrv_find(device); bs = bdrv_find(device);
if (!bs) { if (!bs) {
...@@ -1103,7 +1104,8 @@ static int do_change_block(Monitor *mon, const char *device, ...@@ -1103,7 +1104,8 @@ static int do_change_block(Monitor *mon, const char *device,
if (eject_device(mon, bs, 0) < 0) { if (eject_device(mon, bs, 0) < 0) {
return -1; 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); qerror_report(QERR_OPEN_FILE_FAILED, filename);
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册