1
2
3
4
5
6
7
8
9
10
11
12#include <linux/auto_fs4.h>
13#include <linux/auto_dev-ioctl.h>
14#include <linux/mutex.h>
15#include <linux/spinlock.h>
16#include <linux/list.h>
17
18
19#define AUTOFS_IOC_FIRST AUTOFS_IOC_READY
20#define AUTOFS_IOC_COUNT 32
21
22#define AUTOFS_DEV_IOCTL_IOC_FIRST (AUTOFS_DEV_IOCTL_VERSION)
23#define AUTOFS_DEV_IOCTL_IOC_COUNT (AUTOFS_IOC_COUNT - 11)
24
25#include <linux/kernel.h>
26#include <linux/slab.h>
27#include <linux/time.h>
28#include <linux/string.h>
29#include <linux/wait.h>
30#include <linux/sched.h>
31#include <linux/mount.h>
32#include <linux/namei.h>
33#include <asm/current.h>
34#include <linux/uaccess.h>
35
36
37
38#ifdef pr_fmt
39#undef pr_fmt
40#endif
41#define pr_fmt(fmt) KBUILD_MODNAME ":pid:%d:%s: " fmt, current->pid, __func__
42
43
44
45
46
47
48
49
50
51struct autofs_info {
52 struct dentry *dentry;
53 struct inode *inode;
54
55 int flags;
56
57 struct completion expire_complete;
58
59 struct list_head active;
60 int active_count;
61
62 struct list_head expiring;
63
64 struct autofs_sb_info *sbi;
65 unsigned long last_used;
66 atomic_t count;
67
68 kuid_t uid;
69 kgid_t gid;
70};
71
72#define AUTOFS_INF_EXPIRING (1<<0)
73#define AUTOFS_INF_WANT_EXPIRE (1<<1)
74
75
76
77
78
79
80
81#define AUTOFS_INF_PENDING (1<<2)
82
83struct autofs_wait_queue {
84 wait_queue_head_t queue;
85 struct autofs_wait_queue *next;
86 autofs_wqt_t wait_queue_token;
87
88 struct qstr name;
89 u32 dev;
90 u64 ino;
91 kuid_t uid;
92 kgid_t gid;
93 pid_t pid;
94 pid_t tgid;
95
96 int status;
97 unsigned int wait_ctr;
98};
99
100#define AUTOFS_SBI_MAGIC 0x6d4a556d
101
102struct autofs_sb_info {
103 u32 magic;
104 int pipefd;
105 struct file *pipe;
106 struct pid *oz_pgrp;
107 int catatonic;
108 int version;
109 int sub_version;
110 int min_proto;
111 int max_proto;
112 unsigned long exp_timeout;
113 unsigned int type;
114 int reghost_enabled;
115 int needs_reghost;
116 struct super_block *sb;
117 struct mutex wq_mutex;
118 struct mutex pipe_mutex;
119 spinlock_t fs_lock;
120 struct autofs_wait_queue *queues;
121 spinlock_t lookup_lock;
122 struct list_head active_list;
123 struct list_head expiring_list;
124 struct rcu_head rcu;
125};
126
127static inline struct autofs_sb_info *autofs4_sbi(struct super_block *sb)
128{
129 return (struct autofs_sb_info *)(sb->s_fs_info);
130}
131
132static inline struct autofs_info *autofs4_dentry_ino(struct dentry *dentry)
133{
134 return (struct autofs_info *)(dentry->d_fsdata);
135}
136
137
138
139
140
141static inline int autofs4_oz_mode(struct autofs_sb_info *sbi)
142{
143 return sbi->catatonic || task_pgrp(current) == sbi->oz_pgrp;
144}
145
146struct inode *autofs4_get_inode(struct super_block *, umode_t);
147void autofs4_free_ino(struct autofs_info *);
148
149
150int is_autofs4_dentry(struct dentry *);
151int autofs4_expire_wait(struct dentry *dentry, int rcu_walk);
152int autofs4_expire_run(struct super_block *, struct vfsmount *,
153 struct autofs_sb_info *,
154 struct autofs_packet_expire __user *);
155int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt,
156 struct autofs_sb_info *sbi, int when);
157int autofs4_expire_multi(struct super_block *, struct vfsmount *,
158 struct autofs_sb_info *, int __user *);
159struct dentry *autofs4_expire_direct(struct super_block *sb,
160 struct vfsmount *mnt,
161 struct autofs_sb_info *sbi, int how);
162struct dentry *autofs4_expire_indirect(struct super_block *sb,
163 struct vfsmount *mnt,
164 struct autofs_sb_info *sbi, int how);
165
166
167
168int autofs_dev_ioctl_init(void);
169void autofs_dev_ioctl_exit(void);
170
171
172
173extern const struct inode_operations autofs4_symlink_inode_operations;
174extern const struct inode_operations autofs4_dir_inode_operations;
175extern const struct file_operations autofs4_dir_operations;
176extern const struct file_operations autofs4_root_operations;
177extern const struct dentry_operations autofs4_dentry_operations;
178
179
180static inline void __managed_dentry_set_managed(struct dentry *dentry)
181{
182 dentry->d_flags |= (DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT);
183}
184
185static inline void managed_dentry_set_managed(struct dentry *dentry)
186{
187 spin_lock(&dentry->d_lock);
188 __managed_dentry_set_managed(dentry);
189 spin_unlock(&dentry->d_lock);
190}
191
192static inline void __managed_dentry_clear_managed(struct dentry *dentry)
193{
194 dentry->d_flags &= ~(DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT);
195}
196
197static inline void managed_dentry_clear_managed(struct dentry *dentry)
198{
199 spin_lock(&dentry->d_lock);
200 __managed_dentry_clear_managed(dentry);
201 spin_unlock(&dentry->d_lock);
202}
203
204
205
206int autofs4_fill_super(struct super_block *, void *, int);
207struct autofs_info *autofs4_new_ino(struct autofs_sb_info *);
208void autofs4_clean_ino(struct autofs_info *);
209
210static inline int autofs_prepare_pipe(struct file *pipe)
211{
212 if (!(pipe->f_mode & FMODE_CAN_WRITE))
213 return -EINVAL;
214 if (!S_ISFIFO(file_inode(pipe)->i_mode))
215 return -EINVAL;
216
217 pipe->f_flags |= O_DIRECT;
218 return 0;
219}
220
221
222
223int autofs4_wait(struct autofs_sb_info *, struct dentry *, enum autofs_notify);
224int autofs4_wait_release(struct autofs_sb_info *, autofs_wqt_t, int);
225void autofs4_catatonic_mode(struct autofs_sb_info *);
226
227static inline u32 autofs4_get_dev(struct autofs_sb_info *sbi)
228{
229 return new_encode_dev(sbi->sb->s_dev);
230}
231
232static inline u64 autofs4_get_ino(struct autofs_sb_info *sbi)
233{
234 return d_inode(sbi->sb->s_root)->i_ino;
235}
236
237static inline void __autofs4_add_expiring(struct dentry *dentry)
238{
239 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
240 struct autofs_info *ino = autofs4_dentry_ino(dentry);
241
242 if (ino) {
243 if (list_empty(&ino->expiring))
244 list_add(&ino->expiring, &sbi->expiring_list);
245 }
246}
247
248static inline void autofs4_add_expiring(struct dentry *dentry)
249{
250 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
251 struct autofs_info *ino = autofs4_dentry_ino(dentry);
252
253 if (ino) {
254 spin_lock(&sbi->lookup_lock);
255 if (list_empty(&ino->expiring))
256 list_add(&ino->expiring, &sbi->expiring_list);
257 spin_unlock(&sbi->lookup_lock);
258 }
259}
260
261static inline void autofs4_del_expiring(struct dentry *dentry)
262{
263 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);
264 struct autofs_info *ino = autofs4_dentry_ino(dentry);
265
266 if (ino) {
267 spin_lock(&sbi->lookup_lock);
268 if (!list_empty(&ino->expiring))
269 list_del_init(&ino->expiring);
270 spin_unlock(&sbi->lookup_lock);
271 }
272}
273
274extern void autofs4_kill_sb(struct super_block *);
275