From patchwork Wed Jul 8 09:06:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 6743141 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6CA3BC05AC for ; Wed, 8 Jul 2015 09:09:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96E7520675 for ; Wed, 8 Jul 2015 09:09:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6B9A72071E for ; Wed, 8 Jul 2015 09:09:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933769AbbGHJI3 (ORCPT ); Wed, 8 Jul 2015 05:08:29 -0400 Received: from cantor2.suse.de ([195.135.220.15]:35944 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934517AbbGHJGd (ORCPT ); Wed, 8 Jul 2015 05:06:33 -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 1F3ACAD8C; Wed, 8 Jul 2015 09:06:25 +0000 (UTC) From: Hannes Reinecke To: James Bottomley Cc: Christoph Hellwig , linux-scsi@vger.kernel.org, "Martin K. Petersen" , Bart van Assche , Hannes Reinecke Subject: [PATCH 18/20] scsi_dh_alua: update all port states Date: Wed, 8 Jul 2015 11:06:16 +0200 Message-Id: <1436346378-96518-19-git-send-email-hare@suse.de> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1436346378-96518-1-git-send-email-hare@suse.de> References: <1436346378-96518-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 When we read in the target port group state we should be updating all affected port groups, otherwise we risk running out of sync. Signed-off-by: Hannes Reinecke --- drivers/scsi/device_handler/scsi_dh_alua.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c index aa58659..44b57bc 100644 --- a/drivers/scsi/device_handler/scsi_dh_alua.c +++ b/drivers/scsi/device_handler/scsi_dh_alua.c @@ -560,11 +560,13 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) { unsigned char sense[SCSI_SENSE_BUFFERSIZE]; struct scsi_sense_hdr sense_hdr; + struct alua_port_group *tmp_pg; int len, k, off, valid_states = 0, bufflen = ALUA_RTPG_SIZE; unsigned char *ucp, *buff; unsigned err, retval; unsigned int tpg_desc_tbl_off; unsigned char orig_transition_tmo; + unsigned long flags; if (!pg->expiry) { if (!pg->transition_tmo) @@ -669,17 +671,35 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) else tpg_desc_tbl_off = 4; + spin_lock_irqsave(&port_group_lock, flags); for (k = tpg_desc_tbl_off, ucp = buff + tpg_desc_tbl_off; k < len; k += off, ucp += off) { - if (pg->group_id == (ucp[2] << 8) + ucp[3]) { - pg->state = ucp[0] & 0x0f; - pg->pref = ucp[0] >> 7; - valid_states = ucp[1]; + list_for_each_entry(tmp_pg, &port_group_list, node) { + u16 group_id = get_unaligned_be16(&ucp[2]); + if (tmp_pg->group_id != group_id) + continue; + if (tmp_pg->device_id_size != pg->device_id_size) + continue; + if (memcmp(tmp_pg->device_id, pg->device_id, + tmp_pg->device_id_size)) + continue; + tmp_pg->state = ucp[0] & 0x0f; + tmp_pg->pref = ucp[0] >> 7; + sdev_printk(KERN_INFO, sdev, + "%s: device %s port group %02x " + "state %c %s\n", ALUA_DH_NAME, + tmp_pg->device_id_str, tmp_pg->group_id, + print_alua_state(tmp_pg->state), + tmp_pg->pref ? + "preferred" : "non-preferred"); + if (tmp_pg == pg) + valid_states = ucp[1]; } off = 8 + (ucp[7] * 4); } + spin_unlock_irqrestore(&port_group_lock, flags); sdev_printk(KERN_INFO, sdev, "%s: port group %02x state %c %s supports %c%c%c%c%c%c%c\n",