diff options
Diffstat (limited to 'fs/autofs4/inode.c')
-rw-r--r-- | fs/autofs4/inode.c | 105 |
1 files changed, 86 insertions, 19 deletions
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c index 2d3082854a29..fde78b110ddd 100644 --- a/fs/autofs4/inode.c +++ b/fs/autofs4/inode.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * linux/fs/autofs/inode.c | 3 | * linux/fs/autofs/inode.c |
4 | * | 4 | * |
5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved | 5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved |
6 | * Copyright 2005-2006 Ian Kent <raven@themaw.net> | ||
6 | * | 7 | * |
7 | * This file is part of the Linux kernel and is made available under | 8 | * 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 | * the terms of the GNU General Public License, version 2, or at your |
@@ -13,6 +14,7 @@ | |||
13 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
14 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
15 | #include <linux/file.h> | 16 | #include <linux/file.h> |
17 | #include <linux/seq_file.h> | ||
16 | #include <linux/pagemap.h> | 18 | #include <linux/pagemap.h> |
17 | #include <linux/parser.h> | 19 | #include <linux/parser.h> |
18 | #include <linux/bitops.h> | 20 | #include <linux/bitops.h> |
@@ -46,6 +48,7 @@ struct autofs_info *autofs4_init_ino(struct autofs_info *ino, | |||
46 | ino->size = 0; | 48 | ino->size = 0; |
47 | 49 | ||
48 | ino->last_used = jiffies; | 50 | ino->last_used = jiffies; |
51 | atomic_set(&ino->count, 0); | ||
49 | 52 | ||
50 | ino->sbi = sbi; | 53 | ino->sbi = sbi; |
51 | 54 | ||
@@ -64,10 +67,19 @@ struct autofs_info *autofs4_init_ino(struct autofs_info *ino, | |||
64 | 67 | ||
65 | void autofs4_free_ino(struct autofs_info *ino) | 68 | void autofs4_free_ino(struct autofs_info *ino) |
66 | { | 69 | { |
70 | struct autofs_info *p_ino; | ||
71 | |||
67 | if (ino->dentry) { | 72 | if (ino->dentry) { |
68 | ino->dentry->d_fsdata = NULL; | 73 | ino->dentry->d_fsdata = NULL; |
69 | if (ino->dentry->d_inode) | 74 | if (ino->dentry->d_inode) { |
75 | struct dentry *parent = ino->dentry->d_parent; | ||
76 | if (atomic_dec_and_test(&ino->count)) { | ||
77 | p_ino = autofs4_dentry_ino(parent); | ||
78 | if (p_ino && parent != ino->dentry) | ||
79 | atomic_dec(&p_ino->count); | ||
80 | } | ||
70 | dput(ino->dentry); | 81 | dput(ino->dentry); |
82 | } | ||
71 | ino->dentry = NULL; | 83 | ino->dentry = NULL; |
72 | } | 84 | } |
73 | if (ino->free) | 85 | if (ino->free) |
@@ -145,20 +157,44 @@ static void autofs4_put_super(struct super_block *sb) | |||
145 | autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */ | 157 | autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */ |
146 | 158 | ||
147 | /* Clean up and release dangling references */ | 159 | /* Clean up and release dangling references */ |
148 | if (sbi) | 160 | autofs4_force_release(sbi); |
149 | autofs4_force_release(sbi); | ||
150 | 161 | ||
151 | kfree(sbi); | 162 | kfree(sbi); |
152 | 163 | ||
153 | DPRINTK("shutting down"); | 164 | DPRINTK("shutting down"); |
154 | } | 165 | } |
155 | 166 | ||
167 | static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt) | ||
168 | { | ||
169 | struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb); | ||
170 | |||
171 | if (!sbi) | ||
172 | return 0; | ||
173 | |||
174 | seq_printf(m, ",fd=%d", sbi->pipefd); | ||
175 | seq_printf(m, ",pgrp=%d", sbi->oz_pgrp); | ||
176 | seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ); | ||
177 | seq_printf(m, ",minproto=%d", sbi->min_proto); | ||
178 | seq_printf(m, ",maxproto=%d", sbi->max_proto); | ||
179 | |||
180 | if (sbi->type & AUTOFS_TYPE_OFFSET) | ||
181 | seq_printf(m, ",offset"); | ||
182 | else if (sbi->type & AUTOFS_TYPE_DIRECT) | ||
183 | seq_printf(m, ",direct"); | ||
184 | else | ||
185 | seq_printf(m, ",indirect"); | ||
186 | |||
187 | return 0; | ||
188 | } | ||
189 | |||
156 | static struct super_operations autofs4_sops = { | 190 | static struct super_operations autofs4_sops = { |
157 | .put_super = autofs4_put_super, | 191 | .put_super = autofs4_put_super, |
158 | .statfs = simple_statfs, | 192 | .statfs = simple_statfs, |
193 | .show_options = autofs4_show_options, | ||
159 | }; | 194 | }; |
160 | 195 | ||
161 | enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto}; | 196 | enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, |
197 | Opt_indirect, Opt_direct, Opt_offset}; | ||
162 | 198 | ||
163 | static match_table_t tokens = { | 199 | static match_table_t tokens = { |
164 | {Opt_fd, "fd=%u"}, | 200 | {Opt_fd, "fd=%u"}, |
@@ -167,11 +203,15 @@ static match_table_t tokens = { | |||
167 | {Opt_pgrp, "pgrp=%u"}, | 203 | {Opt_pgrp, "pgrp=%u"}, |
168 | {Opt_minproto, "minproto=%u"}, | 204 | {Opt_minproto, "minproto=%u"}, |
169 | {Opt_maxproto, "maxproto=%u"}, | 205 | {Opt_maxproto, "maxproto=%u"}, |
206 | {Opt_indirect, "indirect"}, | ||
207 | {Opt_direct, "direct"}, | ||
208 | {Opt_offset, "offset"}, | ||
170 | {Opt_err, NULL} | 209 | {Opt_err, NULL} |
171 | }; | 210 | }; |
172 | 211 | ||
173 | static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, | 212 | static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, |
174 | pid_t *pgrp, int *minproto, int *maxproto) | 213 | pid_t *pgrp, unsigned int *type, |
214 | int *minproto, int *maxproto) | ||
175 | { | 215 | { |
176 | char *p; | 216 | char *p; |
177 | substring_t args[MAX_OPT_ARGS]; | 217 | substring_t args[MAX_OPT_ARGS]; |
@@ -225,6 +265,15 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, | |||
225 | return 1; | 265 | return 1; |
226 | *maxproto = option; | 266 | *maxproto = option; |
227 | break; | 267 | break; |
268 | case Opt_indirect: | ||
269 | *type = AUTOFS_TYPE_INDIRECT; | ||
270 | break; | ||
271 | case Opt_direct: | ||
272 | *type = AUTOFS_TYPE_DIRECT; | ||
273 | break; | ||
274 | case Opt_offset: | ||
275 | *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET; | ||
276 | break; | ||
228 | default: | 277 | default: |
229 | return 1; | 278 | return 1; |
230 | } | 279 | } |
@@ -243,6 +292,10 @@ static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi) | |||
243 | return ino; | 292 | return ino; |
244 | } | 293 | } |
245 | 294 | ||
295 | static struct dentry_operations autofs4_sb_dentry_operations = { | ||
296 | .d_release = autofs4_dentry_release, | ||
297 | }; | ||
298 | |||
246 | int autofs4_fill_super(struct super_block *s, void *data, int silent) | 299 | int autofs4_fill_super(struct super_block *s, void *data, int silent) |
247 | { | 300 | { |
248 | struct inode * root_inode; | 301 | struct inode * root_inode; |
@@ -251,7 +304,6 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) | |||
251 | int pipefd; | 304 | int pipefd; |
252 | struct autofs_sb_info *sbi; | 305 | struct autofs_sb_info *sbi; |
253 | struct autofs_info *ino; | 306 | struct autofs_info *ino; |
254 | int minproto, maxproto; | ||
255 | 307 | ||
256 | sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL); | 308 | sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL); |
257 | if ( !sbi ) | 309 | if ( !sbi ) |
@@ -263,13 +315,17 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) | |||
263 | s->s_fs_info = sbi; | 315 | s->s_fs_info = sbi; |
264 | sbi->magic = AUTOFS_SBI_MAGIC; | 316 | sbi->magic = AUTOFS_SBI_MAGIC; |
265 | sbi->root = NULL; | 317 | sbi->root = NULL; |
318 | sbi->pipefd = -1; | ||
266 | sbi->catatonic = 0; | 319 | sbi->catatonic = 0; |
267 | sbi->exp_timeout = 0; | 320 | sbi->exp_timeout = 0; |
268 | sbi->oz_pgrp = process_group(current); | 321 | sbi->oz_pgrp = process_group(current); |
269 | sbi->sb = s; | 322 | sbi->sb = s; |
270 | sbi->version = 0; | 323 | sbi->version = 0; |
271 | sbi->sub_version = 0; | 324 | sbi->sub_version = 0; |
272 | init_MUTEX(&sbi->wq_sem); | 325 | sbi->type = 0; |
326 | sbi->min_proto = 0; | ||
327 | sbi->max_proto = 0; | ||
328 | mutex_init(&sbi->wq_mutex); | ||
273 | spin_lock_init(&sbi->fs_lock); | 329 | spin_lock_init(&sbi->fs_lock); |
274 | sbi->queues = NULL; | 330 | sbi->queues = NULL; |
275 | s->s_blocksize = 1024; | 331 | s->s_blocksize = 1024; |
@@ -285,38 +341,46 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) | |||
285 | if (!ino) | 341 | if (!ino) |
286 | goto fail_free; | 342 | goto fail_free; |
287 | root_inode = autofs4_get_inode(s, ino); | 343 | root_inode = autofs4_get_inode(s, ino); |
288 | kfree(ino); | ||
289 | if (!root_inode) | 344 | if (!root_inode) |
290 | goto fail_free; | 345 | goto fail_ino; |
291 | 346 | ||
292 | root_inode->i_op = &autofs4_root_inode_operations; | ||
293 | root_inode->i_fop = &autofs4_root_operations; | ||
294 | root = d_alloc_root(root_inode); | 347 | root = d_alloc_root(root_inode); |
295 | pipe = NULL; | ||
296 | |||
297 | if (!root) | 348 | if (!root) |
298 | goto fail_iput; | 349 | goto fail_iput; |
350 | pipe = NULL; | ||
351 | |||
352 | root->d_op = &autofs4_sb_dentry_operations; | ||
353 | root->d_fsdata = ino; | ||
299 | 354 | ||
300 | /* Can this call block? */ | 355 | /* Can this call block? */ |
301 | if (parse_options(data, &pipefd, | 356 | if (parse_options(data, &pipefd, |
302 | &root_inode->i_uid, &root_inode->i_gid, | 357 | &root_inode->i_uid, &root_inode->i_gid, |
303 | &sbi->oz_pgrp, | 358 | &sbi->oz_pgrp, &sbi->type, |
304 | &minproto, &maxproto)) { | 359 | &sbi->min_proto, &sbi->max_proto)) { |
305 | printk("autofs: called with bogus options\n"); | 360 | printk("autofs: called with bogus options\n"); |
306 | goto fail_dput; | 361 | goto fail_dput; |
307 | } | 362 | } |
308 | 363 | ||
364 | root_inode->i_fop = &autofs4_root_operations; | ||
365 | root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ? | ||
366 | &autofs4_direct_root_inode_operations : | ||
367 | &autofs4_indirect_root_inode_operations; | ||
368 | |||
309 | /* Couldn't this be tested earlier? */ | 369 | /* Couldn't this be tested earlier? */ |
310 | if (maxproto < AUTOFS_MIN_PROTO_VERSION || | 370 | if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION || |
311 | minproto > AUTOFS_MAX_PROTO_VERSION) { | 371 | sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) { |
312 | printk("autofs: kernel does not match daemon version " | 372 | printk("autofs: kernel does not match daemon version " |
313 | "daemon (%d, %d) kernel (%d, %d)\n", | 373 | "daemon (%d, %d) kernel (%d, %d)\n", |
314 | minproto, maxproto, | 374 | sbi->min_proto, sbi->max_proto, |
315 | AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION); | 375 | AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION); |
316 | goto fail_dput; | 376 | goto fail_dput; |
317 | } | 377 | } |
318 | 378 | ||
319 | sbi->version = maxproto > AUTOFS_MAX_PROTO_VERSION ? AUTOFS_MAX_PROTO_VERSION : maxproto; | 379 | /* Establish highest kernel protocol version */ |
380 | if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION) | ||
381 | sbi->version = AUTOFS_MAX_PROTO_VERSION; | ||
382 | else | ||
383 | sbi->version = sbi->max_proto; | ||
320 | sbi->sub_version = AUTOFS_PROTO_SUBVERSION; | 384 | sbi->sub_version = AUTOFS_PROTO_SUBVERSION; |
321 | 385 | ||
322 | DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp); | 386 | DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp); |
@@ -329,6 +393,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent) | |||
329 | if ( !pipe->f_op || !pipe->f_op->write ) | 393 | if ( !pipe->f_op || !pipe->f_op->write ) |
330 | goto fail_fput; | 394 | goto fail_fput; |
331 | sbi->pipe = pipe; | 395 | sbi->pipe = pipe; |
396 | sbi->pipefd = pipefd; | ||
332 | 397 | ||
333 | /* | 398 | /* |
334 | * Take a reference to the root dentry so we get a chance to | 399 | * Take a reference to the root dentry so we get a chance to |
@@ -356,6 +421,8 @@ fail_dput: | |||
356 | fail_iput: | 421 | fail_iput: |
357 | printk("autofs: get root dentry failed\n"); | 422 | printk("autofs: get root dentry failed\n"); |
358 | iput(root_inode); | 423 | iput(root_inode); |
424 | fail_ino: | ||
425 | kfree(ino); | ||
359 | fail_free: | 426 | fail_free: |
360 | kfree(sbi); | 427 | kfree(sbi); |
361 | fail_unlock: | 428 | fail_unlock: |