From 6d4736c5937aed1e0a78c14def78fd66c2846078 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig <chellwig@redhat.com> Date: Mon, 17 Jan 2011 14:43:29 -0200 Subject: [PATCH 1/2] block: read-only: open cdrom as read-only when using monitor's change command RH-Author: Christoph Hellwig <chellwig@redhat.com> Message-id: <1295275409-7230-1-git-send-email-chellwig@redhat.com> Patchwork-id: 16383 O-Subject: [RHEL5.7 qemu PATCH] block: read-only: open cdrom as read-only when using monitor's change command Bugzilla: 586173 RH-Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com> RH-Acked-by: Markus Armbruster <armbru@redhat.com> RH-Acked-by: Daniel P. Berrange <berrange@redhat.com> RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com> From: Naphtali Sprei <nsprei@redhat.com> 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> Upstream commit: cb4e5f8ed1b648c451491b10dc92b1af1e324535 BZ: 586173 Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> --- qemu/monitor.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/qemu/monitor.c b/qemu/monitor.c index 2540f3d..94f8e7f 100644 --- a/qemu/monitor.c +++ b/qemu/monitor.c @@ -534,6 +534,7 @@ static void do_change_block(const char *device, const char *filename, const char { BlockDriverState *bs; BlockDriver *drv = NULL; + int bdrv_flags; bs = bdrv_find(device); if (!bs) { @@ -549,7 +550,9 @@ static void do_change_block(const char *device, const char *filename, const char } if (eject_device(bs, 0) < 0) return; - if (bdrv_open2(bs, filename, BDRV_O_RDWR, drv) != 0) { + + bdrv_flags = bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM ? 0 : BDRV_O_RDWR; + if (bdrv_open2(bs, filename, bdrv_flags, drv) != 0) { term_printf("Could not open '%s'\n", filename); return; } -- 1.7.4.rc1.16.gd2f15e