Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  linux/fs/nfs/super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Copyright (C) 1992  Rick Sladkey
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *  nfs superblock handling functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *  Modularised by Alan Cox <alan@lxorguk.ukuu.org.uk>, while hacking some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *  experimental NFS changes. Modularisation taken straight from SYS5 fs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  Change to nfs_read_super() to permit NFS mounts to multi-homed hosts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  *  J.S.Peatfield@damtp.cam.ac.uk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *  Split from inode.c by David Howells <dhowells@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * - superblocks are indexed on server only - all inodes, dentries, etc. associated with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *   particular server are held in the same superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  * - NFS superblocks can have several effective roots to the dentry tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  * - directory type roots are spliced into the tree when a path from one root reaches the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *   of another (see nfs_lookup())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/sunrpc/addr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/sunrpc/metrics.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/sunrpc/xprtsock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/sunrpc/xprtrdma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <linux/nfs_mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/nfs4_mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/lockd/bind.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) #include <linux/nfs_xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #include <linux/magic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) #include <linux/nsproxy.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) #include <linux/nfs_ssc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) #include "callback.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) #include "delegation.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #include "iostat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) #include "fscache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) #include "nfs4session.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #include "pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) #include "nfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define NFSDBG_FACILITY		NFSDBG_VFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) const struct super_operations nfs_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	.alloc_inode	= nfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	.free_inode	= nfs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	.write_inode	= nfs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 	.drop_inode	= nfs_drop_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 	.statfs		= nfs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	.evict_inode	= nfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	.umount_begin	= nfs_umount_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	.show_options	= nfs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	.show_devname	= nfs_show_devname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	.show_path	= nfs_show_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	.show_stats	= nfs_show_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) EXPORT_SYMBOL_GPL(nfs_sops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static const struct nfs_ssc_client_ops nfs_ssc_clnt_ops_tbl = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	.sco_sb_deactive = nfs_sb_deactive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static int __init register_nfs4_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	return register_filesystem(&nfs4_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static void unregister_nfs4_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	unregister_filesystem(&nfs4_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static int __init register_nfs4_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) static void unregister_nfs4_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static void nfs_ssc_register_ops(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	nfs_ssc_register(&nfs_ssc_clnt_ops_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static void nfs_ssc_unregister_ops(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	nfs_ssc_unregister(&nfs_ssc_clnt_ops_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) static struct shrinker acl_shrinker = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	.count_objects	= nfs_access_cache_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	.scan_objects	= nfs_access_cache_scan,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	.seeks		= DEFAULT_SEEKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)  * Register the NFS filesystems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) int __init register_nfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)         ret = register_filesystem(&nfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		goto error_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	ret = register_nfs4_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		goto error_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	ret = nfs_register_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		goto error_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 	ret = register_shrinker(&acl_shrinker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		goto error_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	nfs_ssc_register_ops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) error_3:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	nfs_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) error_2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	unregister_nfs4_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) error_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	unregister_filesystem(&nfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) error_0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  * Unregister the NFS filesystems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) void __exit unregister_nfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	unregister_shrinker(&acl_shrinker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 	nfs_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	unregister_nfs4_fs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	nfs_ssc_unregister_ops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	unregister_filesystem(&nfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) bool nfs_sb_active(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	struct nfs_server *server = NFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	if (!atomic_inc_not_zero(&sb->s_active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	if (atomic_inc_return(&server->active) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 		atomic_dec(&sb->s_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) EXPORT_SYMBOL_GPL(nfs_sb_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) void nfs_sb_deactive(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	struct nfs_server *server = NFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	if (atomic_dec_and_test(&server->active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 		deactivate_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) EXPORT_SYMBOL_GPL(nfs_sb_deactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) static int __nfs_list_for_each_server(struct list_head *head,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		int (*fn)(struct nfs_server *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 		void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	struct nfs_server *server, *last = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	list_for_each_entry_rcu(server, head, client_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 		if (!(server->super && nfs_sb_active(server->super)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		if (last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 			nfs_sb_deactive(last->super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		last = server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 		ret = fn(server, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	if (last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		nfs_sb_deactive(last->super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) int nfs_client_for_each_server(struct nfs_client *clp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		int (*fn)(struct nfs_server *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	return __nfs_list_for_each_server(&clp->cl_superblocks, fn, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) EXPORT_SYMBOL_GPL(nfs_client_for_each_server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232)  * Deliver file system statistics to userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 	struct nfs_server *server = NFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	unsigned char blockbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	unsigned long blockres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	struct nfs_fh *fh = NFS_FH(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	struct nfs_fsstat res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	int error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	res.fattr = nfs_alloc_fattr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	if (res.fattr == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	if (unlikely(error == -ESTALE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		struct dentry *pd_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 		pd_dentry = dget_parent(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 		nfs_zap_caches(d_inode(pd_dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		dput(pd_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 	nfs_free_fattr(res.fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	buf->f_type = NFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	 * Current versions of glibc do not correctly handle the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	 * case where f_frsize != f_bsize.  Eventually we want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	 * report the value of wtmult in this field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	buf->f_frsize = dentry->d_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	 * On most *nix systems, f_blocks, f_bfree, and f_bavail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	 * are reported in units of f_frsize.  Linux hasn't had
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 	 * an f_frsize field in its statfs struct until recently,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	 * thus historically Linux's sys_statfs reports these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 	 * fields in units of f_bsize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	buf->f_bsize = dentry->d_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	blockbits = dentry->d_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	blockres = (1 << blockbits) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	buf->f_blocks = (res.tbytes + blockres) >> blockbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	buf->f_bfree = (res.fbytes + blockres) >> blockbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	buf->f_bavail = (res.abytes + blockres) >> blockbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	buf->f_files = res.tfiles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	buf->f_ffree = res.afiles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	buf->f_namelen = server->namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	dprintk("%s: statfs error = %d\n", __func__, -error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) EXPORT_SYMBOL_GPL(nfs_statfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  * Map the security flavour number to a name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		rpc_authflavor_t flavour;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	} sec_flavours[NFS_AUTH_INFO_MAX_FLAVORS] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		/* update NFS_AUTH_INFO_MAX_FLAVORS when this list changes! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		{ RPC_AUTH_NULL, "null" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		{ RPC_AUTH_UNIX, "sys" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		{ RPC_AUTH_GSS_KRB5, "krb5" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		{ RPC_AUTH_GSS_KRB5I, "krb5i" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		{ RPC_AUTH_GSS_KRB5P, "krb5p" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		{ RPC_AUTH_GSS_LKEY, "lkey" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		{ RPC_AUTH_GSS_LKEYI, "lkeyi" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		{ RPC_AUTH_GSS_LKEYP, "lkeyp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		{ RPC_AUTH_GSS_SPKM, "spkm" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		{ RPC_AUTH_GSS_SPKMI, "spkmi" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		{ RPC_AUTH_GSS_SPKMP, "spkmp" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		{ UINT_MAX, "unknown" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	for (i = 0; sec_flavours[i].flavour != UINT_MAX; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		if (sec_flavours[i].flavour == flavour)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	return sec_flavours[i].str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) static void nfs_show_mountd_netid(struct seq_file *m, struct nfs_server *nfss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 				  int showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	struct sockaddr *sap = (struct sockaddr *) &nfss->mountd_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	char *proto = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	switch (sap->sa_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 	case AF_INET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		switch (nfss->mountd_protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		case IPPROTO_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 			proto = RPCBIND_NETID_UDP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		case IPPROTO_TCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 			proto = RPCBIND_NETID_TCP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	case AF_INET6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		switch (nfss->mountd_protocol) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		case IPPROTO_UDP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 			proto = RPCBIND_NETID_UDP6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		case IPPROTO_TCP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			proto = RPCBIND_NETID_TCP6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	if (proto || showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		seq_printf(m, ",mountproto=%s", proto ?: "auto");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 				    int showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	if (nfss->flags & NFS_MOUNT_LEGACY_INTERFACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	switch (sap->sa_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	case AF_INET: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		struct sockaddr_in *sin = (struct sockaddr_in *)sap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		seq_printf(m, ",mountaddr=%pI4", &sin->sin_addr.s_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	case AF_INET6: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		seq_printf(m, ",mountaddr=%pI6c", &sin6->sin6_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		if (showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 			seq_puts(m, ",mountaddr=unspecified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	if (nfss->mountd_version || showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 		seq_printf(m, ",mountvers=%u", nfss->mountd_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	if ((nfss->mountd_port &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		nfss->mountd_port != (unsigned short)NFS_UNSPEC_PORT) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		seq_printf(m, ",mountport=%u", nfss->mountd_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	nfs_show_mountd_netid(m, nfss, showdefaults);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 				    int showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	struct nfs_client *clp = nfss->nfs_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) static void nfs_show_nfsv4_options(struct seq_file *m, struct nfs_server *nfss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 				    int showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) static void nfs_show_nfs_version(struct seq_file *m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		unsigned int version,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		unsigned int minorversion)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	seq_printf(m, ",vers=%u", version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	if (version == 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		seq_printf(m, ".%u", minorversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  * Describe the mount options in force on this server representation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 				   int showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	static const struct proc_nfs_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		int flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 		const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		const char *nostr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	} nfs_info[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		{ NFS_MOUNT_SOFT, ",soft", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		{ NFS_MOUNT_SOFTERR, ",softerr", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		{ NFS_MOUNT_SOFTREVAL, ",softreval", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		{ NFS_MOUNT_POSIX, ",posix", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		{ NFS_MOUNT_NOCTO, ",nocto", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 		{ NFS_MOUNT_NOAC, ",noac", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		{ NFS_MOUNT_NONLM, ",nolock", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 		{ NFS_MOUNT_NOACL, ",noacl", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		{ NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		{ NFS_MOUNT_UNSHARED, ",nosharecache", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		{ NFS_MOUNT_NORESVPORT, ",noresvport", "" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		{ 0, NULL, NULL }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	const struct proc_nfs_info *nfs_infop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	struct nfs_client *clp = nfss->nfs_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	u32 version = clp->rpc_ops->version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	int local_flock, local_fcntl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	nfs_show_nfs_version(m, version, clp->cl_minorversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	seq_printf(m, ",rsize=%u", nfss->rsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	seq_printf(m, ",wsize=%u", nfss->wsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	if (nfss->bsize != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 		seq_printf(m, ",bsize=%u", nfss->bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	seq_printf(m, ",namlen=%u", nfss->namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	if (nfss->acregmin != NFS_DEF_ACREGMIN*HZ || showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	if (nfss->acregmax != NFS_DEF_ACREGMAX*HZ || showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 		seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	if (nfss->acdirmin != NFS_DEF_ACDIRMIN*HZ || showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	if (nfss->acdirmax != NFS_DEF_ACDIRMAX*HZ || showdefaults)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	if (!(nfss->flags & (NFS_MOUNT_SOFT|NFS_MOUNT_SOFTERR)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			seq_puts(m, ",hard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		if (nfss->flags & nfs_infop->flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			seq_puts(m, nfs_infop->str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			seq_puts(m, nfs_infop->nostr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	seq_printf(m, ",proto=%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		   rpc_peeraddr2str(nfss->client, RPC_DISPLAY_NETID));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	if (clp->cl_nconnect > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		seq_printf(m, ",nconnect=%u", clp->cl_nconnect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	if (version == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		if (nfss->port != NFS_PORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			seq_printf(m, ",port=%u", nfss->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 		if (nfss->port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 			seq_printf(m, ",port=%u", nfss->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 	seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	if (version != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		nfs_show_mountd_options(m, nfss, showdefaults);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		nfs_show_nfsv4_options(m, nfss, showdefaults);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	if (nfss->options & NFS_OPTION_FSCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		seq_puts(m, ",fsc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	if (nfss->options & NFS_OPTION_MIGRATION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 		seq_puts(m, ",migration");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONEG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		if (nfss->flags & NFS_MOUNT_LOOKUP_CACHE_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 			seq_puts(m, ",lookupcache=none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			seq_puts(m, ",lookupcache=pos");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	local_flock = nfss->flags & NFS_MOUNT_LOCAL_FLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	local_fcntl = nfss->flags & NFS_MOUNT_LOCAL_FCNTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	if (!local_flock && !local_fcntl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 		seq_puts(m, ",local_lock=none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	else if (local_flock && local_fcntl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		seq_puts(m, ",local_lock=all");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	else if (local_flock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		seq_puts(m, ",local_lock=flock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		seq_puts(m, ",local_lock=posix");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517)  * Describe the mount options on this VFS mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) int nfs_show_options(struct seq_file *m, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	struct nfs_server *nfss = NFS_SB(root->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	nfs_show_mount_options(m, nfss, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	seq_printf(m, ",addr=%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 			rpc_peeraddr2str(nfss->nfs_client->cl_rpcclient,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 							RPC_DISPLAY_ADDR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) EXPORT_SYMBOL_GPL(nfs_show_options);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) static void show_lease(struct seq_file *m, struct nfs_server *server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	struct nfs_client *clp = server->nfs_client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	unsigned long expire;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	seq_printf(m, ",lease_time=%ld", clp->cl_lease_time / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	expire = clp->cl_last_renewal + clp->cl_lease_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	seq_printf(m, ",lease_expired=%ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		   time_after(expire, jiffies) ?  0 : (jiffies - expire) / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) #ifdef CONFIG_NFS_V4_1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) static void show_sessions(struct seq_file *m, struct nfs_server *server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	if (nfs4_has_session(server->nfs_client))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		seq_puts(m, ",sessions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) static void show_sessions(struct seq_file *m, struct nfs_server *server) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) #ifdef CONFIG_NFS_V4_1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) static void show_pnfs(struct seq_file *m, struct nfs_server *server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	seq_printf(m, ",pnfs=");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	if (server->pnfs_curr_ld)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		seq_printf(m, "%s", server->pnfs_curr_ld->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		seq_printf(m, "not configured");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	if (nfss->nfs_client && nfss->nfs_client->cl_implid) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 		struct nfs41_impl_id *impl_id = nfss->nfs_client->cl_implid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		seq_printf(m, "\n\timpl_id:\tname='%s',domain='%s',"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 			   "date='%llu,%u'",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 			   impl_id->name, impl_id->domain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 			   impl_id->date.seconds, impl_id->date.nseconds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) static void show_pnfs(struct seq_file *m, struct nfs_server *server)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) static void show_implementation_id(struct seq_file *m, struct nfs_server *nfss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) int nfs_show_devname(struct seq_file *m, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	char *page = (char *) __get_free_page(GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	char *devname, *dummy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	devname = nfs_path(&dummy, root, page, PAGE_SIZE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	if (IS_ERR(devname))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		err = PTR_ERR(devname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		seq_escape(m, devname, " \t\n\\");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	free_page((unsigned long)page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) EXPORT_SYMBOL_GPL(nfs_show_devname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) int nfs_show_path(struct seq_file *m, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	seq_puts(m, "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) EXPORT_SYMBOL_GPL(nfs_show_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613)  * Present statistical information for this VFS mountpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) int nfs_show_stats(struct seq_file *m, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	int i, cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	struct nfs_server *nfss = NFS_SB(root->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	struct rpc_auth *auth = nfss->client->cl_auth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	struct nfs_iostats totals = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	seq_printf(m, "statvers=%s", NFS_IOSTAT_VERS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	 * Display all mount option settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	seq_puts(m, "\n\topts:\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	seq_puts(m, sb_rdonly(root->d_sb) ? "ro" : "rw");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	seq_puts(m, root->d_sb->s_flags & SB_SYNCHRONOUS ? ",sync" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	seq_puts(m, root->d_sb->s_flags & SB_NOATIME ? ",noatime" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	seq_puts(m, root->d_sb->s_flags & SB_NODIRATIME ? ",nodiratime" : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	nfs_show_mount_options(m, nfss, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	seq_printf(m, "\n\tage:\t%lu", (jiffies - nfss->mount_time) / HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	show_implementation_id(m, nfss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	seq_puts(m, "\n\tcaps:\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	seq_printf(m, "caps=0x%x", nfss->caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	seq_printf(m, ",wtmult=%u", nfss->wtmult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	seq_printf(m, ",dtsize=%u", nfss->dtsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	seq_printf(m, ",bsize=%u", nfss->bsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	seq_printf(m, ",namlen=%u", nfss->namelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	if (nfss->nfs_client->rpc_ops->version == 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		seq_puts(m, "\n\tnfsv4:\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		seq_printf(m, "bm0=0x%x", nfss->attr_bitmask[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		seq_printf(m, ",bm1=0x%x", nfss->attr_bitmask[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		seq_printf(m, ",bm2=0x%x", nfss->attr_bitmask[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		seq_printf(m, ",acl=0x%x", nfss->acl_bitmask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		show_sessions(m, nfss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		show_pnfs(m, nfss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 		show_lease(m, nfss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	 * Display security flavor in effect for this mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (auth->au_flavor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	 * Display superblock I/O counters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		struct nfs_iostats *stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		stats = per_cpu_ptr(nfss->io_stats, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 		for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			totals.events[i] += stats->events[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 		for (i = 0; i < __NFSIOS_BYTESMAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			totals.bytes[i] += stats->bytes[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) #ifdef CONFIG_NFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			totals.fscache[i] += stats->fscache[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 		preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	seq_puts(m, "\n\tevents:\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	for (i = 0; i < __NFSIOS_COUNTSMAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		seq_printf(m, "%lu ", totals.events[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	seq_puts(m, "\n\tbytes:\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	for (i = 0; i < __NFSIOS_BYTESMAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 		seq_printf(m, "%Lu ", totals.bytes[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) #ifdef CONFIG_NFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	if (nfss->options & NFS_OPTION_FSCACHE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		seq_puts(m, "\n\tfsc:\t");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		for (i = 0; i < __NFSIOS_FSCACHEMAX; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			seq_printf(m, "%Lu ", totals.fscache[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	seq_putc(m, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	rpc_clnt_show_stats(m, nfss->client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) EXPORT_SYMBOL_GPL(nfs_show_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  * Begin unmount by attempting to remove all automounted mountpoints we added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709)  * in response to xdev traversals and referrals
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) void nfs_umount_begin(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	struct nfs_server *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	struct rpc_clnt *rpc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	server = NFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	/* -EIO all pending I/O */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	rpc = server->client_acl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	if (!IS_ERR(rpc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		rpc_killall_tasks(rpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	rpc = server->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 	if (!IS_ERR(rpc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		rpc_killall_tasks(rpc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) EXPORT_SYMBOL_GPL(nfs_umount_begin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728)  * Return true if 'match' is in auth_info or auth_info is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729)  * Return false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) bool nfs_auth_info_match(const struct nfs_auth_info *auth_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 			 rpc_authflavor_t match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	if (!auth_info->flavor_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	for (i = 0; i < auth_info->flavor_len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		if (auth_info->flavors[i] == match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) EXPORT_SYMBOL_GPL(nfs_auth_info_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748)  * Ensure that a specified authtype in ctx->auth_info is supported by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749)  * the server. Returns 0 and sets ctx->selected_flavor if it's ok, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750)  * -EACCES if not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) static int nfs_verify_authflavors(struct nfs_fs_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 				  rpc_authflavor_t *server_authlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 				  unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	rpc_authflavor_t flavor = RPC_AUTH_MAXFLAVOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	bool found_auth_null = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	 * If the sec= mount option is used, the specified flavor or AUTH_NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	 * must be in the list returned by the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	 * AUTH_NULL has a special meaning when it's in the server list - it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	 * means that the server will ignore the rpc creds, so any flavor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	 * can be used but still use the sec= that was specified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	 * Note also that the MNT procedure in MNTv1 does not return a list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	 * of supported security flavors. In this case, nfs_mount() fabricates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	 * a security flavor list containing just AUTH_NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		flavor = server_authlist[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		if (nfs_auth_info_match(&ctx->auth_info, flavor))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		if (flavor == RPC_AUTH_NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 			found_auth_null = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	if (found_auth_null) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		flavor = ctx->auth_info.flavors[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	dfprintk(MOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		 "NFS: specified auth flavors not supported by server\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	ctx->selected_flavor = flavor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	dfprintk(MOUNT, "NFS: using auth flavor %u\n", ctx->selected_flavor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798)  * Use the remote server's MOUNT service to request the NFS file handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799)  * corresponding to the provided path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) static int nfs_request_mount(struct fs_context *fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			     struct nfs_fh *root_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			     rpc_authflavor_t *server_authlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			     unsigned int *server_authlist_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	struct nfs_mount_request request = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 		.sap		= (struct sockaddr *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 						&ctx->mount_server.address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 		.dirpath	= ctx->nfs_server.export_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		.protocol	= ctx->mount_server.protocol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		.fh		= root_fh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 		.noresvport	= ctx->flags & NFS_MOUNT_NORESVPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		.auth_flav_len	= server_authlist_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		.auth_flavs	= server_authlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		.net		= fc->net_ns,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	if (ctx->mount_server.version == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 		switch (ctx->version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 				ctx->mount_server.version = NFS_MNT3_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 				ctx->mount_server.version = NFS_MNT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	request.version = ctx->mount_server.version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	if (ctx->mount_server.hostname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		request.hostname = ctx->mount_server.hostname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		request.hostname = ctx->nfs_server.hostname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	 * Construct the mount server's address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	if (ctx->mount_server.address.sa_family == AF_UNSPEC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		memcpy(request.sap, &ctx->nfs_server.address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 		       ctx->nfs_server.addrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 		ctx->mount_server.addrlen = ctx->nfs_server.addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	request.salen = ctx->mount_server.addrlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	nfs_set_port(request.sap, &ctx->mount_server.port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	 * Now ask the mount server to map our export path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 	 * to a file handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	status = nfs_mount(&request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	if (status != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		dfprintk(MOUNT, "NFS: unable to mount server %s, error %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 				request.hostname, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	bool tried_auth_unix = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	bool auth_null_in_list = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	struct nfs_server *server = ERR_PTR(-EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 	rpc_authflavor_t authlist[NFS_MAX_SECFLAVORS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	unsigned int authlist_len = ARRAY_SIZE(authlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	status = nfs_request_mount(fc, ctx->mntfh, authlist, &authlist_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		return ERR_PTR(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 	 * Was a sec= authflavor specified in the options? First, verify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	 * whether the server supports it, and then just try to use it if so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	if (ctx->auth_info.flavor_len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		status = nfs_verify_authflavors(ctx, authlist, authlist_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		dfprintk(MOUNT, "NFS: using auth flavor %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 			 ctx->selected_flavor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 			return ERR_PTR(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		return ctx->nfs_mod->rpc_ops->create_server(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	 * No sec= option was provided. RFC 2623, section 2.7 suggests we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	 * SHOULD prefer the flavor listed first. However, some servers list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	 * AUTH_NULL first. Avoid ever choosing AUTH_NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	for (i = 0; i < authlist_len; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		rpc_authflavor_t flavor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		struct rpcsec_gss_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		flavor = authlist[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		switch (flavor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		case RPC_AUTH_UNIX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 			tried_auth_unix = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		case RPC_AUTH_NULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 			auth_null_in_list = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		ctx->selected_flavor = flavor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		server = ctx->nfs_mod->rpc_ops->create_server(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		if (!IS_ERR(server))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 			return server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	 * Nothing we tried so far worked. At this point, give up if we've
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	 * already tried AUTH_UNIX or if the server's list doesn't contain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	 * AUTH_NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	if (tried_auth_unix || !auth_null_in_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		return server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	/* Last chance! Try AUTH_UNIX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", RPC_AUTH_UNIX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	ctx->selected_flavor = RPC_AUTH_UNIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	return ctx->nfs_mod->rpc_ops->create_server(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) int nfs_try_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	if (ctx->need_mount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		ctx->server = nfs_try_mount_request(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		ctx->server = ctx->nfs_mod->rpc_ops->create_server(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	return nfs_get_tree_common(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) EXPORT_SYMBOL_GPL(nfs_try_get_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) #define NFS_REMOUNT_CMP_FLAGMASK ~(NFS_MOUNT_INTR \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		| NFS_MOUNT_SECURE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		| NFS_MOUNT_TCP \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		| NFS_MOUNT_VER3 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 		| NFS_MOUNT_KERBEROS \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 		| NFS_MOUNT_NONLM \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 		| NFS_MOUNT_BROKEN_SUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 		| NFS_MOUNT_STRICTLOCK \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 		| NFS_MOUNT_LEGACY_INTERFACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) #define NFS_MOUNT_CMP_FLAGMASK (NFS_REMOUNT_CMP_FLAGMASK & \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		~(NFS_MOUNT_UNSHARED | NFS_MOUNT_NORESVPORT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) nfs_compare_remount_data(struct nfs_server *nfss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 			 struct nfs_fs_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	if ((ctx->flags ^ nfss->flags) & NFS_REMOUNT_CMP_FLAGMASK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	    ctx->rsize != nfss->rsize ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	    ctx->wsize != nfss->wsize ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	    ctx->version != nfss->nfs_client->rpc_ops->version ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	    ctx->minorversion != nfss->nfs_client->cl_minorversion ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	    ctx->retrans != nfss->client->cl_timeout->to_retries ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	    !nfs_auth_info_match(&ctx->auth_info, nfss->client->cl_auth->au_flavor) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	    ctx->acregmin != nfss->acregmin / HZ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	    ctx->acregmax != nfss->acregmax / HZ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	    ctx->acdirmin != nfss->acdirmin / HZ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	    ctx->acdirmax != nfss->acdirmax / HZ ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	    ctx->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	    (ctx->options & NFS_OPTION_FSCACHE) != (nfss->options & NFS_OPTION_FSCACHE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	    ctx->nfs_server.port != nfss->port ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	    ctx->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 	    !rpc_cmp_addr((struct sockaddr *)&ctx->nfs_server.address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			  (struct sockaddr *)&nfss->nfs_client->cl_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) int nfs_reconfigure(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	struct super_block *sb = fc->root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	struct nfs_server *nfss = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	 * Userspace mount programs that send binary options generally send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	 * them populated with default values. We have no way to know which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	 * ones were explicitly specified. Fall back to legacy behavior and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	 * just return success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	if (ctx->skip_reconfig_option_check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	 * noac is a special case. It implies -o sync, but that's not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	 * necessarily reflected in the mtab options. reconfigure_super
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	 * will clear SB_SYNCHRONOUS if -o sync wasn't specified in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	 * remount options, so we have to explicitly reset it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	if (ctx->flags & NFS_MOUNT_NOAC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		fc->sb_flags |= SB_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		fc->sb_flags_mask |= SB_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	/* compare new mount options with old ones */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	return nfs_compare_remount_data(nfss, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) EXPORT_SYMBOL_GPL(nfs_reconfigure);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)  * Finish setting up an NFS superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	struct nfs_server *server = NFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	sb->s_blocksize_bits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	sb->s_blocksize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	sb->s_op = server->nfs_client->cl_nfs_mod->sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 	if (ctx && ctx->bsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		sb->s_blocksize = nfs_block_size(ctx->bsize, &sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	if (server->nfs_client->rpc_ops->version != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		/* The VFS shouldn't apply the umask to mode bits. We will do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		 * so ourselves when necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		sb->s_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		sb->s_export_op = &nfs_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		sb->s_time_gran = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	if (server->nfs_client->rpc_ops->version != 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		sb->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		sb->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		sb->s_time_min = S64_MIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		sb->s_time_max = S64_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	sb->s_magic = NFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	/* We probably want something more informative here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	snprintf(sb->s_id, sizeof(sb->s_id),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		 "%u:%u", MAJOR(sb->s_dev), MINOR(sb->s_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	if (sb->s_blocksize == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 		sb->s_blocksize = nfs_block_bits(server->wsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 						 &sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	nfs_super_set_maxbytes(sb, server->maxfilesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static int nfs_compare_mount_options(const struct super_block *s, const struct nfs_server *b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 				     const struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	const struct nfs_server *a = s->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	const struct rpc_clnt *clnt_a = a->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	const struct rpc_clnt *clnt_b = b->client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	if ((s->s_flags & NFS_SB_MASK) != (fc->sb_flags & NFS_SB_MASK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	if (a->nfs_client != b->nfs_client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	if ((a->flags ^ b->flags) & NFS_MOUNT_CMP_FLAGMASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	if (a->wsize != b->wsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	if (a->rsize != b->rsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	if (a->acregmin != b->acregmin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	if (a->acregmax != b->acregmax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	if (a->acdirmin != b->acdirmin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	if (a->acdirmax != b->acdirmax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	if (clnt_a->cl_auth->au_flavor != clnt_b->cl_auth->au_flavor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		goto Ebusy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) Ebusy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static int nfs_set_super(struct super_block *s, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	struct nfs_server *server = fc->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	s->s_d_op = server->nfs_client->rpc_ops->dentry_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	ret = set_anon_super(s, server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		server->s_dev = s->s_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) static int nfs_compare_super_address(struct nfs_server *server1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 				     struct nfs_server *server2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	struct sockaddr *sap1, *sap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	struct rpc_xprt *xprt1 = server1->client->cl_xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	struct rpc_xprt *xprt2 = server2->client->cl_xprt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	if (!net_eq(xprt1->xprt_net, xprt2->xprt_net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	if (sap1->sa_family != sap2->sa_family)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	switch (sap1->sa_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	case AF_INET: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 		if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		if (sin1->sin_port != sin2->sin_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	case AF_INET6: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 		struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 		struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		if (sin1->sin6_port != sin2->sin6_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) static int nfs_compare_userns(const struct nfs_server *old,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		const struct nfs_server *new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	const struct user_namespace *oldns = &init_user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	const struct user_namespace *newns = &init_user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	if (old->client && old->client->cl_cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 		oldns = old->client->cl_cred->user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	if (new->client && new->client->cl_cred)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 		newns = new->client->cl_cred->user_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	if (oldns != newns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) static int nfs_compare_super(struct super_block *sb, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	struct nfs_server *server = fc->s_fs_info, *old = NFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	if (!nfs_compare_super_address(old, server))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	/* Note: NFS_MOUNT_UNSHARED == NFS4_MOUNT_UNSHARED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	if (old->flags & NFS_MOUNT_UNSHARED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	if (memcmp(&old->fsid, &server->fsid, sizeof(old->fsid)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	if (!nfs_compare_userns(old, server))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	return nfs_compare_mount_options(sb, server, fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) #ifdef CONFIG_NFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) static void nfs_get_cache_cookie(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 				 struct nfs_fs_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	struct nfs_server *nfss = NFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	char *uniq = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	int ulen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	nfss->fscache_key = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	nfss->fscache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	if (ctx->clone_data.sb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		struct nfs_server *mnt_s = NFS_SB(ctx->clone_data.sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 		if (!(mnt_s->options & NFS_OPTION_FSCACHE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 		if (mnt_s->fscache_key) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 			uniq = mnt_s->fscache_key->key.uniquifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 			ulen = mnt_s->fscache_key->key.uniq_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 		if (!(ctx->options & NFS_OPTION_FSCACHE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		if (ctx->fscache_uniq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 			uniq = ctx->fscache_uniq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 			ulen = strlen(ctx->fscache_uniq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	nfs_fscache_get_super_cookie(sb, uniq, ulen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) static void nfs_get_cache_cookie(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 				 struct nfs_fs_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) int nfs_get_tree_common(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	struct super_block *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	int (*compare_super)(struct super_block *, struct fs_context *) = nfs_compare_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	struct nfs_server *server = ctx->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	ctx->server = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	if (IS_ERR(server))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 		return PTR_ERR(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	if (server->flags & NFS_MOUNT_UNSHARED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 		compare_super = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	/* -o noac implies -o sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	if (server->flags & NFS_MOUNT_NOAC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 		fc->sb_flags |= SB_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	if (ctx->clone_data.sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		if (ctx->clone_data.sb->s_flags & SB_SYNCHRONOUS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 			fc->sb_flags |= SB_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	if (server->caps & NFS_CAP_SECURITY_LABEL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		fc->lsm_flags |= SECURITY_LSM_NATIVE_LABELS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	/* Get a superblock - note that we may end up sharing one that already exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	fc->s_fs_info = server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	s = sget_fc(fc, compare_super, nfs_set_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	fc->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	if (IS_ERR(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		error = PTR_ERR(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		nfs_errorf(fc, "NFS: Couldn't get superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		goto out_err_nosb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	if (s->s_fs_info != server) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		nfs_free_server(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 		server = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		error = super_setup_bdi_name(s, "%u:%u", MAJOR(server->s_dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 					     MINOR(server->s_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 			goto error_splat_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 		s->s_bdi->io_pages = server->rpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 		server->super = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	if (!s->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		unsigned bsize = ctx->clone_data.inherited_bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		/* initial superblock/root creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		nfs_fill_super(s, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		if (bsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			s->s_blocksize_bits = bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 			s->s_blocksize = 1U << bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		nfs_get_cache_cookie(s, ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 	error = nfs_get_root(s, fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		nfs_errorf(fc, "NFS: Couldn't get root dentry");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		goto error_splat_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	s->s_flags |= SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) out_err_nosb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 	nfs_free_server(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) error_splat_super:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	deactivate_locked_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)  * Destroy an NFS2/3 superblock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) void nfs_kill_super(struct super_block *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	struct nfs_server *server = NFS_SB(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	dev_t dev = s->s_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	generic_shutdown_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	nfs_fscache_release_super_cookie(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	nfs_free_server(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	free_anon_bdev(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) EXPORT_SYMBOL_GPL(nfs_kill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)  * NFS v4 module parameters need to stay in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)  * NFS client for backwards compatibility
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) unsigned int nfs_callback_set_tcpport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) unsigned short nfs_callback_nr_threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) /* Default cache timeout is 10 minutes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) unsigned int nfs_idmap_cache_timeout = 600;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) /* Turn off NFSv4 uid/gid mapping when using AUTH_SYS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) bool nfs4_disable_idmapping = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) unsigned short max_session_slots = NFS4_DEF_SLOT_TABLE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) unsigned short max_session_cb_slots = NFS4_DEF_CB_SLOT_TABLE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) unsigned short send_implementation_id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) char nfs4_client_id_uniquifier[NFS4_CLIENT_ID_UNIQ_LEN] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) bool recover_lost_locks = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) EXPORT_SYMBOL_GPL(nfs_callback_nr_threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) EXPORT_SYMBOL_GPL(nfs_callback_set_tcpport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) EXPORT_SYMBOL_GPL(nfs_idmap_cache_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) EXPORT_SYMBOL_GPL(nfs4_disable_idmapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) EXPORT_SYMBOL_GPL(max_session_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) EXPORT_SYMBOL_GPL(max_session_cb_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) EXPORT_SYMBOL_GPL(send_implementation_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) EXPORT_SYMBOL_GPL(nfs4_client_id_uniquifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) EXPORT_SYMBOL_GPL(recover_lost_locks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) #define NFS_CALLBACK_MAXPORTNR (65535U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) static int param_set_portnr(const char *val, const struct kernel_param *kp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 	unsigned long num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	if (!val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	ret = kstrtoul(val, 0, &num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	if (ret || num > NFS_CALLBACK_MAXPORTNR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	*((unsigned int *)kp->arg) = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) static const struct kernel_param_ops param_ops_portnr = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	.set = param_set_portnr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	.get = param_get_uint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) #define param_check_portnr(name, p) __param_check(name, p, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) module_param_named(callback_tcpport, nfs_callback_set_tcpport, portnr, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) module_param_named(callback_nr_threads, nfs_callback_nr_threads, ushort, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) MODULE_PARM_DESC(callback_nr_threads, "Number of threads that will be "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		"assigned to the NFSv4 callback channels.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) module_param(nfs_idmap_cache_timeout, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) module_param(nfs4_disable_idmapping, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) module_param_string(nfs4_unique_id, nfs4_client_id_uniquifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 			NFS4_CLIENT_ID_UNIQ_LEN, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) MODULE_PARM_DESC(nfs4_disable_idmapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		"Turn off NFSv4 idmapping when using 'sec=sys'");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) module_param(max_session_slots, ushort, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) MODULE_PARM_DESC(max_session_slots, "Maximum number of outstanding NFSv4.1 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		"requests the client will negotiate");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) module_param(max_session_cb_slots, ushort, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) MODULE_PARM_DESC(max_session_cb_slots, "Maximum number of parallel NFSv4.1 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 		"callbacks the client will process for a given server");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) module_param(send_implementation_id, ushort, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) MODULE_PARM_DESC(send_implementation_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 		"Send implementation ID with NFSv4.1 exchange_id");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) MODULE_PARM_DESC(nfs4_unique_id, "nfs_client_id4 uniquifier string");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) module_param(recover_lost_locks, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) MODULE_PARM_DESC(recover_lost_locks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		 "If the server reports that a lock might be lost, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		 "try to recover it risking data corruption.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) #endif /* CONFIG_NFS_V4 */