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 | { |
| 99 | struct dentry *this_parent = sbi->root; |
| 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 | |
| 130 | if (this_parent != sbi->root) { |
| 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); |
| 143 | |
| 144 | dput(sbi->root); |
| 145 | sbi->root = NULL; |
| 146 | shrink_dcache_sb(sbi->sb); |
| 147 | |
| 148 | return; |
| 149 | } |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | static void autofs4_put_super(struct super_block *sb) |
| 152 | { |
| 153 | struct autofs_sb_info *sbi = autofs4_sbi(sb); |
| 154 | |
| 155 | sb->s_fs_info = NULL; |
| 156 | |
| 157 | if ( !sbi->catatonic ) |
| 158 | autofs4_catatonic_mode(sbi); /* Free wait queues, close pipe */ |
| 159 | |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 160 | /* Clean up and release dangling references */ |
Dave Jones | 3370c74 | 2006-03-27 01:14:57 -0800 | [diff] [blame] | 161 | autofs4_force_release(sbi); |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | kfree(sbi); |
| 164 | |
| 165 | DPRINTK("shutting down"); |
| 166 | } |
| 167 | |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 168 | static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 169 | { |
| 170 | struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb); |
| 171 | |
| 172 | if (!sbi) |
| 173 | return 0; |
| 174 | |
| 175 | seq_printf(m, ",fd=%d", sbi->pipefd); |
| 176 | seq_printf(m, ",pgrp=%d", sbi->oz_pgrp); |
| 177 | seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ); |
| 178 | seq_printf(m, ",minproto=%d", sbi->min_proto); |
| 179 | seq_printf(m, ",maxproto=%d", sbi->max_proto); |
| 180 | |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 181 | if (sbi->type & AUTOFS_TYPE_OFFSET) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 182 | seq_printf(m, ",offset"); |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 183 | else if (sbi->type & AUTOFS_TYPE_DIRECT) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 184 | seq_printf(m, ",direct"); |
| 185 | else |
| 186 | seq_printf(m, ",indirect"); |
| 187 | |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | static struct super_operations autofs4_sops = { |
| 192 | .put_super = autofs4_put_super, |
| 193 | .statfs = simple_statfs, |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 194 | .show_options = autofs4_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 197 | enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto, |
| 198 | Opt_indirect, Opt_direct, Opt_offset}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | static match_table_t tokens = { |
| 201 | {Opt_fd, "fd=%u"}, |
| 202 | {Opt_uid, "uid=%u"}, |
| 203 | {Opt_gid, "gid=%u"}, |
| 204 | {Opt_pgrp, "pgrp=%u"}, |
| 205 | {Opt_minproto, "minproto=%u"}, |
| 206 | {Opt_maxproto, "maxproto=%u"}, |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 207 | {Opt_indirect, "indirect"}, |
| 208 | {Opt_direct, "direct"}, |
| 209 | {Opt_offset, "offset"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | {Opt_err, NULL} |
| 211 | }; |
| 212 | |
| 213 | 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] | 214 | pid_t *pgrp, unsigned int *type, |
| 215 | int *minproto, int *maxproto) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | char *p; |
| 218 | substring_t args[MAX_OPT_ARGS]; |
| 219 | int option; |
| 220 | |
| 221 | *uid = current->uid; |
| 222 | *gid = current->gid; |
| 223 | *pgrp = process_group(current); |
| 224 | |
| 225 | *minproto = AUTOFS_MIN_PROTO_VERSION; |
| 226 | *maxproto = AUTOFS_MAX_PROTO_VERSION; |
| 227 | |
| 228 | *pipefd = -1; |
| 229 | |
| 230 | if (!options) |
| 231 | return 1; |
| 232 | |
| 233 | while ((p = strsep(&options, ",")) != NULL) { |
| 234 | int token; |
| 235 | if (!*p) |
| 236 | continue; |
| 237 | |
| 238 | token = match_token(p, tokens, args); |
| 239 | switch (token) { |
| 240 | case Opt_fd: |
| 241 | if (match_int(args, pipefd)) |
| 242 | return 1; |
| 243 | break; |
| 244 | case Opt_uid: |
| 245 | if (match_int(args, &option)) |
| 246 | return 1; |
| 247 | *uid = option; |
| 248 | break; |
| 249 | case Opt_gid: |
| 250 | if (match_int(args, &option)) |
| 251 | return 1; |
| 252 | *gid = option; |
| 253 | break; |
| 254 | case Opt_pgrp: |
| 255 | if (match_int(args, &option)) |
| 256 | return 1; |
| 257 | *pgrp = option; |
| 258 | break; |
| 259 | case Opt_minproto: |
| 260 | if (match_int(args, &option)) |
| 261 | return 1; |
| 262 | *minproto = option; |
| 263 | break; |
| 264 | case Opt_maxproto: |
| 265 | if (match_int(args, &option)) |
| 266 | return 1; |
| 267 | *maxproto = option; |
| 268 | break; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 269 | case Opt_indirect: |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 270 | *type = AUTOFS_TYPE_INDIRECT; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 271 | break; |
| 272 | case Opt_direct: |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 273 | *type = AUTOFS_TYPE_DIRECT; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 274 | break; |
| 275 | case Opt_offset: |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 276 | *type = AUTOFS_TYPE_DIRECT | AUTOFS_TYPE_OFFSET; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 277 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | default: |
| 279 | return 1; |
| 280 | } |
| 281 | } |
| 282 | return (*pipefd < 0); |
| 283 | } |
| 284 | |
| 285 | static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi) |
| 286 | { |
| 287 | struct autofs_info *ino; |
| 288 | |
| 289 | ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755); |
| 290 | if (!ino) |
| 291 | return NULL; |
| 292 | |
| 293 | return ino; |
| 294 | } |
| 295 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 296 | static struct dentry_operations autofs4_sb_dentry_operations = { |
| 297 | .d_release = autofs4_dentry_release, |
| 298 | }; |
| 299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | int autofs4_fill_super(struct super_block *s, void *data, int silent) |
| 301 | { |
| 302 | struct inode * root_inode; |
| 303 | struct dentry * root; |
| 304 | struct file * pipe; |
| 305 | int pipefd; |
| 306 | struct autofs_sb_info *sbi; |
| 307 | struct autofs_info *ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | sbi = (struct autofs_sb_info *) kmalloc(sizeof(*sbi), GFP_KERNEL); |
| 310 | if ( !sbi ) |
| 311 | goto fail_unlock; |
| 312 | DPRINTK("starting up, sbi = %p",sbi); |
| 313 | |
| 314 | memset(sbi, 0, sizeof(*sbi)); |
| 315 | |
| 316 | s->s_fs_info = sbi; |
| 317 | sbi->magic = AUTOFS_SBI_MAGIC; |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 318 | sbi->root = NULL; |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 319 | sbi->pipefd = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | sbi->catatonic = 0; |
| 321 | sbi->exp_timeout = 0; |
| 322 | sbi->oz_pgrp = process_group(current); |
| 323 | sbi->sb = s; |
| 324 | sbi->version = 0; |
| 325 | sbi->sub_version = 0; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 326 | sbi->type = 0; |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 327 | sbi->min_proto = 0; |
| 328 | sbi->max_proto = 0; |
Ingo Molnar | 1d5599e | 2006-03-23 03:00:41 -0800 | [diff] [blame] | 329 | mutex_init(&sbi->wq_mutex); |
Ian Kent | 3a9720c | 2005-05-01 08:59:17 -0700 | [diff] [blame] | 330 | spin_lock_init(&sbi->fs_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | sbi->queues = NULL; |
| 332 | s->s_blocksize = 1024; |
| 333 | s->s_blocksize_bits = 10; |
| 334 | s->s_magic = AUTOFS_SUPER_MAGIC; |
| 335 | s->s_op = &autofs4_sops; |
| 336 | s->s_time_gran = 1; |
| 337 | |
| 338 | /* |
| 339 | * Get the root inode and dentry, but defer checking for errors. |
| 340 | */ |
| 341 | ino = autofs4_mkroot(sbi); |
| 342 | if (!ino) |
| 343 | goto fail_free; |
| 344 | root_inode = autofs4_get_inode(s, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | if (!root_inode) |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 346 | goto fail_ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | root = d_alloc_root(root_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if (!root) |
| 350 | goto fail_iput; |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 351 | pipe = NULL; |
| 352 | |
| 353 | root->d_op = &autofs4_sb_dentry_operations; |
| 354 | root->d_fsdata = ino; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /* Can this call block? */ |
| 357 | if (parse_options(data, &pipefd, |
| 358 | &root_inode->i_uid, &root_inode->i_gid, |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 359 | &sbi->oz_pgrp, &sbi->type, |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 360 | &sbi->min_proto, &sbi->max_proto)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | printk("autofs: called with bogus options\n"); |
| 362 | goto fail_dput; |
| 363 | } |
| 364 | |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 365 | root_inode->i_fop = &autofs4_root_operations; |
Ian Kent | 44d53eb | 2006-03-27 01:14:56 -0800 | [diff] [blame] | 366 | root_inode->i_op = sbi->type & AUTOFS_TYPE_DIRECT ? |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 367 | &autofs4_direct_root_inode_operations : |
| 368 | &autofs4_indirect_root_inode_operations; |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* Couldn't this be tested earlier? */ |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 371 | if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION || |
| 372 | sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | printk("autofs: kernel does not match daemon version " |
| 374 | "daemon (%d, %d) kernel (%d, %d)\n", |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 375 | sbi->min_proto, sbi->max_proto, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION); |
| 377 | goto fail_dput; |
| 378 | } |
| 379 | |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 380 | /* Establish highest kernel protocol version */ |
| 381 | if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION) |
| 382 | sbi->version = AUTOFS_MAX_PROTO_VERSION; |
| 383 | else |
| 384 | sbi->version = sbi->max_proto; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | sbi->sub_version = AUTOFS_PROTO_SUBVERSION; |
| 386 | |
| 387 | DPRINTK("pipe fd = %d, pgrp = %u", pipefd, sbi->oz_pgrp); |
| 388 | pipe = fget(pipefd); |
| 389 | |
| 390 | if ( !pipe ) { |
| 391 | printk("autofs: could not open pipe file descriptor\n"); |
| 392 | goto fail_dput; |
| 393 | } |
| 394 | if ( !pipe->f_op || !pipe->f_op->write ) |
| 395 | goto fail_fput; |
| 396 | sbi->pipe = pipe; |
Ian Kent | d7c4a5f | 2006-03-27 01:14:49 -0800 | [diff] [blame] | 397 | sbi->pipefd = pipefd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | /* |
Ian Kent | 104e49f | 2005-07-27 11:43:45 -0700 | [diff] [blame] | 400 | * Take a reference to the root dentry so we get a chance to |
| 401 | * clean up the dentry tree on umount. |
| 402 | * See autofs4_force_release. |
| 403 | */ |
| 404 | sbi->root = dget(root); |
| 405 | |
| 406 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | * Success! Install the root dentry now to indicate completion. |
| 408 | */ |
| 409 | s->s_root = root; |
| 410 | return 0; |
| 411 | |
| 412 | /* |
| 413 | * Failure ... clean up. |
| 414 | */ |
| 415 | fail_fput: |
| 416 | printk("autofs: pipe file descriptor does not contain proper ops\n"); |
| 417 | fput(pipe); |
| 418 | /* fall through */ |
| 419 | fail_dput: |
| 420 | dput(root); |
| 421 | goto fail_free; |
| 422 | fail_iput: |
| 423 | printk("autofs: get root dentry failed\n"); |
| 424 | iput(root_inode); |
Ian Kent | 34ca959 | 2006-03-27 01:14:54 -0800 | [diff] [blame] | 425 | fail_ino: |
| 426 | kfree(ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | fail_free: |
| 428 | kfree(sbi); |
| 429 | fail_unlock: |
| 430 | return -EINVAL; |
| 431 | } |
| 432 | |
| 433 | struct inode *autofs4_get_inode(struct super_block *sb, |
| 434 | struct autofs_info *inf) |
| 435 | { |
| 436 | struct inode *inode = new_inode(sb); |
| 437 | |
| 438 | if (inode == NULL) |
| 439 | return NULL; |
| 440 | |
| 441 | inf->inode = inode; |
| 442 | inode->i_mode = inf->mode; |
| 443 | if (sb->s_root) { |
| 444 | inode->i_uid = sb->s_root->d_inode->i_uid; |
| 445 | inode->i_gid = sb->s_root->d_inode->i_gid; |
| 446 | } else { |
| 447 | inode->i_uid = 0; |
| 448 | inode->i_gid = 0; |
| 449 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | inode->i_blocks = 0; |
| 451 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 452 | |
| 453 | if (S_ISDIR(inf->mode)) { |
| 454 | inode->i_nlink = 2; |
| 455 | inode->i_op = &autofs4_dir_inode_operations; |
| 456 | inode->i_fop = &autofs4_dir_operations; |
| 457 | } else if (S_ISLNK(inf->mode)) { |
| 458 | inode->i_size = inf->size; |
| 459 | inode->i_op = &autofs4_symlink_inode_operations; |
| 460 | } |
| 461 | |
| 462 | return inode; |
| 463 | } |