From patchwork Wed Jul 8 11:09:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6745051 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 05CEA9F319 for ; Wed, 8 Jul 2015 11:10:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D6042060F for ; Wed, 8 Jul 2015 11:10:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C9552060C for ; Wed, 8 Jul 2015 11:10:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933875AbbGHLKF (ORCPT ); Wed, 8 Jul 2015 07:10:05 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45662 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933801AbbGHLJw (ORCPT ); Wed, 8 Jul 2015 07:09:52 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5B0D9AC57; Wed, 8 Jul 2015 11:09:50 +0000 (UTC) From: Hannes Reinecke To: James Bottomley Cc: Bart van Assche , Christoph Hellwig , linux-scsi@vger.kernel.org, Ewan Milne , Hannes Reinecke Subject: [PATCH 4/5] scsi_dh_alua: add 'state' callback function Date: Wed, 8 Jul 2015 13:09:47 +0200 Message-Id: <1436353788-104911-5-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1436353788-104911-1-git-send-email-hare@suse.de> References: <1436353788-104911-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=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 a 'state' callback function to display the current path status in sysfs. Signed-off-by: Hannes Reinecke --- drivers/scsi/device_handler/scsi_dh_alua.c | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index 5b52017..99c4b0f 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -1182,6 +1182,52 @@ static void alua_check(struct scsi_device *sdev, bool force) } /* + * alua_state - report path status + * @sdev: device on the path to be checked + * + * Check the device status + */ +static int alua_state(struct scsi_device *sdev) +{ + struct alua_dh_data *h = sdev->handler_data; + struct alua_port_group *pg = NULL; + int access_state = SCSI_ACCESS_STATE_UNKNOWN; + + rcu_read_lock(); + if (h) + pg = rcu_dereference(h->pg); + if (pg) { + switch (pg->state) { + case TPGS_STATE_OPTIMIZED: + access_state = SCSI_ACCESS_STATE_OPTIMAL; + break; + case TPGS_STATE_NONOPTIMIZED: + access_state = SCSI_ACCESS_STATE_ACTIVE; + break; + case TPGS_STATE_STANDBY: + access_state = SCSI_ACCESS_STATE_PASSIVE; + break; + case TPGS_STATE_UNAVAILABLE: + access_state = SCSI_ACCESS_STATE_UNAVAILABLE; + break; + case TPGS_STATE_LBA_DEPENDENT: + access_state = SCSI_ACCESS_STATE_LBA; + break; + case TPGS_STATE_OFFLINE: + access_state = SCSI_ACCESS_STATE_OFFLINE; + break; + case TPGS_STATE_TRANSITIONING: + access_state = SCSI_ACCESS_STATE_TRANSITIONING; + break; + } + if (pg->pref) + access_state |= SCSI_ACCESS_STATE_PREFERRED; + } + rcu_read_unlock(); + return access_state; +} + +/* * alua_prep_fn - request callback * * Fail I/O to all paths not in state @@ -1288,6 +1334,7 @@ static struct scsi_device_handler alua_dh = { .activate = alua_activate, .rescan = alua_rescan, .set_params = alua_set_params, + .state = alua_state, }; static int __init alua_init(void)