From patchwork Tue Sep 20 15:26:46 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 115588 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 D2E76B6FA3 for ; Wed, 21 Sep 2011 01:48:05 +1000 (EST) Received: from localhost ([::1]:41794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R62Ei-0007DT-O9 for incoming@patchwork.ozlabs.org; Tue, 20 Sep 2011 11:27:52 -0400 Received: from eggs.gnu.org ([140.186.70.92]:34417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R62E1-0005Xs-Cw for qemu-devel@nongnu.org; Tue, 20 Sep 2011 11:27:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R62Dz-0005Sh-R7 for qemu-devel@nongnu.org; Tue, 20 Sep 2011 11:27:09 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:37270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R62Dz-0005Pb-FI for qemu-devel@nongnu.org; Tue, 20 Sep 2011 11:27:07 -0400 Received: by mail-wy0-f173.google.com with SMTP id 22so679909wyh.4 for ; Tue, 20 Sep 2011 08:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=CTMfmDtGG4sa10N/a1U2sGUL1esnxSzlEXB8EMBJAxk=; b=JXZuGi16S66fXgE7LU4fS31wal5XpQrAmVr8zwDjEHGz5rgf5zDxPfw4aLP9vOFnZt /WU5RHu/d15x4flEF+SJ8sMoeDax1MHJ/JWV9R0dqeT2ikWq8UfLRMu/rUhnbmyylEpk Ng2qrYNvgez2KJeiqf7kT1FRemtKN6A2hX4R4= Received: by 10.216.14.91 with SMTP id c69mr1035313wec.81.1316532427001; Tue, 20 Sep 2011 08:27:07 -0700 (PDT) Received: from localhost.localdomain (93-34-188-71.ip51.fastwebnet.it. [93.34.188.71]) by mx.google.com with ESMTPS id j18sm2778312wbo.6.2011.09.20.08.27.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Sep 2011 08:27:06 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 20 Sep 2011 17:26:46 +0200 Message-Id: <1316532406-25340-13-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1316532406-25340-1-git-send-email-pbonzini@redhat.com> References: <1316532406-25340-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Subject: [Qemu-devel] [PATCH 12/12] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION 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 This adds support for media change notification via the GET EVENT STATUS NOTIFICATION command, used by Linux versions 2.6.38 and newer. Signed-off-by: Paolo Bonzini --- hw/scsi-disk.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 53 insertions(+), 4 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 778332e..6f5d607 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -72,6 +72,7 @@ struct SCSIDiskState uint32_t removable; uint64_t max_lba; bool media_changed; + bool new_media; QEMUBH *bh; char *version; char *serial; @@ -681,11 +682,58 @@ fail: return -1; } -static int scsi_get_event_status_notification(SCSIDiskState *s, - SCSIDiskReq *r, uint8_t *outbuf) +static int scsi_event_status_media(SCSIDiskState *s, uint8_t *outbuf) { - scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE)); - return -1; + uint8_t event_code, media_status; + + media_status = 0; + if (s->tray_open) { + media_status = MS_TRAY_OPEN; + } else if (bdrv_is_inserted(s->bs)) { + media_status = MS_MEDIA_PRESENT; + } + + /* Event notification descriptor */ + event_code = MEC_NO_CHANGE; + if (media_status != MS_TRAY_OPEN && s->new_media) { + event_code = MEC_NEW_MEDIA; + s->new_media = false; + } + + outbuf[0] = event_code; + outbuf[1] = media_status; + + /* These fields are reserved, just clear them. */ + outbuf[2] = 0; + outbuf[3] = 0; + return 4; +} + +static int scsi_get_event_status_notification(SCSIDiskState *s, SCSIDiskReq *r, + uint8_t *outbuf) +{ + int size; + uint8_t *buf = r->req.cmd.buf; + uint8_t notification_class_request = buf[4]; + if (s->qdev.type != TYPE_ROM) { + return -1; + } + if ((buf[1] & 1) == 0) { + /* asynchronous */ + return -1; + } + + size = 4; + outbuf[0] = outbuf[1] = 0; + outbuf[3] = 1 << GESN_MEDIA; /* supported events */ + if (notification_class_request & (1 << GESN_MEDIA)) { + outbuf[2] = GESN_MEDIA; + size += scsi_event_status_media(s, &outbuf[size]); + } else { + outbuf[2] = 0x80; + } + stw_be_p(outbuf, size - 4); + return size; } static int scsi_get_configuration(SCSIDiskState *s, uint8_t *outbuf) @@ -1415,6 +1463,7 @@ static void scsi_cd_change_media_cb(void *opaque, bool load) s->media_changed = load; s->tray_open = !load; s->qdev.unit_attention = SENSE_CODE(UNIT_ATTENTION_NO_MEDIUM); + s->new_media = true; } static bool scsi_cd_is_tray_open(void *opaque)