From patchwork Fri Jul 27 15:02:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 173738 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7F3282C0090 for ; Sat, 28 Jul 2012 02:32:01 +1000 (EST) Received: from localhost ([::1]:49252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5m-000896-3D for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 11:04:38 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5c-0007wE-3G for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sum5V-0007V4-UP for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:28 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:59010) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5V-0007FU-Nr for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:21 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro12so4974590pbb.4 for ; Fri, 27 Jul 2012 08:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=CddXbwNykTEiBoD4YKETdntgyIXKbVsI7lA50IMNvfE=; b=VZ5DRfltPNLSSTzncxtZdKhOoVGTrkCYfR+O5TVuAo0UXUpB/iY+gssNRx+hTzhXMY CUNT45Y0CNiVge2LW0rJOCznL3CP9lr9HgObYqtyc9iJpaERXps7SQdAC1hdkCxcZpFY cmHe9QDkF0vdLzA+pV1MXIcRFrCBnE5xzSeBrzVT2PeJqXyzu/KvLH+C4MK9s9xwPZWW CWJmbrbG25WoQZ2UNMVy+uIlXKbW9gGzHKUKKqcjRpNowxUq4X7x5CPBoEzrwg8VIcjL ABFQXNRSQix6pA3S4ldr1l7WiB8IOV84kHPJVsABOb1FByOKlO4D1CZaSof1N7ts9Xvj ZN2g== Received: by 10.68.237.103 with SMTP id vb7mr14976004pbc.38.1343401461389; Fri, 27 Jul 2012 08:04:21 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-189-113.ip51.fastwebnet.it. [93.34.189.113]) by mx.google.com with ESMTPS id nk3sm2062530pbc.27.2012.07.27.08.04.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jul 2012 08:04:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 17:02:51 +0200 Message-Id: <1343401379-19495-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> References: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 24/32] scsi: establish precedence levels for unit attention 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 a device is resized, we will report a unit attention condition for CAPACITY DATA HAS CHANGED. However, we should ensure that this condition does not override a more important unit attention condition. Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- hw/scsi-disk.c | 4 ++-- hw/scsi.h | 1 + trace-events | 1 + 4 files changed, 55 insertions(+), 3 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 6ee0c10..c38c0ec 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1531,6 +1531,55 @@ void scsi_req_abort(SCSIRequest *req, int status) scsi_req_unref(req); } +static int scsi_ua_precedence(SCSISense sense) +{ + if (sense.key != UNIT_ATTENTION) { + return INT_MAX; + } + if (sense.asc == 0x29 && sense.ascq == 0x04) { + /* DEVICE INTERNAL RESET goes with POWER ON OCCURRED */ + return 1; + } else if (sense.asc == 0x3F && sense.ascq == 0x01) { + /* MICROCODE HAS BEEN CHANGED goes with SCSI BUS RESET OCCURRED */ + return 2; + } else if (sense.asc == 0x29 && (sense.ascq == 0x05 || sense.ascq == 0x06)) { + /* These two go with "all others". */ + ; + } else if (sense.asc == 0x29 && sense.ascq <= 0x07) { + /* POWER ON, RESET OR BUS DEVICE RESET OCCURRED = 0 + * POWER ON OCCURRED = 1 + * SCSI BUS RESET OCCURRED = 2 + * BUS DEVICE RESET FUNCTION OCCURRED = 3 + * I_T NEXUS LOSS OCCURRED = 7 + */ + return sense.ascq; + } else if (sense.asc == 0x2F && sense.ascq == 0x01) { + /* COMMANDS CLEARED BY POWER LOSS NOTIFICATION */ + return 8; + } + return (sense.asc << 8) | sense.ascq; +} + +void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense) +{ + int prec1, prec2; + if (sense.key != UNIT_ATTENTION) { + return; + } + trace_scsi_device_set_ua(sdev->id, sdev->lun, sense.key, + sense.asc, sense.ascq); + + /* + * Override a pre-existing unit attention condition, except for a more + * important reset condition. + */ + prec1 = scsi_ua_precedence(sdev->unit_attention); + prec2 = scsi_ua_precedence(sense); + if (prec2 < prec1) { + sdev->unit_attention = sense; + } +} + void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense) { SCSIRequest *req; @@ -1539,7 +1588,8 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense) req = QTAILQ_FIRST(&sdev->requests); scsi_req_cancel(req); } - sdev->unit_attention = sense; + + scsi_device_set_ua(sdev, sense); } static char *scsibus_get_dev_path(DeviceState *dev) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index b52e304..734fe13 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1876,7 +1876,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); + scsi_device_set_ua(&s->qdev, SENSE_CODE(UNIT_ATTENTION_NO_MEDIUM)); s->media_event = true; s->eject_request = false; } @@ -1913,7 +1913,7 @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev) SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev); if (s->media_changed) { s->media_changed = false; - s->qdev.unit_attention = SENSE_CODE(MEDIUM_CHANGED); + scsi_device_set_ua(&s->qdev, SENSE_CODE(MEDIUM_CHANGED)); } } diff --git a/hw/scsi.h b/hw/scsi.h index 088d519..f920208 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -239,6 +239,7 @@ void scsi_req_abort(SCSIRequest *req, int status); void scsi_req_cancel(SCSIRequest *req); void scsi_req_retry(SCSIRequest *req); void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense); +void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense); int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed); SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun); diff --git a/trace-events b/trace-events index 7aa28b1..6b12f83 100644 --- a/trace-events +++ b/trace-events @@ -412,6 +412,7 @@ scsi_req_parsed(int target, int lun, int tag, int cmd, int mode, int xfer) "targ scsi_req_parsed_lba(int target, int lun, int tag, int cmd, uint64_t lba) "target %d lun %d tag %d command %d lba %"PRIu64 scsi_req_parse_bad(int target, int lun, int tag, int cmd) "target %d lun %d tag %d command %d" scsi_req_build_sense(int target, int lun, int tag, int key, int asc, int ascq) "target %d lun %d tag %d key %#02x asc %#02x ascq %#02x" +scsi_device_set_ua(int target, int lun, int key, int asc, int ascq) "target %d lun %d key %#02x asc %#02x ascq %#02x" scsi_report_luns(int target, int lun, int tag) "target %d lun %d tag %d" scsi_inquiry(int target, int lun, int tag, int cdb1, int cdb2) "target %d lun %d tag %d page %#02x/%#02x" scsi_test_unit_ready(int target, int lun, int tag) "target %d lun %d tag %d"