Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp35977lqb; Tue, 4 Jun 2024 04:27:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYe2A4CfF7KaROOMIUCBTeTOYS+vlMMgb2aeUzSSFBcCmXfnJSX9GQ1VTRJSYD/BGsTmhSlHeE1sLrs+Cwj/cNqK+7uXbiL0gWZqIZzQ== X-Google-Smtp-Source: AGHT+IEU9ZIbBA1WJ4DgVCBQpi0GSEgKEMTmNhGPpPe7rUWQY0I19VVYl1/mzMlR5vqACj07x02H X-Received: by 2002:a05:6e02:1a49:b0:374:8b19:81c0 with SMTP id e9e14a558f8ab-3748b96ae64mr133089805ab.1.1717500431978; Tue, 04 Jun 2024 04:27:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717500431; cv=pass; d=google.com; s=arc-20160816; b=mYcm012DT14fzlUZX7oA353x38XxcXk7PjcBk+LGpwsH3v1smmlCXsOrV/1kmtooYa aO+xjxSdppFgNmSReLo4Vfjh7Vt+qVUBbeaz6yRU/5JfAceGOCXJrdAZ+LLxc+YSKjgz FoO0EXKGP9q6btLmrE68rnEmcQsExCZOeFDEwywTZIXkFvJv13jkTSMQQJqqXt/B1Z5M ZlhwFauK8JXAHnfo6fp3wLREfYoJZf8syU8mml7KCTxuCKJetR02xNPQcBE5072uxqbo DDPYvtajzKlHpQZwq6ytalTBclkRqC+2TzxRYC2LS0LFJC8cPjbbWo2ncNtyYXFp68XZ tKCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=MoI8Y0LVo44d4dVQplGDVlFz5OSJ/grrB0t8tVmYkqQ=; fh=mpP/l7LrRPqu5lHiLHg4EESmQF0tzCgSdXO6FWsFTZg=; b=Ru0yXHf05vKmIgRyCIYOcFEY6vYievr/cgmS322juDR6GbX0s4xqwFDbMOu8Etseyh 7Ub0kgX2zUY4xdOwu7Lo7BeTVRATzjq5F9+tj4EENMTSv+QIVz6cyOd3uY72vfQR0opc dri3+7pg8WB6LVUN6XP3lzxLudD0nv6O/XaUO0yRe1OX7WNXBPd9XInsE2LvPQcOt/ki c481fnyZUmcHj1/w36j2GDDAP6id4OYNK+fZqHtiO51yd9GmpXF3x30b3r4ld+MNbOj0 cb18Iw1ggSRH8z7MyNhL/gU13rRWYyi2gGlxH2f69fAKGekn/egNjg0iTkPZWo7Jtrwg BHRw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-nfs+bounces-3542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3542-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c359e09a14si7617293a12.343.2024.06.04.04.27.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 04:27:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs+bounces-3542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-nfs+bounces-3542-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-3542-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 79ED328311A for ; Tue, 4 Jun 2024 11:27:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 341BF145B1F; Tue, 4 Jun 2024 11:26:43 +0000 (UTC) X-Original-To: linux-nfs@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E278F145343; Tue, 4 Jun 2024 11:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717500403; cv=none; b=fnSZQJBm3OuqOd+v2L26GZLH2dBJm2L9gKTU2EUDoak6Sc+pS3gW67oFVkJmrnN2ZGZzmfwFGTI3CifwCAW6nIAMHDJLEOYhiTa6r/tgiQz5VUt5nVjBdfUhztBelBmoBY3OrSIOecDEuxQ8R6NURh9P03wxoH2kPGekuOK4LfY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717500403; c=relaxed/simple; bh=2sqRP+cDWakjPW2TLGsMmWbJp1y1dv+ct4RW2zKc/Jg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ovaM7Cbv1o0/0QFRYuoL7trceEwRa352OEwnSLSo0PohalmudRVYbzSubsOePK9f/f+yNsC6qLaueK4/Iyh0DSbgIWZkgrVi8Ji7+8ZQD22T1tMMkXyNMOofT4n8J6Z5hztyHNiWHyvrc+PNU1J/Xi7jJu/L6czCHlocZ/38IiA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VtpFZ2z71z4f3mJP; Tue, 4 Jun 2024 19:26:26 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 78BD21A0CB7; Tue, 4 Jun 2024 19:26:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAXKwTp+V5mJkItOg--.61165S6; Tue, 04 Jun 2024 19:26:36 +0800 (CST) From: Li Lingfeng To: dhowells@redhat.com, marc.dionne@auristor.com, raven@themaw.net, gregkh@linuxfoundation.org, rafael@kernel.org, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, miklos@szeredi.hu, trond.myklebust@hammerspace.com, anna@kernel.org, sfrench@samba.org, pc@manguebit.com, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, djwong@kernel.org Cc: linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org, autofs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, yi.zhang@huawei.com, yangerkun@huawei.com, zhangxiaoxu5@huawei.com, lilingfeng@huaweicloud.com, lilingfeng3@huawei.com Subject: [PATCH RFC 2/2] NFSv4: set sb_flags to second superblock Date: Tue, 4 Jun 2024 19:26:36 +0800 Message-Id: <20240604112636.236517-3-lilingfeng@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240604112636.236517-1-lilingfeng@huaweicloud.com> References: <20240604112636.236517-1-lilingfeng@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-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v67AKxVW8JVWxJw CI42IY6I8E87Iv6xkF7I0E14v26r4UJVWxJrUvcSsGvfC2KfnxnUUI43ZEXa7VUbvtC7UU UUU== X-CM-SenderInfo: polox0xjih0w46kxt4xhlfz01xgou0bp/ From: Li Lingfeng During the process of mounting an NFSv4 client, two superblocks will be created in sequence. The first superblock corresponds to the root directory exported by the server, and the second superblock corresponds to the directory that will be actually mounted. The first superblock will eventually be destroyed. The flag passed from user mode will only be passed to the first superblock, resulting in the actual used superblock not carrying the flag passed from user mode(fs_context_for_submount() will set sb_flags as 0). If the 'ro' parameter is used in two consecutive mount commands, only the first execution will create a new vfsmount, and the kernel will return EBUSY on the second execution. However, if a remount command with the 'ro' parameter is executed between the two mount commands, both mount commands will create new vfsmounts. The superblock generated after the first mount command does not have the 'ro' flag, and the read-only status of the file system is implemented by checking the read-only flag of the vfsmount. After executing the remount command, the 'ro' flag will be added to the superblock. When the second mount command is executed, the comparison result between the superblock with the 'ro' flag and the fs_context without the flag in the nfs_compare_mount_options() function will be different, resulting in the creation of a new vfsmount. This problem can be reproduced by performing the following operations: mount -t nfs -o ro,vers=4.0 192.168.240.250:/sdb /mnt/sdb mount -t nfs -o remount,ro,vers=4.0 192.168.240.250:/sdb /mnt/sdb mount -t nfs -o ro,vers=4.0 192.168.240.250:/sdb /mnt/sdb Two vfsmounts are generated: [root@localhost ~]# mount | grep nfs 192.168.240.250:/sdb on /mnt/sdb type nfs4 (ro,relatime,vers=4.0, rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2, sec=sys,clientaddr=192.168.240.251,local_lock=none,addr=192.168.240.250) 192.168.240.250:/sdb on /mnt/sdb type nfs4 (ro,relatime,vers=4.0, rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2, sec=sys,clientaddr=192.168.240.251,local_lock=none,addr=192.168.240.250) Fix this by setting sb_flags to second superblock. Signed-off-by: Li Lingfeng --- fs/nfs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c index 887aeacedebd..8b3d75af60d4 100644 --- a/fs/nfs/namespace.c +++ b/fs/nfs/namespace.c @@ -158,7 +158,7 @@ struct vfsmount *nfs_d_automount(struct path *path, unsigned int sb_flags) /* Open a new filesystem context, transferring parameters from the * parent superblock, including the network namespace. */ - fc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry, 0); + fc = fs_context_for_submount(path->mnt->mnt_sb->s_type, path->dentry, sb_flags); if (IS_ERR(fc)) return ERR_CAST(fc); -- 2.39.2