2 * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
3 * Copyright 2005-2006 Ian Kent <raven@themaw.net>
5 * This file is part of the Linux kernel and is made available under
6 * the terms of the GNU General Public License, version 2, or at your
7 * option, any later version, incorporated herein by reference.
10 #include <linux/seq_file.h>
11 #include <linux/pagemap.h>
12 #include <linux/parser.h>
16 struct autofs_info
*autofs_new_ino(struct autofs_sb_info
*sbi
)
18 struct autofs_info
*ino
;
20 ino
= kzalloc(sizeof(*ino
), GFP_KERNEL
);
22 INIT_LIST_HEAD(&ino
->active
);
23 INIT_LIST_HEAD(&ino
->expiring
);
24 ino
->last_used
= jiffies
;
30 void autofs_clean_ino(struct autofs_info
*ino
)
32 ino
->uid
= GLOBAL_ROOT_UID
;
33 ino
->gid
= GLOBAL_ROOT_GID
;
34 ino
->last_used
= jiffies
;
37 void autofs_free_ino(struct autofs_info
*ino
)
42 void autofs_kill_sb(struct super_block
*sb
)
44 struct autofs_sb_info
*sbi
= autofs_sbi(sb
);
47 * In the event of a failure in get_sb_nodev the superblock
48 * info is not present so nothing else has been setup, so
49 * just call kill_anon_super when we are called from
53 /* Free wait queues, close pipe */
54 autofs_catatonic_mode(sbi
);
55 put_pid(sbi
->oz_pgrp
);
58 pr_debug("shutting down\n");
59 kill_litter_super(sb
);
64 static int autofs_show_options(struct seq_file
*m
, struct dentry
*root
)
66 struct autofs_sb_info
*sbi
= autofs_sbi(root
->d_sb
);
67 struct inode
*root_inode
= d_inode(root
->d_sb
->s_root
);
72 seq_printf(m
, ",fd=%d", sbi
->pipefd
);
73 if (!uid_eq(root_inode
->i_uid
, GLOBAL_ROOT_UID
))
74 seq_printf(m
, ",uid=%u",
75 from_kuid_munged(&init_user_ns
, root_inode
->i_uid
));
76 if (!gid_eq(root_inode
->i_gid
, GLOBAL_ROOT_GID
))
77 seq_printf(m
, ",gid=%u",
78 from_kgid_munged(&init_user_ns
, root_inode
->i_gid
));
79 seq_printf(m
, ",pgrp=%d", pid_vnr(sbi
->oz_pgrp
));
80 seq_printf(m
, ",timeout=%lu", sbi
->exp_timeout
/HZ
);
81 seq_printf(m
, ",minproto=%d", sbi
->min_proto
);
82 seq_printf(m
, ",maxproto=%d", sbi
->max_proto
);
84 if (autofs_type_offset(sbi
->type
))
85 seq_printf(m
, ",offset");
86 else if (autofs_type_direct(sbi
->type
))
87 seq_printf(m
, ",direct");
89 seq_printf(m
, ",indirect");
90 if (sbi
->flags
& AUTOFS_SBI_STRICTEXPIRE
)
91 seq_printf(m
, ",strictexpire");
92 if (sbi
->flags
& AUTOFS_SBI_IGNORE
)
93 seq_printf(m
, ",ignore");
94 #ifdef CONFIG_CHECKPOINT_RESTORE
96 seq_printf(m
, ",pipe_ino=%ld", file_inode(sbi
->pipe
)->i_ino
);
98 seq_printf(m
, ",pipe_ino=-1");
103 static void autofs_evict_inode(struct inode
*inode
)
106 kfree(inode
->i_private
);
109 static const struct super_operations autofs_sops
= {
110 .statfs
= simple_statfs
,
111 .show_options
= autofs_show_options
,
112 .evict_inode
= autofs_evict_inode
,
115 enum {Opt_err
, Opt_fd
, Opt_uid
, Opt_gid
, Opt_pgrp
, Opt_minproto
, Opt_maxproto
,
116 Opt_indirect
, Opt_direct
, Opt_offset
, Opt_strictexpire
,
119 static const match_table_t tokens
= {
123 {Opt_pgrp
, "pgrp=%u"},
124 {Opt_minproto
, "minproto=%u"},
125 {Opt_maxproto
, "maxproto=%u"},
126 {Opt_indirect
, "indirect"},
127 {Opt_direct
, "direct"},
128 {Opt_offset
, "offset"},
129 {Opt_strictexpire
, "strictexpire"},
130 {Opt_ignore
, "ignore"},
134 static int parse_options(char *options
,
135 struct inode
*root
, int *pgrp
, bool *pgrp_set
,
136 struct autofs_sb_info
*sbi
)
139 substring_t args
[MAX_OPT_ARGS
];
145 root
->i_uid
= current_uid();
146 root
->i_gid
= current_gid();
148 sbi
->min_proto
= AUTOFS_MIN_PROTO_VERSION
;
149 sbi
->max_proto
= AUTOFS_MAX_PROTO_VERSION
;
156 while ((p
= strsep(&options
, ",")) != NULL
) {
162 token
= match_token(p
, tokens
, args
);
165 if (match_int(args
, &pipefd
))
167 sbi
->pipefd
= pipefd
;
170 if (match_int(args
, &option
))
172 uid
= make_kuid(current_user_ns(), option
);
178 if (match_int(args
, &option
))
180 gid
= make_kgid(current_user_ns(), option
);
186 if (match_int(args
, &option
))
192 if (match_int(args
, &option
))
194 sbi
->min_proto
= option
;
197 if (match_int(args
, &option
))
199 sbi
->max_proto
= option
;
202 set_autofs_type_indirect(&sbi
->type
);
205 set_autofs_type_direct(&sbi
->type
);
208 set_autofs_type_offset(&sbi
->type
);
210 case Opt_strictexpire
:
211 sbi
->flags
|= AUTOFS_SBI_STRICTEXPIRE
;
214 sbi
->flags
|= AUTOFS_SBI_IGNORE
;
220 return (sbi
->pipefd
< 0);
223 int autofs_fill_super(struct super_block
*s
, void *data
, int silent
)
225 struct inode
*root_inode
;
228 struct autofs_sb_info
*sbi
;
229 struct autofs_info
*ino
;
231 bool pgrp_set
= false;
234 sbi
= kzalloc(sizeof(*sbi
), GFP_KERNEL
);
237 pr_debug("starting up, sbi = %p\n", sbi
);
240 sbi
->magic
= AUTOFS_SBI_MAGIC
;
243 sbi
->exp_timeout
= 0;
247 sbi
->sub_version
= 0;
248 sbi
->flags
= AUTOFS_SBI_CATATONIC
;
249 set_autofs_type_indirect(&sbi
->type
);
252 mutex_init(&sbi
->wq_mutex
);
253 mutex_init(&sbi
->pipe_mutex
);
254 spin_lock_init(&sbi
->fs_lock
);
256 spin_lock_init(&sbi
->lookup_lock
);
257 INIT_LIST_HEAD(&sbi
->active_list
);
258 INIT_LIST_HEAD(&sbi
->expiring_list
);
259 s
->s_blocksize
= 1024;
260 s
->s_blocksize_bits
= 10;
261 s
->s_magic
= AUTOFS_SUPER_MAGIC
;
262 s
->s_op
= &autofs_sops
;
263 s
->s_d_op
= &autofs_dentry_operations
;
267 * Get the root inode and dentry, but defer checking for errors.
269 ino
= autofs_new_ino(sbi
);
274 root_inode
= autofs_get_inode(s
, S_IFDIR
| 0755);
275 root
= d_make_root(root_inode
);
282 root
->d_fsdata
= ino
;
284 /* Can this call block? */
285 if (parse_options(data
, root_inode
, &pgrp
, &pgrp_set
, sbi
)) {
286 pr_err("called with bogus options\n");
290 /* Test versions first */
291 if (sbi
->max_proto
< AUTOFS_MIN_PROTO_VERSION
||
292 sbi
->min_proto
> AUTOFS_MAX_PROTO_VERSION
) {
293 pr_err("kernel does not match daemon version "
294 "daemon (%d, %d) kernel (%d, %d)\n",
295 sbi
->min_proto
, sbi
->max_proto
,
296 AUTOFS_MIN_PROTO_VERSION
, AUTOFS_MAX_PROTO_VERSION
);
300 /* Establish highest kernel protocol version */
301 if (sbi
->max_proto
> AUTOFS_MAX_PROTO_VERSION
)
302 sbi
->version
= AUTOFS_MAX_PROTO_VERSION
;
304 sbi
->version
= sbi
->max_proto
;
305 sbi
->sub_version
= AUTOFS_PROTO_SUBVERSION
;
308 sbi
->oz_pgrp
= find_get_pid(pgrp
);
310 pr_err("could not find process group %d\n",
315 sbi
->oz_pgrp
= get_task_pid(current
, PIDTYPE_PGID
);
318 if (autofs_type_trigger(sbi
->type
))
319 __managed_dentry_set_managed(root
);
321 root_inode
->i_fop
= &autofs_root_operations
;
322 root_inode
->i_op
= &autofs_dir_inode_operations
;
324 pr_debug("pipe fd = %d, pgrp = %u\n",
325 sbi
->pipefd
, pid_nr(sbi
->oz_pgrp
));
326 pipe
= fget(sbi
->pipefd
);
329 pr_err("could not open pipe file descriptor\n");
332 ret
= autofs_prepare_pipe(pipe
);
336 sbi
->flags
&= ~AUTOFS_SBI_CATATONIC
;
339 * Success! Install the root dentry now to indicate completion.
345 * Failure ... clean up.
348 pr_err("pipe file descriptor does not contain proper ops\n");
351 put_pid(sbi
->oz_pgrp
);
356 autofs_free_ino(ino
);
363 struct inode
*autofs_get_inode(struct super_block
*sb
, umode_t mode
)
365 struct inode
*inode
= new_inode(sb
);
370 inode
->i_mode
= mode
;
372 inode
->i_uid
= d_inode(sb
->s_root
)->i_uid
;
373 inode
->i_gid
= d_inode(sb
->s_root
)->i_gid
;
375 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= current_time(inode
);
376 inode
->i_ino
= get_next_ino();
380 inode
->i_op
= &autofs_dir_inode_operations
;
381 inode
->i_fop
= &autofs_dir_operations
;
382 } else if (S_ISLNK(mode
)) {
383 inode
->i_op
= &autofs_symlink_inode_operations
;