From patchwork Mon Apr 12 00:50:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 420589 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, 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 7452DC43460 for ; Mon, 12 Apr 2021 00:51:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 418E66120A for ; Mon, 12 Apr 2021 00:51:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236199AbhDLAva (ORCPT ); Sun, 11 Apr 2021 20:51:30 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:47358 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236191AbhDLAv3 (ORCPT ); Sun, 11 Apr 2021 20:51:29 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13C0hvTl125226; Mon, 12 Apr 2021 00:50:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2020-01-29; bh=05pUn6y81TJ+Z5O1EOahcdiXgWzFShidFYYhkG6fB1U=; b=b49hVe/HMaDnUZat9u7kAPDHyCzHngyxEp3xgAH88zxd3kMl2wni8ZL4uFjdPuBheEXy B0o4oJa4faJD+2z/+TWkOFw4iFqZwMmXUChedxQd/4zEdcoruxzZg1wCoLlYx2vNKBjK +b1RV8lJNYeqhy+5hKBPGZUNeFWBLCzlEMSirobQwrsxEJ8StAMOqqQZmKyle4rivS79 z9QQhNRqHrFBvU2wvLyADUpv46WKkAuE+Q/e6OtjxeGOMBSotQUNrLa4FTaqQ2S9B+DU Nl8u4+AeoPVGW5jApK8S4j5actY6JuRQhnLmKLeC8jfEtf2Ko5oaUbeuMD9mq477dYPu 5g== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 37u3era14g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Apr 2021 00:50:59 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 13C0aGvF037388; Mon, 12 Apr 2021 00:50:59 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2100.outbound.protection.outlook.com [104.47.70.100]) by userp3030.oracle.com with ESMTP id 37unxur477-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Apr 2021 00:50:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OzN/RgzO1K0DidFQERChddfPEgipeXLlNa9Qn9Wnyerwmsy5GYfgItPSo0mAqM5sY82Zl3us667fa1SekYkNnfIywLOsHVhlREbof+IzJK5Zc3z49V6Iqk0/yp1JQSDQx0vQRTlIH60NKqiy0hV27RIbgK4Mrt0Z1uaUCSO0aZPnroT+ECf0ndKTGLCAA99KPlfr6fm9wToloh9FxEluk67nm4QJPB8C4iEv+MOOS9qrNev6k2Qf8A+H+if1/LQgzGXnhZXxm0sxcENMz8p5HyC59BpSrClzy8D0/EUwpgxoi/G9hk+kDuabObhNnn798CTBAsltR38+4piInMByng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=05pUn6y81TJ+Z5O1EOahcdiXgWzFShidFYYhkG6fB1U=; b=MmEpMgCD4LorinqpgtNFSeX3Ipmg7ti+hE4njyqOp9MLeEbE0VRxK8tMqMVgYxcpKgZ6gij7M/p75lTSQtSdhbqueFDD/vEYoA60EpD9cwfAkk0olAePJQ4uL1GXDIg03ce8pAq9C3QJXxxD3CJryec7RtOisTWc71kNhijQm6N1Cvxs8/9qGDGLjP44Ic00LtdVnB/b9I0RLtlSv3AaamKOOdn0VjA5sAkSmVfDL2YP7DwqexrFfzGP93fqS2BuPMUofQJUDXMpgehrkczX8Zk1wDHwkO/HYyLONX1X8Bduiir5Sa+XL6ymKyocexin0sSxTssabb3741HbNhSPWg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=05pUn6y81TJ+Z5O1EOahcdiXgWzFShidFYYhkG6fB1U=; b=seNb07EEW2KZQ3puakKVPDEfnucY7gdDyEIh9mHipxyPuMk7PydJ0L0raEpDOHTRfJU30t3Rqn19R/XBrFtUUlBATrMMWC8K6htOUq34JOrpxXy+nc7cFXOsRoeSB+SjpmKX29WP7vL0Bwwy3tLnNrXv5Y9mEhe8VeJRkXgMHjM= Authentication-Results: google.com; dkim=none (message not signed) header.d=none; google.com; dmarc=none action=none header.from=oracle.com; Received: from BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) by BY5PR10MB4307.namprd10.prod.outlook.com (2603:10b6:a03:212::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.21; Mon, 12 Apr 2021 00:50:56 +0000 Received: from BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::50bb:7b66:35ee:4a4]) by BYAPR10MB3573.namprd10.prod.outlook.com ([fe80::50bb:7b66:35ee:4a4%7]) with mapi id 15.20.4020.018; Mon, 12 Apr 2021 00:50:56 +0000 From: Mike Christie To: khazhy@google.com, lduncan@suse.com, martin.petersen@oracle.com, rbharath@google.com, krisman@collabora.com, linux-scsi@vger.kernel.org, jejb@linux.ibm.com Cc: Mike Christie Subject: [RFC v2 4/7] scsi: iscsi: have callers do the put on iscsi_lookup_endpoint Date: Sun, 11 Apr 2021 19:50:40 -0500 Message-Id: <20210412005043.5121-5-michael.christie@oracle.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210412005043.5121-1-michael.christie@oracle.com> References: <20210412005043.5121-1-michael.christie@oracle.com> X-Originating-IP: [73.88.28.6] X-ClientProxiedBy: DM6PR06CA0062.namprd06.prod.outlook.com (2603:10b6:5:54::39) To BYAPR10MB3573.namprd10.prod.outlook.com (2603:10b6:a03:11e::32) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (73.88.28.6) by DM6PR06CA0062.namprd06.prod.outlook.com (2603:10b6:5:54::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4020.17 via Frontend Transport; Mon, 12 Apr 2021 00:50:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd80b366-e76d-4435-9de6-08d8fd4d0820 X-MS-TrafficTypeDiagnostic: BY5PR10MB4307: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D8oTST8IU5WCDo5ZGE+gqq1aB1iz7qISZfhPLuZzpik9pCg9Fv/yGEdPVolzw5zjd6xG6GHHJHniivYEVHRud92iqHp8sjHH80gJ9YCMEaF1+4QO7ap41IUTuo0I3QRBfDozoxxzoSebbBx8N24BDMszahDA9joZwtU2jo7pinX9af7JJyeuHayjjSoxBSs02InR0qEb/KyShAkmMWVDhYf1la9LswGuWzOUCS08YgbT/5KNIm9eRQDaJcvCrAzVzAvDuwLo3ajew+LJpO9+BD3YXOMR7G80AJarwEtMrzkvMsIL+W7tFnYHlBduQgs1p7CUu6nBwS+Fy6Ytx2y2gxINdAIJAvLFeWz3A3s04nqbRtPOyuDeENxGeCov4k+YDOup2xzudXmxqsF2Bfh7QuG8CdlsvJ4uP04ylMqsbDgMkijBu5LFdEV69XIOerSXhXN4JjRnYC6fI6Yb9NKiURI+x26bZE8xg6/wuts7Jlx4ZG7ldo1M8/kfJsnqKrKQmblB/1+jSYySbimcdV9cljWq9unG5tZ/6bDMEN4cG8sPFuJHT5AuLI7GQO9mlvJs+eVEzN2470beePUsR1oVAbafdFvanJJd9NmJMyKWt3Hkq4r2g9SWw7uWmjI0bDauleT3OVtT2nrLWmflrhcIO4oH2kLyNb5836XXAzWSPCLPTl2Q5RQuLXFPn/hvJ5TR X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3573.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(136003)(376002)(396003)(366004)(39860400002)(26005)(316002)(186003)(16526019)(2906002)(86362001)(83380400001)(1076003)(4326008)(107886003)(956004)(66556008)(478600001)(8676002)(38100700002)(8936002)(69590400012)(2616005)(66946007)(5660300002)(6506007)(6486002)(38350700002)(6512007)(6666004)(36756003)(52116002)(66476007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: kY68G739JH7RRExrvrOfp7OCqqm0iIyw50Moo5zfQTki6XaUQ8TKTf6ZuveZH+dCsm0rL2UfBcc0ooD1Q3/DXVmkFsDjI8QgMJLSehuIkWQsrxkwWRPpkdvROhsQWCCY26ZKl/wrs0+8N7wluDnJbRpRSEPfpbQWHS1s+6QgXyrywJ+SSo2OzGTTXLRhztyM9THOuAVuhulHDm1GoTMYQvbbwImc+ibhrV0UKCoWl334KFmX5O/udvW/1EmILe2u89M3KGhWpQ0ten4RZqEPeL3Q/PrwHirb6VSMl3WU1BY1AUuzHO6ncEvmUFJv4aB+xvfWMjWIfxt/wQ5P57fLSQHsxad7wpNypLrZ/AP0DKFvwYGJAkzTJUpQiRwLJwyF/rM+bR9sL6ViGrT6/iuTJwPhwdkHTMHwypSVEAXA/m2NKHUJAO4hNu4NH5NqQX+TUa3z5zbuQhDAFjijsnuC86SWERGa4QvptZa58/1AN0c0BOLmd3/x96oKX2GfllSZkT6ceUpeKGWR6o6za7tZEemwcYRPIsm6TdGIK+Uk/Fj4yL2Fi4NQEws2CiMh+g7znIce46Pp041VsdlJA3z2yVdzNFu8aQ6UTbbX5RNg2X7XnUQT4QYiGew3fjiIa4YK9E6ihW2COac1Xh1IfcgAAPwwnyZRh9FuT8kqa88ARhNQ3nHs/rX0dKkYONr5bzzQg8rvxTqmcgkXe0+VCvEZ+bh0tvcYm7086IsFc/JV5aB1Q6155wigcaaLxjt2chF/PAy8myH4CfB1GQkGlogBfPgMUwtk4/yvJPX3n7s0GWcnU8dHJiwK8p9z383VWAOPGaaq3xF+OqsapgdUN/JWg889XOiqq/MiE5p7x3ALE72cLQMTQolfAn4BBckH2RNaDJ0JUbrC4QUJaBhjlbVM2RvfX9u1fV10lh4gPi5m+myQ81Qr+Rk76HA16SCYRPqWseeDqLDT7Z8cn7p/siY41fxrO0iihbqXGBLVWAOgaAzuC/iMI+AEFYPIcN8kPlZB0IE32QAVmXTPu/5LGXAnTLJ5ZeSv3koPLEhJkY/8b3NZ4eJicAmmtc/vzcq0fZM0Y4qVGf8f1awBWOHDLX0kVmkVsjawqqDLT2UgMpVHLdlzH9JvTQE6Hj9wbpqJf5sb858TaMgXPUa8B6XTehMRYOMUPUOhtVUuFvhiJxIqvqq5caJbuJbVc7CXoyE49tsRoUJvBgBmeHjkzsKefMufAWeK6PNvJLA+gaQPaqikqaPE7plblGJuRPB821Qva/j3zgsEOcyxUNsNeKGP5L8sw8NsGx5zRE8zPan7NZRYJK8Iz0OwjLvbYnwwXTUE4J4j X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd80b366-e76d-4435-9de6-08d8fd4d0820 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3573.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2021 00:50:56.5178 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bBEZn449z4MHGsUWWAgXqvzac/OG2EWkSdXVxI7K15+X9y6e1SxXeOqVQnAgMiN1zINHlge9JdU7TPXAGDY7YGqzQGy5WSJksHzO9XAUplw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR10MB4307 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9951 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104120001 X-Proofpoint-ORIG-GUID: MVLwFkGLSbVqBRyyoVdTpg4ifad8B6t4 X-Proofpoint-GUID: MVLwFkGLSbVqBRyyoVdTpg4ifad8B6t4 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9951 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 clxscore=1015 adultscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 spamscore=0 impostorscore=0 suspectscore=0 mlxscore=0 phishscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104120001 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The next patches allow the kernel to do ep_disconnect. In that case we will have to get a proper refcount on the ep so one thread does not delete it from under another. Signed-off-by: Mike Christie --- drivers/infiniband/ulp/iser/iscsi_iser.c | 1 + drivers/scsi/be2iscsi/be_iscsi.c | 19 ++++++++++++------ drivers/scsi/bnx2i/bnx2i_iscsi.c | 23 +++++++++++++++------- drivers/scsi/cxgbi/libcxgbi.c | 12 ++++++++---- drivers/scsi/qedi/qedi_iscsi.c | 25 +++++++++++++++++------- drivers/scsi/qla4xxx/ql4_os.c | 1 + drivers/scsi/scsi_transport_iscsi.c | 25 ++++++++++++++++-------- include/scsi/scsi_transport_iscsi.h | 1 + 8 files changed, 75 insertions(+), 32 deletions(-) diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index 8fcaa1136f2c..54d756e5c033 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c @@ -506,6 +506,7 @@ iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session, iser_conn->iscsi_conn = conn; out: + iscsi_put_endpoint(ep); mutex_unlock(&iser_conn->state_mutex); return error; } diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c index a13c203ef7a9..c4881657a807 100644 --- a/drivers/scsi/be2iscsi/be_iscsi.c +++ b/drivers/scsi/be2iscsi/be_iscsi.c @@ -182,6 +182,7 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, struct beiscsi_endpoint *beiscsi_ep; struct iscsi_endpoint *ep; uint16_t cri_index; + int rc = 0; ep = iscsi_lookup_endpoint(transport_fd); if (!ep) @@ -189,15 +190,17 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, beiscsi_ep = ep->dd_data; - if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) - return -EINVAL; + if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) { + rc = -EINVAL; + goto put_ep; + } if (beiscsi_ep->phba != phba) { beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n", beiscsi_ep->phba, phba); - - return -EEXIST; + rc = -EEXIST; + goto put_ep; } cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid); if (phba->conn_table[cri_index]) { @@ -209,7 +212,8 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, beiscsi_ep->ep_cid, beiscsi_conn, phba->conn_table[cri_index]); - return -EINVAL; + rc = -EINVAL; + goto put_ep; } } @@ -226,7 +230,10 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, "BS_%d : cid %d phba->conn_table[%u]=%p\n", beiscsi_ep->ep_cid, cri_index, beiscsi_conn); phba->conn_table[cri_index] = beiscsi_conn; - return 0; + +put_ep: + iscsi_put_endpoint(ep); + return rc; } static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba) diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c index 1e6d8f62ea3c..b119285cfa8d 100644 --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c @@ -1420,17 +1420,23 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, * Forcefully terminate all in progress connection recovery at the * earliest, either in bind(), send_pdu(LOGIN), or conn_start() */ - if (bnx2i_adapter_ready(hba)) - return -EIO; + if (bnx2i_adapter_ready(hba)) { + ret_code = -EIO; + goto put_ep; + } bnx2i_ep = ep->dd_data; if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) || - (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD)) + (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD)) { /* Peer disconnect via' FIN or RST */ - return -EINVAL; + ret_code = -EINVAL; + goto put_ep; + } - if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) - return -EINVAL; + if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) { + ret_code = -EINVAL; + goto put_ep; + } if (bnx2i_ep->hba != hba) { /* Error - TCP connection does not belong to this device @@ -1441,7 +1447,8 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, "belong to hba (%s)\n", hba->netdev->name); - return -EEXIST; + ret_code = -EEXIST; + goto put_ep; } bnx2i_ep->conn = bnx2i_conn; bnx2i_conn->ep = bnx2i_ep; @@ -1458,6 +1465,8 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, bnx2i_put_rq_buf(bnx2i_conn, 0); bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE); +put_ep: + iscsi_put_endpoint(ep); return ret_code; } diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index f078b3c4e083..f6bcae829c29 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -2690,11 +2690,13 @@ int cxgbi_bind_conn(struct iscsi_cls_session *cls_session, err = csk->cdev->csk_ddp_setup_pgidx(csk, csk->tid, ppm->tformat.pgsz_idx_dflt); if (err < 0) - return err; + goto put_ep; err = iscsi_conn_bind(cls_session, cls_conn, is_leading); - if (err) - return -EINVAL; + if (err) { + err = -EINVAL; + goto put_ep; + } /* calculate the tag idx bits needed for this conn based on cmds_max */ cconn->task_idx_bits = (__ilog2_u32(conn->session->cmds_max - 1)) + 1; @@ -2715,7 +2717,9 @@ int cxgbi_bind_conn(struct iscsi_cls_session *cls_session, /* init recv engine */ iscsi_tcp_hdr_recv_prep(tcp_conn); - return 0; +put_ep: + iscsi_put_endpoint(ep); + return err; } EXPORT_SYMBOL_GPL(cxgbi_bind_conn); diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c index 08c05403cd72..76d40c79e6ef 100644 --- a/drivers/scsi/qedi/qedi_iscsi.c +++ b/drivers/scsi/qedi/qedi_iscsi.c @@ -377,6 +377,7 @@ static int qedi_conn_bind(struct iscsi_cls_session *cls_session, struct qedi_ctx *qedi = iscsi_host_priv(shost); struct qedi_endpoint *qedi_ep; struct iscsi_endpoint *ep; + int rc = 0; ep = iscsi_lookup_endpoint(transport_fd); if (!ep) @@ -384,11 +385,16 @@ static int qedi_conn_bind(struct iscsi_cls_session *cls_session, qedi_ep = ep->dd_data; if ((qedi_ep->state == EP_STATE_TCP_FIN_RCVD) || - (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) - return -EINVAL; + (qedi_ep->state == EP_STATE_TCP_RST_RCVD)) { + rc = -EINVAL; + goto put_ep; + } + + if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) { + rc = -EINVAL; + goto put_ep; + } - if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) - return -EINVAL; qedi_ep->conn = qedi_conn; qedi_conn->ep = qedi_ep; @@ -398,13 +404,18 @@ static int qedi_conn_bind(struct iscsi_cls_session *cls_session, qedi_conn->cmd_cleanup_req = 0; qedi_conn->cmd_cleanup_cmpl = 0; - if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) - return -EINVAL; + if (qedi_bind_conn_to_iscsi_cid(qedi, qedi_conn)) { + rc = -EINVAL; + goto put_ep; + } + spin_lock_init(&qedi_conn->tmf_work_lock); INIT_LIST_HEAD(&qedi_conn->tmf_work_list); init_waitqueue_head(&qedi_conn->wait_queue); - return 0; +put_ep: + iscsi_put_endpoint(ep); + return rc; } static int qedi_iscsi_update_conn(struct qedi_ctx *qedi, diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 7bd9a4a04ad5..18d63a0af14c 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -3234,6 +3234,7 @@ static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session, conn = cls_conn->dd_data; qla_conn = conn->dd_data; qla_conn->qla_ep = ep->dd_data; + iscsi_put_endpoint(ep); return 0; } diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 0ea8ed288f54..036486310260 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -268,9 +268,20 @@ void iscsi_destroy_endpoint(struct iscsi_endpoint *ep) } EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint); +void iscsi_put_endpoint(struct iscsi_endpoint *ep) +{ + put_device(&ep->dev); +} +EXPORT_SYMBOL_GPL(iscsi_put_endpoint); + +/** + * iscsi_lookup_endpoint - get ep from handle + * @handle: endpoint handle + * + * Caller must do a iscsi_put_endpoint. + */ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle) { - struct iscsi_endpoint *ep; struct device *dev; dev = class_find_device(&iscsi_endpoint_class, NULL, &handle, @@ -278,13 +289,7 @@ struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle) if (!dev) return NULL; - ep = iscsi_dev_to_endpoint(dev); - /* - * we can drop this now because the interface will prevent - * removals and lookups from racing. - */ - put_device(dev); - return ep; + return iscsi_dev_to_endpoint(dev); } EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint); @@ -2984,6 +2989,7 @@ static int iscsi_if_ep_disconnect(struct iscsi_transport *transport, } transport->ep_disconnect(ep); + iscsi_put_endpoint(ep); return 0; } @@ -3009,6 +3015,7 @@ iscsi_if_transport_ep(struct iscsi_transport *transport, ev->r.retcode = transport->ep_poll(ep, ev->u.ep_poll.timeout_ms); + iscsi_put_endpoint(ep); break; case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: rc = iscsi_if_ep_disconnect(transport, @@ -3691,6 +3698,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) ev->u.c_bound_session.initial_cmdsn, ev->u.c_bound_session.cmds_max, ev->u.c_bound_session.queue_depth); + iscsi_put_endpoint(ep); break; case ISCSI_UEVENT_DESTROY_SESSION: session = iscsi_session_lookup(ev->u.d_session.sid); @@ -3762,6 +3770,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) mutex_lock(&conn->ep_mutex); conn->ep = ep; mutex_unlock(&conn->ep_mutex); + iscsi_put_endpoint(ep); } else iscsi_cls_conn_printk(KERN_ERR, conn, "Could not set ep conn " diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index fc5a39839b4b..165e629fba02 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -441,6 +441,7 @@ extern int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time); extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size); extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep); extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle); +extern void iscsi_put_endpoint(struct iscsi_endpoint *ep); extern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd); extern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *t,