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