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