| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- c -*- --------------------------------------------------------------- * | 
 | 2 |  * | 
 | 3 |  * linux/fs/autofs/root.c | 
 | 4 |  * | 
 | 5 |  *  Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved | 
 | 6 |  *  Copyright 1999-2000 Jeremy Fitzhardinge <jeremy@goop.org> | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 7 |  *  Copyright 2001-2006 Ian Kent <raven@themaw.net> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 |  * | 
 | 9 |  * This file is part of the Linux kernel and is made available under | 
 | 10 |  * the terms of the GNU General Public License, version 2, or at your | 
 | 11 |  * option, any later version, incorporated herein by reference. | 
 | 12 |  * | 
 | 13 |  * ------------------------------------------------------------------------- */ | 
 | 14 |  | 
| Randy Dunlap | 16f7e0f | 2006-01-11 12:17:46 -0800 | [diff] [blame] | 15 | #include <linux/capability.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/errno.h> | 
 | 17 | #include <linux/stat.h> | 
 | 18 | #include <linux/param.h> | 
 | 19 | #include <linux/time.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "autofs_i.h" | 
 | 21 |  | 
 | 22 | static int autofs4_dir_symlink(struct inode *,struct dentry *,const char *); | 
 | 23 | static int autofs4_dir_unlink(struct inode *,struct dentry *); | 
 | 24 | static int autofs4_dir_rmdir(struct inode *,struct dentry *); | 
 | 25 | static int autofs4_dir_mkdir(struct inode *,struct dentry *,int); | 
 | 26 | static int autofs4_root_ioctl(struct inode *, struct file *,unsigned int,unsigned long); | 
 | 27 | static int autofs4_dir_open(struct inode *inode, struct file *file); | 
 | 28 | static int autofs4_dir_close(struct inode *inode, struct file *file); | 
 | 29 | static int autofs4_dir_readdir(struct file * filp, void * dirent, filldir_t filldir); | 
 | 30 | static int autofs4_root_readdir(struct file * filp, void * dirent, filldir_t filldir); | 
 | 31 | static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 32 | static void *autofs4_follow_link(struct dentry *, struct nameidata *); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 |  | 
| Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 34 | const struct file_operations autofs4_root_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | 	.open		= dcache_dir_open, | 
 | 36 | 	.release	= dcache_dir_close, | 
 | 37 | 	.read		= generic_read_dir, | 
 | 38 | 	.readdir	= autofs4_root_readdir, | 
 | 39 | 	.ioctl		= autofs4_root_ioctl, | 
 | 40 | }; | 
 | 41 |  | 
| Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 42 | const struct file_operations autofs4_dir_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | 	.open		= autofs4_dir_open, | 
 | 44 | 	.release	= autofs4_dir_close, | 
 | 45 | 	.read		= generic_read_dir, | 
 | 46 | 	.readdir	= autofs4_dir_readdir, | 
 | 47 | }; | 
 | 48 |  | 
| Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 49 | const struct inode_operations autofs4_indirect_root_inode_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | 	.lookup		= autofs4_lookup, | 
 | 51 | 	.unlink		= autofs4_dir_unlink, | 
 | 52 | 	.symlink	= autofs4_dir_symlink, | 
 | 53 | 	.mkdir		= autofs4_dir_mkdir, | 
 | 54 | 	.rmdir		= autofs4_dir_rmdir, | 
 | 55 | }; | 
 | 56 |  | 
| Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 57 | const struct inode_operations autofs4_direct_root_inode_operations = { | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 58 | 	.lookup		= autofs4_lookup, | 
| Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 59 | 	.unlink		= autofs4_dir_unlink, | 
 | 60 | 	.mkdir		= autofs4_dir_mkdir, | 
 | 61 | 	.rmdir		= autofs4_dir_rmdir, | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 62 | 	.follow_link	= autofs4_follow_link, | 
 | 63 | }; | 
 | 64 |  | 
| Arjan van de Ven | 754661f | 2007-02-12 00:55:38 -0800 | [diff] [blame] | 65 | const struct inode_operations autofs4_dir_inode_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | 	.lookup		= autofs4_lookup, | 
 | 67 | 	.unlink		= autofs4_dir_unlink, | 
 | 68 | 	.symlink	= autofs4_dir_symlink, | 
 | 69 | 	.mkdir		= autofs4_dir_mkdir, | 
 | 70 | 	.rmdir		= autofs4_dir_rmdir, | 
 | 71 | }; | 
 | 72 |  | 
 | 73 | static int autofs4_root_readdir(struct file *file, void *dirent, | 
 | 74 | 				filldir_t filldir) | 
 | 75 | { | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 76 | 	struct autofs_sb_info *sbi = autofs4_sbi(file->f_path.dentry->d_sb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | 	int oz_mode = autofs4_oz_mode(sbi); | 
 | 78 |  | 
 | 79 | 	DPRINTK("called, filp->f_pos = %lld", file->f_pos); | 
 | 80 |  | 
 | 81 | 	/* | 
 | 82 | 	 * Don't set reghost flag if: | 
 | 83 | 	 * 1) f_pos is larger than zero -- we've already been here. | 
 | 84 | 	 * 2) we haven't even enabled reghosting in the 1st place. | 
 | 85 | 	 * 3) this is the daemon doing a readdir | 
 | 86 | 	 */ | 
 | 87 | 	if (oz_mode && file->f_pos == 0 && sbi->reghost_enabled) | 
 | 88 | 		sbi->needs_reghost = 1; | 
 | 89 |  | 
 | 90 | 	DPRINTK("needs_reghost = %d", sbi->needs_reghost); | 
 | 91 |  | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 92 | 	return dcache_readdir(file, dirent, filldir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | } | 
 | 94 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static int autofs4_dir_open(struct inode *inode, struct file *file) | 
 | 96 | { | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 97 | 	struct dentry *dentry = file->f_path.dentry; | 
 | 98 | 	struct vfsmount *mnt = file->f_path.mnt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | 	struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 100 | 	struct dentry *cursor; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | 	int status; | 
 | 102 |  | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 103 | 	status = dcache_dir_open(inode, file); | 
 | 104 | 	if (status) | 
 | 105 | 		goto out; | 
 | 106 |  | 
 | 107 | 	cursor = file->private_data; | 
 | 108 | 	cursor->d_fsdata = NULL; | 
 | 109 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | 	DPRINTK("file=%p dentry=%p %.*s", | 
 | 111 | 		file, dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 112 |  | 
 | 113 | 	if (autofs4_oz_mode(sbi)) | 
 | 114 | 		goto out; | 
 | 115 |  | 
 | 116 | 	if (autofs4_ispending(dentry)) { | 
 | 117 | 		DPRINTK("dentry busy"); | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 118 | 		dcache_dir_close(inode, file); | 
 | 119 | 		status = -EBUSY; | 
 | 120 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | 	} | 
 | 122 |  | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 123 | 	status = -ENOENT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | 	if (!d_mountpoint(dentry) && dentry->d_op && dentry->d_op->d_revalidate) { | 
 | 125 | 		struct nameidata nd; | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 126 | 		int empty, ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 |  | 
 | 128 | 		/* In case there are stale directory dentrys from a failed mount */ | 
 | 129 | 		spin_lock(&dcache_lock); | 
 | 130 | 		empty = list_empty(&dentry->d_subdirs); | 
 | 131 | 		spin_unlock(&dcache_lock); | 
 | 132 |  | 
 | 133 | 		if (!empty) | 
 | 134 | 			d_invalidate(dentry); | 
 | 135 |  | 
 | 136 | 		nd.flags = LOOKUP_DIRECTORY; | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 137 | 		ret = (dentry->d_op->d_revalidate)(dentry, &nd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
| Ian Kent | bcdc5e0 | 2006-09-27 01:50:44 -0700 | [diff] [blame] | 139 | 		if (ret <= 0) { | 
 | 140 | 			if (ret < 0) | 
 | 141 | 				status = ret; | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 142 | 			dcache_dir_close(inode, file); | 
 | 143 | 			goto out; | 
 | 144 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | 	} | 
 | 146 |  | 
 | 147 | 	if (d_mountpoint(dentry)) { | 
 | 148 | 		struct file *fp = NULL; | 
 | 149 | 		struct vfsmount *fp_mnt = mntget(mnt); | 
 | 150 | 		struct dentry *fp_dentry = dget(dentry); | 
 | 151 |  | 
| Ian Kent | 9b1e3af | 2005-06-21 17:16:38 -0700 | [diff] [blame] | 152 | 		if (!autofs4_follow_mount(&fp_mnt, &fp_dentry)) { | 
 | 153 | 			dput(fp_dentry); | 
 | 154 | 			mntput(fp_mnt); | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 155 | 			dcache_dir_close(inode, file); | 
 | 156 | 			goto out; | 
| Ian Kent | 9b1e3af | 2005-06-21 17:16:38 -0700 | [diff] [blame] | 157 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 |  | 
 | 159 | 		fp = dentry_open(fp_dentry, fp_mnt, file->f_flags); | 
 | 160 | 		status = PTR_ERR(fp); | 
 | 161 | 		if (IS_ERR(fp)) { | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 162 | 			dcache_dir_close(inode, file); | 
 | 163 | 			goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | 		} | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 165 | 		cursor->d_fsdata = fp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | 	return 0; | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 168 | out: | 
 | 169 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } | 
 | 171 |  | 
 | 172 | static int autofs4_dir_close(struct inode *inode, struct file *file) | 
 | 173 | { | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 174 | 	struct dentry *dentry = file->f_path.dentry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | 	struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 176 | 	struct dentry *cursor = file->private_data; | 
 | 177 | 	int status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 |  | 
 | 179 | 	DPRINTK("file=%p dentry=%p %.*s", | 
 | 180 | 		file, dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 181 |  | 
 | 182 | 	if (autofs4_oz_mode(sbi)) | 
 | 183 | 		goto out; | 
 | 184 |  | 
 | 185 | 	if (autofs4_ispending(dentry)) { | 
 | 186 | 		DPRINTK("dentry busy"); | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 187 | 		status = -EBUSY; | 
 | 188 | 		goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | 	} | 
 | 190 |  | 
 | 191 | 	if (d_mountpoint(dentry)) { | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 192 | 		struct file *fp = cursor->d_fsdata; | 
 | 193 | 		if (!fp) { | 
 | 194 | 			status = -ENOENT; | 
 | 195 | 			goto out; | 
 | 196 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | 		filp_close(fp, current->files); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | 	} | 
 | 199 | out: | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 200 | 	dcache_dir_close(inode, file); | 
 | 201 | 	return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } | 
 | 203 |  | 
 | 204 | static int autofs4_dir_readdir(struct file *file, void *dirent, filldir_t filldir) | 
 | 205 | { | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 206 | 	struct dentry *dentry = file->f_path.dentry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | 	struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 208 | 	struct dentry *cursor = file->private_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | 	int status; | 
 | 210 |  | 
 | 211 | 	DPRINTK("file=%p dentry=%p %.*s", | 
 | 212 | 		file, dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 213 |  | 
 | 214 | 	if (autofs4_oz_mode(sbi)) | 
 | 215 | 		goto out; | 
 | 216 |  | 
 | 217 | 	if (autofs4_ispending(dentry)) { | 
 | 218 | 		DPRINTK("dentry busy"); | 
 | 219 | 		return -EBUSY; | 
 | 220 | 	} | 
 | 221 |  | 
 | 222 | 	if (d_mountpoint(dentry)) { | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 223 | 		struct file *fp = cursor->d_fsdata; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 |  | 
 | 225 | 		if (!fp) | 
 | 226 | 			return -ENOENT; | 
 | 227 |  | 
 | 228 | 		if (!fp->f_op || !fp->f_op->readdir) | 
 | 229 | 			goto out; | 
 | 230 |  | 
 | 231 | 		status = vfs_readdir(fp, filldir, dirent); | 
 | 232 | 		file->f_pos = fp->f_pos; | 
 | 233 | 		if (status) | 
 | 234 | 			autofs4_copy_atime(file, fp); | 
 | 235 | 		return status; | 
 | 236 | 	} | 
 | 237 | out: | 
| Ian Kent | f360ce3 | 2006-03-27 01:14:43 -0800 | [diff] [blame] | 238 | 	return dcache_readdir(file, dirent, filldir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } | 
 | 240 |  | 
| Ian Kent | 862b110 | 2006-03-27 01:14:48 -0800 | [diff] [blame] | 241 | static int try_to_fill_dentry(struct dentry *dentry, int flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { | 
| Ian Kent | 862b110 | 2006-03-27 01:14:48 -0800 | [diff] [blame] | 243 | 	struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 244 | 	struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | 	int status = 0; | 
 | 246 |  | 
 | 247 | 	/* Block on any pending expiry here; invalidate the dentry | 
 | 248 |            when expiration is done to trigger mount request with a new | 
 | 249 |            dentry */ | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 250 | 	if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | 		DPRINTK("waiting for expire %p name=%.*s", | 
 | 252 | 			 dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 253 |  | 
 | 254 | 		status = autofs4_wait(sbi, dentry, NFY_NONE); | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 255 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | 		DPRINTK("expire done status=%d", status); | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 257 |  | 
| Ian Kent | 1684b2b | 2005-06-21 17:16:41 -0700 | [diff] [blame] | 258 | 		/* | 
 | 259 | 		 * If the directory still exists the mount request must | 
 | 260 | 		 * continue otherwise it can't be followed at the right | 
 | 261 | 		 * time during the walk. | 
 | 262 | 		 */ | 
 | 263 | 		status = d_invalidate(dentry); | 
 | 264 | 		if (status != -EBUSY) | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 265 | 			return -EAGAIN; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 	} | 
 | 267 |  | 
 | 268 | 	DPRINTK("dentry=%p %.*s ino=%p", | 
 | 269 | 		 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode); | 
 | 270 |  | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 271 | 	/* | 
 | 272 | 	 * Wait for a pending mount, triggering one if there | 
 | 273 | 	 * isn't one already | 
 | 274 | 	 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | 	if (dentry->d_inode == NULL) { | 
 | 276 | 		DPRINTK("waiting for mount name=%.*s", | 
 | 277 | 			 dentry->d_name.len, dentry->d_name.name); | 
 | 278 |  | 
 | 279 | 		status = autofs4_wait(sbi, dentry, NFY_MOUNT); | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 280 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | 		DPRINTK("mount done status=%d", status); | 
 | 282 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | 		/* Turn this into a real negative dentry? */ | 
 | 284 | 		if (status == -ENOENT) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | 			spin_lock(&dentry->d_lock); | 
 | 286 | 			dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 
 | 287 | 			spin_unlock(&dentry->d_lock); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 288 | 			return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | 		} else if (status) { | 
 | 290 | 			/* Return a negative dentry, but leave it "pending" */ | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 291 | 			return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | 		} | 
 | 293 | 	/* Trigger mount for path component or follow link */ | 
 | 294 | 	} else if (flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY) || | 
 | 295 | 			current->link_count) { | 
 | 296 | 		DPRINTK("waiting for mount name=%.*s", | 
 | 297 | 			dentry->d_name.len, dentry->d_name.name); | 
 | 298 |  | 
 | 299 | 		spin_lock(&dentry->d_lock); | 
 | 300 | 		dentry->d_flags |= DCACHE_AUTOFS_PENDING; | 
 | 301 | 		spin_unlock(&dentry->d_lock); | 
 | 302 | 		status = autofs4_wait(sbi, dentry, NFY_MOUNT); | 
 | 303 |  | 
 | 304 | 		DPRINTK("mount done status=%d", status); | 
 | 305 |  | 
 | 306 | 		if (status) { | 
 | 307 | 			spin_lock(&dentry->d_lock); | 
 | 308 | 			dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 
 | 309 | 			spin_unlock(&dentry->d_lock); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 310 | 			return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | 		} | 
 | 312 | 	} | 
 | 313 |  | 
| Ian Kent | e0a7aae | 2006-03-27 01:14:47 -0800 | [diff] [blame] | 314 | 	/* Initialize expiry counter after successful mount */ | 
 | 315 | 	if (ino) | 
 | 316 | 		ino->last_used = jiffies; | 
 | 317 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | 	spin_lock(&dentry->d_lock); | 
 | 319 | 	dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 
 | 320 | 	spin_unlock(&dentry->d_lock); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 321 | 	return status; | 
 | 322 | } | 
 | 323 |  | 
 | 324 | /* For autofs direct mounts the follow link triggers the mount */ | 
 | 325 | static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd) | 
 | 326 | { | 
 | 327 | 	struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb); | 
| Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 328 | 	struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 329 | 	int oz_mode = autofs4_oz_mode(sbi); | 
 | 330 | 	unsigned int lookup_type; | 
 | 331 | 	int status; | 
 | 332 |  | 
 | 333 | 	DPRINTK("dentry=%p %.*s oz_mode=%d nd->flags=%d", | 
 | 334 | 		dentry, dentry->d_name.len, dentry->d_name.name, oz_mode, | 
 | 335 | 		nd->flags); | 
 | 336 |  | 
 | 337 | 	/* If it's our master or we shouldn't trigger a mount we're done */ | 
 | 338 | 	lookup_type = nd->flags & (LOOKUP_CONTINUE | LOOKUP_DIRECTORY); | 
 | 339 | 	if (oz_mode || !lookup_type) | 
 | 340 | 		goto done; | 
 | 341 |  | 
| Ian Kent | a537055 | 2006-05-15 09:43:51 -0700 | [diff] [blame] | 342 | 	/* If an expire request is pending wait for it. */ | 
 | 343 | 	if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { | 
| Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 344 | 		DPRINTK("waiting for active request %p name=%.*s", | 
 | 345 | 			dentry, dentry->d_name.len, dentry->d_name.name); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 346 |  | 
| Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 347 | 		status = autofs4_wait(sbi, dentry, NFY_NONE); | 
 | 348 |  | 
 | 349 | 		DPRINTK("request done status=%d", status); | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 350 | 	} | 
 | 351 |  | 
| Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 352 | 	/* | 
 | 353 | 	 * If the dentry contains directories then it is an | 
 | 354 | 	 * autofs multi-mount with no root mount offset. So | 
 | 355 | 	 * don't try to mount it again. | 
 | 356 | 	 */ | 
 | 357 | 	spin_lock(&dcache_lock); | 
| Ian Kent | be3ca7f | 2006-09-29 02:00:53 -0700 | [diff] [blame] | 358 | 	if (!d_mountpoint(dentry) && __simple_empty(dentry)) { | 
| Ian Kent | 871f943 | 2006-03-27 01:14:58 -0800 | [diff] [blame] | 359 | 		spin_unlock(&dcache_lock); | 
 | 360 |  | 
 | 361 | 		status = try_to_fill_dentry(dentry, 0); | 
 | 362 | 		if (status) | 
 | 363 | 			goto out_error; | 
 | 364 |  | 
 | 365 | 		/* | 
 | 366 | 		 * The mount succeeded but if there is no root mount | 
 | 367 | 		 * it must be an autofs multi-mount with no root offset | 
 | 368 | 		 * so we don't need to follow the mount. | 
 | 369 | 		 */ | 
 | 370 | 		if (d_mountpoint(dentry)) { | 
 | 371 | 			if (!autofs4_follow_mount(&nd->mnt, &nd->dentry)) { | 
 | 372 | 				status = -ENOENT; | 
 | 373 | 				goto out_error; | 
 | 374 | 			} | 
 | 375 | 		} | 
 | 376 |  | 
 | 377 | 		goto done; | 
 | 378 | 	} | 
 | 379 | 	spin_unlock(&dcache_lock); | 
 | 380 |  | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 381 | done: | 
 | 382 | 	return NULL; | 
 | 383 |  | 
 | 384 | out_error: | 
 | 385 | 	path_release(nd); | 
 | 386 | 	return ERR_PTR(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } | 
 | 388 |  | 
 | 389 | /* | 
 | 390 |  * Revalidate is called on every cache lookup.  Some of those | 
 | 391 |  * cache lookups may actually happen while the dentry is not | 
 | 392 |  * yet completely filled in, and revalidate has to delay such | 
 | 393 |  * lookups.. | 
 | 394 |  */ | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 395 | static int autofs4_revalidate(struct dentry *dentry, struct nameidata *nd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | { | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 397 | 	struct inode *dir = dentry->d_parent->d_inode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | 	struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 
 | 399 | 	int oz_mode = autofs4_oz_mode(sbi); | 
 | 400 | 	int flags = nd ? nd->flags : 0; | 
| Ian Kent | bcdc5e0 | 2006-09-27 01:50:44 -0700 | [diff] [blame] | 401 | 	int status = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 |  | 
 | 403 | 	/* Pending dentry */ | 
 | 404 | 	if (autofs4_ispending(dentry)) { | 
| Ian Kent | bcdc5e0 | 2006-09-27 01:50:44 -0700 | [diff] [blame] | 405 | 		/* The daemon never causes a mount to trigger */ | 
 | 406 | 		if (oz_mode) | 
 | 407 | 			return 1; | 
 | 408 |  | 
 | 409 | 		/* | 
 | 410 | 		 * A zero status is success otherwise we have a | 
 | 411 | 		 * negative error code. | 
 | 412 | 		 */ | 
 | 413 | 		status = try_to_fill_dentry(dentry, flags); | 
 | 414 | 		if (status == 0) | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 415 | 			return 1; | 
 | 416 |  | 
 | 417 | 		/* | 
 | 418 | 		 * A status of EAGAIN here means that the dentry has gone | 
 | 419 | 		 * away while waiting for an expire to complete. If we are | 
 | 420 | 		 * racing with expire lookup will wait for it so this must | 
 | 421 | 		 * be a revalidate and we need to send it to lookup. | 
 | 422 | 		 */ | 
 | 423 | 		if (status == -EAGAIN) | 
 | 424 | 			return 0; | 
| Ian Kent | bcdc5e0 | 2006-09-27 01:50:44 -0700 | [diff] [blame] | 425 |  | 
 | 426 | 		return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | 	} | 
 | 428 |  | 
 | 429 | 	/* Negative dentry.. invalidate if "old" */ | 
 | 430 | 	if (dentry->d_inode == NULL) | 
| Ian Kent | 2d753e6 | 2006-03-27 01:14:44 -0800 | [diff] [blame] | 431 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 |  | 
 | 433 | 	/* Check for a non-mountpoint directory with no contents */ | 
 | 434 | 	spin_lock(&dcache_lock); | 
 | 435 | 	if (S_ISDIR(dentry->d_inode->i_mode) && | 
 | 436 | 	    !d_mountpoint(dentry) &&  | 
| Ian Kent | 90a59c7 | 2006-03-27 01:14:50 -0800 | [diff] [blame] | 437 | 	    __simple_empty(dentry)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | 		DPRINTK("dentry=%p %.*s, emptydir", | 
 | 439 | 			 dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 440 | 		spin_unlock(&dcache_lock); | 
| Ian Kent | bcdc5e0 | 2006-09-27 01:50:44 -0700 | [diff] [blame] | 441 | 		/* The daemon never causes a mount to trigger */ | 
 | 442 | 		if (oz_mode) | 
 | 443 | 			return 1; | 
 | 444 |  | 
 | 445 | 		/* | 
 | 446 | 		 * A zero status is success otherwise we have a | 
 | 447 | 		 * negative error code. | 
 | 448 | 		 */ | 
 | 449 | 		status = try_to_fill_dentry(dentry, flags); | 
 | 450 | 		if (status == 0) | 
 | 451 | 			return 1; | 
 | 452 |  | 
 | 453 | 		return status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | 	} | 
 | 455 | 	spin_unlock(&dcache_lock); | 
 | 456 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | 	return 1; | 
 | 458 | } | 
 | 459 |  | 
| Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 460 | void autofs4_dentry_release(struct dentry *de) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { | 
 | 462 | 	struct autofs_info *inf; | 
 | 463 |  | 
 | 464 | 	DPRINTK("releasing %p", de); | 
 | 465 |  | 
 | 466 | 	inf = autofs4_dentry_ino(de); | 
 | 467 | 	de->d_fsdata = NULL; | 
 | 468 |  | 
 | 469 | 	if (inf) { | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 470 | 		struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb); | 
 | 471 |  | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 472 | 		if (sbi) { | 
 | 473 | 			spin_lock(&sbi->rehash_lock); | 
 | 474 | 			if (!list_empty(&inf->rehash)) | 
 | 475 | 				list_del(&inf->rehash); | 
 | 476 | 			spin_unlock(&sbi->rehash_lock); | 
 | 477 | 		} | 
 | 478 |  | 
| Jeff Mahoney | c3724b1 | 2007-04-11 23:28:46 -0700 | [diff] [blame] | 479 | 		inf->dentry = NULL; | 
 | 480 | 		inf->inode = NULL; | 
 | 481 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | 		autofs4_free_ino(inf); | 
 | 483 | 	} | 
 | 484 | } | 
 | 485 |  | 
 | 486 | /* For dentries of directories in the root dir */ | 
 | 487 | static struct dentry_operations autofs4_root_dentry_operations = { | 
 | 488 | 	.d_revalidate	= autofs4_revalidate, | 
 | 489 | 	.d_release	= autofs4_dentry_release, | 
 | 490 | }; | 
 | 491 |  | 
 | 492 | /* For other dentries */ | 
 | 493 | static struct dentry_operations autofs4_dentry_operations = { | 
 | 494 | 	.d_revalidate	= autofs4_revalidate, | 
 | 495 | 	.d_release	= autofs4_dentry_release, | 
 | 496 | }; | 
 | 497 |  | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 498 | static struct dentry *autofs4_lookup_unhashed(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name) | 
 | 499 | { | 
 | 500 | 	unsigned int len = name->len; | 
 | 501 | 	unsigned int hash = name->hash; | 
 | 502 | 	const unsigned char *str = name->name; | 
 | 503 | 	struct list_head *p, *head; | 
 | 504 |  | 
 | 505 | 	spin_lock(&dcache_lock); | 
 | 506 | 	spin_lock(&sbi->rehash_lock); | 
 | 507 | 	head = &sbi->rehash_list; | 
 | 508 | 	list_for_each(p, head) { | 
 | 509 | 		struct autofs_info *ino; | 
 | 510 | 		struct dentry *dentry; | 
 | 511 | 		struct qstr *qstr; | 
 | 512 |  | 
 | 513 | 		ino = list_entry(p, struct autofs_info, rehash); | 
 | 514 | 		dentry = ino->dentry; | 
 | 515 |  | 
 | 516 | 		spin_lock(&dentry->d_lock); | 
 | 517 |  | 
 | 518 | 		/* Bad luck, we've already been dentry_iput */ | 
 | 519 | 		if (!dentry->d_inode) | 
 | 520 | 			goto next; | 
 | 521 |  | 
 | 522 | 		qstr = &dentry->d_name; | 
 | 523 |  | 
 | 524 | 		if (dentry->d_name.hash != hash) | 
 | 525 | 			goto next; | 
 | 526 | 		if (dentry->d_parent != parent) | 
 | 527 | 			goto next; | 
 | 528 |  | 
 | 529 | 		if (qstr->len != len) | 
 | 530 | 			goto next; | 
 | 531 | 		if (memcmp(qstr->name, str, len)) | 
 | 532 | 			goto next; | 
 | 533 |  | 
 | 534 | 		if (d_unhashed(dentry)) { | 
 | 535 | 			struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
 | 536 | 			struct inode *inode = dentry->d_inode; | 
 | 537 |  | 
 | 538 | 			list_del_init(&ino->rehash); | 
 | 539 | 			dget(dentry); | 
 | 540 | 			/* | 
 | 541 | 			 * Make the rehashed dentry negative so the VFS | 
 | 542 | 			 * behaves as it should. | 
 | 543 | 			 */ | 
 | 544 | 			if (inode) { | 
 | 545 | 				dentry->d_inode = NULL; | 
 | 546 | 				list_del_init(&dentry->d_alias); | 
 | 547 | 				spin_unlock(&dentry->d_lock); | 
 | 548 | 				spin_unlock(&sbi->rehash_lock); | 
 | 549 | 				spin_unlock(&dcache_lock); | 
 | 550 | 				iput(inode); | 
 | 551 | 				return dentry; | 
 | 552 | 			} | 
 | 553 | 			spin_unlock(&dentry->d_lock); | 
 | 554 | 			spin_unlock(&sbi->rehash_lock); | 
 | 555 | 			spin_unlock(&dcache_lock); | 
 | 556 | 			return dentry; | 
 | 557 | 		} | 
 | 558 | next: | 
 | 559 | 		spin_unlock(&dentry->d_lock); | 
 | 560 | 	} | 
 | 561 | 	spin_unlock(&sbi->rehash_lock); | 
 | 562 | 	spin_unlock(&dcache_lock); | 
 | 563 |  | 
 | 564 | 	return NULL; | 
 | 565 | } | 
 | 566 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | /* Lookups in the root directory */ | 
 | 568 | static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) | 
 | 569 | { | 
 | 570 | 	struct autofs_sb_info *sbi; | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 571 | 	struct dentry *unhashed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | 	int oz_mode; | 
 | 573 |  | 
 | 574 | 	DPRINTK("name = %.*s", | 
 | 575 | 		dentry->d_name.len, dentry->d_name.name); | 
 | 576 |  | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 577 | 	/* File name too long to exist */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | 	if (dentry->d_name.len > NAME_MAX) | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 579 | 		return ERR_PTR(-ENAMETOOLONG); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 |  | 
 | 581 | 	sbi = autofs4_sbi(dir->i_sb); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | 	oz_mode = autofs4_oz_mode(sbi); | 
| Ian Kent | 718c604 | 2006-03-27 01:14:42 -0800 | [diff] [blame] | 583 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | 	DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d", | 
 | 585 | 		 current->pid, process_group(current), sbi->catatonic, oz_mode); | 
 | 586 |  | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 587 | 	unhashed = autofs4_lookup_unhashed(sbi, dentry->d_parent, &dentry->d_name); | 
 | 588 | 	if (!unhashed) { | 
 | 589 | 		/* | 
 | 590 | 		 * Mark the dentry incomplete, but add it. This is needed so | 
 | 591 | 		 * that the VFS layer knows about the dentry, and we can count | 
 | 592 | 		 * on catching any lookups through the revalidate. | 
 | 593 | 		 * | 
 | 594 | 		 * Let all the hard work be done by the revalidate function that | 
 | 595 | 		 * needs to be able to do this anyway.. | 
 | 596 | 		 * | 
 | 597 | 		 * We need to do this before we release the directory semaphore. | 
 | 598 | 		 */ | 
 | 599 | 		dentry->d_op = &autofs4_root_dentry_operations; | 
 | 600 |  | 
 | 601 | 		dentry->d_fsdata = NULL; | 
 | 602 | 		d_add(dentry, NULL); | 
 | 603 | 	} else { | 
 | 604 | 		struct autofs_info *ino = autofs4_dentry_ino(unhashed); | 
 | 605 | 		DPRINTK("rehash %p with %p", dentry, unhashed); | 
 | 606 | 		/* | 
 | 607 | 		 * If we are racing with expire the request might not | 
 | 608 | 		 * be quite complete but the directory has been removed | 
 | 609 | 		 * so it must have been successful, so just wait for it. | 
 | 610 | 		 */ | 
 | 611 | 		if (ino && (ino->flags & AUTOFS_INF_EXPIRING)) { | 
 | 612 | 			DPRINTK("wait for incomplete expire %p name=%.*s", | 
 | 613 | 				unhashed, unhashed->d_name.len, | 
 | 614 | 				unhashed->d_name.name); | 
 | 615 | 			autofs4_wait(sbi, unhashed, NFY_NONE); | 
 | 616 | 			DPRINTK("request completed"); | 
 | 617 | 		} | 
 | 618 | 		d_rehash(unhashed); | 
 | 619 | 		dentry = unhashed; | 
 | 620 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 |  | 
 | 622 | 	if (!oz_mode) { | 
 | 623 | 		spin_lock(&dentry->d_lock); | 
 | 624 | 		dentry->d_flags |= DCACHE_AUTOFS_PENDING; | 
 | 625 | 		spin_unlock(&dentry->d_lock); | 
 | 626 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 |  | 
 | 628 | 	if (dentry->d_op && dentry->d_op->d_revalidate) { | 
| Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 629 | 		mutex_unlock(&dir->i_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | 		(dentry->d_op->d_revalidate)(dentry, nd); | 
| Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 631 | 		mutex_lock(&dir->i_mutex); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | 	} | 
 | 633 |  | 
 | 634 | 	/* | 
 | 635 | 	 * If we are still pending, check if we had to handle | 
 | 636 | 	 * a signal. If so we can force a restart.. | 
 | 637 | 	 */ | 
 | 638 | 	if (dentry->d_flags & DCACHE_AUTOFS_PENDING) { | 
 | 639 | 		/* See if we were interrupted */ | 
 | 640 | 		if (signal_pending(current)) { | 
 | 641 | 			sigset_t *sigset = ¤t->pending.signal; | 
 | 642 | 			if (sigismember (sigset, SIGKILL) || | 
 | 643 | 			    sigismember (sigset, SIGQUIT) || | 
 | 644 | 			    sigismember (sigset, SIGINT)) { | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 645 | 			    if (unhashed) | 
 | 646 | 				dput(unhashed); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | 			    return ERR_PTR(-ERESTARTNOINTR); | 
 | 648 | 			} | 
 | 649 | 		} | 
| Ian Kent | 44938af | 2006-09-29 02:00:54 -0700 | [diff] [blame] | 650 | 		spin_lock(&dentry->d_lock); | 
 | 651 | 		dentry->d_flags &= ~DCACHE_AUTOFS_PENDING; | 
 | 652 | 		spin_unlock(&dentry->d_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | 	} | 
 | 654 |  | 
 | 655 | 	/* | 
 | 656 | 	 * If this dentry is unhashed, then we shouldn't honour this | 
| Ian Kent | c9ffec4 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 657 | 	 * lookup.  Returning ENOENT here doesn't do the right thing | 
 | 658 | 	 * for all system calls, but it should be OK for the operations | 
 | 659 | 	 * we permit from an autofs. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | 	 */ | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 661 | 	if (dentry->d_inode && d_unhashed(dentry)) { | 
| Ian Kent | c9ffec4 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 662 | 		/* | 
 | 663 | 		 * A user space application can (and has done in the past) | 
 | 664 | 		 * remove and re-create this directory during the callback. | 
 | 665 | 		 * This can leave us with an unhashed dentry, but a | 
 | 666 | 		 * successful mount!  So we need to perform another | 
 | 667 | 		 * cached lookup in case the dentry now exists. | 
 | 668 | 		 */ | 
 | 669 | 		struct dentry *parent = dentry->d_parent; | 
 | 670 | 		struct dentry *new = d_lookup(parent, &dentry->d_name); | 
 | 671 | 		if (new != NULL) | 
 | 672 | 			dentry = new; | 
 | 673 | 		else | 
 | 674 | 			dentry = ERR_PTR(-ENOENT); | 
 | 675 |  | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 676 | 		if (unhashed) | 
 | 677 | 			dput(unhashed); | 
| Ian Kent | c9ffec4 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 678 |  | 
 | 679 | 		return dentry; | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 680 | 	} | 
 | 681 |  | 
 | 682 | 	if (unhashed) | 
 | 683 | 		return dentry; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 |  | 
 | 685 | 	return NULL; | 
 | 686 | } | 
 | 687 |  | 
 | 688 | static int autofs4_dir_symlink(struct inode *dir,  | 
 | 689 | 			       struct dentry *dentry, | 
 | 690 | 			       const char *symname) | 
 | 691 | { | 
 | 692 | 	struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 
 | 693 | 	struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 694 | 	struct autofs_info *p_ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | 	struct inode *inode; | 
 | 696 | 	char *cp; | 
 | 697 |  | 
 | 698 | 	DPRINTK("%s <- %.*s", symname, | 
 | 699 | 		dentry->d_name.len, dentry->d_name.name); | 
 | 700 |  | 
 | 701 | 	if (!autofs4_oz_mode(sbi)) | 
 | 702 | 		return -EACCES; | 
 | 703 |  | 
 | 704 | 	ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555); | 
 | 705 | 	if (ino == NULL) | 
 | 706 | 		return -ENOSPC; | 
 | 707 |  | 
 | 708 | 	ino->size = strlen(symname); | 
 | 709 | 	ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL); | 
 | 710 |  | 
 | 711 | 	if (cp == NULL) { | 
 | 712 | 		kfree(ino); | 
 | 713 | 		return -ENOSPC; | 
 | 714 | 	} | 
 | 715 |  | 
 | 716 | 	strcpy(cp, symname); | 
 | 717 |  | 
 | 718 | 	inode = autofs4_get_inode(dir->i_sb, ino); | 
 | 719 | 	d_instantiate(dentry, inode); | 
 | 720 |  | 
 | 721 | 	if (dir == dir->i_sb->s_root->d_inode) | 
 | 722 | 		dentry->d_op = &autofs4_root_dentry_operations; | 
 | 723 | 	else | 
 | 724 | 		dentry->d_op = &autofs4_dentry_operations; | 
 | 725 |  | 
 | 726 | 	dentry->d_fsdata = ino; | 
 | 727 | 	ino->dentry = dget(dentry); | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 728 | 	atomic_inc(&ino->count); | 
 | 729 | 	p_ino = autofs4_dentry_ino(dentry->d_parent); | 
 | 730 | 	if (p_ino && dentry->d_parent != dentry) | 
 | 731 | 		atomic_inc(&p_ino->count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | 	ino->inode = inode; | 
 | 733 |  | 
 | 734 | 	dir->i_mtime = CURRENT_TIME; | 
 | 735 |  | 
 | 736 | 	return 0; | 
 | 737 | } | 
 | 738 |  | 
 | 739 | /* | 
 | 740 |  * NOTE! | 
 | 741 |  * | 
 | 742 |  * Normal filesystems would do a "d_delete()" to tell the VFS dcache | 
 | 743 |  * that the file no longer exists. However, doing that means that the | 
 | 744 |  * VFS layer can turn the dentry into a negative dentry.  We don't want | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 745 |  * this, because the unlink is probably the result of an expire. | 
 | 746 |  * We simply d_drop it and add it to a rehash candidates list in the | 
 | 747 |  * super block, which allows the dentry lookup to reuse it retaining | 
 | 748 |  * the flags, such as expire in progress, in case we're racing with expire. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 |  * | 
 | 750 |  * If a process is blocked on the dentry waiting for the expire to finish, | 
 | 751 |  * it will invalidate the dentry and try to mount with a new one. | 
 | 752 |  * | 
 | 753 |  * Also see autofs4_dir_rmdir().. | 
 | 754 |  */ | 
 | 755 | static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry) | 
 | 756 | { | 
 | 757 | 	struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 
 | 758 | 	struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 759 | 	struct autofs_info *p_ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | 	 | 
 | 761 | 	/* This allows root to remove symlinks */ | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 762 | 	if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | 		return -EACCES; | 
 | 764 |  | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 765 | 	if (atomic_dec_and_test(&ino->count)) { | 
 | 766 | 		p_ino = autofs4_dentry_ino(dentry->d_parent); | 
 | 767 | 		if (p_ino && dentry->d_parent != dentry) | 
 | 768 | 			atomic_dec(&p_ino->count); | 
 | 769 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | 	dput(ino->dentry); | 
 | 771 |  | 
 | 772 | 	dentry->d_inode->i_size = 0; | 
| Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 773 | 	clear_nlink(dentry->d_inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 |  | 
 | 775 | 	dir->i_mtime = CURRENT_TIME; | 
 | 776 |  | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 777 | 	spin_lock(&dcache_lock); | 
 | 778 | 	spin_lock(&sbi->rehash_lock); | 
 | 779 | 	list_add(&ino->rehash, &sbi->rehash_list); | 
 | 780 | 	spin_unlock(&sbi->rehash_lock); | 
 | 781 | 	spin_lock(&dentry->d_lock); | 
 | 782 | 	__d_drop(dentry); | 
 | 783 | 	spin_unlock(&dentry->d_lock); | 
 | 784 | 	spin_unlock(&dcache_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 |  | 
 | 786 | 	return 0; | 
 | 787 | } | 
 | 788 |  | 
 | 789 | static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry) | 
 | 790 | { | 
 | 791 | 	struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 
 | 792 | 	struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 793 | 	struct autofs_info *p_ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | 	 | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 795 | 	DPRINTK("dentry %p, removing %.*s", | 
 | 796 | 		dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 797 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | 	if (!autofs4_oz_mode(sbi)) | 
 | 799 | 		return -EACCES; | 
 | 800 |  | 
 | 801 | 	spin_lock(&dcache_lock); | 
 | 802 | 	if (!list_empty(&dentry->d_subdirs)) { | 
 | 803 | 		spin_unlock(&dcache_lock); | 
 | 804 | 		return -ENOTEMPTY; | 
 | 805 | 	} | 
| Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 806 | 	spin_lock(&sbi->rehash_lock); | 
 | 807 | 	list_add(&ino->rehash, &sbi->rehash_list); | 
 | 808 | 	spin_unlock(&sbi->rehash_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | 	spin_lock(&dentry->d_lock); | 
 | 810 | 	__d_drop(dentry); | 
 | 811 | 	spin_unlock(&dentry->d_lock); | 
 | 812 | 	spin_unlock(&dcache_lock); | 
 | 813 |  | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 814 | 	if (atomic_dec_and_test(&ino->count)) { | 
 | 815 | 		p_ino = autofs4_dentry_ino(dentry->d_parent); | 
 | 816 | 		if (p_ino && dentry->d_parent != dentry) | 
 | 817 | 			atomic_dec(&p_ino->count); | 
 | 818 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | 	dput(ino->dentry); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | 	dentry->d_inode->i_size = 0; | 
| Dave Hansen | ce71ec3 | 2006-09-30 23:29:06 -0700 | [diff] [blame] | 821 | 	clear_nlink(dentry->d_inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 |  | 
 | 823 | 	if (dir->i_nlink) | 
| Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 824 | 		drop_nlink(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 |  | 
 | 826 | 	return 0; | 
 | 827 | } | 
 | 828 |  | 
 | 829 | static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode) | 
 | 830 | { | 
 | 831 | 	struct autofs_sb_info *sbi = autofs4_sbi(dir->i_sb); | 
 | 832 | 	struct autofs_info *ino = autofs4_dentry_ino(dentry); | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 833 | 	struct autofs_info *p_ino; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | 	struct inode *inode; | 
 | 835 |  | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 836 | 	if (!autofs4_oz_mode(sbi)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | 		return -EACCES; | 
 | 838 |  | 
 | 839 | 	DPRINTK("dentry %p, creating %.*s", | 
 | 840 | 		dentry, dentry->d_name.len, dentry->d_name.name); | 
 | 841 |  | 
 | 842 | 	ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555); | 
 | 843 | 	if (ino == NULL) | 
 | 844 | 		return -ENOSPC; | 
 | 845 |  | 
 | 846 | 	inode = autofs4_get_inode(dir->i_sb, ino); | 
 | 847 | 	d_instantiate(dentry, inode); | 
 | 848 |  | 
 | 849 | 	if (dir == dir->i_sb->s_root->d_inode) | 
 | 850 | 		dentry->d_op = &autofs4_root_dentry_operations; | 
 | 851 | 	else | 
 | 852 | 		dentry->d_op = &autofs4_dentry_operations; | 
 | 853 |  | 
 | 854 | 	dentry->d_fsdata = ino; | 
 | 855 | 	ino->dentry = dget(dentry); | 
| Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 856 | 	atomic_inc(&ino->count); | 
 | 857 | 	p_ino = autofs4_dentry_ino(dentry->d_parent); | 
 | 858 | 	if (p_ino && dentry->d_parent != dentry) | 
 | 859 | 		atomic_inc(&p_ino->count); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | 	ino->inode = inode; | 
| Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 861 | 	inc_nlink(dir); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | 	dir->i_mtime = CURRENT_TIME; | 
 | 863 |  | 
 | 864 | 	return 0; | 
 | 865 | } | 
 | 866 |  | 
 | 867 | /* Get/set timeout ioctl() operation */ | 
 | 868 | static inline int autofs4_get_set_timeout(struct autofs_sb_info *sbi, | 
 | 869 | 					 unsigned long __user *p) | 
 | 870 | { | 
 | 871 | 	int rv; | 
 | 872 | 	unsigned long ntimeout; | 
 | 873 |  | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 874 | 	if ((rv = get_user(ntimeout, p)) || | 
 | 875 | 	     (rv = put_user(sbi->exp_timeout/HZ, p))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | 		return rv; | 
 | 877 |  | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 878 | 	if (ntimeout > ULONG_MAX/HZ) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | 		sbi->exp_timeout = 0; | 
 | 880 | 	else | 
 | 881 | 		sbi->exp_timeout = ntimeout * HZ; | 
 | 882 |  | 
 | 883 | 	return 0; | 
 | 884 | } | 
 | 885 |  | 
 | 886 | /* Return protocol version */ | 
 | 887 | static inline int autofs4_get_protover(struct autofs_sb_info *sbi, int __user *p) | 
 | 888 | { | 
 | 889 | 	return put_user(sbi->version, p); | 
 | 890 | } | 
 | 891 |  | 
 | 892 | /* Return protocol sub version */ | 
 | 893 | static inline int autofs4_get_protosubver(struct autofs_sb_info *sbi, int __user *p) | 
 | 894 | { | 
 | 895 | 	return put_user(sbi->sub_version, p); | 
 | 896 | } | 
 | 897 |  | 
 | 898 | /* | 
 | 899 |  * Tells the daemon whether we need to reghost or not. Also, clears | 
 | 900 |  * the reghost_needed flag. | 
 | 901 |  */ | 
 | 902 | static inline int autofs4_ask_reghost(struct autofs_sb_info *sbi, int __user *p) | 
 | 903 | { | 
 | 904 | 	int status; | 
 | 905 |  | 
 | 906 | 	DPRINTK("returning %d", sbi->needs_reghost); | 
 | 907 |  | 
 | 908 | 	status = put_user(sbi->needs_reghost, p); | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 909 | 	if (status) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | 		return status; | 
 | 911 |  | 
 | 912 | 	sbi->needs_reghost = 0; | 
 | 913 | 	return 0; | 
 | 914 | } | 
 | 915 |  | 
 | 916 | /* | 
 | 917 |  * Enable / Disable reghosting ioctl() operation | 
 | 918 |  */ | 
 | 919 | static inline int autofs4_toggle_reghost(struct autofs_sb_info *sbi, int __user *p) | 
 | 920 | { | 
 | 921 | 	int status; | 
 | 922 | 	int val; | 
 | 923 |  | 
 | 924 | 	status = get_user(val, p); | 
 | 925 |  | 
 | 926 | 	DPRINTK("reghost = %d", val); | 
 | 927 |  | 
 | 928 | 	if (status) | 
 | 929 | 		return status; | 
 | 930 |  | 
 | 931 | 	/* turn on/off reghosting, with the val */ | 
 | 932 | 	sbi->reghost_enabled = val; | 
 | 933 | 	return 0; | 
 | 934 | } | 
 | 935 |  | 
 | 936 | /* | 
 | 937 | * Tells the daemon whether it can umount the autofs mount. | 
 | 938 | */ | 
 | 939 | static inline int autofs4_ask_umount(struct vfsmount *mnt, int __user *p) | 
 | 940 | { | 
 | 941 | 	int status = 0; | 
 | 942 |  | 
| Ian Kent | e3474a8 | 2006-03-27 01:14:51 -0800 | [diff] [blame] | 943 | 	if (may_umount(mnt)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | 		status = 1; | 
 | 945 |  | 
 | 946 | 	DPRINTK("returning %d", status); | 
 | 947 |  | 
 | 948 | 	status = put_user(status, p); | 
 | 949 |  | 
 | 950 | 	return status; | 
 | 951 | } | 
 | 952 |  | 
 | 953 | /* Identify autofs4_dentries - this is so we can tell if there's | 
 | 954 |    an extra dentry refcount or not.  We only hold a refcount on the | 
 | 955 |    dentry if its non-negative (ie, d_inode != NULL) | 
 | 956 | */ | 
 | 957 | int is_autofs4_dentry(struct dentry *dentry) | 
 | 958 | { | 
 | 959 | 	return dentry && dentry->d_inode && | 
 | 960 | 		(dentry->d_op == &autofs4_root_dentry_operations || | 
 | 961 | 		 dentry->d_op == &autofs4_dentry_operations) && | 
 | 962 | 		dentry->d_fsdata != NULL; | 
 | 963 | } | 
 | 964 |  | 
 | 965 | /* | 
 | 966 |  * ioctl()'s on the root directory is the chief method for the daemon to | 
 | 967 |  * generate kernel reactions | 
 | 968 |  */ | 
 | 969 | static int autofs4_root_ioctl(struct inode *inode, struct file *filp, | 
 | 970 | 			     unsigned int cmd, unsigned long arg) | 
 | 971 | { | 
 | 972 | 	struct autofs_sb_info *sbi = autofs4_sbi(inode->i_sb); | 
 | 973 | 	void __user *p = (void __user *)arg; | 
 | 974 |  | 
 | 975 | 	DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u", | 
 | 976 | 		cmd,arg,sbi,process_group(current)); | 
 | 977 |  | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 978 | 	if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) || | 
 | 979 | 	     _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | 		return -ENOTTY; | 
 | 981 | 	 | 
| Sukadev Bhattiprolu | d78e53c | 2007-05-10 22:23:06 -0700 | [diff] [blame] | 982 | 	if (!autofs4_oz_mode(sbi) && !capable(CAP_SYS_ADMIN)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | 		return -EPERM; | 
 | 984 | 	 | 
 | 985 | 	switch(cmd) { | 
 | 986 | 	case AUTOFS_IOC_READY:	/* Wait queue: go ahead and retry */ | 
 | 987 | 		return autofs4_wait_release(sbi,(autofs_wqt_t)arg,0); | 
 | 988 | 	case AUTOFS_IOC_FAIL:	/* Wait queue: fail with ENOENT */ | 
 | 989 | 		return autofs4_wait_release(sbi,(autofs_wqt_t)arg,-ENOENT); | 
 | 990 | 	case AUTOFS_IOC_CATATONIC: /* Enter catatonic mode (daemon shutdown) */ | 
 | 991 | 		autofs4_catatonic_mode(sbi); | 
 | 992 | 		return 0; | 
 | 993 | 	case AUTOFS_IOC_PROTOVER: /* Get protocol version */ | 
 | 994 | 		return autofs4_get_protover(sbi, p); | 
 | 995 | 	case AUTOFS_IOC_PROTOSUBVER: /* Get protocol sub version */ | 
 | 996 | 		return autofs4_get_protosubver(sbi, p); | 
 | 997 | 	case AUTOFS_IOC_SETTIMEOUT: | 
 | 998 | 		return autofs4_get_set_timeout(sbi, p); | 
 | 999 |  | 
 | 1000 | 	case AUTOFS_IOC_TOGGLEREGHOST: | 
 | 1001 | 		return autofs4_toggle_reghost(sbi, p); | 
 | 1002 | 	case AUTOFS_IOC_ASKREGHOST: | 
 | 1003 | 		return autofs4_ask_reghost(sbi, p); | 
 | 1004 |  | 
 | 1005 | 	case AUTOFS_IOC_ASKUMOUNT: | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 1006 | 		return autofs4_ask_umount(filp->f_path.mnt, p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 |  | 
 | 1008 | 	/* return a single thing to expire */ | 
 | 1009 | 	case AUTOFS_IOC_EXPIRE: | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 1010 | 		return autofs4_expire_run(inode->i_sb,filp->f_path.mnt,sbi, p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | 	/* same as above, but can send multiple expires through pipe */ | 
 | 1012 | 	case AUTOFS_IOC_EXPIRE_MULTI: | 
| Josef "Jeff" Sipek | a4669ed | 2006-12-08 02:36:46 -0800 | [diff] [blame] | 1013 | 		return autofs4_expire_multi(inode->i_sb,filp->f_path.mnt,sbi, p); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 |  | 
 | 1015 | 	default: | 
 | 1016 | 		return -ENOSYS; | 
 | 1017 | 	} | 
 | 1018 | } |