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