1 /* -*- c -*- --------------------------------------------------------------- *
3 * linux/fs/autofs/inode.c
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
7 * This file is part of the Linux kernel and is made available under
8 * the terms of the GNU General Public License, version 2, or at your
9 * option, any later version, incorporated herein by reference.
11 * ------------------------------------------------------------------------- */
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
15 #include <linux/file.h>
16 #include <linux/pagemap.h>
17 #include <linux/parser.h>
18 #include <linux/bitops.h>
19 #include <linux/smp_lock.h>
21 #include <linux/module.h>
23 static void ino_lnkfree(struct autofs_info *ino)
25 kfree(ino->u.symlink);
26 ino->u.symlink = NULL;
29 struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
30 struct autofs_sb_info *sbi, mode_t mode)
36 ino = kmalloc(sizeof(*ino), GFP_KERNEL);
48 ino->last_used = jiffies;
52 if (reinit && ino->free)
55 memset(&ino->u, 0, sizeof(ino->u));
60 ino->free = ino_lnkfree;
65 void autofs4_free_ino(struct autofs_info *ino)
68 ino->dentry->d_fsdata = NULL;
69 if (ino->dentry->d_inode)
79 * Deal with the infamous "Busy inodes after umount ..." message.
81 * Clean up the dentry tree. This happens with autofs if the user
82 * space program goes away due to a SIGKILL, SIGSEGV etc.
84 static void autofs4_force_release(struct autofs_sb_info *sbi)
86 struct dentry *this_parent = sbi->root;
87 struct list_head *next;
89 spin_lock(&dcache_lock);
91 next = this_parent->d_subdirs.next;
93 while (next != &this_parent->d_subdirs) {
94 struct dentry *dentry = list_entry(next, struct dentry, d_child);
96 /* Negative dentry - don`t care */
97 if (!simple_positive(dentry)) {
102 if (!list_empty(&dentry->d_subdirs)) {
103 this_parent = dentry;
108 spin_unlock(&dcache_lock);
110 DPRINTK("dentry %p %.*s",
111 dentry, (int)dentry->d_name.len, dentry->d_name.name);
114 spin_lock(&dcache_lock);
117 if (this_parent != sbi->root) {
118 struct dentry *dentry = this_parent;
120 next = this_parent->d_child.next;
121 this_parent = this_parent->d_parent;
122 spin_unlock(&dcache_lock);
123 DPRINTK("parent dentry %p %.*s",
124 dentry, (int)dentry->d_name.len, dentry->d_name.name);
126 spin_lock(&dcache_lock);
129 spin_unlock(&dcache_lock);
133 shrink_dcache_sb(sbi->sb);
138 static void autofs4_put_super(struct super_block *sb)
140 struct autofs_sb_info *sbi = autofs4_sbi(sb);
142 sb->s_fs_info = NULL;
144 if ( !sbi->catatonic )
145 autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */
147 /* Clean up and release dangling references */
149 autofs4_force_release(sbi);
153 DPRINTK("shutting down");
156 static struct super_operations autofs4_sops = {
157 .put_super = autofs4_put_super,
158 .statfs = simple_statfs,
161 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
163 static match_table_t tokens = {
167 {Opt_pgrp, "pgrp=%u"},
168 {Opt_minproto, "minproto=%u"},
169 {Opt_maxproto, "maxproto=%u"},
173 static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
174 pid_t *pgrp, int *minproto, int *maxproto)
177 substring_t args[MAX_OPT_ARGS];
182 *pgrp = process_group(current);
184 *minproto = AUTOFS_MIN_PROTO_VERSION;
185 *maxproto = AUTOFS_MAX_PROTO_VERSION;
192 while ((p = strsep(&options, ",")) != NULL) {
197 token = match_token(p, tokens, args);
200 if (match_int(args, pipefd))
204 if (match_int(args, &option))
209 if (match_int(args, &option))
214 if (match_int(args, &option))
219 if (match_int(args, &option))
224 if (match_int(args, &option))
232 return (*pipefd < 0);
235 static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
237 struct autofs_info *ino;
239 ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755);
246 int autofs4_fill_super(struct super_block *s, void *data, int silent)
248 struct inode * root_inode;
249 struct dentry * root;
252 struct autofs_sb_info *sbi;
253 struct autofs_info *ino;
254 int minproto, maxproto;
256 sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL);
259 DPRINTK("starting up, sbi = %p",sbi);
261 memset(sbi, 0, sizeof(*sbi));
264 sbi->magic = AUTOFS_SBI_MAGIC;
267 sbi->exp_timeout = 0;
268 sbi->oz_pgrp = process_group(current);
271 sbi->sub_version = 0;
272 init_MUTEX(&sbi->wq_sem);
273 spin_lock_init(&sbi->fs_lock);
275 s->s_blocksize = 1024;
276 s->s_blocksize_bits = 10;
277 s->s_magic = AUTOFS_SUPER_MAGIC;
278 s->s_op = &autofs4_sops;
282 * Get the root inode and dentry, but defer checking for errors.
284 ino = autofs4_mkroot(sbi);
287 root_inode = autofs4_get_inode(s, ino);
292 root_inode->i_op = &autofs4_root_inode_operations;
293 root_inode->i_fop = &autofs4_root_operations;
294 root = d_alloc_root(root_inode);
300 /* Can this call block? */
301 if (parse_options(data, &pipefd,
302 &root_inode->i_uid, &root_inode->i_gid,
304 &minproto, &maxproto)) {
305 printk("autofs: called with bogus options\n");
309 /* Couldn't this be tested earlier? */
310 if (maxproto < AUTOFS_MIN_PROTO_VERSION ||
311 minproto > AUTOFS_MAX_PROTO_VERSION) {
312 printk("autofs: kernel does not match daemon version "
313 "daemon (%d, %d) kernel (%d, %d)\n",
315 AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
319 sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto;
320 sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
322 DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp);
326 printk("autofs: could not open pipe file descriptor\n");
329 if ( !pipe->f_op || !pipe->f_op->write )
334 * Take a reference to the root dentry so we get a chance to
335 * clean up the dentry tree on umount.
336 * See autofs4_force_release.
338 sbi->root = dget(root);
341 * Success! Install the root dentry now to indicate completion.
347 * Failure ... clean up.
350 printk("autofs: pipe file descriptor does not contain proper ops\n");
357 printk("autofs: get root dentry failed\n");
365 struct inode *autofs4_get_inode(struct super_block *sb,
366 struct autofs_info *inf)
368 struct inode *inode = new_inode(sb);
374 inode->i_mode = inf->mode;
376 inode->i_uid = sb->s_root->d_inode->i_uid;
377 inode->i_gid = sb->s_root->d_inode->i_gid;
382 inode->i_blksize = PAGE_CACHE_SIZE;
384 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
386 if (S_ISDIR(inf->mode)) {
388 inode->i_op = &autofs4_dir_inode_operations;
389 inode->i_fop = &autofs4_dir_operations;
390 } else if (S_ISLNK(inf->mode)) {
391 inode->i_size = inf->size;
392 inode->i_op = &autofs4_symlink_inode_operations;