From patchwork Wed Jun 12 11:29:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Riemer X-Patchwork-Id: 2709411 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 44BA69F1E2 for ; Wed, 12 Jun 2013 11:30:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B15C20227 for ; Wed, 12 Jun 2013 11:30:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC8F92020B for ; Wed, 12 Jun 2013 11:30:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751307Ab3FLLaA (ORCPT ); Wed, 12 Jun 2013 07:30:00 -0400 Received: from mail-bk0-f42.google.com ([209.85.214.42]:38379 "EHLO mail-bk0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751171Ab3FLL37 (ORCPT ); Wed, 12 Jun 2013 07:29:59 -0400 Received: by mail-bk0-f42.google.com with SMTP id jk13so4585014bkc.15 for ; Wed, 12 Jun 2013 04:29:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=oM3QhUmdIiO6bPCxyOQVPwXFhvsb6JjVc0T6Lpqtu9w=; b=e8uanRdwjXl+7gyamsNwKHF8fhciB7+LcHREBePthxd1+LEy1rmEg2dPTZIAgTv9oH ol4ePDanCGMNeI7l4o0C6TqxIxG6loGxqIfOz7CAxm8kL3QOs4l9LO9shfEqXO2IkEw9 7PQkLBYEMC+6gpOTfu078hPglzRQpjcNFt/olTc9V8EaJctkC7xzDn4yut4APeJjXETn +X22D/9qarSJOM+hwYIYlm7WB+pLX/ocku4XBON/qMz9paU5OeWrLBmWYBuU63PiUxBb 4kKTaP55kuGAMBibTqH0fJoBS8XmZnQzhOvUtP9eHUnXGKnghtIwGkARA9OGX9EF0Y+x Glzw== X-Received: by 10.204.79.70 with SMTP id o6mr2946884bkk.94.1371036598460; Wed, 12 Jun 2013 04:29:58 -0700 (PDT) Received: from hebron.pb.local ([62.217.45.26]) by mx.google.com with ESMTPSA id oy6sm4652034bkb.14.2013.06.12.04.29.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 12 Jun 2013 04:29:57 -0700 (PDT) From: Sebastian Riemer To: linux-rdma@vger.kernel.org Cc: Sebastian Riemer , Bart Van Assche , David Dillow , Vu Pham , Sagi Grimberg , Oren Duer , Or Gerlitz Subject: [PATCH] IB/srp: Maintain a single connection per I_T nexus Date: Wed, 12 Jun 2013 13:29:57 +0200 Message-Id: <1371036597-23483-1-git-send-email-sebastian.riemer@profitbricks.com> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnbwJEn12Myh08ygKxZ9y6vveHy/p9v4VtjSuID4h/8XXBp7Li7SQsbuCCNx7XN8PYEacL7 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.1 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 The sysfs attribute 'add_target' may not be used for multiple logins to the same target. If doing so with multipathing, this crashes the multipath-tools. Furthermore, we want to prevent the possibility of data corruption here. If manual reconnect is necessary, then the user can use the 'delete' sysfs attribute of the remote port before connecting. Note: The function srp_conn_unique() has been taken from Bart Van Assche. Cc: Bart Van Assche Cc: David Dillow Cc: Vu Pham Cc: Sagi Grimberg Cc: Oren Duer Cc: Or Gerlitz Signed-off-by: Sebastian Riemer Reviewed-by: Christoph Hellwig --- drivers/infiniband/ulp/srp/ib_srp.c | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 7ccf328..d14cc4b 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -2219,6 +2219,36 @@ out: return ret; } +/** + * srp_conn_unique() - Check whether the connection to a target is unique. + * + * Consider targets in state SRP_TARGET_REMOVED as not unique because these + * may already have been removed from the target list. + */ +static bool srp_conn_unique(struct srp_host *host, + struct srp_target_port *target) +{ + struct srp_target_port *t; + bool ret = true; + + if (target->state == SRP_TARGET_REMOVED) + return false; + + spin_lock(&host->target_lock); + list_for_each_entry(t, &host->target_list, list) { + if (t != target && + target->id_ext == t->id_ext && + target->ioc_guid == t->ioc_guid && + target->initiator_ext == t->initiator_ext) { + ret = false; + break; + } + } + spin_unlock(&host->target_lock); + + return ret; +} + static ssize_t srp_create_target(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -2257,6 +2287,14 @@ static ssize_t srp_create_target(struct device *dev, if (ret) goto err; + /* Don't allow multiple logins to the same target port */ + if (!srp_conn_unique(target->srp_host, target)) { + shost_printk(KERN_INFO, target->scsi_host, + PFX "SRP target port is already connected\n"); + ret = -EEXIST; + goto err; + } + if (!host->srp_dev->fmr_pool && !target->allow_ext_sg && target->cmd_sg_cnt < target->sg_tablesize) { pr_warn("No FMR pool and no external indirect descriptors, limiting sg_tablesize to cmd_sg_cnt\n");