From patchwork Mon Jul 16 14:25:54 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 171210 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 3C1EC2C00E0 for ; Tue, 17 Jul 2012 00:26:45 +1000 (EST) Received: from localhost ([::1]:37748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqmG3-00071u-8w for incoming@patchwork.ozlabs.org; Mon, 16 Jul 2012 10:26:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqmFh-0006dX-91 for qemu-devel@nongnu.org; Mon, 16 Jul 2012 10:26:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SqmFc-0003so-Pv for qemu-devel@nongnu.org; Mon, 16 Jul 2012 10:26:21 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:40152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SqmFc-0003sh-Ku for qemu-devel@nongnu.org; Mon, 16 Jul 2012 10:26:16 -0400 Received: by yhpp34 with SMTP id p34so3515167yhp.4 for ; Mon, 16 Jul 2012 07:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=fvWwG9aF/Ko7KjbvM9LJA7YWBGQ8CCYxUjd0cqnocXE=; b=uHUd1c56qs5O58K4adYA0VvFt6FYFK2xQfYLE2tk82EYsNHwyV6q3DY2nmPlash1Cb RbUpyXci2zzK2h4M1JHt68hG3dcgN2/cBsw5WpkaTy/d4FdtPGUsBpUPy+gE7VUBa3N4 a+dXW8cBhzBqRz4SPpKmH8Uis6YAgOUqSxi1IFfm9/VQ+a78fSsf7szir/RlB63so76n q1AADOUsGQTX5Sb/LeWSlTJ4t2wKl5aePEjhlHodOvjdvyF6Aw/QaBV3VfxBfHoqDddu PqrIe6M6ePyAbXSrCSDbDYrocCkHwzcKfklAO+WF5I3NdCfYnf0OitqygAbGVzlhoSk2 gxsg== Received: by 10.68.237.103 with SMTP id vb7mr27850896pbc.38.1342448775910; Mon, 16 Jul 2012 07:26:15 -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 qa5sm11997476pbb.19.2012.07.16.07.26.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 07:26:14 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 16 Jul 2012 16:25:54 +0200 Message-Id: <1342448756-7582-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1342448756-7582-1-git-send-email-pbonzini@redhat.com> References: <1342448756-7582-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.213.45 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 3/5] 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 2547c50..d5e1fb0 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1530,6 +1530,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; @@ -1538,7 +1587,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 0905446..fabd0bf 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1886,7 +1886,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; } @@ -1925,7 +1925,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 e901350..4804be9 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 7baa42d..90e9c2a 100644 --- a/trace-events +++ b/trace-events @@ -393,6 +393,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"