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