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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2001-2006 Ian Kent <raven@themaw.net>
^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/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "autofs_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) static int autofs_dir_symlink(struct inode *, struct dentry *, const char *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static int autofs_dir_unlink(struct inode *, struct dentry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) static int autofs_dir_rmdir(struct inode *, struct dentry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static int autofs_dir_mkdir(struct inode *, struct dentry *, umode_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static long autofs_root_ioctl(struct file *, unsigned int, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static long autofs_root_compat_ioctl(struct file *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 				     unsigned int, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) static int autofs_dir_open(struct inode *inode, struct file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static struct dentry *autofs_lookup(struct inode *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 				    struct dentry *, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct vfsmount *autofs_d_automount(struct path *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int autofs_d_manage(const struct path *, bool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void autofs_dentry_release(struct dentry *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) const struct file_operations autofs_root_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	.open		= dcache_dir_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	.release	= dcache_dir_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	.read		= generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.iterate_shared	= dcache_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.llseek		= dcache_dir_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	.unlocked_ioctl	= autofs_root_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	.compat_ioctl	= autofs_root_compat_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #endif
^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) const struct file_operations autofs_dir_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.open		= autofs_dir_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.release	= dcache_dir_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.read		= generic_read_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.iterate_shared	= dcache_readdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.llseek		= dcache_dir_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) const struct inode_operations autofs_dir_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.lookup		= autofs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.unlink		= autofs_dir_unlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.symlink	= autofs_dir_symlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.mkdir		= autofs_dir_mkdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.rmdir		= autofs_dir_rmdir,
^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) const struct dentry_operations autofs_dentry_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	.d_automount	= autofs_d_automount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	.d_manage	= autofs_d_manage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.d_release	= autofs_dentry_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static void autofs_del_active(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	list_del_init(&ino->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static int autofs_dir_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct dentry *dentry = file->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	pr_debug("file=%p dentry=%p %pd\n", file, dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (autofs_oz_mode(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * An empty directory in an autofs file system is always a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * mount point. The daemon must have failed to mount this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * during lookup so it doesn't exist. This can happen, for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 * example, if user space returns an incorrect status for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	 * mount request. Otherwise we're doing a readdir on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	 * autofs file system so just let the libfs routines handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	 * it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!path_is_mountpoint(&file->f_path) && simple_empty(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return dcache_dir_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void autofs_dentry_release(struct dentry *de)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct autofs_info *ino = autofs_dentry_ino(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct autofs_sb_info *sbi = autofs_sbi(de->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	pr_debug("releasing %p\n", de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (!ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (sbi) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		if (!list_empty(&ino->active))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			list_del(&ino->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (!list_empty(&ino->expiring))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			list_del(&ino->expiring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	autofs_free_ino(ino);
^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) static struct dentry *autofs_lookup_active(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct dentry *parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	const struct qstr *name = &dentry->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	unsigned int len = name->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	unsigned int hash = name->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	const unsigned char *str = name->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct list_head *p, *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	head = &sbi->active_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	list_for_each(p, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		struct dentry *active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		const struct qstr *qstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		ino = list_entry(p, struct autofs_info, active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		active = ino->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		spin_lock(&active->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		/* Already gone? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		if ((int) d_count(active) <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		qstr = &active->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if (active->d_name.hash != hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		if (active->d_parent != parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (qstr->len != len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		if (memcmp(qstr->name, str, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (d_unhashed(active)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			dget_dlock(active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			spin_unlock(&active->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			return active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		spin_unlock(&active->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) static struct dentry *autofs_lookup_expiring(struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 					     bool rcu_walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	struct dentry *parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	const struct qstr *name = &dentry->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned int len = name->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	unsigned int hash = name->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	const unsigned char *str = name->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	struct list_head *p, *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	head = &sbi->expiring_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	list_for_each(p, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		struct dentry *expiring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		const struct qstr *qstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		if (rcu_walk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			return ERR_PTR(-ECHILD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		ino = list_entry(p, struct autofs_info, expiring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		expiring = ino->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		spin_lock(&expiring->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		/* We've already been dentry_iput or unlinked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		if (d_really_is_negative(expiring))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		qstr = &expiring->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (expiring->d_name.hash != hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		if (expiring->d_parent != parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (qstr->len != len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		if (memcmp(qstr->name, str, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		if (d_unhashed(expiring)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			dget_dlock(expiring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			spin_unlock(&expiring->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			return expiring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		spin_unlock(&expiring->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static int autofs_mount_wait(const struct path *path, bool rcu_walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct autofs_sb_info *sbi = autofs_sbi(path->dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct autofs_info *ino = autofs_dentry_ino(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (ino->flags & AUTOFS_INF_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		if (rcu_walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			return -ECHILD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		pr_debug("waiting for mount name=%pd\n", path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		status = autofs_wait(sbi, path, NFY_MOUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		pr_debug("mount wait done status=%d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		ino->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	if (!(sbi->flags & AUTOFS_SBI_STRICTEXPIRE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		ino->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static int do_expire_wait(const struct path *path, bool rcu_walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	struct dentry *expiring;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	expiring = autofs_lookup_expiring(dentry, rcu_walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (IS_ERR(expiring))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		return PTR_ERR(expiring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (!expiring)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		return autofs_expire_wait(path, rcu_walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		const struct path this = { .mnt = path->mnt, .dentry = expiring };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		 * If we are racing with expire the request might not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		 * be quite complete, but the directory has been removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		 * so it must have been successful, just wait for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		autofs_expire_wait(&this, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		autofs_del_expiring(expiring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		dput(expiring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static struct dentry *autofs_mountpoint_changed(struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 * If this is an indirect mount the dentry could have gone away
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * as a result of an expire and a new one created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	if (autofs_type_indirect(sbi->type) && d_unhashed(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		struct dentry *parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		struct dentry *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		new = d_lookup(parent, &dentry->d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		if (!new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		ino = autofs_dentry_ino(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		ino->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		dput(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		path->dentry = new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static struct vfsmount *autofs_d_automount(struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	struct autofs_info *ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	pr_debug("dentry=%p %pd\n", dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	/* The daemon never triggers a mount. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	if (autofs_oz_mode(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	 * If an expire request is pending everyone must wait.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	 * If the expire fails we're still mounted so continue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	 * the follow and return. A return of -EAGAIN (which only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	 * happens with indirect mounts) means the expire completed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	 * and the directory was removed, so just go ahead and try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	 * the mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	status = do_expire_wait(path, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (status && status != -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/* Callback to the daemon to perform the mount or wait */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	spin_lock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	if (ino->flags & AUTOFS_INF_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		status = autofs_mount_wait(path, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 			return ERR_PTR(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * If the dentry is a symlink it's equivalent to a directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 * having path_is_mountpoint() true, so there's no need to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 * back to the daemon.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	if (d_really_is_positive(dentry) && d_is_symlink(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (!path_is_mountpoint(path)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		 * It's possible that user space hasn't removed directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		 * after umounting a rootless multi-mount, although it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		 * should. For v5 path_has_submounts() is sufficient to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		 * handle this because the leaves of the directory tree under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		 * the mount never trigger mounts themselves (they have an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		 * autofs trigger mount mounted on them). But v4 pseudo direct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		 * mounts do need the leaves to trigger mounts. In this case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		 * we have no choice but to use the list_empty() check and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		 * require user space behave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (sbi->version > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			if (path_has_submounts(path)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 				spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 			if (!simple_empty(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 				goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		ino->flags |= AUTOFS_INF_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		status = autofs_mount_wait(path, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		spin_lock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		ino->flags &= ~AUTOFS_INF_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 			spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 			return ERR_PTR(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	/* Mount succeeded, check if we ended up with a new dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	dentry = autofs_mountpoint_changed(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	if (!dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static int autofs_d_manage(const struct path *path, bool rcu_walk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	struct autofs_info *ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	pr_debug("dentry=%p %pd\n", dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	/* The daemon never waits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	if (autofs_oz_mode(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 		if (!path_is_mountpoint(path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			return -EISDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	/* Wait for pending expires */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (do_expire_wait(path, rcu_walk) == -ECHILD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		return -ECHILD;
^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) 	 * This dentry may be under construction so wait on mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	 * completion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	status = autofs_mount_wait(path, rcu_walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	if (rcu_walk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 		/* We don't need fs_lock in rcu_walk mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		 * just testing 'AUTOFS_INFO_NO_RCU' is enough.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		 * simple_empty() takes a spinlock, so leave it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		 * to last.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		 * We only return -EISDIR when certain this isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		 * a mount-trap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		if (ino->flags & AUTOFS_INF_WANT_EXPIRE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		if (path_is_mountpoint(path))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		inode = d_inode_rcu(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		if (inode && S_ISLNK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			return -EISDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		if (list_empty(&dentry->d_subdirs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		if (!simple_empty(dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 			return -EISDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	spin_lock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	 * If the dentry has been selected for expire while we slept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	 * on the lock then it might go away. We'll deal with that in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	 * ->d_automount() and wait on a new mount if the expire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	 * succeeds or return here if it doesn't (since there's no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	 * mount to follow with a rootless multi-mount).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	if (!(ino->flags & AUTOFS_INF_EXPIRING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		 * Any needed mounting has been completed and the path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		 * updated so check if this is a rootless multi-mount so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		 * we can avoid needless calls ->d_automount() and avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		 * an incorrect ELOOP error return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		if ((!path_is_mountpoint(path) && !simple_empty(dentry)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		    (d_really_is_positive(dentry) && d_is_symlink(dentry)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			status = -EISDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	spin_unlock(&sbi->fs_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /* Lookups in the root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static struct dentry *autofs_lookup(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 				    struct dentry *dentry, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	struct autofs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	struct autofs_info *ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	struct dentry *active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	pr_debug("name = %pd\n", dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	/* File name too long to exist */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (dentry->d_name.len > NAME_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	sbi = autofs_sbi(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	pr_debug("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		 current->pid, task_pgrp_nr(current),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		 sbi->flags & AUTOFS_SBI_CATATONIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		 autofs_oz_mode(sbi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	active = autofs_lookup_active(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	if (active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		return active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		 * A dentry that is not within the root can never trigger a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		 * mount operation, unless the directory already exists, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		 * can return fail immediately.  The daemon however does need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		 * to create directories within the file system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		if (!autofs_oz_mode(sbi) && !IS_ROOT(dentry->d_parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		ino = autofs_new_ino(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 		if (!ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		spin_lock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		/* Mark entries in the root as mount triggers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		if (IS_ROOT(dentry->d_parent) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		    autofs_type_indirect(sbi->type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 			__managed_dentry_set_managed(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		dentry->d_fsdata = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		ino->dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		list_add(&ino->active, &sbi->active_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		spin_unlock(&dentry->d_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static int autofs_dir_symlink(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 			       struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			       const char *symname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	struct autofs_info *ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	struct autofs_info *p_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	size_t size = strlen(symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	char *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	pr_debug("%s <- %pd\n", symname, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	if (!autofs_oz_mode(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	/* autofs_oz_mode() needs to allow path walks when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	 * autofs mount is catatonic but the state of an autofs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	 * file system needs to be preserved over restarts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	BUG_ON(!ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	autofs_clean_ino(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	autofs_del_active(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	cp = kmalloc(size + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	if (!cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	strcpy(cp, symname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	inode = autofs_get_inode(dir->i_sb, S_IFLNK | 0555);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		kfree(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	inode->i_private = cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	inode->i_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	ino->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	p_ino = autofs_dentry_ino(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	p_ino->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	dir->i_mtime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^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)  * NOTE!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)  * Normal filesystems would do a "d_delete()" to tell the VFS dcache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)  * that the file no longer exists. However, doing that means that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)  * VFS layer can turn the dentry into a negative dentry.  We don't want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)  * this, because the unlink is probably the result of an expire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)  * We simply d_drop it and add it to a expiring list in the super block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * which allows the dentry lookup to check for an incomplete expire.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  * If a process is blocked on the dentry waiting for the expire to finish,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  * it will invalidate the dentry and try to mount with a new one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)  * Also see autofs_dir_rmdir()..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	struct autofs_info *ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	struct autofs_info *p_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	if (!autofs_oz_mode(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	/* autofs_oz_mode() needs to allow path walks when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	 * autofs mount is catatonic but the state of an autofs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	 * file system needs to be preserved over restarts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	ino->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	p_ino = autofs_dentry_ino(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	p_ino->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	dput(ino->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	d_inode(dentry)->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	clear_nlink(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	dir->i_mtime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	__autofs_add_expiring(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * Version 4 of autofs provides a pseudo direct mount implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  * that relies on directories at the leaves of a directory tree under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)  * an indirect mount to trigger mounts. To allow for this we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)  * set the DMANAGED_AUTOMOUNT and DMANAGED_TRANSIT flags on the leaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635)  * of the directory tree. There is no need to clear the automount flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)  * following a mount or restore it after an expire because these mounts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)  * are always covered. However, it is necessary to ensure that these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638)  * flags are clear on non-empty directories to avoid unnecessary calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)  * during path walks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static void autofs_set_leaf_automount_flags(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	/* root and dentrys in the root are already handled */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	if (IS_ROOT(dentry->d_parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	managed_dentry_set_managed(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	/* only consider parents below dentrys in the root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	if (IS_ROOT(parent->d_parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	managed_dentry_clear_managed(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) static void autofs_clear_leaf_automount_flags(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	struct dentry *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	/* flags for dentrys in the root are handled elsewhere */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (IS_ROOT(dentry->d_parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	managed_dentry_clear_managed(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	parent = dentry->d_parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	/* only consider parents below dentrys in the root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	if (IS_ROOT(parent->d_parent))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	if (autofs_dentry_ino(parent)->count == 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		managed_dentry_set_managed(parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	struct autofs_info *ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 	struct autofs_info *p_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	pr_debug("dentry %p, removing %pd\n", dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	if (!autofs_oz_mode(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	/* autofs_oz_mode() needs to allow path walks when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	 * autofs mount is catatonic but the state of an autofs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	 * file system needs to be preserved over restarts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	if (ino->count != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 		return -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	spin_lock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	__autofs_add_expiring(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	spin_unlock(&sbi->lookup_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	if (sbi->version < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		autofs_clear_leaf_automount_flags(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 	ino->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	p_ino = autofs_dentry_ino(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	p_ino->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	dput(ino->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 	d_inode(dentry)->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	clear_nlink(d_inode(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	if (dir->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		drop_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static int autofs_dir_mkdir(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 			    struct dentry *dentry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	struct autofs_info *ino = autofs_dentry_ino(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	struct autofs_info *p_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	if (!autofs_oz_mode(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 	/* autofs_oz_mode() needs to allow path walks when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	 * autofs mount is catatonic but the state of an autofs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 	 * file system needs to be preserved over restarts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	if (sbi->flags & AUTOFS_SBI_CATATONIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 		return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 	pr_debug("dentry %p, creating %pd\n", dentry, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	BUG_ON(!ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	autofs_clean_ino(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 	autofs_del_active(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 	inode = autofs_get_inode(dir->i_sb, S_IFDIR | mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	d_add(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	if (sbi->version < 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 		autofs_set_leaf_automount_flags(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	dget(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	ino->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	p_ino = autofs_dentry_ino(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	p_ino->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	inc_nlink(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 	dir->i_mtime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) /* Get/set timeout ioctl() operation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) static inline int autofs_compat_get_set_timeout(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 						 compat_ulong_t __user *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	unsigned long ntimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	rv = get_user(ntimeout, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 	rv = put_user(sbi->exp_timeout/HZ, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	if (ntimeout > UINT_MAX/HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 		sbi->exp_timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) 		sbi->exp_timeout = ntimeout * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) static inline int autofs_get_set_timeout(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 					  unsigned long __user *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 	unsigned long ntimeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 	rv = get_user(ntimeout, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	rv = put_user(sbi->exp_timeout/HZ, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 		goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 	if (ntimeout > ULONG_MAX/HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 		sbi->exp_timeout = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 		sbi->exp_timeout = ntimeout * HZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) 	return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) /* Return protocol version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) static inline int autofs_get_protover(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 				       int __user *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 	return put_user(sbi->version, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* Return protocol sub version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) static inline int autofs_get_protosubver(struct autofs_sb_info *sbi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 					  int __user *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 	return put_user(sbi->sub_version, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) * Tells the daemon whether it can umount the autofs mount.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) static inline int autofs_ask_umount(struct vfsmount *mnt, int __user *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	if (may_umount(mnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 		status = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 	pr_debug("may umount %d\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 	status = put_user(status, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) /* Identify autofs_dentries - this is so we can tell if there's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)  * an extra dentry refcount or not.  We only hold a refcount on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)  * dentry if its non-negative (ie, d_inode != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) int is_autofs_dentry(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) 	return dentry && d_really_is_positive(dentry) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 		dentry->d_op == &autofs_dentry_operations &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) 		dentry->d_fsdata != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)  * ioctl()'s on the root directory is the chief method for the daemon to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)  * generate kernel reactions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) static int autofs_root_ioctl_unlocked(struct inode *inode, struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 				       unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) 	struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	void __user *p = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 	pr_debug("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) 		 cmd, arg, sbi, task_pgrp_nr(current));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) 	     _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) 	if (!autofs_oz_mode(sbi) && !capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) 	case AUTOFS_IOC_READY:	/* Wait queue: go ahead and retry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) 		return autofs_wait_release(sbi, (autofs_wqt_t) arg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) 	case AUTOFS_IOC_FAIL:	/* Wait queue: fail with ENOENT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) 		return autofs_wait_release(sbi, (autofs_wqt_t) arg, -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) 	case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) 		autofs_catatonic_mode(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) 	case AUTOFS_IOC_PROTOVER: /* Get protocol version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) 		return autofs_get_protover(sbi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) 	case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) 		return autofs_get_protosubver(sbi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) 	case AUTOFS_IOC_SETTIMEOUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) 		return autofs_get_set_timeout(sbi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) 	case AUTOFS_IOC_SETTIMEOUT32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) 		return autofs_compat_get_set_timeout(sbi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) 	case AUTOFS_IOC_ASKUMOUNT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) 		return autofs_ask_umount(filp->f_path.mnt, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) 	/* return a single thing to expire */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) 	case AUTOFS_IOC_EXPIRE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) 		return autofs_expire_run(inode->i_sb, filp->f_path.mnt, sbi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) 	/* same as above, but can send multiple expires through pipe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) 	case AUTOFS_IOC_EXPIRE_MULTI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) 		return autofs_expire_multi(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) 					   filp->f_path.mnt, sbi, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) static long autofs_root_ioctl(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) 			       unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) 	struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) 	return autofs_root_ioctl_unlocked(inode, filp, cmd, arg);
^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) #ifdef CONFIG_COMPAT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) static long autofs_root_compat_ioctl(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) 				      unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) 	struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) 	if (cmd == AUTOFS_IOC_READY || cmd == AUTOFS_IOC_FAIL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) 		ret = autofs_root_ioctl_unlocked(inode, filp, cmd, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) 		ret = autofs_root_ioctl_unlocked(inode, filp, cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) 					      (unsigned long) compat_ptr(arg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) #endif