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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* AFS dynamic root handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/namei.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/dns_resolver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static atomic_t afs_autocell_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * iget5() comparator for inode created by autocell operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * These pseudo inodes don't match anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static int afs_iget5_pseudo_test(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * iget5() inode initialiser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int afs_iget5_pseudo_set(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct afs_super_info *as = AFS_FS_S(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct afs_vnode *vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct afs_fid *fid = opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	vnode->volume		= as->volume;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	vnode->fid		= *fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	inode->i_ino		= fid->vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	inode->i_generation	= fid->unique;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * Create an inode for a dynamic root directory or an autocell dynamic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * automount dir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) struct inode *afs_iget_pseudo_dir(struct super_block *sb, bool root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct afs_super_info *as = AFS_FS_S(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct afs_vnode *vnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct afs_fid fid = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	_enter("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (as->volume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		fid.vid = as->volume->vid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		fid.vnode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		fid.unique = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		fid.vnode = atomic_inc_return(&afs_autocell_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		fid.unique = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	inode = iget5_locked(sb, fid.vnode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			     afs_iget5_pseudo_test, afs_iget5_pseudo_set, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		_leave(" = -ENOMEM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	_debug("GOT INODE %p { ino=%lu, vl=%llx, vn=%llx, u=%x }",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	       inode, inode->i_ino, fid.vid, fid.vnode, fid.unique);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	vnode = AFS_FS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	/* there shouldn't be an existing inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	BUG_ON(!(inode->i_state & I_NEW));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	inode->i_size		= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	inode->i_mode		= S_IFDIR | S_IRUGO | S_IXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		inode->i_op	= &afs_dynroot_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		inode->i_fop	= &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		inode->i_op	= &afs_autocell_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	inode->i_uid		= GLOBAL_ROOT_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	inode->i_gid		= GLOBAL_ROOT_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	inode->i_ctime = inode->i_atime = inode->i_mtime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	inode->i_blocks		= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	inode->i_generation	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	set_bit(AFS_VNODE_PSEUDODIR, &vnode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (!root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		set_bit(AFS_VNODE_MOUNTPOINT, &vnode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		inode->i_flags |= S_AUTOMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	inode->i_flags |= S_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	_leave(" = %p", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * Probe to see if a cell may exist.  This prevents positive dentries from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * being created unnecessarily.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static int afs_probe_cell_name(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct afs_cell *cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct afs_net *net = afs_d2net(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	const char *name = dentry->d_name.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	size_t len = dentry->d_name.len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	/* Names prefixed with a dot are R/W mounts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (name[0] == '.') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		if (len == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		name++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		len--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	cell = afs_find_cell(net, name, len, afs_cell_trace_use_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (!IS_ERR(cell)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		afs_unuse_cell(net, cell, afs_cell_trace_unuse_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	ret = dns_query(net->net, "afsdb", name, len, "srv=1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			NULL, NULL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (ret == -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		ret = -EDESTADDRREQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * Try to auto mount the mountpoint with pseudo directory, if the autocell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * operation is setted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct inode *afs_try_auto_mntpt(struct dentry *dentry, struct inode *dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	struct afs_vnode *vnode = AFS_FS_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	_enter("%p{%pd}, {%llx:%llu}",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	       dentry, dentry, vnode->fid.vid, vnode->fid.vnode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (!test_bit(AFS_VNODE_AUTOCELL, &vnode->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	ret = afs_probe_cell_name(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	inode = afs_iget_pseudo_dir(dir->i_sb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		ret = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	_leave("= %p", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	_leave("= %d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return ret == -ENOENT ? NULL : ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * Look up @cell in a dynroot directory.  This is a substitution for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  * local cell name for the net namespace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static struct dentry *afs_lookup_atcell(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct afs_cell *cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct afs_net *net = afs_d2net(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct dentry *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (!net->ws_cell)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ret = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	name = kmalloc(AFS_MAXCELLNAME + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto out_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	down_read(&net->cells_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	cell = net->ws_cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (cell) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		len = cell->name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		memcpy(name, cell->name, len + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	up_read(&net->cells_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	ret = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (!cell)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		goto out_n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	ret = lookup_one_len(name, dentry->d_parent, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* We don't want to d_add() the @cell dentry here as we don't want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	 * the cached dentry to hide changes to the local cell name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) out_n:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	kfree(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) out_p:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * Look up an entry in a dynroot directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static struct dentry *afs_dynroot_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 					 unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	_enter("%pd", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	ASSERTCMP(d_inode(dentry), ==, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (flags & LOOKUP_CREATE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return ERR_PTR(-EOPNOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (dentry->d_name.len >= AFSNAMEMAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		_leave(" = -ENAMETOOLONG");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (dentry->d_name.len == 5 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	    memcmp(dentry->d_name.name, "@cell", 5) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		return afs_lookup_atcell(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return d_splice_alias(afs_try_auto_mntpt(dentry, dir), dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) const struct inode_operations afs_dynroot_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	.lookup		= afs_dynroot_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * Dirs in the dynamic root don't need revalidation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static int afs_dynroot_d_revalidate(struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * Allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * - called from dput() when d_count is going to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * - return 1 to request dentry be unhashed, 0 otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int afs_dynroot_d_delete(const struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	return d_really_is_positive(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) const struct dentry_operations afs_dynroot_dentry_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	.d_revalidate	= afs_dynroot_d_revalidate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	.d_delete	= afs_dynroot_d_delete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	.d_release	= afs_d_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	.d_automount	= afs_d_automount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)  * Create a manually added cell mount directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)  * - The caller must hold net->proc_cells_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int afs_dynroot_mkdir(struct afs_net *net, struct afs_cell *cell)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct super_block *sb = net->dynroot_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct dentry *root, *subdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (!sb || atomic_read(&sb->s_active) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	/* Let the ->lookup op do the creation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	root = sb->s_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	inode_lock(root->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	subdir = lookup_one_len(cell->name, root, cell->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (IS_ERR(subdir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		ret = PTR_ERR(subdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	/* Note that we're retaining an extra ref on the dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	subdir->d_fsdata = (void *)1UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	inode_unlock(root->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * Remove a manually added cell mount directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * - The caller must hold net->proc_cells_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) void afs_dynroot_rmdir(struct afs_net *net, struct afs_cell *cell)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct super_block *sb = net->dynroot_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct dentry *root, *subdir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	if (!sb || atomic_read(&sb->s_active) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	root = sb->s_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	inode_lock(root->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	/* Don't want to trigger a lookup call, which will re-add the cell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	subdir = try_lookup_one_len(cell->name, root, cell->name_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (IS_ERR_OR_NULL(subdir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		_debug("lookup %ld", PTR_ERR(subdir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		goto no_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	_debug("rmdir %pd %u", subdir, d_count(subdir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (subdir->d_fsdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		_debug("unpin %u", d_count(subdir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		subdir->d_fsdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		dput(subdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	dput(subdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) no_dentry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	inode_unlock(root->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	_leave("");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  * Populate a newly created dynamic root with cell names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) int afs_dynroot_populate(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct afs_cell *cell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct afs_net *net = afs_sb2net(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	mutex_lock(&net->proc_cells_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	net->dynroot_sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	hlist_for_each_entry(cell, &net->proc_cells, proc_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		ret = afs_dynroot_mkdir(net, cell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	mutex_unlock(&net->proc_cells_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	net->dynroot_sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  * When a dynamic root that's in the process of being destroyed, depopulate it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * of pinned directories.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) void afs_dynroot_depopulate(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	struct afs_net *net = afs_sb2net(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	struct dentry *root = sb->s_root, *subdir, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* Prevent more subdirs from being created */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	mutex_lock(&net->proc_cells_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	if (net->dynroot_sb == sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		net->dynroot_sb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	mutex_unlock(&net->proc_cells_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	if (root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		inode_lock(root->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		/* Remove all the pins for dirs created for manually added cells */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		list_for_each_entry_safe(subdir, tmp, &root->d_subdirs, d_child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			if (subdir->d_fsdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 				subdir->d_fsdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 				dput(subdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		inode_unlock(root->d_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) }