1 /* -*- c -*- --------------------------------------------------------------- *
3 * linux/fs/autofs/inode.c
5 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
6 * Copyright 2005-2006 Ian Kent <raven@themaw.net>
8 * This file is part of the Linux kernel and is made available under
9 * the terms of the GNU General Public License, version 2, or at your
10 * option, any later version, incorporated herein by reference.
12 * ------------------------------------------------------------------------- */
14 #include <linux/kernel.h>
15 #include <linux/slab.h>
16 #include <linux/file.h>
17 #include <linux/seq_file.h>
18 #include <linux/pagemap.h>
19 #include <linux/parser.h>
20 #include <linux/bitops.h>
21 #include <linux/magic.h>
22 #include <linux/compat.h>
24 #include <linux/module.h>
26 struct autofs_info
*autofs4_new_ino(struct autofs_sb_info
*sbi
)
28 struct autofs_info
*ino
= kzalloc(sizeof(*ino
), GFP_KERNEL
);
30 INIT_LIST_HEAD(&ino
->active
);
31 INIT_LIST_HEAD(&ino
->expiring
);
32 ino
->last_used
= jiffies
;
38 void autofs4_clean_ino(struct autofs_info
*ino
)
42 ino
->last_used
= jiffies
;
45 void autofs4_free_ino(struct autofs_info
*ino
)
50 void autofs4_kill_sb(struct super_block
*sb
)
52 struct autofs_sb_info
*sbi
= autofs4_sbi(sb
);
55 * In the event of a failure in get_sb_nodev the superblock
56 * info is not present so nothing else has been setup, so
57 * just call kill_anon_super when we are called from
63 /* Free wait queues, close pipe */
64 autofs4_catatonic_mode(sbi
);
70 DPRINTK("shutting down");
71 kill_litter_super(sb
);
74 static int autofs4_show_options(struct seq_file
*m
, struct dentry
*root
)
76 struct autofs_sb_info
*sbi
= autofs4_sbi(root
->d_sb
);
77 struct inode
*root_inode
= root
->d_sb
->s_root
->d_inode
;
82 seq_printf(m
, ",fd=%d", sbi
->pipefd
);
83 if (root_inode
->i_uid
!= 0)
84 seq_printf(m
, ",uid=%u", root_inode
->i_uid
);
85 if (root_inode
->i_gid
!= 0)
86 seq_printf(m
, ",gid=%u", root_inode
->i_gid
);
87 seq_printf(m
, ",pgrp=%d", sbi
->oz_pgrp
);
88 seq_printf(m
, ",timeout=%lu", sbi
->exp_timeout
/HZ
);
89 seq_printf(m
, ",minproto=%d", sbi
->min_proto
);
90 seq_printf(m
, ",maxproto=%d", sbi
->max_proto
);
92 if (autofs_type_offset(sbi
->type
))
93 seq_printf(m
, ",offset");
94 else if (autofs_type_direct(sbi
->type
))
95 seq_printf(m
, ",direct");
97 seq_printf(m
, ",indirect");
102 static void autofs4_evict_inode(struct inode
*inode
)
104 end_writeback(inode
);
105 kfree(inode
->i_private
);
108 static const struct super_operations autofs4_sops
= {
109 .statfs
= simple_statfs
,
110 .show_options
= autofs4_show_options
,
111 .evict_inode
= autofs4_evict_inode
,
114 enum {Opt_err
, Opt_fd
, Opt_uid
, Opt_gid
, Opt_pgrp
, Opt_minproto
, Opt_maxproto
,
115 Opt_indirect
, Opt_direct
, Opt_offset
};
117 static const match_table_t tokens
= {
121 {Opt_pgrp
, "pgrp=%u"},
122 {Opt_minproto
, "minproto=%u"},
123 {Opt_maxproto
, "maxproto=%u"},
124 {Opt_indirect
, "indirect"},
125 {Opt_direct
, "direct"},
126 {Opt_offset
, "offset"},
130 static int parse_options(char *options
, int *pipefd
, uid_t
*uid
, gid_t
*gid
,
131 pid_t
*pgrp
, unsigned int *type
, int *minproto
, int *maxproto
)
134 substring_t args
[MAX_OPT_ARGS
];
137 *uid
= current_uid();
138 *gid
= current_gid();
139 *pgrp
= task_pgrp_nr(current
);
141 *minproto
= AUTOFS_MIN_PROTO_VERSION
;
142 *maxproto
= AUTOFS_MAX_PROTO_VERSION
;
149 while ((p
= strsep(&options
, ",")) != NULL
) {
154 token
= match_token(p
, tokens
, args
);
157 if (match_int(args
, pipefd
))
161 if (match_int(args
, &option
))
166 if (match_int(args
, &option
))
171 if (match_int(args
, &option
))
176 if (match_int(args
, &option
))
181 if (match_int(args
, &option
))
186 set_autofs_type_indirect(type
);
189 set_autofs_type_direct(type
);
192 set_autofs_type_offset(type
);
198 return (*pipefd
< 0);
201 int autofs4_fill_super(struct super_block
*s
, void *data
, int silent
)
203 struct inode
* root_inode
;
204 struct dentry
* root
;
207 struct autofs_sb_info
*sbi
;
208 struct autofs_info
*ino
;
210 sbi
= kzalloc(sizeof(*sbi
), GFP_KERNEL
);
213 DPRINTK("starting up, sbi = %p",sbi
);
216 sbi
->magic
= AUTOFS_SBI_MAGIC
;
220 sbi
->exp_timeout
= 0;
221 sbi
->oz_pgrp
= task_pgrp_nr(current
);
224 sbi
->sub_version
= 0;
225 set_autofs_type_indirect(&sbi
->type
);
228 sbi
->compat_daemon
= is_compat_task();
229 mutex_init(&sbi
->wq_mutex
);
230 mutex_init(&sbi
->pipe_mutex
);
231 spin_lock_init(&sbi
->fs_lock
);
233 spin_lock_init(&sbi
->lookup_lock
);
234 INIT_LIST_HEAD(&sbi
->active_list
);
235 INIT_LIST_HEAD(&sbi
->expiring_list
);
236 s
->s_blocksize
= 1024;
237 s
->s_blocksize_bits
= 10;
238 s
->s_magic
= AUTOFS_SUPER_MAGIC
;
239 s
->s_op
= &autofs4_sops
;
240 s
->s_d_op
= &autofs4_dentry_operations
;
244 * Get the root inode and dentry, but defer checking for errors.
246 ino
= autofs4_new_ino(sbi
);
249 root_inode
= autofs4_get_inode(s
, S_IFDIR
| 0755);
253 root
= d_alloc_root(root_inode
);
258 root
->d_fsdata
= ino
;
260 /* Can this call block? */
261 if (parse_options(data
, &pipefd
, &root_inode
->i_uid
, &root_inode
->i_gid
,
262 &sbi
->oz_pgrp
, &sbi
->type
, &sbi
->min_proto
,
264 printk("autofs: called with bogus options\n");
268 if (autofs_type_trigger(sbi
->type
))
269 __managed_dentry_set_managed(root
);
271 root_inode
->i_fop
= &autofs4_root_operations
;
272 root_inode
->i_op
= &autofs4_dir_inode_operations
;
274 /* Couldn't this be tested earlier? */
275 if (sbi
->max_proto
< AUTOFS_MIN_PROTO_VERSION
||
276 sbi
->min_proto
> AUTOFS_MAX_PROTO_VERSION
) {
277 printk("autofs: kernel does not match daemon version "
278 "daemon (%d, %d) kernel (%d, %d)\n",
279 sbi
->min_proto
, sbi
->max_proto
,
280 AUTOFS_MIN_PROTO_VERSION
, AUTOFS_MAX_PROTO_VERSION
);
284 /* Establish highest kernel protocol version */
285 if (sbi
->max_proto
> AUTOFS_MAX_PROTO_VERSION
)
286 sbi
->version
= AUTOFS_MAX_PROTO_VERSION
;
288 sbi
->version
= sbi
->max_proto
;
289 sbi
->sub_version
= AUTOFS_PROTO_SUBVERSION
;
291 DPRINTK("pipe fd = %d, pgrp = %u", pipefd
, sbi
->oz_pgrp
);
295 printk("autofs: could not open pipe file descriptor\n");
298 if (!pipe
->f_op
|| !pipe
->f_op
->write
)
301 sbi
->pipefd
= pipefd
;
305 * Success! Install the root dentry now to indicate completion.
311 * Failure ... clean up.
314 printk("autofs: pipe file descriptor does not contain proper ops\n");
321 printk("autofs: get root dentry failed\n");
332 struct inode
*autofs4_get_inode(struct super_block
*sb
, umode_t mode
)
334 struct inode
*inode
= new_inode(sb
);
339 inode
->i_mode
= mode
;
341 inode
->i_uid
= sb
->s_root
->d_inode
->i_uid
;
342 inode
->i_gid
= sb
->s_root
->d_inode
->i_gid
;
344 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
345 inode
->i_ino
= get_next_ino();
349 inode
->i_op
= &autofs4_dir_inode_operations
;
350 inode
->i_fop
= &autofs4_dir_operations
;
351 } else if (S_ISLNK(mode
)) {
352 inode
->i_op
= &autofs4_symlink_inode_operations
;