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