Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- c -*- --------------------------------------------------------------- * |
| 2 | * |
| 3 | * linux/fs/autofs/inode.c |
| 4 | * |
| 5 | * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 6 | * Copyright 2005-2006 Ian Kent <raven@themaw.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 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. |
| 11 | * |
| 12 | * ------------------------------------------------------------------------- */ |
| 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/file.h> |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 17 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/pagemap.h> |
| 19 | #include <linux/parser.h> |
| 20 | #include <linux/bitops.h> |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 21 | #include <linux/smp_lock.h> |
Jeff Garzik | e18fa70 | 2006-09-24 11:13:19 -0400 | [diff] [blame] | 22 | #include <linux/magic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "autofs_i.h" |
| 24 | #include <linux/module.h> |
| 25 | |
| 26 | static void ino_lnkfree(struct autofs_info *ino) |
| 27 | { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 28 | kfree(ino->u.symlink); |
| 29 | ino->u.symlink = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | struct autofs_info *autofs4_init_ino(struct autofs_info *ino, |
| 33 | struct autofs_sb_info *sbi, mode_t mode) |
| 34 | { |
| 35 | int reinit = 1; |
| 36 | |
| 37 | if (ino == NULL) { |
| 38 | reinit = 0; |
| 39 | ino = kmalloc(sizeof(*ino), GFP_KERNEL); |
| 40 | } |
| 41 | |
| 42 | if (ino == NULL) |
| 43 | return NULL; |
| 44 | |
| 45 | ino->flags = 0; |
| 46 | ino->mode = mode; |
| 47 | ino->inode = NULL; |
| 48 | ino->dentry = NULL; |
| 49 | ino->size = 0; |
| 50 | |
Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 51 | INIT_LIST_HEAD(&ino->rehash); |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | ino->last_used = jiffies; |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 54 | atomic_set(&ino->count, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | ino->sbi = sbi; |
| 57 | |
| 58 | if (reinit && ino->free) |
| 59 | (ino->free)(ino); |
| 60 | |
| 61 | memset(&ino->u, 0, sizeof(ino->u)); |
| 62 | |
| 63 | ino->free = NULL; |
| 64 | |
| 65 | if (S_ISLNK(mode)) |
| 66 | ino->free = ino_lnkfree; |
| 67 | |
| 68 | return ino; |
| 69 | } |
| 70 | |
| 71 | void autofs4_free_ino(struct autofs_info *ino) |
| 72 | { |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 73 | struct autofs_info *p_ino; |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | if (ino->dentry) { |
| 76 | ino->dentry->d_fsdata = NULL; |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 77 | if (ino->dentry->d_inode) { |
| 78 | struct dentry *parent = ino->dentry->d_parent; |
| 79 | if (atomic_dec_and_test(&ino->count)) { |
| 80 | p_ino = autofs4_dentry_ino(parent); |
| 81 | if (p_ino && parent != ino->dentry) |
| 82 | atomic_dec(&p_ino->count); |
| 83 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | dput(ino->dentry); |
Ian Kent | 1aff3c8 | 2006-03-27 01:14:46 -0800 | [diff] [blame] | 85 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | ino->dentry = NULL; |
| 87 | } |
| 88 | if (ino->free) |
| 89 | (ino->free)(ino); |
| 90 | kfree(ino); |
| 91 | } |
| 92 | |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 93 | /* |
| 94 | * Deal with the infamous "Busy inodes after umount ..." message. |
| 95 | * |
| 96 | * Clean up the dentry tree. This happens with autofs if the user |
| 97 | * space program goes away due to a SIGKILL, SIGSEGV etc. |
| 98 | */ |
| 99 | static void autofs4_force_release(struct autofs_sb_info *sbi) |
| 100 | { |
David Howells | 6ce3152 | 2006-10-11 01:22:15 -0700 | [diff] [blame] | 101 | struct dentry *this_parent = sbi->sb->s_root; |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 102 | struct list_head *next; |
| 103 | |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 104 | if (!sbi->sb->s_root) |
| 105 | return; |
| 106 | |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 107 | spin_lock(&dcache_lock); |
| 108 | repeat: |
| 109 | next = this_parent->d_subdirs.next; |
| 110 | resume: |
| 111 | while (next != &this_parent->d_subdirs) { |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 112 | struct dentry *dentry = list_entry(next, struct dentry, d_u.d_child); |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 113 | |
| 114 | /* Negative dentry - don`t care */ |
| 115 | if (!simple_positive(dentry)) { |
| 116 | next = next->next; |
| 117 | continue; |
| 118 | } |
| 119 | |
| 120 | if (!list_empty(&dentry->d_subdirs)) { |
| 121 | this_parent = dentry; |
| 122 | goto repeat; |
| 123 | } |
| 124 | |
| 125 | next = next->next; |
| 126 | spin_unlock(&dcache_lock); |
| 127 | |
| 128 | DPRINTK("dentry %p %.*s", |
| 129 | dentry, (int)dentry->d_name.len, dentry->d_name.name); |
| 130 | |
| 131 | dput(dentry); |
| 132 | spin_lock(&dcache_lock); |
| 133 | } |
| 134 | |
David Howells | 6ce3152 | 2006-10-11 01:22:15 -0700 | [diff] [blame] | 135 | if (this_parent != sbi->sb->s_root) { |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 136 | struct dentry *dentry = this_parent; |
| 137 | |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 138 | next = this_parent->d_u.d_child.next; |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 139 | this_parent = this_parent->d_parent; |
| 140 | spin_unlock(&dcache_lock); |
| 141 | DPRINTK("parent dentry %p %.*s", |
| 142 | dentry, (int)dentry->d_name.len, dentry->d_name.name); |
| 143 | dput(dentry); |
| 144 | spin_lock(&dcache_lock); |
| 145 | goto resume; |
| 146 | } |
| 147 | spin_unlock(&dcache_lock); |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 148 | } |
| 149 | |
David Howells | 6ce3152 | 2006-10-11 01:22:15 -0700 | [diff] [blame] | 150 | void autofs4_kill_sb(struct super_block *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | { |
| 152 | struct autofs_sb_info *sbi = autofs4_sbi(sb); |
| 153 | |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 154 | /* |
| 155 | * In the event of a failure in get_sb_nodev the superblock |
| 156 | * info is not present so nothing else has been setup, so |
Jiri Kosina | c949d4e | 2006-12-06 20:39:38 -0800 | [diff] [blame] | 157 | * just call kill_anon_super when we are called from |
| 158 | * deactivate_super. |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 159 | */ |
| 160 | if (!sbi) |
Jiri Kosina | c949d4e | 2006-12-06 20:39:38 -0800 | [diff] [blame] | 161 | goto out_kill_sb; |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 162 | |
Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 163 | if (!sbi->catatonic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */ |
| 165 | |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 166 | /* Clean up and release dangling references */ |
Dave Jones | 3370c74 | 2006-03-27 01:14:57 -0800 | [diff] [blame] | 167 | autofs4_force_release(sbi); |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 168 | |
Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 169 | sb->s_fs_info = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | kfree(sbi); |
| 171 | |
Jiri Kosina | c949d4e | 2006-12-06 20:39:38 -0800 | [diff] [blame] | 172 | out_kill_sb: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | DPRINTK("shutting down"); |
David Howells | 6ce3152 | 2006-10-11 01:22:15 -0700 | [diff] [blame] | 174 | kill_anon_super(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 177 | static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 178 | { |
| 179 | struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb); |
| 180 | |
| 181 | if (!sbi) |
| 182 | return 0; |
| 183 | |
| 184 | seq_printf(m, ",fd=%d", sbi->pipefd); |
| 185 | seq_printf(m, ",pgrp=%d", sbi->oz_pgrp); |
| 186 | seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ); |
| 187 | seq_printf(m, ",minproto=%d", sbi->min_proto); |
| 188 | seq_printf(m, ",maxproto=%d", sbi->max_proto); |
| 189 | |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 190 | if (sbi->type & AUTOFS_TYPE_OFFSET) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 191 | seq_printf(m, ",offset"); |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 192 | else if (sbi->type & AUTOFS_TYPE_DIRECT) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 193 | seq_printf(m, ",direct"); |
| 194 | else |
| 195 | seq_printf(m, ",indirect"); |
| 196 | |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 197 | return 0; |
| 198 | } |
| 199 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 200 | static const struct super_operations autofs4_sops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | .statfs = simple_statfs, |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 202 | .show_options = autofs4_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 205 | enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, |
| 206 | Opt_indirect, Opt_direct, Opt_offset}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
| 208 | static match_table_t tokens = { |
| 209 | {Opt_fd, "fd=%u"}, |
| 210 | {Opt_uid, "uid=%u"}, |
| 211 | {Opt_gid, "gid=%u"}, |
| 212 | {Opt_pgrp, "pgrp=%u"}, |
| 213 | {Opt_minproto, "minproto=%u"}, |
| 214 | {Opt_maxproto, "maxproto=%u"}, |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 215 | {Opt_indirect, "indirect"}, |
| 216 | {Opt_direct, "direct"}, |
| 217 | {Opt_offset, "offset"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | {Opt_err, NULL} |
| 219 | }; |
| 220 | |
| 221 | static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid, |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 222 | pid_t *pgrp, unsigned int *type, |
| 223 | int *minproto, int *maxproto) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | char *p; |
| 226 | substring_t args[MAX_OPT_ARGS]; |
| 227 | int option; |
| 228 | |
| 229 | *uid = current->uid; |
| 230 | *gid = current->gid; |
| 231 | *pgrp = process_group(current); |
| 232 | |
| 233 | *minproto = AUTOFS_MIN_PROTO_VERSION; |
| 234 | *maxproto = AUTOFS_MAX_PROTO_VERSION; |
| 235 | |
| 236 | *pipefd = -1; |
| 237 | |
| 238 | if (!options) |
| 239 | return 1; |
| 240 | |
| 241 | while ((p = strsep(&options, ",")) != NULL) { |
| 242 | int token; |
| 243 | if (!*p) |
| 244 | continue; |
| 245 | |
| 246 | token = match_token(p, tokens, args); |
| 247 | switch (token) { |
| 248 | case Opt_fd: |
| 249 | if (match_int(args, pipefd)) |
| 250 | return 1; |
| 251 | break; |
| 252 | case Opt_uid: |
| 253 | if (match_int(args, &option)) |
| 254 | return 1; |
| 255 | *uid = option; |
| 256 | break; |
| 257 | case Opt_gid: |
| 258 | if (match_int(args, &option)) |
| 259 | return 1; |
| 260 | *gid = option; |
| 261 | break; |
| 262 | case Opt_pgrp: |
| 263 | if (match_int(args, &option)) |
| 264 | return 1; |
| 265 | *pgrp = option; |
| 266 | break; |
| 267 | case Opt_minproto: |
| 268 | if (match_int(args, &option)) |
| 269 | return 1; |
| 270 | *minproto = option; |
| 271 | break; |
| 272 | case Opt_maxproto: |
| 273 | if (match_int(args, &option)) |
| 274 | return 1; |
| 275 | *maxproto = option; |
| 276 | break; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 277 | case Opt_indirect: |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 278 | *type = AUTOFS_TYPE_INDIRECT; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 279 | break; |
| 280 | case Opt_direct: |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 281 | *type = AUTOFS_TYPE_DIRECT; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 282 | break; |
| 283 | case Opt_offset: |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 284 | *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 285 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | default: |
| 287 | return 1; |
| 288 | } |
| 289 | } |
| 290 | return (*pipefd < 0); |
| 291 | } |
| 292 | |
| 293 | static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi) |
| 294 | { |
| 295 | struct autofs_info *ino; |
| 296 | |
| 297 | ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755); |
| 298 | if (!ino) |
| 299 | return NULL; |
| 300 | |
| 301 | return ino; |
| 302 | } |
| 303 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 304 | static struct dentry_operations autofs4_sb_dentry_operations = { |
| 305 | .d_release = autofs4_dentry_release, |
| 306 | }; |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | int autofs4_fill_super(struct super_block *s, void *data, int silent) |
| 309 | { |
| 310 | struct inode * root_inode; |
| 311 | struct dentry * root; |
| 312 | struct file * pipe; |
| 313 | int pipefd; |
| 314 | struct autofs_sb_info *sbi; |
| 315 | struct autofs_info *ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 317 | sbi = kmalloc(sizeof(*sbi), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if ( !sbi ) |
| 319 | goto fail_unlock; |
| 320 | DPRINTK("starting up, sbi = %p",sbi); |
| 321 | |
| 322 | memset(sbi, 0, sizeof(*sbi)); |
| 323 | |
| 324 | s->s_fs_info = sbi; |
| 325 | sbi->magic = AUTOFS_SBI_MAGIC; |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 326 | sbi->pipefd = -1; |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 327 | sbi->pipe = NULL; |
| 328 | sbi->catatonic = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | sbi->exp_timeout = 0; |
| 330 | sbi->oz_pgrp = process_group(current); |
| 331 | sbi->sb = s; |
| 332 | sbi->version = 0; |
| 333 | sbi->sub_version = 0; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 334 | sbi->type = 0; |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 335 | sbi->min_proto = 0; |
| 336 | sbi->max_proto = 0; |
Ingo Molnar | 1d5599e | 2006-03-23 03:00:41 -0800 | [diff] [blame] | 337 | mutex_init(&sbi->wq_mutex); |
Ian Kent | 3a9720c | 2005-05-01 08:59:17 -0700 | [diff] [blame] | 338 | spin_lock_init(&sbi->fs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | sbi->queues = NULL; |
Ian Kent | f50b6f8 | 2007-02-20 13:58:10 -0800 | [diff] [blame] | 340 | spin_lock_init(&sbi->rehash_lock); |
| 341 | INIT_LIST_HEAD(&sbi->rehash_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | s->s_blocksize = 1024; |
| 343 | s->s_blocksize_bits = 10; |
| 344 | s->s_magic = AUTOFS_SUPER_MAGIC; |
| 345 | s->s_op = &autofs4_sops; |
| 346 | s->s_time_gran = 1; |
| 347 | |
| 348 | /* |
| 349 | * Get the root inode and dentry, but defer checking for errors. |
| 350 | */ |
| 351 | ino = autofs4_mkroot(sbi); |
| 352 | if (!ino) |
| 353 | goto fail_free; |
| 354 | root_inode = autofs4_get_inode(s, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | if (!root_inode) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 356 | goto fail_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | root = d_alloc_root(root_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (!root) |
| 360 | goto fail_iput; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 361 | pipe = NULL; |
| 362 | |
| 363 | root->d_op = &autofs4_sb_dentry_operations; |
| 364 | root->d_fsdata = ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | /* Can this call block? */ |
| 367 | if (parse_options(data, &pipefd, |
| 368 | &root_inode->i_uid, &root_inode->i_gid, |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 369 | &sbi->oz_pgrp, &sbi->type, |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 370 | &sbi->min_proto, &sbi->max_proto)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | printk("autofs: called with bogus options\n"); |
| 372 | goto fail_dput; |
| 373 | } |
| 374 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 375 | root_inode->i_fop = &autofs4_root_operations; |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 376 | root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ? |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 377 | &autofs4_direct_root_inode_operations : |
| 378 | &autofs4_indirect_root_inode_operations; |
| 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | /* Couldn't this be tested earlier? */ |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 381 | if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION || |
| 382 | sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | printk("autofs: kernel does not match daemon version " |
| 384 | "daemon (%d, %d) kernel (%d, %d)\n", |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 385 | sbi->min_proto, sbi->max_proto, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION); |
| 387 | goto fail_dput; |
| 388 | } |
| 389 | |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 390 | /* Establish highest kernel protocol version */ |
| 391 | if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION) |
| 392 | sbi->version = AUTOFS_MAX_PROTO_VERSION; |
| 393 | else |
| 394 | sbi->version = sbi->max_proto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | sbi->sub_version = AUTOFS_PROTO_SUBVERSION; |
| 396 | |
| 397 | DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp); |
| 398 | pipe = fget(pipefd); |
| 399 | |
| 400 | if ( !pipe ) { |
| 401 | printk("autofs: could not open pipe file descriptor\n"); |
| 402 | goto fail_dput; |
| 403 | } |
| 404 | if ( !pipe->f_op || !pipe->f_op->write ) |
| 405 | goto fail_fput; |
| 406 | sbi->pipe = pipe; |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 407 | sbi->pipefd = pipefd; |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 408 | sbi->catatonic = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | * Success! Install the root dentry now to indicate completion. |
| 412 | */ |
| 413 | s->s_root = root; |
| 414 | return 0; |
| 415 | |
| 416 | /* |
| 417 | * Failure ... clean up. |
| 418 | */ |
| 419 | fail_fput: |
| 420 | printk("autofs: pipe file descriptor does not contain proper ops\n"); |
| 421 | fput(pipe); |
| 422 | /* fall through */ |
| 423 | fail_dput: |
| 424 | dput(root); |
| 425 | goto fail_free; |
| 426 | fail_iput: |
| 427 | printk("autofs: get root dentry failed\n"); |
| 428 | iput(root_inode); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 429 | fail_ino: |
| 430 | kfree(ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | fail_free: |
| 432 | kfree(sbi); |
Ian Kent | ba8df43 | 2006-11-14 02:03:29 -0800 | [diff] [blame] | 433 | s->s_fs_info = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | fail_unlock: |
| 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | struct inode *autofs4_get_inode(struct super_block *sb, |
| 439 | struct autofs_info *inf) |
| 440 | { |
| 441 | struct inode *inode = new_inode(sb); |
| 442 | |
| 443 | if (inode == NULL) |
| 444 | return NULL; |
| 445 | |
| 446 | inf->inode = inode; |
| 447 | inode->i_mode = inf->mode; |
| 448 | if (sb->s_root) { |
| 449 | inode->i_uid = sb->s_root->d_inode->i_uid; |
| 450 | inode->i_gid = sb->s_root->d_inode->i_gid; |
| 451 | } else { |
| 452 | inode->i_uid = 0; |
| 453 | inode->i_gid = 0; |
| 454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | inode->i_blocks = 0; |
| 456 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 457 | |
| 458 | if (S_ISDIR(inf->mode)) { |
| 459 | inode->i_nlink = 2; |
| 460 | inode->i_op = &autofs4_dir_inode_operations; |
| 461 | inode->i_fop = &autofs4_dir_operations; |
| 462 | } else if (S_ISLNK(inf->mode)) { |
| 463 | inode->i_size = inf->size; |
| 464 | inode->i_op = &autofs4_symlink_inode_operations; |
| 465 | } |
| 466 | |
| 467 | return inode; |
| 468 | } |