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