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