Message ID | 20221122213040.4128105-1-haowenchao@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2075088wrr; Tue, 22 Nov 2022 00:26:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QXzN4NnIwS7A8JbQ1k9STmfYaHUTbn53zPJp/mmC9ihYp+lsI+gSkm8tNxv04664hqNvZ X-Received: by 2002:a05:6402:1a2e:b0:461:2915:e41d with SMTP id be14-20020a0564021a2e00b004612915e41dmr19776826edb.184.1669105562650; Tue, 22 Nov 2022 00:26:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669105562; cv=none; d=google.com; s=arc-20160816; b=Gsaa/fX6U1j0NP4oasBTtYHlu6nwc+bMo48cC/ytwVg+9HxWgRA5UYjCUcKsN/L6/W wJzEbV4xXbo5D1JLmcmTwSaEkllcUPBidgD1bMQjp7AOZFXSo+O0PnoVB9sMNrJ1NflK IcFDkO4sIYp1tI+9tKLvEaQufZ8ts9AIu9/nRDXmRF7sZkRGIPsvSRUMXEh+5jXQzu+a y7zDY+F0vQsu94ZdraBP/IOCl/iasMb12yaF1/4KGmFgaXGH/7cXxASXa440vQEcmvvo oozwfhm+CXLbgkB6NSf9V/ImpC8AKVnDabt3/N2AL+arWFYTdw3IoATnzbALHw0rDeMD AHcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3o1TL1LKeenWyw70yWqkgUiAF1+9HyrFU5rsZ8McWzk=; b=gSIP/hl9xgeES+32AWagucjP9nzKAyaSiT7f5uirL5BTI/5gaFBAc3u4AhwlYXulWr BN0JaCY66ySqhGsKG7gLdOsjbvYLP4ck01KdxBcVqkDfNaTMBzl4fg/j0enbtPidEu3y zCW8c/Iip4rtbF6I2XMMWFnB1UH4QA6xEYr/qosBQjL+eWK1obpA9gPD4yOY9UCErG58 mCYdP9sb1VWeXvROlbdwp5QKn/bghxvwLD1KkdskKTpzNpgOwXiFOIKUDMIB71RZ3vZD Ejv0C8KH8ExxYs2h3rlSMXbrP05YTzxOQTvSXe6jIzWC2LAEvdzKuPyK1wL/s5tHHVdf /itQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb17-20020a1709071c9100b007ae2368c8b3si6521941ejc.730.2022.11.22.00.25.27; Tue, 22 Nov 2022 00:26:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232609AbiKVIO7 (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Tue, 22 Nov 2022 03:14:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbiKVIO4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 22 Nov 2022 03:14:56 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F29402183B; Tue, 22 Nov 2022 00:14:53 -0800 (PST) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NGcVP5Kjbz15Mqx; Tue, 22 Nov 2022 16:14:21 +0800 (CST) Received: from dggpemm500017.china.huawei.com (7.185.36.178) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 16:14:51 +0800 Received: from build.huawei.com (10.175.101.6) by dggpemm500017.china.huawei.com (7.185.36.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 22 Nov 2022 16:14:50 +0800 From: Wenchao Hao <haowenchao@huawei.com> To: Lee Duncan <lduncan@suse.com>, Chris Leech <cleech@redhat.com>, "Mike Christie" <michael.christie@oracle.com>, "James E . J . Bottomley" <jejb@linux.ibm.com>, "Martin K . Petersen" <martin.petersen@oracle.com>, <open-iscsi@googlegroups.com>, <linux-scsi@vger.kernel.org> CC: <linux-kernel@vger.kernel.org>, <liuzhiqiang26@huawei.com>, <linfeilong@huawei.com>, Wenchao Hao <haowenchao@huawei.com> Subject: [PATCH] scsi:iscsi: Record session's startup mode in kernel Date: Tue, 22 Nov 2022 21:30:41 +0000 Message-ID: <20221122213040.4128105-1-haowenchao@huawei.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500017.china.huawei.com (7.185.36.178) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_12_24, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750184034463661680?= X-GMAIL-MSGID: =?utf-8?q?1750184034463661680?= |
Series |
scsi:iscsi: Record session's startup mode in kernel
|
|
Commit Message
Wenchao Hao
Nov. 22, 2022, 9:30 p.m. UTC
There are 3 iscsi session's startup mode which are onboot, manual and
automatic. We can boot from iSCSI disks with help of dracut's service
in initrd, which would set node's startup mode to onboot, then create
iSCSI sessions.
While the configure of onboot mode is recorded in file of initrd stage
and would be lost when switch to rootfs. Even if we update the startup
mode to onboot by hand after switch to rootfs, it is possible that the
configure would be covered by another discovery command.
root would be mounted on iSCSI disks when boot from iSCSI disks, if the
sessions is logged out, the related disks would be removed, which would
cause the whole system halt.
So we need record session's start up mode in kernel and check this
mode before logout this session.
Signed-off-by: Wenchao Hao <haowenchao@huawei.com>
---
drivers/infiniband/ulp/iser/iscsi_iser.c | 1 +
drivers/scsi/be2iscsi/be_iscsi.c | 1 +
drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 +
drivers/scsi/cxgbi/libcxgbi.c | 1 +
drivers/scsi/iscsi_tcp.c | 1 +
drivers/scsi/libiscsi.c | 5 +++++
drivers/scsi/qedi/qedi_iscsi.c | 1 +
drivers/scsi/qla4xxx/ql4_os.c | 1 +
drivers/scsi/scsi_transport_iscsi.c | 4 ++++
include/scsi/iscsi_if.h | 1 +
include/scsi/libiscsi.h | 1 +
11 files changed, 18 insertions(+)
Comments
On 11/22/22 3:30 PM, Wenchao Hao wrote: > There are 3 iscsi session's startup mode which are onboot, manual and > automatic. We can boot from iSCSI disks with help of dracut's service > in initrd, which would set node's startup mode to onboot, then create > iSCSI sessions. > > While the configure of onboot mode is recorded in file of initrd stage > and would be lost when switch to rootfs. Even if we update the startup > mode to onboot by hand after switch to rootfs, it is possible that the > configure would be covered by another discovery command. > > root would be mounted on iSCSI disks when boot from iSCSI disks, if the > sessions is logged out, the related disks would be removed, which would > cause the whole system halt. The userspace tools check for this already don't they? Running iscsiadm on the root disk returns a failure and message about it being in use. Userspace can check the session's disks and see if they are mounted and what they are being used for.
On Wed, Nov 23, 2022 at 1:27 AM Mike Christie <michael.christie@oracle.com> wrote: > > On 11/22/22 3:30 PM, Wenchao Hao wrote: > > There are 3 iscsi session's startup mode which are onboot, manual and > > automatic. We can boot from iSCSI disks with help of dracut's service > > in initrd, which would set node's startup mode to onboot, then create > > iSCSI sessions. > > > > While the configure of onboot mode is recorded in file of initrd stage > > and would be lost when switch to rootfs. Even if we update the startup > > mode to onboot by hand after switch to rootfs, it is possible that the > > configure would be covered by another discovery command. > > > > root would be mounted on iSCSI disks when boot from iSCSI disks, if the > > sessions is logged out, the related disks would be removed, which would > > cause the whole system halt. > > The userspace tools check for this already don't they? Running iscsiadm > on the root disk returns a failure and message about it being in use. > It seems we did not check. > Userspace can check the session's disks and see if they are mounted and > what they are being used for. It's hard to check if iSCSI disk is in used. If iSCSI disk is used to build multipath device mapper, , and lvm is built on these dm devices, the root is mounted on these lvm devices, like following: sde 8:64 0 60G 0 disk └─360014051a174917ce514486bca53b324 253:4 0 60G 0 mpath ├─lvm-root 253:0 0 38.3G 0 lvm / ├─lvm-swap 253:1 0 2.1G 0 lvm [SWAP] └─lvm-home 253:2 0 18.7G 0 lvm /home It's too coupling to check these dm devices.
On 11/22/22 13:30, Wenchao Hao wrote: > There are 3 iscsi session's startup mode which are onboot, manual and > automatic. We can boot from iSCSI disks with help of dracut's service > in initrd, which would set node's startup mode to onboot, then create > iSCSI sessions. > > While the configure of onboot mode is recorded in file of initrd stage > and would be lost when switch to rootfs. Even if we update the startup > mode to onboot by hand after switch to rootfs, it is possible that the > configure would be covered by another discovery command. > > root would be mounted on iSCSI disks when boot from iSCSI disks, if the > sessions is logged out, the related disks would be removed, which would > cause the whole system halt. > > So we need record session's start up mode in kernel and check this > mode before logout this session. > > Signed-off-by: Wenchao Hao <haowenchao@huawei.com> > --- > drivers/infiniband/ulp/iser/iscsi_iser.c | 1 + > drivers/scsi/be2iscsi/be_iscsi.c | 1 + > drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 + > drivers/scsi/cxgbi/libcxgbi.c | 1 + > drivers/scsi/iscsi_tcp.c | 1 + > drivers/scsi/libiscsi.c | 5 +++++ > drivers/scsi/qedi/qedi_iscsi.c | 1 + > drivers/scsi/qla4xxx/ql4_os.c | 1 + > drivers/scsi/scsi_transport_iscsi.c | 4 ++++ > include/scsi/iscsi_if.h | 1 + > include/scsi/libiscsi.h | 1 + > 11 files changed, 18 insertions(+) > > diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c > index 620ae5b2d80d..778c023673ea 100644 > --- a/drivers/infiniband/ulp/iser/iscsi_iser.c > +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c > @@ -947,6 +947,7 @@ static umode_t iser_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_IFACE_NAME: > case ISCSI_PARAM_INITIATOR_NAME: > case ISCSI_PARAM_DISCOVERY_SESS: > + case ISCSI_PARAM_NODE_STARTUP: > return S_IRUGO; > default: > return 0; > diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c > index 8aeaddc93b16..a21a4d9ab8b8 100644 > --- a/drivers/scsi/be2iscsi/be_iscsi.c > +++ b/drivers/scsi/be2iscsi/be_iscsi.c > @@ -1401,6 +1401,7 @@ umode_t beiscsi_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_LU_RESET_TMO: > case ISCSI_PARAM_IFACE_NAME: > case ISCSI_PARAM_INITIATOR_NAME: > + case ISCSI_PARAM_NODE_STARTUP: > return S_IRUGO; > default: > return 0; > diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c > index a3c800e04a2e..d1fb06d8a92e 100644 > --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c > +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c > @@ -2237,6 +2237,7 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_BOOT_ROOT: > case ISCSI_PARAM_BOOT_NIC: > case ISCSI_PARAM_BOOT_TARGET: > + case ISCSI_PARAM_NODE_STARTUP: > return S_IRUGO; > default: > return 0; > diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c > index af281e271f88..111b2ac78964 100644 > --- a/drivers/scsi/cxgbi/libcxgbi.c > +++ b/drivers/scsi/cxgbi/libcxgbi.c > @@ -3063,6 +3063,7 @@ umode_t cxgbi_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_TGT_RESET_TMO: > case ISCSI_PARAM_IFACE_NAME: > case ISCSI_PARAM_INITIATOR_NAME: > + case ISCSI_PARAM_NODE_STARTUP: > return S_IRUGO; > default: > return 0; > diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c > index 5fb1f364e815..47a73fb3e4b0 100644 > --- a/drivers/scsi/iscsi_tcp.c > +++ b/drivers/scsi/iscsi_tcp.c > @@ -1036,6 +1036,7 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_TGT_RESET_TMO: > case ISCSI_PARAM_IFACE_NAME: > case ISCSI_PARAM_INITIATOR_NAME: > + case ISCSI_PARAM_NODE_STARTUP: > return S_IRUGO; > default: > return 0; > diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c > index d95f4bcdeb2e..1f2b0a9a029e 100644 > --- a/drivers/scsi/libiscsi.c > +++ b/drivers/scsi/libiscsi.c > @@ -3576,6 +3576,8 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn, > break; > case ISCSI_PARAM_LOCAL_IPADDR: > return iscsi_switch_str_param(&conn->local_ipaddr, buf); > + case ISCSI_PARAM_NODE_STARTUP: > + return iscsi_switch_str_param(&session->node_startup, buf); > default: > return -ENOSYS; > } > @@ -3712,6 +3714,9 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session, > else > len = sysfs_emit(buf, "\n"); > break; > + case ISCSI_PARAM_NODE_STARTUP: > + len = sysfs_emit(buf, "%s\n", session->node_startup); > + break; > default: > return -ENOSYS; > } > diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c > index 31ec429104e2..b947a5bca380 100644 > --- a/drivers/scsi/qedi/qedi_iscsi.c > +++ b/drivers/scsi/qedi/qedi_iscsi.c > @@ -1437,6 +1437,7 @@ static umode_t qedi_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_BOOT_ROOT: > case ISCSI_PARAM_BOOT_NIC: > case ISCSI_PARAM_BOOT_TARGET: > + case ISCSI_PARAM_NODE_STARTUP: > return 0444; > default: > return 0; > diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c > index 9e849f6b0d0f..1cb7c6dbe9d3 100644 > --- a/drivers/scsi/qla4xxx/ql4_os.c > +++ b/drivers/scsi/qla4xxx/ql4_os.c > @@ -468,6 +468,7 @@ static umode_t qla4_attr_is_visible(int param_type, int param) > case ISCSI_PARAM_DISCOVERY_PARENT_IDX: > case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: > case ISCSI_PARAM_LOCAL_IPADDR: > + case ISCSI_PARAM_NODE_STARTUP: > return S_IRUGO; > default: > return 0; > diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c > index c3fe5ecfee59..39c14d2a8aad 100644 > --- a/drivers/scsi/scsi_transport_iscsi.c > +++ b/drivers/scsi/scsi_transport_iscsi.c > @@ -4367,6 +4367,7 @@ iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0); > iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); > iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); > iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); > +iscsi_session_attr(node_startup, ISCSI_PARAM_NODE_STARTUP, 0); > > static ssize_t > show_priv_session_state(struct device *dev, struct device_attribute *attr, > @@ -4488,6 +4489,7 @@ static struct attribute *iscsi_session_attrs[] = { > &dev_attr_sess_def_taskmgmt_tmo.attr, > &dev_attr_sess_discovery_parent_idx.attr, > &dev_attr_sess_discovery_parent_type.attr, > + &dev_attr_sess_node_startup.attr, > NULL, > }; > > @@ -4587,6 +4589,8 @@ static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, > return S_IRUGO; > else if (attr == &dev_attr_priv_sess_target_id.attr) > return S_IRUGO; > + else if (attr == &dev_attr_sess_node_startup.attr) > + param = ISCSI_PARAM_NODE_STARTUP; > else { > WARN_ONCE(1, "Invalid session attr"); > return 0; > diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h > index 5225a23f2d0e..e46e69c1fd02 100644 > --- a/include/scsi/iscsi_if.h > +++ b/include/scsi/iscsi_if.h > @@ -610,6 +610,7 @@ enum iscsi_param { > ISCSI_PARAM_DISCOVERY_PARENT_IDX, > ISCSI_PARAM_DISCOVERY_PARENT_TYPE, > ISCSI_PARAM_LOCAL_IPADDR, > + ISCSI_PARAM_NODE_STARTUP, > /* must always be last */ > ISCSI_PARAM_MAX, > }; > diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h > index 654cc3918c94..af4ccdcc1140 100644 > --- a/include/scsi/libiscsi.h > +++ b/include/scsi/libiscsi.h > @@ -327,6 +327,7 @@ struct iscsi_session { > char *boot_target; > char *portal_type; > char *discovery_parent_type; > + char *node_startup; > uint16_t discovery_parent_idx; > uint16_t def_taskmgmt_tmo; > uint16_t tsid; The iscsiadm/iscsid tools refuse to logout of an ONBOOT session.
On 2022/11/23 4:00, Lee Duncan wrote: > On 11/22/22 13:30, Wenchao Hao wrote: >> There are 3 iscsi session's startup mode which are onboot, manual and >> automatic. We can boot from iSCSI disks with help of dracut's service >> in initrd, which would set node's startup mode to onboot, then create >> iSCSI sessions. >> >> While the configure of onboot mode is recorded in file of initrd stage >> and would be lost when switch to rootfs. Even if we update the startup >> mode to onboot by hand after switch to rootfs, it is possible that the >> configure would be covered by another discovery command. >> >> root would be mounted on iSCSI disks when boot from iSCSI disks, if the >> sessions is logged out, the related disks would be removed, which would >> cause the whole system halt. >> >> So we need record session's start up mode in kernel and check this >> mode before logout this session. >> >> Signed-off-by: Wenchao Hao <haowenchao@huawei.com> >> --- >> drivers/infiniband/ulp/iser/iscsi_iser.c | 1 + >> drivers/scsi/be2iscsi/be_iscsi.c | 1 + >> drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 + >> drivers/scsi/cxgbi/libcxgbi.c | 1 + >> drivers/scsi/iscsi_tcp.c | 1 + >> drivers/scsi/libiscsi.c | 5 +++++ >> drivers/scsi/qedi/qedi_iscsi.c | 1 + >> drivers/scsi/qla4xxx/ql4_os.c | 1 + >> drivers/scsi/scsi_transport_iscsi.c | 4 ++++ >> include/scsi/iscsi_if.h | 1 + >> include/scsi/libiscsi.h | 1 + >> 11 files changed, 18 insertions(+) >> >> diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c >> index 620ae5b2d80d..778c023673ea 100644 >> --- a/drivers/infiniband/ulp/iser/iscsi_iser.c >> +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c >> @@ -947,6 +947,7 @@ static umode_t iser_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_IFACE_NAME: >> case ISCSI_PARAM_INITIATOR_NAME: >> case ISCSI_PARAM_DISCOVERY_SESS: >> + case ISCSI_PARAM_NODE_STARTUP: >> return S_IRUGO; >> default: >> return 0; >> diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c >> index 8aeaddc93b16..a21a4d9ab8b8 100644 >> --- a/drivers/scsi/be2iscsi/be_iscsi.c >> +++ b/drivers/scsi/be2iscsi/be_iscsi.c >> @@ -1401,6 +1401,7 @@ umode_t beiscsi_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_LU_RESET_TMO: >> case ISCSI_PARAM_IFACE_NAME: >> case ISCSI_PARAM_INITIATOR_NAME: >> + case ISCSI_PARAM_NODE_STARTUP: >> return S_IRUGO; >> default: >> return 0; >> diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c >> index a3c800e04a2e..d1fb06d8a92e 100644 >> --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c >> +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c >> @@ -2237,6 +2237,7 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_BOOT_ROOT: >> case ISCSI_PARAM_BOOT_NIC: >> case ISCSI_PARAM_BOOT_TARGET: >> + case ISCSI_PARAM_NODE_STARTUP: >> return S_IRUGO; >> default: >> return 0; >> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c >> index af281e271f88..111b2ac78964 100644 >> --- a/drivers/scsi/cxgbi/libcxgbi.c >> +++ b/drivers/scsi/cxgbi/libcxgbi.c >> @@ -3063,6 +3063,7 @@ umode_t cxgbi_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_TGT_RESET_TMO: >> case ISCSI_PARAM_IFACE_NAME: >> case ISCSI_PARAM_INITIATOR_NAME: >> + case ISCSI_PARAM_NODE_STARTUP: >> return S_IRUGO; >> default: >> return 0; >> diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c >> index 5fb1f364e815..47a73fb3e4b0 100644 >> --- a/drivers/scsi/iscsi_tcp.c >> +++ b/drivers/scsi/iscsi_tcp.c >> @@ -1036,6 +1036,7 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_TGT_RESET_TMO: >> case ISCSI_PARAM_IFACE_NAME: >> case ISCSI_PARAM_INITIATOR_NAME: >> + case ISCSI_PARAM_NODE_STARTUP: >> return S_IRUGO; >> default: >> return 0; >> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c >> index d95f4bcdeb2e..1f2b0a9a029e 100644 >> --- a/drivers/scsi/libiscsi.c >> +++ b/drivers/scsi/libiscsi.c >> @@ -3576,6 +3576,8 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn, >> break; >> case ISCSI_PARAM_LOCAL_IPADDR: >> return iscsi_switch_str_param(&conn->local_ipaddr, buf); >> + case ISCSI_PARAM_NODE_STARTUP: >> + return iscsi_switch_str_param(&session->node_startup, buf); >> default: >> return -ENOSYS; >> } >> @@ -3712,6 +3714,9 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session, >> else >> len = sysfs_emit(buf, "\n"); >> break; >> + case ISCSI_PARAM_NODE_STARTUP: >> + len = sysfs_emit(buf, "%s\n", session->node_startup); >> + break; >> default: >> return -ENOSYS; >> } >> diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c >> index 31ec429104e2..b947a5bca380 100644 >> --- a/drivers/scsi/qedi/qedi_iscsi.c >> +++ b/drivers/scsi/qedi/qedi_iscsi.c >> @@ -1437,6 +1437,7 @@ static umode_t qedi_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_BOOT_ROOT: >> case ISCSI_PARAM_BOOT_NIC: >> case ISCSI_PARAM_BOOT_TARGET: >> + case ISCSI_PARAM_NODE_STARTUP: >> return 0444; >> default: >> return 0; >> diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c >> index 9e849f6b0d0f..1cb7c6dbe9d3 100644 >> --- a/drivers/scsi/qla4xxx/ql4_os.c >> +++ b/drivers/scsi/qla4xxx/ql4_os.c >> @@ -468,6 +468,7 @@ static umode_t qla4_attr_is_visible(int param_type, int param) >> case ISCSI_PARAM_DISCOVERY_PARENT_IDX: >> case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: >> case ISCSI_PARAM_LOCAL_IPADDR: >> + case ISCSI_PARAM_NODE_STARTUP: >> return S_IRUGO; >> default: >> return 0; >> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c >> index c3fe5ecfee59..39c14d2a8aad 100644 >> --- a/drivers/scsi/scsi_transport_iscsi.c >> +++ b/drivers/scsi/scsi_transport_iscsi.c >> @@ -4367,6 +4367,7 @@ iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0); >> iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); >> iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); >> iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); >> +iscsi_session_attr(node_startup, ISCSI_PARAM_NODE_STARTUP, 0); >> static ssize_t >> show_priv_session_state(struct device *dev, struct device_attribute *attr, >> @@ -4488,6 +4489,7 @@ static struct attribute *iscsi_session_attrs[] = { >> &dev_attr_sess_def_taskmgmt_tmo.attr, >> &dev_attr_sess_discovery_parent_idx.attr, >> &dev_attr_sess_discovery_parent_type.attr, >> + &dev_attr_sess_node_startup.attr, >> NULL, >> }; >> @@ -4587,6 +4589,8 @@ static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, >> return S_IRUGO; >> else if (attr == &dev_attr_priv_sess_target_id.attr) >> return S_IRUGO; >> + else if (attr == &dev_attr_sess_node_startup.attr) >> + param = ISCSI_PARAM_NODE_STARTUP; >> else { >> WARN_ONCE(1, "Invalid session attr"); >> return 0; >> diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h >> index 5225a23f2d0e..e46e69c1fd02 100644 >> --- a/include/scsi/iscsi_if.h >> +++ b/include/scsi/iscsi_if.h >> @@ -610,6 +610,7 @@ enum iscsi_param { >> ISCSI_PARAM_DISCOVERY_PARENT_IDX, >> ISCSI_PARAM_DISCOVERY_PARENT_TYPE, >> ISCSI_PARAM_LOCAL_IPADDR, >> + ISCSI_PARAM_NODE_STARTUP, >> /* must always be last */ >> ISCSI_PARAM_MAX, >> }; >> diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h >> index 654cc3918c94..af4ccdcc1140 100644 >> --- a/include/scsi/libiscsi.h >> +++ b/include/scsi/libiscsi.h >> @@ -327,6 +327,7 @@ struct iscsi_session { >> char *boot_target; >> char *portal_type; >> char *discovery_parent_type; >> + char *node_startup; >> uint16_t discovery_parent_idx; >> uint16_t def_taskmgmt_tmo; >> uint16_t tsid; > > The iscsiadm/iscsid tools refuse to logout of an ONBOOT session. > Sorry I did not highlight the key points. The root reason we need to record node_startup mode in kernel is userspace's node_startup mode is unreliable in some scenarios: 1. iscsi node and session is created in initrd, the configure files of these nodes would be lost after we switch to rootfs 2. someone do iscsiadm -m discovery but did not specify the operation mode, the iscsi node's node_startup would be updated to which specified in iscsid.conf 3. someone do iscsiadm -m node -o update to update nodes' configure What's more, it seems "iscsiadm/iscsid" only refuse to logout of an ONBOOT session when logout is specificed by "--logoutall". We still can logout an ONBOOT session with "iscsiadm -m node -u comamnd". Based on these analysis, I think we should record the node_startup mode in kernel and check in userspace to avoid logout ONBOOT sessions.
On 11/22/22 20:41, Wenchao Hao wrote: > On 2022/11/23 4:00, Lee Duncan wrote: >> On 11/22/22 13:30, Wenchao Hao wrote: >>> There are 3 iscsi session's startup mode which are onboot, manual and >>> automatic. We can boot from iSCSI disks with help of dracut's service >>> in initrd, which would set node's startup mode to onboot, then create >>> iSCSI sessions. >>> >>> While the configure of onboot mode is recorded in file of initrd stage >>> and would be lost when switch to rootfs. Even if we update the startup >>> mode to onboot by hand after switch to rootfs, it is possible that the >>> configure would be covered by another discovery command. >>> >>> root would be mounted on iSCSI disks when boot from iSCSI disks, if the >>> sessions is logged out, the related disks would be removed, which would >>> cause the whole system halt. >>> >>> So we need record session's start up mode in kernel and check this >>> mode before logout this session. >>> >>> Signed-off-by: Wenchao Hao <haowenchao@huawei.com> >>> --- >>> drivers/infiniband/ulp/iser/iscsi_iser.c | 1 + >>> drivers/scsi/be2iscsi/be_iscsi.c | 1 + >>> drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 + >>> drivers/scsi/cxgbi/libcxgbi.c | 1 + >>> drivers/scsi/iscsi_tcp.c | 1 + >>> drivers/scsi/libiscsi.c | 5 +++++ >>> drivers/scsi/qedi/qedi_iscsi.c | 1 + >>> drivers/scsi/qla4xxx/ql4_os.c | 1 + >>> drivers/scsi/scsi_transport_iscsi.c | 4 ++++ >>> include/scsi/iscsi_if.h | 1 + >>> include/scsi/libiscsi.h | 1 + >>> 11 files changed, 18 insertions(+) >>> >>> diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c >>> index 620ae5b2d80d..778c023673ea 100644 >>> --- a/drivers/infiniband/ulp/iser/iscsi_iser.c >>> +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c >>> @@ -947,6 +947,7 @@ static umode_t iser_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_IFACE_NAME: >>> case ISCSI_PARAM_INITIATOR_NAME: >>> case ISCSI_PARAM_DISCOVERY_SESS: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return S_IRUGO; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c >>> index 8aeaddc93b16..a21a4d9ab8b8 100644 >>> --- a/drivers/scsi/be2iscsi/be_iscsi.c >>> +++ b/drivers/scsi/be2iscsi/be_iscsi.c >>> @@ -1401,6 +1401,7 @@ umode_t beiscsi_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_LU_RESET_TMO: >>> case ISCSI_PARAM_IFACE_NAME: >>> case ISCSI_PARAM_INITIATOR_NAME: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return S_IRUGO; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c >>> index a3c800e04a2e..d1fb06d8a92e 100644 >>> --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c >>> +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c >>> @@ -2237,6 +2237,7 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_BOOT_ROOT: >>> case ISCSI_PARAM_BOOT_NIC: >>> case ISCSI_PARAM_BOOT_TARGET: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return S_IRUGO; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c >>> index af281e271f88..111b2ac78964 100644 >>> --- a/drivers/scsi/cxgbi/libcxgbi.c >>> +++ b/drivers/scsi/cxgbi/libcxgbi.c >>> @@ -3063,6 +3063,7 @@ umode_t cxgbi_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_TGT_RESET_TMO: >>> case ISCSI_PARAM_IFACE_NAME: >>> case ISCSI_PARAM_INITIATOR_NAME: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return S_IRUGO; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c >>> index 5fb1f364e815..47a73fb3e4b0 100644 >>> --- a/drivers/scsi/iscsi_tcp.c >>> +++ b/drivers/scsi/iscsi_tcp.c >>> @@ -1036,6 +1036,7 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_TGT_RESET_TMO: >>> case ISCSI_PARAM_IFACE_NAME: >>> case ISCSI_PARAM_INITIATOR_NAME: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return S_IRUGO; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c >>> index d95f4bcdeb2e..1f2b0a9a029e 100644 >>> --- a/drivers/scsi/libiscsi.c >>> +++ b/drivers/scsi/libiscsi.c >>> @@ -3576,6 +3576,8 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn, >>> break; >>> case ISCSI_PARAM_LOCAL_IPADDR: >>> return iscsi_switch_str_param(&conn->local_ipaddr, buf); >>> + case ISCSI_PARAM_NODE_STARTUP: >>> + return iscsi_switch_str_param(&session->node_startup, buf); >>> default: >>> return -ENOSYS; >>> } >>> @@ -3712,6 +3714,9 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session, >>> else >>> len = sysfs_emit(buf, "\n"); >>> break; >>> + case ISCSI_PARAM_NODE_STARTUP: >>> + len = sysfs_emit(buf, "%s\n", session->node_startup); >>> + break; >>> default: >>> return -ENOSYS; >>> } >>> diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c >>> index 31ec429104e2..b947a5bca380 100644 >>> --- a/drivers/scsi/qedi/qedi_iscsi.c >>> +++ b/drivers/scsi/qedi/qedi_iscsi.c >>> @@ -1437,6 +1437,7 @@ static umode_t qedi_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_BOOT_ROOT: >>> case ISCSI_PARAM_BOOT_NIC: >>> case ISCSI_PARAM_BOOT_TARGET: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return 0444; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c >>> index 9e849f6b0d0f..1cb7c6dbe9d3 100644 >>> --- a/drivers/scsi/qla4xxx/ql4_os.c >>> +++ b/drivers/scsi/qla4xxx/ql4_os.c >>> @@ -468,6 +468,7 @@ static umode_t qla4_attr_is_visible(int param_type, int param) >>> case ISCSI_PARAM_DISCOVERY_PARENT_IDX: >>> case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: >>> case ISCSI_PARAM_LOCAL_IPADDR: >>> + case ISCSI_PARAM_NODE_STARTUP: >>> return S_IRUGO; >>> default: >>> return 0; >>> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c >>> index c3fe5ecfee59..39c14d2a8aad 100644 >>> --- a/drivers/scsi/scsi_transport_iscsi.c >>> +++ b/drivers/scsi/scsi_transport_iscsi.c >>> @@ -4367,6 +4367,7 @@ iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0); >>> iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); >>> iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); >>> iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); >>> +iscsi_session_attr(node_startup, ISCSI_PARAM_NODE_STARTUP, 0); >>> static ssize_t >>> show_priv_session_state(struct device *dev, struct device_attribute *attr, >>> @@ -4488,6 +4489,7 @@ static struct attribute *iscsi_session_attrs[] = { >>> &dev_attr_sess_def_taskmgmt_tmo.attr, >>> &dev_attr_sess_discovery_parent_idx.attr, >>> &dev_attr_sess_discovery_parent_type.attr, >>> + &dev_attr_sess_node_startup.attr, >>> NULL, >>> }; >>> @@ -4587,6 +4589,8 @@ static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, >>> return S_IRUGO; >>> else if (attr == &dev_attr_priv_sess_target_id.attr) >>> return S_IRUGO; >>> + else if (attr == &dev_attr_sess_node_startup.attr) >>> + param = ISCSI_PARAM_NODE_STARTUP; >>> else { >>> WARN_ONCE(1, "Invalid session attr"); >>> return 0; >>> diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h >>> index 5225a23f2d0e..e46e69c1fd02 100644 >>> --- a/include/scsi/iscsi_if.h >>> +++ b/include/scsi/iscsi_if.h >>> @@ -610,6 +610,7 @@ enum iscsi_param { >>> ISCSI_PARAM_DISCOVERY_PARENT_IDX, >>> ISCSI_PARAM_DISCOVERY_PARENT_TYPE, >>> ISCSI_PARAM_LOCAL_IPADDR, >>> + ISCSI_PARAM_NODE_STARTUP, >>> /* must always be last */ >>> ISCSI_PARAM_MAX, >>> }; >>> diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h >>> index 654cc3918c94..af4ccdcc1140 100644 >>> --- a/include/scsi/libiscsi.h >>> +++ b/include/scsi/libiscsi.h >>> @@ -327,6 +327,7 @@ struct iscsi_session { >>> char *boot_target; >>> char *portal_type; >>> char *discovery_parent_type; >>> + char *node_startup; >>> uint16_t discovery_parent_idx; >>> uint16_t def_taskmgmt_tmo; >>> uint16_t tsid; >> >> The iscsiadm/iscsid tools refuse to logout of an ONBOOT session. >> > > Sorry I did not highlight the key points. The root reason we need to record > node_startup mode in kernel is userspace's node_startup mode is unreliable in > some scenarios: > > 1. iscsi node and session is created in initrd, the configure files of these > nodes would be lost after we switch to rootfs That is not my experience. When I boot from iscsi root, after the system is running, if I tell the iscsiadm to logout of the root iscsi target it refuses. I will test again to verify. > 2. someone do iscsiadm -m discovery but did not specify the operation mode, > the iscsi node's node_startup would be updated to which specified in iscsid.conf The default on iscsiadm discovery mode is to replace the info on a discovered target, but there are other modes. And they don't effect the current (root) session. > 3. someone do iscsiadm -m node -o update to update nodes' configure Again, does not effect the currently-running session, and can be considered shooting oneself in the foot. > > What's more, it seems "iscsiadm/iscsid" only refuse to logout of an ONBOOT > session when logout is specificed by "--logoutall". We still can logout an > ONBOOT session with "iscsiadm -m node -u comamnd". Again, I don't believe that's correct. I will test it. > > Based on these analysis, I think we should record the node_startup mode in kernel > and check in userspace to avoid logout ONBOOT sessions.
On 11/22/22 10:41 PM, Wenchao Hao wrote: > Sorry I did not highlight the key points. The root reason we need to record > node_startup mode in kernel is userspace's node_startup mode is unreliable in > some scenarios: > > 1. iscsi node and session is created in initrd, the configure files of these > nodes would be lost after we switch to rootfs > 2. someone do iscsiadm -m discovery but did not specify the operation mode, > the iscsi node's node_startup would be updated to which specified in iscsid.conf > 3. someone do iscsiadm -m node -o update to update nodes' configure > > What's more, it seems "iscsiadm/iscsid" only refuse to logout of an ONBOOT > session when logout is specificed by "--logoutall". We still can logout an > ONBOOT session with "iscsiadm -m node -u comamnd". logout_by_startup does go by the startup setting, but I think you missed the session_in_use related code. It checks the mounts and holders already. Just change it for whatever you need. I think your lvm use case should be covered by the holder check. If not, add it.
On Thu, Nov 24, 2022 at 12:51 AM Lee Duncan <lduncan@suse.com> wrote: > > On 11/22/22 20:41, Wenchao Hao wrote: > > On 2022/11/23 4:00, Lee Duncan wrote: > >> On 11/22/22 13:30, Wenchao Hao wrote: > >>> There are 3 iscsi session's startup mode which are onboot, manual and > >>> automatic. We can boot from iSCSI disks with help of dracut's service > >>> in initrd, which would set node's startup mode to onboot, then create > >>> iSCSI sessions. > >>> > >>> While the configure of onboot mode is recorded in file of initrd stage > >>> and would be lost when switch to rootfs. Even if we update the startup > >>> mode to onboot by hand after switch to rootfs, it is possible that the > >>> configure would be covered by another discovery command. > >>> > >>> root would be mounted on iSCSI disks when boot from iSCSI disks, if the > >>> sessions is logged out, the related disks would be removed, which would > >>> cause the whole system halt. > >>> > >>> So we need record session's start up mode in kernel and check this > >>> mode before logout this session. > >>> > >>> Signed-off-by: Wenchao Hao <haowenchao@huawei.com> > >>> --- > >>> drivers/infiniband/ulp/iser/iscsi_iser.c | 1 + > >>> drivers/scsi/be2iscsi/be_iscsi.c | 1 + > >>> drivers/scsi/bnx2i/bnx2i_iscsi.c | 1 + > >>> drivers/scsi/cxgbi/libcxgbi.c | 1 + > >>> drivers/scsi/iscsi_tcp.c | 1 + > >>> drivers/scsi/libiscsi.c | 5 +++++ > >>> drivers/scsi/qedi/qedi_iscsi.c | 1 + > >>> drivers/scsi/qla4xxx/ql4_os.c | 1 + > >>> drivers/scsi/scsi_transport_iscsi.c | 4 ++++ > >>> include/scsi/iscsi_if.h | 1 + > >>> include/scsi/libiscsi.h | 1 + > >>> 11 files changed, 18 insertions(+) > >>> > >>> diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c > >>> index 620ae5b2d80d..778c023673ea 100644 > >>> --- a/drivers/infiniband/ulp/iser/iscsi_iser.c > >>> +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c > >>> @@ -947,6 +947,7 @@ static umode_t iser_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_IFACE_NAME: > >>> case ISCSI_PARAM_INITIATOR_NAME: > >>> case ISCSI_PARAM_DISCOVERY_SESS: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return S_IRUGO; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c > >>> index 8aeaddc93b16..a21a4d9ab8b8 100644 > >>> --- a/drivers/scsi/be2iscsi/be_iscsi.c > >>> +++ b/drivers/scsi/be2iscsi/be_iscsi.c > >>> @@ -1401,6 +1401,7 @@ umode_t beiscsi_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_LU_RESET_TMO: > >>> case ISCSI_PARAM_IFACE_NAME: > >>> case ISCSI_PARAM_INITIATOR_NAME: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return S_IRUGO; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c > >>> index a3c800e04a2e..d1fb06d8a92e 100644 > >>> --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c > >>> +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c > >>> @@ -2237,6 +2237,7 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_BOOT_ROOT: > >>> case ISCSI_PARAM_BOOT_NIC: > >>> case ISCSI_PARAM_BOOT_TARGET: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return S_IRUGO; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c > >>> index af281e271f88..111b2ac78964 100644 > >>> --- a/drivers/scsi/cxgbi/libcxgbi.c > >>> +++ b/drivers/scsi/cxgbi/libcxgbi.c > >>> @@ -3063,6 +3063,7 @@ umode_t cxgbi_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_TGT_RESET_TMO: > >>> case ISCSI_PARAM_IFACE_NAME: > >>> case ISCSI_PARAM_INITIATOR_NAME: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return S_IRUGO; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c > >>> index 5fb1f364e815..47a73fb3e4b0 100644 > >>> --- a/drivers/scsi/iscsi_tcp.c > >>> +++ b/drivers/scsi/iscsi_tcp.c > >>> @@ -1036,6 +1036,7 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_TGT_RESET_TMO: > >>> case ISCSI_PARAM_IFACE_NAME: > >>> case ISCSI_PARAM_INITIATOR_NAME: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return S_IRUGO; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c > >>> index d95f4bcdeb2e..1f2b0a9a029e 100644 > >>> --- a/drivers/scsi/libiscsi.c > >>> +++ b/drivers/scsi/libiscsi.c > >>> @@ -3576,6 +3576,8 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn, > >>> break; > >>> case ISCSI_PARAM_LOCAL_IPADDR: > >>> return iscsi_switch_str_param(&conn->local_ipaddr, buf); > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> + return iscsi_switch_str_param(&session->node_startup, buf); > >>> default: > >>> return -ENOSYS; > >>> } > >>> @@ -3712,6 +3714,9 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session, > >>> else > >>> len = sysfs_emit(buf, "\n"); > >>> break; > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> + len = sysfs_emit(buf, "%s\n", session->node_startup); > >>> + break; > >>> default: > >>> return -ENOSYS; > >>> } > >>> diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c > >>> index 31ec429104e2..b947a5bca380 100644 > >>> --- a/drivers/scsi/qedi/qedi_iscsi.c > >>> +++ b/drivers/scsi/qedi/qedi_iscsi.c > >>> @@ -1437,6 +1437,7 @@ static umode_t qedi_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_BOOT_ROOT: > >>> case ISCSI_PARAM_BOOT_NIC: > >>> case ISCSI_PARAM_BOOT_TARGET: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return 0444; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c > >>> index 9e849f6b0d0f..1cb7c6dbe9d3 100644 > >>> --- a/drivers/scsi/qla4xxx/ql4_os.c > >>> +++ b/drivers/scsi/qla4xxx/ql4_os.c > >>> @@ -468,6 +468,7 @@ static umode_t qla4_attr_is_visible(int param_type, int param) > >>> case ISCSI_PARAM_DISCOVERY_PARENT_IDX: > >>> case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: > >>> case ISCSI_PARAM_LOCAL_IPADDR: > >>> + case ISCSI_PARAM_NODE_STARTUP: > >>> return S_IRUGO; > >>> default: > >>> return 0; > >>> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c > >>> index c3fe5ecfee59..39c14d2a8aad 100644 > >>> --- a/drivers/scsi/scsi_transport_iscsi.c > >>> +++ b/drivers/scsi/scsi_transport_iscsi.c > >>> @@ -4367,6 +4367,7 @@ iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0); > >>> iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); > >>> iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); > >>> iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); > >>> +iscsi_session_attr(node_startup, ISCSI_PARAM_NODE_STARTUP, 0); > >>> static ssize_t > >>> show_priv_session_state(struct device *dev, struct device_attribute *attr, > >>> @@ -4488,6 +4489,7 @@ static struct attribute *iscsi_session_attrs[] = { > >>> &dev_attr_sess_def_taskmgmt_tmo.attr, > >>> &dev_attr_sess_discovery_parent_idx.attr, > >>> &dev_attr_sess_discovery_parent_type.attr, > >>> + &dev_attr_sess_node_startup.attr, > >>> NULL, > >>> }; > >>> @@ -4587,6 +4589,8 @@ static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, > >>> return S_IRUGO; > >>> else if (attr == &dev_attr_priv_sess_target_id.attr) > >>> return S_IRUGO; > >>> + else if (attr == &dev_attr_sess_node_startup.attr) > >>> + param = ISCSI_PARAM_NODE_STARTUP; > >>> else { > >>> WARN_ONCE(1, "Invalid session attr"); > >>> return 0; > >>> diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h > >>> index 5225a23f2d0e..e46e69c1fd02 100644 > >>> --- a/include/scsi/iscsi_if.h > >>> +++ b/include/scsi/iscsi_if.h > >>> @@ -610,6 +610,7 @@ enum iscsi_param { > >>> ISCSI_PARAM_DISCOVERY_PARENT_IDX, > >>> ISCSI_PARAM_DISCOVERY_PARENT_TYPE, > >>> ISCSI_PARAM_LOCAL_IPADDR, > >>> + ISCSI_PARAM_NODE_STARTUP, > >>> /* must always be last */ > >>> ISCSI_PARAM_MAX, > >>> }; > >>> diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h > >>> index 654cc3918c94..af4ccdcc1140 100644 > >>> --- a/include/scsi/libiscsi.h > >>> +++ b/include/scsi/libiscsi.h > >>> @@ -327,6 +327,7 @@ struct iscsi_session { > >>> char *boot_target; > >>> char *portal_type; > >>> char *discovery_parent_type; > >>> + char *node_startup; > >>> uint16_t discovery_parent_idx; > >>> uint16_t def_taskmgmt_tmo; > >>> uint16_t tsid; > >> > >> The iscsiadm/iscsid tools refuse to logout of an ONBOOT session. > >> > > > > Sorry I did not highlight the key points. The root reason we need to record > > node_startup mode in kernel is userspace's node_startup mode is unreliable in > > some scenarios: > > > > 1. iscsi node and session is created in initrd, the configure files of these > > nodes would be lost after we switch to rootfs > > That is not my experience. When I boot from iscsi root, after the system > is running, if I tell the iscsiadm to logout of the root iscsi target it > refuses. I will test again to verify. > > > 2. someone do iscsiadm -m discovery but did not specify the operation mode, > > the iscsi node's node_startup would be updated to which specified in iscsid.conf > > The default on iscsiadm discovery mode is to replace the info on a > discovered target, but there are other modes. And they don't effect the > current (root) session. > > > 3. someone do iscsiadm -m node -o update to update nodes' configure > > Again, does not effect the currently-running session, and can be > considered shooting oneself in the foot. > > > > > What's more, it seems "iscsiadm/iscsid" only refuse to logout of an ONBOOT > > session when logout is specificed by "--logoutall". We still can logout an > > ONBOOT session with "iscsiadm -m node -u comamnd". > > Again, I don't believe that's correct. I will test it. > > > > > Based on these analysis, I think we should record the node_startup mode in kernel > > and check in userspace to avoid logout ONBOOT sessions. > I cloned the source code from github and built to test. Here is my brief test steps: 1. discovery an iSCSI node and login, the default startup mode is manual 2. using iscsiadm -m node -o update command to update the startup mode to onboot(it did not refused) 3. logout the session with iscsiadm -m node -u the logout succeed too.
On Thu, Nov 24, 2022 at 1:29 AM Mike Christie <michael.christie@oracle.com> wrote: > > On 11/22/22 10:41 PM, Wenchao Hao wrote: > > Sorry I did not highlight the key points. The root reason we need to record > > node_startup mode in kernel is userspace's node_startup mode is unreliable in > > some scenarios: > > > > 1. iscsi node and session is created in initrd, the configure files of these > > nodes would be lost after we switch to rootfs > > 2. someone do iscsiadm -m discovery but did not specify the operation mode, > > the iscsi node's node_startup would be updated to which specified in iscsid.conf > > 3. someone do iscsiadm -m node -o update to update nodes' configure > > > > What's more, it seems "iscsiadm/iscsid" only refuse to logout of an ONBOOT > > session when logout is specificed by "--logoutall". We still can logout an > > ONBOOT session with "iscsiadm -m node -u comamnd". > > logout_by_startup does go by the startup setting, but I think you missed the > session_in_use related code. It checks the mounts and holders already. Just > change it for whatever you need. I think your lvm use case should be covered > by the holder check. If not, add it. I did not enable the iscsid.safe_logout in iscsid.conf, so the session still could be logged out. If tested with iscsid.safe_logout set to "Yes", the issue is solved. Thanks a lot
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index 620ae5b2d80d..778c023673ea 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c @@ -947,6 +947,7 @@ static umode_t iser_attr_is_visible(int param_type, int param) case ISCSI_PARAM_IFACE_NAME: case ISCSI_PARAM_INITIATOR_NAME: case ISCSI_PARAM_DISCOVERY_SESS: + case ISCSI_PARAM_NODE_STARTUP: return S_IRUGO; default: return 0; diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c index 8aeaddc93b16..a21a4d9ab8b8 100644 --- a/drivers/scsi/be2iscsi/be_iscsi.c +++ b/drivers/scsi/be2iscsi/be_iscsi.c @@ -1401,6 +1401,7 @@ umode_t beiscsi_attr_is_visible(int param_type, int param) case ISCSI_PARAM_LU_RESET_TMO: case ISCSI_PARAM_IFACE_NAME: case ISCSI_PARAM_INITIATOR_NAME: + case ISCSI_PARAM_NODE_STARTUP: return S_IRUGO; default: return 0; diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c index a3c800e04a2e..d1fb06d8a92e 100644 --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c @@ -2237,6 +2237,7 @@ static umode_t bnx2i_attr_is_visible(int param_type, int param) case ISCSI_PARAM_BOOT_ROOT: case ISCSI_PARAM_BOOT_NIC: case ISCSI_PARAM_BOOT_TARGET: + case ISCSI_PARAM_NODE_STARTUP: return S_IRUGO; default: return 0; diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index af281e271f88..111b2ac78964 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -3063,6 +3063,7 @@ umode_t cxgbi_attr_is_visible(int param_type, int param) case ISCSI_PARAM_TGT_RESET_TMO: case ISCSI_PARAM_IFACE_NAME: case ISCSI_PARAM_INITIATOR_NAME: + case ISCSI_PARAM_NODE_STARTUP: return S_IRUGO; default: return 0; diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 5fb1f364e815..47a73fb3e4b0 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -1036,6 +1036,7 @@ static umode_t iscsi_sw_tcp_attr_is_visible(int param_type, int param) case ISCSI_PARAM_TGT_RESET_TMO: case ISCSI_PARAM_IFACE_NAME: case ISCSI_PARAM_INITIATOR_NAME: + case ISCSI_PARAM_NODE_STARTUP: return S_IRUGO; default: return 0; diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index d95f4bcdeb2e..1f2b0a9a029e 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -3576,6 +3576,8 @@ int iscsi_set_param(struct iscsi_cls_conn *cls_conn, break; case ISCSI_PARAM_LOCAL_IPADDR: return iscsi_switch_str_param(&conn->local_ipaddr, buf); + case ISCSI_PARAM_NODE_STARTUP: + return iscsi_switch_str_param(&session->node_startup, buf); default: return -ENOSYS; } @@ -3712,6 +3714,9 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session, else len = sysfs_emit(buf, "\n"); break; + case ISCSI_PARAM_NODE_STARTUP: + len = sysfs_emit(buf, "%s\n", session->node_startup); + break; default: return -ENOSYS; } diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c index 31ec429104e2..b947a5bca380 100644 --- a/drivers/scsi/qedi/qedi_iscsi.c +++ b/drivers/scsi/qedi/qedi_iscsi.c @@ -1437,6 +1437,7 @@ static umode_t qedi_attr_is_visible(int param_type, int param) case ISCSI_PARAM_BOOT_ROOT: case ISCSI_PARAM_BOOT_NIC: case ISCSI_PARAM_BOOT_TARGET: + case ISCSI_PARAM_NODE_STARTUP: return 0444; default: return 0; diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 9e849f6b0d0f..1cb7c6dbe9d3 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -468,6 +468,7 @@ static umode_t qla4_attr_is_visible(int param_type, int param) case ISCSI_PARAM_DISCOVERY_PARENT_IDX: case ISCSI_PARAM_DISCOVERY_PARENT_TYPE: case ISCSI_PARAM_LOCAL_IPADDR: + case ISCSI_PARAM_NODE_STARTUP: return S_IRUGO; default: return 0; diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index c3fe5ecfee59..39c14d2a8aad 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -4367,6 +4367,7 @@ iscsi_session_attr(tsid, ISCSI_PARAM_TSID, 0); iscsi_session_attr(def_taskmgmt_tmo, ISCSI_PARAM_DEF_TASKMGMT_TMO, 0); iscsi_session_attr(discovery_parent_idx, ISCSI_PARAM_DISCOVERY_PARENT_IDX, 0); iscsi_session_attr(discovery_parent_type, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, 0); +iscsi_session_attr(node_startup, ISCSI_PARAM_NODE_STARTUP, 0); static ssize_t show_priv_session_state(struct device *dev, struct device_attribute *attr, @@ -4488,6 +4489,7 @@ static struct attribute *iscsi_session_attrs[] = { &dev_attr_sess_def_taskmgmt_tmo.attr, &dev_attr_sess_discovery_parent_idx.attr, &dev_attr_sess_discovery_parent_type.attr, + &dev_attr_sess_node_startup.attr, NULL, }; @@ -4587,6 +4589,8 @@ static umode_t iscsi_session_attr_is_visible(struct kobject *kobj, return S_IRUGO; else if (attr == &dev_attr_priv_sess_target_id.attr) return S_IRUGO; + else if (attr == &dev_attr_sess_node_startup.attr) + param = ISCSI_PARAM_NODE_STARTUP; else { WARN_ONCE(1, "Invalid session attr"); return 0; diff --git a/include/scsi/iscsi_if.h b/include/scsi/iscsi_if.h index 5225a23f2d0e..e46e69c1fd02 100644 --- a/include/scsi/iscsi_if.h +++ b/include/scsi/iscsi_if.h @@ -610,6 +610,7 @@ enum iscsi_param { ISCSI_PARAM_DISCOVERY_PARENT_IDX, ISCSI_PARAM_DISCOVERY_PARENT_TYPE, ISCSI_PARAM_LOCAL_IPADDR, + ISCSI_PARAM_NODE_STARTUP, /* must always be last */ ISCSI_PARAM_MAX, }; diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 654cc3918c94..af4ccdcc1140 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -327,6 +327,7 @@ struct iscsi_session { char *boot_target; char *portal_type; char *discovery_parent_type; + char *node_startup; uint16_t discovery_parent_idx; uint16_t def_taskmgmt_tmo; uint16_t tsid;