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