From patchwork Thu Nov 5 06:09:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 318312 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MIME_HEADER_CTYPE_ONLY,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, T_TVD_MIME_NO_HEADERS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C818CC00A89 for ; Thu, 5 Nov 2020 13:03:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 63CE020756 for ; Thu, 5 Nov 2020 13:03:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="Gc6EY/T5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730669AbgKENDd (ORCPT ); Thu, 5 Nov 2020 08:03:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgKENDb (ORCPT ); Thu, 5 Nov 2020 08:03:31 -0500 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74B1C0613CF for ; Thu, 5 Nov 2020 05:03:31 -0800 (PST) Received: by mail-pj1-x1041.google.com with SMTP id b23so45963pju.5 for ; Thu, 05 Nov 2020 05:03:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nwJXdfa81GZUf6tOrWB3ofabgq/Xcim3w7/tL7ez6Pk=; b=Gc6EY/T5G4tml13g54s3u+8UmgNqtwcvKyLH19KmbrWhfkDfeP+hDHxi0xTVbpAUi7 bXN4MIyT/O7DXEveUbZo0A+giTb8ePHpTSZFwbCS4C5EhbKdHTpgN4LfpApDtahfzw2b axw2b8dOVzNq/t1tnwxdrAcp2NlRA4K+ZRY7Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nwJXdfa81GZUf6tOrWB3ofabgq/Xcim3w7/tL7ez6Pk=; b=PbsZa3mVLmEX/4s8E/wo91LCXYPeWYBZHz3kIzabeNn1BKSn3Dava2izqoo8ANL0mr UfXahaxpDBZ9Oti8zz7Svm3YZuo63kXr42PqJlXgdb/FMDRmsA5PBm9gD0ZtMOWj0BQ2 vF855WD6w0xBVaXshAg4iIldPJ+VP3hPEt7d+qFOQMKfXNWGTP/wmGmfaD2QKoUMm7Qr 8fNQRPySFfzSFSNmwco8EO0IDOBmvfWrljDwr4jgVDU9ZC1jeTL5cjELkzxt1Fdj6WuO 22I8ZLnAtkddIJJok3dUVkS6FPQcIK+r9gsVvXlt3kpisBryPu3Etb0L2POlVPKMAAwk 0H3A== X-Gm-Message-State: AOAM530V8v5YbTaZWRy77OvqmxrU5U+AXZAv2sS+Is8Mw9lpYGxP8Ka3 WpZ4TA9mUnuen+BYNJSsS8Ble+AqOoHZygplK0atCuu7J+l/sq1z5HdngbK5XGjtsN5vfCqvHk1 BsIKnJG+WlCbBVAb96azS4eE/zha/XcKwljKn81enRg9N5ryW4XBEZn35W2iO7HxWAkhkadbAbf aHVtRSywBa+KQ= X-Google-Smtp-Source: ABdhPJwkQbnpu7ojOU5mjaQXN+31L3kjkq5Zmf8G6LEuXtIrfcBjk/Vj8fkSa+l8TfmZfGJmVlgolA== X-Received: by 2002:a17:90a:8b93:: with SMTP id z19mr2337078pjn.123.1604581408571; Thu, 05 Nov 2020 05:03:28 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id y141sm2491319pfb.17.2020.11.05.05.03.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Nov 2020 05:03:28 -0800 (PST) From: Muneendra To: linux-scsi@vger.kernel.org, michael.christie@oracle.com, hare@suse.de Cc: jsmart2021@gmail.com, emilne@redhat.com, mkumar@redhat.com, Muneendra Subject: [PATCH v6 4/4] scsi_transport_fc: Added store fucntionality to set the rport port_state using sysfs Date: Thu, 5 Nov 2020 11:39:56 +0530 Message-Id: <1604556596-27228-5-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1604556596-27228-1-git-send-email-muneendra.kumar@broadcom.com> References: <1604556596-27228-1-git-send-email-muneendra.kumar@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Added a store functionality to set rport port_state using sysfs under fc_remote_ports/rport-*/port_state With this functionality the user can move the port_state from Marginal -> Online and Online->Marginal. On Marginal :This interface will set SCMD_NORETRIES_ABORT bit in scmd->state for all the pending io's on the scsi device associated with target port. On Online :This interface will clear SCMD_NORETRIES_ABORT bit in scmd->state for all the pending io's on the scsi device associated with target port. Below is the interface provided to set the port state to Marginal and Online. echo "Marginal" >> /sys/class/fc_remote_ports/rport-X\:Y-Z/port_state echo "Online" >> /sys/class/fc_remote_ports/rport-X\:Y-Z/port_state Signed-off-by: Muneendra --- v6: No change v5: No change v4: Addressed the error reported by kernel test robot Removed the code needed to traverse all the devices under rport to set/clear SCMD_NORETRIES_ABORT Removed unncessary comments. Return the error values on failure while setting the port_state v3: Removed the port_state from starget attributes. Enabled the store functionality for port_state under remote port. used the starget_for_each_device to traverse around all the devices under rport v2: Changed from a noretries_abort attribute under fc_transport/target*/ to port_state for changing the port_state to a marginal state --- drivers/scsi/scsi_transport_fc.c | 56 ++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c index 276826db0832..764bff609c5d 100644 --- a/drivers/scsi/scsi_transport_fc.c +++ b/drivers/scsi/scsi_transport_fc.c @@ -943,7 +943,59 @@ show_fc_rport_roles (struct device *dev, struct device_attribute *attr, static FC_DEVICE_ATTR(rport, roles, S_IRUGO, show_fc_rport_roles, NULL); -fc_private_rport_rd_enum_attr(port_state, FC_PORTSTATE_MAX_NAMELEN); +static ssize_t fc_rport_set_marginal_state(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct fc_rport *rport = transport_class_to_rport(dev); + enum fc_port_state port_state; + int ret = 0; + + ret = get_fc_port_state_match(buf, &port_state); + if (ret) + return -EINVAL; + if (port_state == FC_PORTSTATE_MARGINAL) { + /* + * Change the state to marginal only if the + * current rport state is Online + * Allow only Online->marginal + */ + if (rport->port_state == FC_PORTSTATE_ONLINE) + rport->port_state = port_state; + else + return -EINVAL; + } else if (port_state == FC_PORTSTATE_ONLINE) { + /* + * Change the state to Online only if the + * current rport state is Marginal + * Allow only MArginal->Online + */ + if (rport->port_state == FC_PORTSTATE_MARGINAL) + rport->port_state = port_state; + else + return -EINVAL; + } else + return -EINVAL; + return count; +} + +static ssize_t +show_fc_rport_port_state(struct device *dev, + struct device_attribute *attr, char *buf) +{ + const char *name; + struct fc_rport *rport = transport_class_to_rport(dev); + + name = get_fc_port_state_name(rport->port_state); + if (!name) + return -EINVAL; + + return snprintf(buf, 20, "%s\n", name); +} + +static FC_DEVICE_ATTR(rport, port_state, 0444 | 0200, + show_fc_rport_port_state, fc_rport_set_marginal_state); + fc_private_rport_rd_attr(scsi_target_id, "%d\n", 20); /* @@ -2267,7 +2319,7 @@ fc_attach_transport(struct fc_function_template *ft) SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_name); SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_id); SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(roles); - SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(port_state); + SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(port_state); SETUP_PRIVATE_RPORT_ATTRIBUTE_RD(scsi_target_id); SETUP_PRIVATE_RPORT_ATTRIBUTE_RW(fast_io_fail_tmo);