d691005856b05 (Thomas Gleixner 2019-05-22 09:51:29 +0200 1) // SPDX-License-Identifier: GPL-2.0-or-later
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 2) /*
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 3) * Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 4) * Copyright 2005-2006 Ian Kent <raven@themaw.net>
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 5) */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 6)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 7) #include <linux/seq_file.h>
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 8) #include <linux/pagemap.h>
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 9) #include <linux/parser.h>
6471e93863d64 (Ian Kent 2018-06-07 17:11:48 -0700 10)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 11) #include "autofs_i.h"
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 12)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 13) struct autofs_info *autofs_new_ino(struct autofs_sb_info *sbi)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 14) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 15) struct autofs_info *ino;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 16)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 17) ino = kzalloc(sizeof(*ino), GFP_KERNEL);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 18) if (ino) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 19) INIT_LIST_HEAD(&ino->active);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 20) INIT_LIST_HEAD(&ino->expiring);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 21) ino->last_used = jiffies;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 22) ino->sbi = sbi;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 23) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 24) return ino;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 25) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 26)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 27) void autofs_clean_ino(struct autofs_info *ino)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 28) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 29) ino->uid = GLOBAL_ROOT_UID;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 30) ino->gid = GLOBAL_ROOT_GID;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 31) ino->last_used = jiffies;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 32) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 33)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 34) void autofs_free_ino(struct autofs_info *ino)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 35) {
ce285c267a003 (Al Viro 2019-04-02 15:17:34 -0400 36) kfree_rcu(ino, rcu);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 37) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 38)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 39) void autofs_kill_sb(struct super_block *sb)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 40) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 41) struct autofs_sb_info *sbi = autofs_sbi(sb);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 42)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 43) /*
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 44) * In the event of a failure in get_sb_nodev the superblock
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 45) * info is not present so nothing else has been setup, so
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 46) * just call kill_anon_super when we are called from
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 47) * deactivate_super.
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 48) */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 49) if (sbi) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 50) /* Free wait queues, close pipe */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 51) autofs_catatonic_mode(sbi);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 52) put_pid(sbi->oz_pgrp);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 53) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 54)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 55) pr_debug("shutting down\n");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 56) kill_litter_super(sb);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 57) if (sbi)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 58) kfree_rcu(sbi, rcu);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 59) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 60)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 61) static int autofs_show_options(struct seq_file *m, struct dentry *root)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 62) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 63) struct autofs_sb_info *sbi = autofs_sbi(root->d_sb);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 64) struct inode *root_inode = d_inode(root->d_sb->s_root);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 65)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 66) if (!sbi)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 67) return 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 68)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 69) seq_printf(m, ",fd=%d", sbi->pipefd);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 70) if (!uid_eq(root_inode->i_uid, GLOBAL_ROOT_UID))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 71) seq_printf(m, ",uid=%u",
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 72) from_kuid_munged(&init_user_ns, root_inode->i_uid));
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 73) if (!gid_eq(root_inode->i_gid, GLOBAL_ROOT_GID))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 74) seq_printf(m, ",gid=%u",
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 75) from_kgid_munged(&init_user_ns, root_inode->i_gid));
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 76) seq_printf(m, ",pgrp=%d", pid_vnr(sbi->oz_pgrp));
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 77) seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 78) seq_printf(m, ",minproto=%d", sbi->min_proto);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 79) seq_printf(m, ",maxproto=%d", sbi->max_proto);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 80)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 81) if (autofs_type_offset(sbi->type))
874d22d62bc6d (Ian Kent 2019-03-07 16:29:12 -0800 82) seq_puts(m, ",offset");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 83) else if (autofs_type_direct(sbi->type))
874d22d62bc6d (Ian Kent 2019-03-07 16:29:12 -0800 84) seq_puts(m, ",direct");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 85) else
874d22d62bc6d (Ian Kent 2019-03-07 16:29:12 -0800 86) seq_puts(m, ",indirect");
f5162216b7dab (Ian Kent 2019-01-03 15:27:43 -0800 87) if (sbi->flags & AUTOFS_SBI_STRICTEXPIRE)
874d22d62bc6d (Ian Kent 2019-03-07 16:29:12 -0800 88) seq_puts(m, ",strictexpire");
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 89) if (sbi->flags & AUTOFS_SBI_IGNORE)
874d22d62bc6d (Ian Kent 2019-03-07 16:29:12 -0800 90) seq_puts(m, ",ignore");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 91) #ifdef CONFIG_CHECKPOINT_RESTORE
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 92) if (sbi->pipe)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 93) seq_printf(m, ",pipe_ino=%ld", file_inode(sbi->pipe)->i_ino);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 94) else
874d22d62bc6d (Ian Kent 2019-03-07 16:29:12 -0800 95) seq_puts(m, ",pipe_ino=-1");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 96) #endif
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 97) return 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 98) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 99)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 100) static void autofs_evict_inode(struct inode *inode)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 101) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 102) clear_inode(inode);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 103) kfree(inode->i_private);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 104) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 105)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 106) static const struct super_operations autofs_sops = {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 107) .statfs = simple_statfs,
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 108) .show_options = autofs_show_options,
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 109) .evict_inode = autofs_evict_inode,
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 110) };
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 111)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 112) enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 113) Opt_indirect, Opt_direct, Opt_offset, Opt_strictexpire,
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 114) Opt_ignore};
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 115)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 116) static const match_table_t tokens = {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 117) {Opt_fd, "fd=%u"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 118) {Opt_uid, "uid=%u"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 119) {Opt_gid, "gid=%u"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 120) {Opt_pgrp, "pgrp=%u"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 121) {Opt_minproto, "minproto=%u"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 122) {Opt_maxproto, "maxproto=%u"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 123) {Opt_indirect, "indirect"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 124) {Opt_direct, "direct"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 125) {Opt_offset, "offset"},
f5162216b7dab (Ian Kent 2019-01-03 15:27:43 -0800 126) {Opt_strictexpire, "strictexpire"},
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 127) {Opt_ignore, "ignore"},
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 128) {Opt_err, NULL}
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 129) };
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 130)
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 131) static int parse_options(char *options,
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 132) struct inode *root, int *pgrp, bool *pgrp_set,
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 133) struct autofs_sb_info *sbi)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 134) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 135) char *p;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 136) substring_t args[MAX_OPT_ARGS];
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 137) int option;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 138) int pipefd = -1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 139) kuid_t uid;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 140) kgid_t gid;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 141)
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 142) root->i_uid = current_uid();
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 143) root->i_gid = current_gid();
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 144)
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 145) sbi->min_proto = AUTOFS_MIN_PROTO_VERSION;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 146) sbi->max_proto = AUTOFS_MAX_PROTO_VERSION;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 147)
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 148) sbi->pipefd = -1;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 149)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 150) if (!options)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 151) return 1;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 152)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 153) while ((p = strsep(&options, ",")) != NULL) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 154) int token;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 155)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 156) if (!*p)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 157) continue;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 158)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 159) token = match_token(p, tokens, args);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 160) switch (token) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 161) case Opt_fd:
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 162) if (match_int(args, &pipefd))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 163) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 164) sbi->pipefd = pipefd;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 165) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 166) case Opt_uid:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 167) if (match_int(args, &option))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 168) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 169) uid = make_kuid(current_user_ns(), option);
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 170) if (!uid_valid(uid))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 171) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 172) root->i_uid = uid;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 173) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 174) case Opt_gid:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 175) if (match_int(args, &option))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 176) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 177) gid = make_kgid(current_user_ns(), option);
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 178) if (!gid_valid(gid))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 179) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 180) root->i_gid = gid;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 181) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 182) case Opt_pgrp:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 183) if (match_int(args, &option))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 184) return 1;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 185) *pgrp = option;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 186) *pgrp_set = true;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 187) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 188) case Opt_minproto:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 189) if (match_int(args, &option))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 190) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 191) sbi->min_proto = option;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 192) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 193) case Opt_maxproto:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 194) if (match_int(args, &option))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 195) return 1;
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 196) sbi->max_proto = option;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 197) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 198) case Opt_indirect:
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 199) set_autofs_type_indirect(&sbi->type);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 200) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 201) case Opt_direct:
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 202) set_autofs_type_direct(&sbi->type);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 203) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 204) case Opt_offset:
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 205) set_autofs_type_offset(&sbi->type);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 206) break;
f5162216b7dab (Ian Kent 2019-01-03 15:27:43 -0800 207) case Opt_strictexpire:
f5162216b7dab (Ian Kent 2019-01-03 15:27:43 -0800 208) sbi->flags |= AUTOFS_SBI_STRICTEXPIRE;
f5162216b7dab (Ian Kent 2019-01-03 15:27:43 -0800 209) break;
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 210) case Opt_ignore:
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 211) sbi->flags |= AUTOFS_SBI_IGNORE;
60d6d04ca3abb (Ian Kent 2019-03-07 16:29:09 -0800 212) break;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 213) default:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 214) return 1;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 215) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 216) }
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 217) return (sbi->pipefd < 0);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 218) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 219)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 220) int autofs_fill_super(struct super_block *s, void *data, int silent)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 221) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 222) struct inode *root_inode;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 223) struct dentry *root;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 224) struct file *pipe;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 225) struct autofs_sb_info *sbi;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 226) struct autofs_info *ino;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 227) int pgrp = 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 228) bool pgrp_set = false;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 229) int ret = -EINVAL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 230)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 231) sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 232) if (!sbi)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 233) return -ENOMEM;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 234) pr_debug("starting up, sbi = %p\n", sbi);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 235)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 236) s->s_fs_info = sbi;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 237) sbi->magic = AUTOFS_SBI_MAGIC;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 238) sbi->pipefd = -1;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 239) sbi->pipe = NULL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 240) sbi->exp_timeout = 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 241) sbi->oz_pgrp = NULL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 242) sbi->sb = s;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 243) sbi->version = 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 244) sbi->sub_version = 0;
9d8719a42e467 (Ian Kent 2019-01-03 15:27:39 -0800 245) sbi->flags = AUTOFS_SBI_CATATONIC;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 246) set_autofs_type_indirect(&sbi->type);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 247) sbi->min_proto = 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 248) sbi->max_proto = 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 249) mutex_init(&sbi->wq_mutex);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 250) mutex_init(&sbi->pipe_mutex);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 251) spin_lock_init(&sbi->fs_lock);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 252) sbi->queues = NULL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 253) spin_lock_init(&sbi->lookup_lock);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 254) INIT_LIST_HEAD(&sbi->active_list);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 255) INIT_LIST_HEAD(&sbi->expiring_list);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 256) s->s_blocksize = 1024;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 257) s->s_blocksize_bits = 10;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 258) s->s_magic = AUTOFS_SUPER_MAGIC;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 259) s->s_op = &autofs_sops;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 260) s->s_d_op = &autofs_dentry_operations;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 261) s->s_time_gran = 1;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 262)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 263) /*
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 264) * Get the root inode and dentry, but defer checking for errors.
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 265) */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 266) ino = autofs_new_ino(sbi);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 267) if (!ino) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 268) ret = -ENOMEM;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 269) goto fail_free;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 270) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 271) root_inode = autofs_get_inode(s, S_IFDIR | 0755);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 272) root = d_make_root(root_inode);
f585b283e3f02 (Ian Kent 2019-02-01 14:21:29 -0800 273) if (!root) {
f585b283e3f02 (Ian Kent 2019-02-01 14:21:29 -0800 274) ret = -ENOMEM;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 275) goto fail_ino;
f585b283e3f02 (Ian Kent 2019-02-01 14:21:29 -0800 276) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 277) pipe = NULL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 278)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 279) root->d_fsdata = ino;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 280)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 281) /* Can this call block? */
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 282) if (parse_options(data, root_inode, &pgrp, &pgrp_set, sbi)) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 283) pr_err("called with bogus options\n");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 284) goto fail_dput;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 285) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 286)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 287) /* Test versions first */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 288) if (sbi->max_proto < AUTOFS_MIN_PROTO_VERSION ||
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 289) sbi->min_proto > AUTOFS_MAX_PROTO_VERSION) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 290) pr_err("kernel does not match daemon version "
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 291) "daemon (%d, %d) kernel (%d, %d)\n",
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 292) sbi->min_proto, sbi->max_proto,
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 293) AUTOFS_MIN_PROTO_VERSION, AUTOFS_MAX_PROTO_VERSION);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 294) goto fail_dput;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 295) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 296)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 297) /* Establish highest kernel protocol version */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 298) if (sbi->max_proto > AUTOFS_MAX_PROTO_VERSION)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 299) sbi->version = AUTOFS_MAX_PROTO_VERSION;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 300) else
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 301) sbi->version = sbi->max_proto;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 302) sbi->sub_version = AUTOFS_PROTO_SUBVERSION;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 303)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 304) if (pgrp_set) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 305) sbi->oz_pgrp = find_get_pid(pgrp);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 306) if (!sbi->oz_pgrp) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 307) pr_err("could not find process group %d\n",
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 308) pgrp);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 309) goto fail_dput;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 310) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 311) } else {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 312) sbi->oz_pgrp = get_task_pid(current, PIDTYPE_PGID);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 313) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 314)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 315) if (autofs_type_trigger(sbi->type))
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 316) __managed_dentry_set_managed(root);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 317)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 318) root_inode->i_fop = &autofs_root_operations;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 319) root_inode->i_op = &autofs_dir_inode_operations;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 320)
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 321) pr_debug("pipe fd = %d, pgrp = %u\n",
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 322) sbi->pipefd, pid_nr(sbi->oz_pgrp));
9bf964c9cee40 (Ian Kent 2019-01-03 15:27:36 -0800 323) pipe = fget(sbi->pipefd);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 324)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 325) if (!pipe) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 326) pr_err("could not open pipe file descriptor\n");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 327) goto fail_put_pid;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 328) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 329) ret = autofs_prepare_pipe(pipe);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 330) if (ret < 0)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 331) goto fail_fput;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 332) sbi->pipe = pipe;
9d8719a42e467 (Ian Kent 2019-01-03 15:27:39 -0800 333) sbi->flags &= ~AUTOFS_SBI_CATATONIC;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 334)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 335) /*
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 336) * Success! Install the root dentry now to indicate completion.
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 337) */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 338) s->s_root = root;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 339) return 0;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 340)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 341) /*
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 342) * Failure ... clean up.
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 343) */
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 344) fail_fput:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 345) pr_err("pipe file descriptor does not contain proper ops\n");
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 346) fput(pipe);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 347) fail_put_pid:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 348) put_pid(sbi->oz_pgrp);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 349) fail_dput:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 350) dput(root);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 351) goto fail_free;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 352) fail_ino:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 353) autofs_free_ino(ino);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 354) fail_free:
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 355) kfree(sbi);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 356) s->s_fs_info = NULL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 357) return ret;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 358) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 359)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 360) struct inode *autofs_get_inode(struct super_block *sb, umode_t mode)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 361) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 362) struct inode *inode = new_inode(sb);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 363)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 364) if (inode == NULL)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 365) return NULL;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 366)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 367) inode->i_mode = mode;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 368) if (sb->s_root) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 369) inode->i_uid = d_inode(sb->s_root)->i_uid;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 370) inode->i_gid = d_inode(sb->s_root)->i_gid;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 371) }
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 372) inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 373) inode->i_ino = get_next_ino();
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 374)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 375) if (S_ISDIR(mode)) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 376) set_nlink(inode, 2);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 377) inode->i_op = &autofs_dir_inode_operations;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 378) inode->i_fop = &autofs_dir_operations;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 379) } else if (S_ISLNK(mode)) {
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 380) inode->i_op = &autofs_symlink_inode_operations;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 381) } else
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 382) WARN_ON(1);
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 383)
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 384) return inode;
ebc921ca9b92a (Ian Kent 2018-06-07 17:11:13 -0700 385) }