From patchwork Wed Jul 20 16:24:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 105932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E013EB6F70 for ; Thu, 21 Jul 2011 15:47:59 +1000 (EST) Received: from localhost ([::1]:60528 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjdoY-0001s7-CB for incoming@patchwork.ozlabs.org; Wed, 20 Jul 2011 16:56:18 -0400 Received: from eggs.gnu.org ([140.186.70.92]:40035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjZhM-00061g-2g for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:32:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjZhD-0001MS-8E for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:32:34 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:39218) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjZhB-0001Ku-Kt for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:32:26 -0400 Received: from oxygen-old.pond.sub.org (unknown [IPv6:2a01:4f8:130:9021::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "oxygen.pond.sub.org", Issuer "CAcert Class 3 Root" (verified OK)) by oxygen.pond.sub.org (Postfix) with ESMTPS id 14A3AA2486; Wed, 20 Jul 2011 18:32:24 +0200 (CEST) Received: from blackfin.pond.sub.org (p5B32D5F4.dip.t-dialin.net [91.50.213.244]) by oxygen-old.pond.sub.org (Postfix) with ESMTPA id A4B612771CC; Wed, 20 Jul 2011 18:32:23 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 98C5135E; Wed, 20 Jul 2011 18:24:32 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 20 Jul 2011 18:24:09 +0200 Message-Id: <1311179069-27882-36-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1311179069-27882-1-git-send-email-armbru@redhat.com> References: <1311179069-27882-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, quintela@redhat.com, dbaryshkov@gmail.com, stefano.stabellini@eu.citrix.com, lcapitulino@redhat.com, amit.shah@redhat.com Subject: [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When scsi-cd is backed by a physical drive, we want the physical tray match the virtual one. To that end, we call bdrv_eject() on guest's load/eject, and bdrv_lock_medium() on guest's prevent/allow removal. But we don't set the initial state on device model init. Fix that. While there, also unlock on device model exit. Signed-off-by: Markus Armbruster Reviewed-by: Christoph Hellwig --- hw/scsi-disk.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index b9de4df..553d8c6 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1270,6 +1270,9 @@ static void scsi_destroy(SCSIDevice *dev) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); scsi_device_purge_requests(&s->qdev); + if (s->drive_kind == SCSI_CD) { + bdrv_lock_medium(s->qdev.conf.bs, 0); + } blockdev_mark_auto_del(s->qdev.conf.bs); } @@ -1332,6 +1335,10 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind) s->qdev.type = TYPE_DISK; qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s); bdrv_set_removable(s->bs, kind == SCSI_CD); + if (kind == SCSI_CD) { + bdrv_lock_medium(s->bs, s->tray_locked); + bdrv_eject(s->bs, s->tray_open); + } add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0"); return 0; }