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