From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O657a-0002Ob-SR for qemu-devel@nongnu.org; Sun, 25 Apr 2010 12:55:54 -0400 Received: from [140.186.70.92] (port=43247 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O657Z-0002OS-PR for qemu-devel@nongnu.org; Sun, 25 Apr 2010 12:55:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O657Y-0004md-7g for qemu-devel@nongnu.org; Sun, 25 Apr 2010 12:55:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54682) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O657Y-0004mD-0L for qemu-devel@nongnu.org; Sun, 25 Apr 2010 12:55:52 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3PGtlu9026469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 25 Apr 2010 12:55:48 -0400 Received: from localhost.localdomain (dhcp-0-60.tlv.redhat.com [10.35.0.60]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3PGUcQO013851 for ; Sun, 25 Apr 2010 12:30:39 -0400 From: Naphtali Sprei Date: Sun, 25 Apr 2010 19:30:37 +0300 Message-Id: <1272213037-30327-1-git-send-email-nsprei@redhat.com> Subject: [Qemu-devel] [PATCH] block: read-only: open cdrom as read-only when using monitor's change command List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- monitor.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/monitor.c b/monitor.c index c25d551..df5a15d 100644 --- a/monitor.c +++ b/monitor.c @@ -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; } -- 1.6.3.3