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