Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21773779ybl; Mon, 6 Jan 2020 10:59:44 -0800 (PST) X-Google-Smtp-Source: APXvYqwa8GqSDQ1X7/VvSf6S/fTJ1YDbgd1anLQUPGCS4u1MrrKETtz/kOu0zUe+BLF6oodCJaZT X-Received: by 2002:a05:6830:1116:: with SMTP id w22mr119144593otq.216.1578337184318; Mon, 06 Jan 2020 10:59:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578337184; cv=none; d=google.com; s=arc-20160816; b=SfQu7APSxdrLU2OG7oprzwPPyTdWYbSsnJRunugxiVrRmilKcTf4GZpX0WeTaxqso3 a+Fd2jK6n0F8VG/gifYpmwEW6Z70N8NULMvewmenVeLoQyidpv893yW61xU7Cumzo6Eq y8cI10VQqA0vJKjWwHwXKeIqU6Z2ozJwEDK6idw4SwUzJ9ChQ08gVtQFN5UWE/7o5vnX Ij4fHJyu893pkBTvay8DOe0SDcIKqeO1psEVV+Xb9nF2qsyKeGaWR9/G7qNNjiRQlPLY +2pqhcqf6R5NuGTc/eZPZbjCKXr1AAu5vc7sHmKvgUAqPu91lgAKYh5FaOCOwcJUzRxK +WGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=nY2KUYgz5So0CtoFPu4OQGNPz4ISY1W30/dWTP1diRM=; b=aEwtusSup8dpfm/t2equYeXizFlWxmCtfIFcgZZ61ooLMff7cXIjwa8j7TGA5RxcXY /KQUWVzxUjzSeOLzU8ZRhkdfHcMvXq6MXVLsSB+C2UdK3ZvT6ZgQFDDZOENSzFTAKukr cWvFiNyrlSTsw9spSXi8Nmt+CJaMliKOv7u4ACnLM5Mv5TAwNShqd1wTjakNxPs15u4z rkyDXNBqDIA1Yvplfhdz8S+MIoCQ/gNVYuJnTv4ggwQMqtG0vlvh6F6qDQS3hsDdQHpd XgGVkuZq1wHuER2p+cHUfDrmeZqwvzDCO5A9fGJk5GubFH/7M6+d7MzDUkbRPS80TEQg KlNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si33250947otl.320.2020.01.06.10.59.32; Mon, 06 Jan 2020 10:59:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726977AbgAFS6j (ORCPT + 99 others); Mon, 6 Jan 2020 13:58:39 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35948 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbgAFS6h (ORCPT ); Mon, 6 Jan 2020 13:58:37 -0500 Received: from localhost (unknown [IPv6:2610:98:8005::147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: krisman) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 5375929196F; Mon, 6 Jan 2020 18:58:35 +0000 (GMT) From: Gabriel Krisman Bertazi To: gregkh@linuxfoundation.org Cc: rafael@kernel.org, lduncan@suse.com, cleech@redhat.com, jejb@linux.ibm.com, martin.petersen@oracle.com, open-iscsi@googlegroups.com, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH 3/3] iscsi: Fail session and connection on transport registration failure Date: Mon, 6 Jan 2020 13:58:17 -0500 Message-Id: <20200106185817.640331-4-krisman@collabora.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200106185817.640331-1-krisman@collabora.com> References: <20200106185817.640331-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the transport cannot be registered, the session/connection creation needs to be failed early to let the initiator know. Otherwise, the system will have an outstanding connection that cannot be used nor removed by open-iscsi. The result is similar to the error below, triggered by injecting a failure in the transport's registration path. openiscsi reports success: root@debian-vm:~# iscsiadm -m node -T iqn:lun1 -p 127.0.0.1 -l Logging in to [iface: default, target: iqn:lun1, portal: 127.0.0.1,3260] Login to [iface: default, target: iqn:lun1, portal:127.0.0.1,3260] successful. But cannot remove the session afterwards, since the kernel is in an inconsistent state. root@debian-vm:~# iscsiadm -m node -T iqn:lun1 -p 127.0.0.1 -u iscsiadm: No matching sessions found Signed-off-by: Gabriel Krisman Bertazi --- drivers/scsi/scsi_transport_iscsi.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index ed8d9709b9b9..2b732b7a9a5b 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -2093,7 +2093,12 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) "could not register session's dev\n"); goto release_ida; } - transport_register_device(&session->dev); + err = transport_register_device(&session->dev); + if (err) { + iscsi_cls_session_printk(KERN_ERR, session, + "could not register transport's dev\n"); + goto release_dev; + } spin_lock_irqsave(&sesslock, flags); list_add(&session->sess_list, &sesslist); @@ -2103,6 +2108,8 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n"); return 0; +release_dev: + device_del(&session->dev); release_ida: if (session->ida_used) ida_simple_remove(&iscsi_sess_ida, session->target_id); @@ -2263,7 +2270,12 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid) "register connection's dev\n"); goto release_parent_ref; } - transport_register_device(&conn->dev); + err = transport_register_device(&conn->dev); + if (err) { + iscsi_cls_session_printk(KERN_ERR, session, "could not " + "register transport's dev\n"); + goto release_conn_ref; + } spin_lock_irqsave(&connlock, flags); list_add(&conn->conn_list, &connlist); @@ -2272,6 +2284,8 @@ iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid) ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n"); return conn; +release_conn_ref: + put_device(&conn->dev); release_parent_ref: put_device(&session->dev); free_conn: -- 2.24.1