From patchwork Tue Sep 29 10:47:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 7285201 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D6D079F32B for ; Tue, 29 Sep 2015 10:48:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 077F0206CC for ; Tue, 29 Sep 2015 10:48:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A8E01206DD for ; Tue, 29 Sep 2015 10:48:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934703AbbI2Ksl (ORCPT ); Tue, 29 Sep 2015 06:48:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:42014 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934709AbbI2KsF (ORCPT ); Tue, 29 Sep 2015 06:48:05 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1959F7503B; Tue, 29 Sep 2015 10:47:49 +0000 (UTC) From: Hannes Reinecke To: James Bottomley Cc: linux-scsi@vger.kernel.org, Christoph Hellwig , Bart van Assche , Ewan Milne , "Martin K. Petersen" , Hannes Reinecke Subject: [PATCH 33/36] scsi: Add 'access_state' attribute Date: Tue, 29 Sep 2015 12:47:35 +0200 Message-Id: <1443523658-87622-34-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1443523658-87622-1-git-send-email-hare@suse.de> References: <1443523658-87622-1-git-send-email-hare@suse.de> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an 'access_state' attribute to struct scsi_device to display the asymmetric LUN access state. Signed-off-by: Hannes Reinecke --- drivers/scsi/scsi_scan.c | 1 + drivers/scsi/scsi_sysfs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_device.h | 1 + include/scsi/scsi_proto.h | 13 ++++++++++++ 4 files changed, 64 insertions(+) diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 5d3e2ae..76e771e 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -230,6 +230,7 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget, sdev->lun = lun; sdev->channel = starget->channel; sdev->sdev_state = SDEV_CREATED; + sdev->access_state = SCSI_ACCESS_STATE_UNKNOWN; INIT_LIST_HEAD(&sdev->siblings); INIT_LIST_HEAD(&sdev->same_target_siblings); INIT_LIST_HEAD(&sdev->cmd_list); diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 37799dc..38e157a 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -81,6 +81,34 @@ const char *scsi_host_state_name(enum scsi_host_state state) return name; } +static const struct { + enum scsi_access_state value; + char *name; +} sdev_access_states[] = { + { SCSI_ACCESS_STATE_OPTIMAL, "active/optimized" }, + { SCSI_ACCESS_STATE_ACTIVE, "active/non-optimized" }, + { SCSI_ACCESS_STATE_STANDBY, "standby" }, + { SCSI_ACCESS_STATE_UNAVAILABLE, "unavailable" }, + { SCSI_ACCESS_STATE_LBA, "lba-dependent" }, + { SCSI_ACCESS_STATE_OFFLINE, "offline" }, + { SCSI_ACCESS_STATE_TRANSITIONING, "transitioning" }, + { SCSI_ACCESS_STATE_UNKNOWN, "unknown" }, +}; + +const char *scsi_access_state_name(enum scsi_access_state state) +{ + int i; + char *name = NULL; + + for (i = 0; i < ARRAY_SIZE(sdev_access_states); i++) { + if (sdev_access_states[i].value == state) { + name = sdev_access_states[i].name; + break; + } + } + return name; +} + static int check_set(unsigned long long *val, char *src) { char *last; @@ -932,6 +960,26 @@ sdev_store_dh_state(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR(dh_state, S_IRUGO | S_IWUSR, sdev_show_dh_state, sdev_store_dh_state); + +static ssize_t +sdev_show_access_state(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct scsi_device *sdev = to_scsi_device(dev); + enum scsi_access_state access_state; + bool pref = false; + + if (sdev->access_state & SCSI_ACCESS_STATE_PREFERRED) + pref = true; + + access_state = (sdev->access_state & SCSI_ACCESS_STATE_MASK); + + return snprintf(buf, 32, "%s%s\n", + scsi_access_state_name(access_state), + pref ? " preferred" :""); +} +static DEVICE_ATTR(access_state, S_IRUGO, sdev_show_access_state, NULL); #endif static ssize_t @@ -1005,6 +1053,7 @@ static struct attribute *scsi_sdev_attrs[] = { &dev_attr_queue_type.attr, #ifdef CONFIG_SCSI_DH &dev_attr_dh_state.attr, + &dev_attr_access_state.attr, #endif &dev_attr_queue_ramp_up_period.attr, REF_EVT(media_change), diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index cfc23a4..666359f 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -200,6 +200,7 @@ struct scsi_device { struct scsi_device_handler *handler; void *handler_data; + enum scsi_access_state access_state; enum scsi_device_state sdev_state; unsigned long sdev_data[0]; } __attribute__((aligned(sizeof(unsigned long)))); diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index a9fbf1b..80e85e7 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -277,5 +277,18 @@ struct scsi_lun { __u8 scsi_lun[8]; }; +/* SPC asymmetric access states */ +enum scsi_access_state { + SCSI_ACCESS_STATE_OPTIMAL = 0, + SCSI_ACCESS_STATE_ACTIVE, + SCSI_ACCESS_STATE_STANDBY, + SCSI_ACCESS_STATE_UNAVAILABLE, + SCSI_ACCESS_STATE_LBA, + SCSI_ACCESS_STATE_OFFLINE = 0xe, + SCSI_ACCESS_STATE_TRANSITIONING = 0xf, + SCSI_ACCESS_STATE_UNKNOWN = 0x70, +}; +#define SCSI_ACCESS_STATE_MASK 0x0f +#define SCSI_ACCESS_STATE_PREFERRED 0x80 #endif /* _SCSI_PROTO_H_ */