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)  * Copyright (c) 2012 Bryan Schumaker <bjschuma@netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/nfs4_mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/nfs_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/nfs_ssc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "delegation.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "nfs4_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "nfs4idmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "dns_resolve.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "pnfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "nfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define NFSDBG_FACILITY		NFSDBG_VFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int nfs4_write_inode(struct inode *inode, struct writeback_control *wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static void nfs4_evict_inode(struct inode *inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static const struct super_operations nfs4_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.alloc_inode	= nfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	.free_inode	= nfs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	.write_inode	= nfs4_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	.drop_inode	= nfs_drop_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	.statfs		= nfs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.evict_inode	= nfs4_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.umount_begin	= nfs_umount_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.show_options	= nfs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.show_devname	= nfs_show_devname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.show_path	= nfs_show_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.show_stats	= nfs_show_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) struct nfs_subversion nfs_v4 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	.owner		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.nfs_fs		= &nfs4_fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.rpc_vers	= &nfs_version4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.rpc_ops	= &nfs_v4_clientops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.sops		= &nfs4_sops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.xattr		= nfs4_xattr_handlers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static int nfs4_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int ret = nfs_write_inode(inode, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		ret = pnfs_layoutcommit_inode(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 				wbc->sync_mode == WB_SYNC_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * Clean out any remaining NFSv4 state that might be left over due
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * to open() calls that passed nfs_atomic_lookup, but failed to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * nfs_open().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static void nfs4_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* If we are holding a delegation, return and free it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	nfs_inode_evict_delegation(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/* Note that above delegreturn would trigger pnfs return-on-close */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	pnfs_return_layout(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	pnfs_destroy_layout_final(NFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	/* First call standard NFS clear_inode() code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	nfs_clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	nfs4_xattr_cache_zap(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) struct nfs_referral_count {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	const struct task_struct *task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int referral_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static LIST_HEAD(nfs_referral_count_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static struct nfs_referral_count *nfs_find_referral_count(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct nfs_referral_count *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	list_for_each_entry(p, &nfs_referral_count_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		if (p->task == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			return p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #define NFS_MAX_NESTED_REFERRALS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int nfs_referral_loop_protect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct nfs_referral_count *p, *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	new = kmalloc(sizeof(*new), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	if (!new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	new->task = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	new->referral_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	spin_lock(&nfs_referral_count_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	p = nfs_find_referral_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (p != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			ret = -ELOOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			p->referral_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		list_add(&new->list, &nfs_referral_count_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		new = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	spin_unlock(&nfs_referral_count_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static void nfs_referral_loop_unprotect(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct nfs_referral_count *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	spin_lock(&nfs_referral_count_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	p = nfs_find_referral_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	p->referral_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (p->referral_count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		list_del(&p->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	spin_unlock(&nfs_referral_count_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	kfree(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int do_nfs4_mount(struct nfs_server *server,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			 struct fs_context *fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			 const char *hostname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			 const char *export_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct nfs_fs_context *root_ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct fs_context *root_fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct vfsmount *root_mnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct fs_parameter param = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		.key	= "source",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		.type	= fs_value_is_string,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		.dirfd	= -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (IS_ERR(server))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return PTR_ERR(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	root_fc = vfs_dup_fs_context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	if (IS_ERR(root_fc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		nfs_free_server(server);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return PTR_ERR(root_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	kfree(root_fc->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	root_fc->source = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	root_ctx = nfs_fc2context(root_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	root_ctx->internal = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	root_ctx->server = server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	/* We leave export_path unset as it's not used to find the root. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	len = strlen(hostname) + 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	param.string = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (param.string == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		put_fs_context(root_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	/* Does hostname needs to be enclosed in brackets? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (strchr(hostname, ':'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		param.size = snprintf(param.string, len, "[%s]:/", hostname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		param.size = snprintf(param.string, len, "%s:/", hostname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ret = vfs_parse_fs_param(root_fc, &param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	kfree(param.string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		put_fs_context(root_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	root_mnt = fc_mount(root_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	put_fs_context(root_fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (IS_ERR(root_mnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		return PTR_ERR(root_mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	ret = nfs_referral_loop_protect();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		mntput(root_mnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	dentry = mount_subtree(root_mnt, export_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	nfs_referral_loop_unprotect();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	if (IS_ERR(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	fc->root = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int nfs4_try_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	dfprintk(MOUNT, "--> nfs4_try_get_tree()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	/* We create a mount for the server's root, walk to the requested
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	 * location and then create another mount for that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	err= do_nfs4_mount(nfs4_create_server(fc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			   fc, ctx->nfs_server.hostname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			   ctx->nfs_server.export_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		nfs_ferrorf(fc, MOUNT, "NFS4: Couldn't follow remote path");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		dfprintk(MOUNT, "<-- nfs4_try_get_tree() = %d [error]\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		dfprintk(MOUNT, "<-- nfs4_try_get_tree() = 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * Create an NFS4 server record on referral traversal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) int nfs4_get_referral_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct nfs_fs_context *ctx = nfs_fc2context(fc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	dprintk("--> nfs4_referral_mount()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/* create a new volume representation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	err = do_nfs4_mount(nfs4_create_referral_server(fc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			    fc, ctx->nfs_server.hostname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 			    ctx->nfs_server.export_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		nfs_ferrorf(fc, MOUNT, "NFS4: Couldn't follow remote path");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		dfprintk(MOUNT, "<-- nfs4_get_referral_tree() = %d [error]\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		dfprintk(MOUNT, "<-- nfs4_get_referral_tree() = 0\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) static int __init init_nfs_v4(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	err = nfs_dns_resolver_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	err = nfs_idmap_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #ifdef CONFIG_NFS_V4_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	err = nfs4_xattr_cache_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	err = nfs4_register_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		goto out2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) #ifdef CONFIG_NFS_V4_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	nfs42_ssc_register_ops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	register_nfs_version(&nfs_v4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) out2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	nfs_idmap_quit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	nfs_dns_resolver_destroy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return err;
^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) static void __exit exit_nfs_v4(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	/* Not called in the _init(), conditionally loaded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	nfs4_pnfs_v3_ds_connect_unload();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	unregister_nfs_version(&nfs_v4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) #ifdef CONFIG_NFS_V4_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	nfs4_xattr_cache_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	nfs42_ssc_unregister_ops();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	nfs4_unregister_sysctl();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	nfs_idmap_quit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	nfs_dns_resolver_destroy();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) module_init(init_nfs_v4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) module_exit(exit_nfs_v4);