]>
Commit | Line | Data |
---|---|---|
2121bcd9 | 1 | SPDX-License-Identifier: GPL-2.0 |
ffa93bbd | 2 | aufs4.x-rcN kbuild patch |
7f207e10 AM |
3 | |
4 | diff --git a/fs/Kconfig b/fs/Kconfig | |
3c1bdaff | 5 | index 7aee6d6..ec92031 100644 |
7f207e10 AM |
6 | --- a/fs/Kconfig |
7 | +++ b/fs/Kconfig | |
3c1bdaff | 8 | @@ -248,6 +248,7 @@ source "fs/pstore/Kconfig" |
5527c038 | 9 | source "fs/sysv/Kconfig" |
7e9cd9fe | 10 | source "fs/ufs/Kconfig" |
7f207e10 AM |
11 | source "fs/exofs/Kconfig" |
12 | +source "fs/aufs/Kconfig" | |
13 | ||
14 | endif # MISC_FILESYSTEMS | |
15 | ||
16 | diff --git a/fs/Makefile b/fs/Makefile | |
2121bcd9 | 17 | index ef772f1..51779e68c 100644 |
7f207e10 AM |
18 | --- a/fs/Makefile |
19 | +++ b/fs/Makefile | |
2121bcd9 | 20 | @@ -129,3 +129,4 @@ obj-y += exofs/ # Multiple modules |
7f207e10 | 21 | obj-$(CONFIG_CEPH_FS) += ceph/ |
bf0370f2 | 22 | obj-$(CONFIG_PSTORE) += pstore/ |
c06a8ce3 | 23 | obj-$(CONFIG_EFIVAR_FS) += efivarfs/ |
86dc4139 | 24 | +obj-$(CONFIG_AUFS_FS) += aufs/ |
2121bcd9 | 25 | SPDX-License-Identifier: GPL-2.0 |
ffa93bbd | 26 | aufs4.x-rcN base patch |
7f207e10 | 27 | |
c1595e42 | 28 | diff --git a/MAINTAINERS b/MAINTAINERS |
2121bcd9 | 29 | index 82ad0ea..7d8b461 100644 |
c1595e42 JR |
30 | --- a/MAINTAINERS |
31 | +++ b/MAINTAINERS | |
2121bcd9 | 32 | @@ -2478,6 +2478,19 @@ F: include/linux/audit.h |
c1595e42 JR |
33 | F: include/uapi/linux/audit.h |
34 | F: kernel/audit* | |
35 | ||
36 | +AUFS (advanced multi layered unification filesystem) FILESYSTEM | |
37 | +M: "J. R. Okajima" <hooanon05g@gmail.com> | |
38 | +L: linux-unionfs@vger.kernel.org | |
39 | +L: aufs-users@lists.sourceforge.net (members only) | |
40 | +W: http://aufs.sourceforge.net | |
5527c038 | 41 | +T: git://github.com/sfjro/aufs4-linux.git |
c1595e42 JR |
42 | +S: Supported |
43 | +F: Documentation/filesystems/aufs/ | |
44 | +F: Documentation/ABI/testing/debugfs-aufs | |
45 | +F: Documentation/ABI/testing/sysfs-aufs | |
46 | +F: fs/aufs/ | |
47 | +F: include/uapi/linux/aufs_type.h | |
48 | + | |
49 | AUXILIARY DISPLAY DRIVERS | |
50 | M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> | |
51 | W: http://miguelojeda.es/auxdisplay.htm | |
392086de | 52 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c |
2121bcd9 | 53 | index bc8e615..e51a59d 100644 |
392086de AM |
54 | --- a/drivers/block/loop.c |
55 | +++ b/drivers/block/loop.c | |
2121bcd9 | 56 | @@ -691,6 +691,24 @@ static inline int is_loop_device(struct file *file) |
392086de AM |
57 | return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR; |
58 | } | |
59 | ||
60 | +/* | |
61 | + * for AUFS | |
62 | + * no get/put for file. | |
63 | + */ | |
64 | +struct file *loop_backing_file(struct super_block *sb) | |
65 | +{ | |
66 | + struct file *ret; | |
67 | + struct loop_device *l; | |
68 | + | |
69 | + ret = NULL; | |
70 | + if (MAJOR(sb->s_dev) == LOOP_MAJOR) { | |
71 | + l = sb->s_bdev->bd_disk->private_data; | |
72 | + ret = l->lo_backing_file; | |
73 | + } | |
74 | + return ret; | |
75 | +} | |
febd17d6 | 76 | +EXPORT_SYMBOL_GPL(loop_backing_file); |
392086de AM |
77 | + |
78 | /* loop sysfs attributes */ | |
79 | ||
80 | static ssize_t loop_attr_show(struct device *dev, char *page, | |
c1595e42 | 81 | diff --git a/fs/dcache.c b/fs/dcache.c |
2121bcd9 | 82 | index 5c7df1d..019f14b 100644 |
c1595e42 JR |
83 | --- a/fs/dcache.c |
84 | +++ b/fs/dcache.c | |
3c1bdaff | 85 | @@ -1197,7 +1197,7 @@ enum d_walk_ret { |
c1595e42 JR |
86 | * |
87 | * The @enter() and @finish() callbacks are called with d_lock held. | |
88 | */ | |
89 | -static void d_walk(struct dentry *parent, void *data, | |
90 | +void d_walk(struct dentry *parent, void *data, | |
91 | enum d_walk_ret (*enter)(void *, struct dentry *), | |
92 | void (*finish)(void *)) | |
93 | { | |
febd17d6 | 94 | diff --git a/fs/fcntl.c b/fs/fcntl.c |
2121bcd9 | 95 | index 0522e28..74c255d 100644 |
febd17d6 JR |
96 | --- a/fs/fcntl.c |
97 | +++ b/fs/fcntl.c | |
2121bcd9 | 98 | @@ -32,7 +32,7 @@ |
febd17d6 JR |
99 | |
100 | #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME) | |
101 | ||
102 | -static int setfl(int fd, struct file * filp, unsigned long arg) | |
103 | +int setfl(int fd, struct file * filp, unsigned long arg) | |
104 | { | |
105 | struct inode * inode = file_inode(filp); | |
106 | int error = 0; | |
2121bcd9 | 107 | @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg) |
febd17d6 JR |
108 | |
109 | if (filp->f_op->check_flags) | |
110 | error = filp->f_op->check_flags(arg); | |
111 | + if (!error && filp->f_op->setfl) | |
112 | + error = filp->f_op->setfl(filp, arg); | |
113 | if (error) | |
114 | return error; | |
115 | ||
5afbbe0d | 116 | diff --git a/fs/inode.c b/fs/inode.c |
2121bcd9 | 117 | index 03102d6..517883c 100644 |
5afbbe0d AM |
118 | --- a/fs/inode.c |
119 | +++ b/fs/inode.c | |
8b6a4947 | 120 | @@ -1655,7 +1655,7 @@ EXPORT_SYMBOL(generic_update_time); |
5afbbe0d AM |
121 | * This does the actual work of updating an inodes time or version. Must have |
122 | * had called mnt_want_write() before calling this. | |
123 | */ | |
124 | -static int update_time(struct inode *inode, struct timespec *time, int flags) | |
125 | +int update_time(struct inode *inode, struct timespec *time, int flags) | |
126 | { | |
127 | int (*update_time)(struct inode *, struct timespec *, int); | |
128 | ||
8b6a4947 | 129 | diff --git a/fs/namespace.c b/fs/namespace.c |
2121bcd9 | 130 | index e158ec6..312bdbd8 100644 |
8b6a4947 AM |
131 | --- a/fs/namespace.c |
132 | +++ b/fs/namespace.c | |
133 | @@ -846,6 +846,12 @@ static inline int check_mnt(struct mount *mnt) | |
134 | return mnt->mnt_ns == current->nsproxy->mnt_ns; | |
135 | } | |
136 | ||
137 | +/* for aufs, CONFIG_AUFS_BR_FUSE */ | |
138 | +int is_current_mnt_ns(struct vfsmount *mnt) | |
139 | +{ | |
140 | + return check_mnt(real_mount(mnt)); | |
141 | +} | |
142 | + | |
143 | /* | |
144 | * vfsmount lock must be held for write | |
145 | */ | |
5527c038 | 146 | diff --git a/fs/read_write.c b/fs/read_write.c |
2121bcd9 | 147 | index f8547b8..0a5c47b 100644 |
5527c038 JR |
148 | --- a/fs/read_write.c |
149 | +++ b/fs/read_write.c | |
2121bcd9 | 150 | @@ -484,6 +484,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count, |
8b6a4947 | 151 | return -EINVAL; |
5527c038 | 152 | } |
5527c038 JR |
153 | |
154 | +vfs_readf_t vfs_readf(struct file *file) | |
155 | +{ | |
156 | + const struct file_operations *fop = file->f_op; | |
157 | + | |
158 | + if (fop->read) | |
159 | + return fop->read; | |
160 | + if (fop->read_iter) | |
161 | + return new_sync_read; | |
162 | + return ERR_PTR(-ENOSYS); | |
163 | +} | |
164 | + | |
165 | +vfs_writef_t vfs_writef(struct file *file) | |
166 | +{ | |
167 | + const struct file_operations *fop = file->f_op; | |
168 | + | |
169 | + if (fop->write) | |
170 | + return fop->write; | |
171 | + if (fop->write_iter) | |
172 | + return new_sync_write; | |
173 | + return ERR_PTR(-ENOSYS); | |
174 | +} | |
175 | + | |
8b6a4947 | 176 | ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) |
5527c038 JR |
177 | { |
178 | mm_segment_t old_fs; | |
7f207e10 | 179 | diff --git a/fs/splice.c b/fs/splice.c |
2121bcd9 | 180 | index 39e2dc0..c5fb195 100644 |
7f207e10 AM |
181 | --- a/fs/splice.c |
182 | +++ b/fs/splice.c | |
8b6a4947 | 183 | @@ -837,8 +837,8 @@ EXPORT_SYMBOL(generic_splice_sendpage); |
7f207e10 AM |
184 | /* |
185 | * Attempt to initiate a splice from pipe to file. | |
186 | */ | |
187 | -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
188 | - loff_t *ppos, size_t len, unsigned int flags) | |
189 | +long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
190 | + loff_t *ppos, size_t len, unsigned int flags) | |
191 | { | |
192 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, | |
193 | loff_t *, size_t, unsigned int); | |
8b6a4947 | 194 | @@ -854,9 +854,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
7f207e10 AM |
195 | /* |
196 | * Attempt to initiate a splice from a file to a pipe. | |
197 | */ | |
198 | -static long do_splice_to(struct file *in, loff_t *ppos, | |
199 | - struct pipe_inode_info *pipe, size_t len, | |
200 | - unsigned int flags) | |
201 | +long do_splice_to(struct file *in, loff_t *ppos, | |
202 | + struct pipe_inode_info *pipe, size_t len, | |
203 | + unsigned int flags) | |
204 | { | |
205 | ssize_t (*splice_read)(struct file *, loff_t *, | |
206 | struct pipe_inode_info *, size_t, unsigned int); | |
a2654f78 | 207 | diff --git a/fs/sync.c b/fs/sync.c |
2121bcd9 | 208 | index 6e0a2cb..a6891ee 100644 |
a2654f78 AM |
209 | --- a/fs/sync.c |
210 | +++ b/fs/sync.c | |
2121bcd9 | 211 | @@ -28,7 +28,7 @@ |
a2654f78 AM |
212 | * wait == 1 case since in that case write_inode() functions do |
213 | * sync_dirty_buffer() and thus effectively write one block at a time. | |
214 | */ | |
215 | -static int __sync_filesystem(struct super_block *sb, int wait) | |
216 | +int __sync_filesystem(struct super_block *sb, int wait) | |
217 | { | |
218 | if (wait) | |
219 | sync_inodes_sb(sb); | |
b912730e | 220 | diff --git a/include/linux/file.h b/include/linux/file.h |
2121bcd9 | 221 | index 279720d..76e38ea 100644 |
b912730e AM |
222 | --- a/include/linux/file.h |
223 | +++ b/include/linux/file.h | |
2121bcd9 | 224 | @@ -20,6 +20,7 @@ struct dentry; |
b912730e | 225 | struct path; |
a2654f78 | 226 | extern struct file *alloc_file(const struct path *, fmode_t mode, |
b912730e AM |
227 | const struct file_operations *fop); |
228 | +extern struct file *get_empty_filp(void); | |
229 | ||
230 | static inline void fput_light(struct file *file, int fput_needed) | |
231 | { | |
5527c038 | 232 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
2121bcd9 | 233 | index 511fbaa..96e05b3 100644 |
5527c038 JR |
234 | --- a/include/linux/fs.h |
235 | +++ b/include/linux/fs.h | |
2121bcd9 | 236 | @@ -1265,6 +1265,7 @@ extern void fasync_free(struct fasync_struct *); |
febd17d6 JR |
237 | /* can be called from interrupts */ |
238 | extern void kill_fasync(struct fasync_struct **, int, int); | |
239 | ||
240 | +extern int setfl(int fd, struct file * filp, unsigned long arg); | |
241 | extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force); | |
3c1bdaff | 242 | extern int f_setown(struct file *filp, unsigned long arg, int force); |
febd17d6 | 243 | extern void f_delown(struct file *filp); |
2121bcd9 | 244 | @@ -1712,6 +1713,7 @@ struct file_operations { |
febd17d6 JR |
245 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); |
246 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); | |
247 | int (*check_flags)(int); | |
248 | + int (*setfl)(struct file *, unsigned long); | |
249 | int (*flock) (struct file *, int, struct file_lock *); | |
250 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); | |
251 | ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); | |
2121bcd9 | 252 | @@ -1782,6 +1784,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, |
5527c038 JR |
253 | struct iovec *fast_pointer, |
254 | struct iovec **ret_pointer); | |
255 | ||
256 | +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *); | |
257 | +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t, | |
258 | + loff_t *); | |
259 | +vfs_readf_t vfs_readf(struct file *file); | |
260 | +vfs_writef_t vfs_writef(struct file *file); | |
261 | + | |
262 | extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *); | |
5527c038 | 263 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); |
8b6a4947 | 264 | extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); |
2121bcd9 | 265 | @@ -2201,6 +2209,7 @@ extern int current_umask(void); |
5afbbe0d AM |
266 | extern void ihold(struct inode * inode); |
267 | extern void iput(struct inode *); | |
268 | extern int generic_update_time(struct inode *, struct timespec *, int); | |
269 | +extern int update_time(struct inode *, struct timespec *, int); | |
270 | ||
271 | /* /sys/fs */ | |
272 | extern struct kobject *fs_kobj; | |
2121bcd9 | 273 | @@ -2481,6 +2490,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb) |
a2654f78 AM |
274 | return false; |
275 | } | |
276 | #endif | |
277 | +extern int __sync_filesystem(struct super_block *, int); | |
278 | extern int sync_filesystem(struct super_block *); | |
279 | extern const struct file_operations def_blk_fops; | |
280 | extern const struct file_operations def_chr_fops; | |
8b6a4947 | 281 | diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h |
2121bcd9 | 282 | index a842551..453e941 100644 |
8b6a4947 AM |
283 | --- a/include/linux/lockdep.h |
284 | +++ b/include/linux/lockdep.h | |
2121bcd9 | 285 | @@ -406,6 +406,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock, |
8b6a4947 AM |
286 | return lock->key == key; |
287 | } | |
288 | ||
289 | +struct lock_class *lockdep_hlock_class(struct held_lock *hlock); | |
290 | + | |
291 | /* | |
292 | * Acquire a lock. | |
293 | * | |
2121bcd9 | 294 | @@ -535,6 +537,7 @@ struct lockdep_map { }; |
8b6a4947 AM |
295 | |
296 | #define lockdep_depth(tsk) (0) | |
297 | ||
298 | +#define lockdep_is_held(lock) (1) | |
299 | #define lockdep_is_held_type(l, r) (1) | |
300 | ||
301 | #define lockdep_assert_held(l) do { (void)(l); } while (0) | |
302 | diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h | |
2121bcd9 | 303 | index 3594208..24f5fd1 100644 |
8b6a4947 AM |
304 | --- a/include/linux/mnt_namespace.h |
305 | +++ b/include/linux/mnt_namespace.h | |
2121bcd9 | 306 | @@ -6,11 +6,14 @@ |
8b6a4947 AM |
307 | struct mnt_namespace; |
308 | struct fs_struct; | |
309 | struct user_namespace; | |
310 | +struct vfsmount; | |
311 | ||
312 | extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, | |
313 | struct user_namespace *, struct fs_struct *); | |
314 | extern void put_mnt_ns(struct mnt_namespace *ns); | |
315 | ||
316 | +extern int is_current_mnt_ns(struct vfsmount *mnt); | |
317 | + | |
318 | extern const struct file_operations proc_mounts_operations; | |
319 | extern const struct file_operations proc_mountinfo_operations; | |
320 | extern const struct file_operations proc_mountstats_operations; | |
1e00d052 | 321 | diff --git a/include/linux/splice.h b/include/linux/splice.h |
2121bcd9 | 322 | index 74b4911..19789fb 100644 |
1e00d052 AM |
323 | --- a/include/linux/splice.h |
324 | +++ b/include/linux/splice.h | |
2121bcd9 | 325 | @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *); |
4b3da204 AM |
326 | |
327 | extern const struct pipe_buf_operations page_cache_pipe_buf_ops; | |
106341ce | 328 | extern const struct pipe_buf_operations default_pipe_buf_ops; |
1e00d052 AM |
329 | + |
330 | +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
331 | + loff_t *ppos, size_t len, unsigned int flags); | |
332 | +extern long do_splice_to(struct file *in, loff_t *ppos, | |
333 | + struct pipe_inode_info *pipe, size_t len, | |
334 | + unsigned int flags); | |
335 | #endif | |
8b6a4947 | 336 | diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c |
2121bcd9 | 337 | index 670d8d7..2cd0282 100644 |
8b6a4947 AM |
338 | --- a/kernel/locking/lockdep.c |
339 | +++ b/kernel/locking/lockdep.c | |
2121bcd9 | 340 | @@ -156,7 +156,7 @@ static struct lock_list list_entries[MAX_LOCKDEP_ENTRIES]; |
8b6a4947 AM |
341 | unsigned long nr_lock_classes; |
342 | static struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; | |
343 | ||
344 | -static inline struct lock_class *hlock_class(struct held_lock *hlock) | |
345 | +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock) | |
346 | { | |
347 | if (!hlock->class_idx) { | |
348 | /* | |
2121bcd9 | 349 | @@ -167,6 +167,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock) |
8b6a4947 AM |
350 | } |
351 | return lock_classes + hlock->class_idx - 1; | |
352 | } | |
353 | +#define hlock_class(hlock) lockdep_hlock_class(hlock) | |
354 | ||
355 | #ifdef CONFIG_LOCK_STAT | |
356 | static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats); | |
2121bcd9 | 357 | SPDX-License-Identifier: GPL-2.0 |
ffa93bbd | 358 | aufs4.x-rcN mmap patch |
fb47a38f | 359 | |
c1595e42 | 360 | diff --git a/fs/proc/base.c b/fs/proc/base.c |
2121bcd9 | 361 | index 60316b5..ce5314e 100644 |
c1595e42 JR |
362 | --- a/fs/proc/base.c |
363 | +++ b/fs/proc/base.c | |
8b6a4947 | 364 | @@ -1987,7 +1987,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) |
c1595e42 JR |
365 | down_read(&mm->mmap_sem); |
366 | vma = find_exact_vma(mm, vm_start, vm_end); | |
367 | if (vma && vma->vm_file) { | |
368 | - *path = vma->vm_file->f_path; | |
369 | + *path = vma_pr_or_file(vma)->f_path; | |
370 | path_get(path); | |
371 | rc = 0; | |
372 | } | |
fb47a38f | 373 | diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c |
a2654f78 | 374 | index 7563437..7c0dc0f 100644 |
fb47a38f JR |
375 | --- a/fs/proc/nommu.c |
376 | +++ b/fs/proc/nommu.c | |
076b876e | 377 | @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region) |
fb47a38f JR |
378 | file = region->vm_file; |
379 | ||
380 | if (file) { | |
381 | - struct inode *inode = file_inode(region->vm_file); | |
382 | + struct inode *inode; | |
076b876e | 383 | + |
fb47a38f JR |
384 | + file = vmr_pr_or_file(region); |
385 | + inode = file_inode(file); | |
386 | dev = inode->i_sb->s_dev; | |
387 | ino = inode->i_ino; | |
388 | } | |
389 | diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c | |
2121bcd9 | 390 | index 339e4c1..1138098 100644 |
fb47a38f JR |
391 | --- a/fs/proc/task_mmu.c |
392 | +++ b/fs/proc/task_mmu.c | |
2121bcd9 | 393 | @@ -306,7 +306,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid) |
fb47a38f JR |
394 | const char *name = NULL; |
395 | ||
396 | if (file) { | |
397 | - struct inode *inode = file_inode(vma->vm_file); | |
398 | + struct inode *inode; | |
076b876e | 399 | + |
fb47a38f JR |
400 | + file = vma_pr_or_file(vma); |
401 | + inode = file_inode(file); | |
402 | dev = inode->i_sb->s_dev; | |
403 | ino = inode->i_ino; | |
404 | pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; | |
2121bcd9 | 405 | @@ -1736,7 +1739,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid) |
076b876e AM |
406 | struct proc_maps_private *proc_priv = &numa_priv->proc_maps; |
407 | struct vm_area_struct *vma = v; | |
408 | struct numa_maps *md = &numa_priv->md; | |
409 | - struct file *file = vma->vm_file; | |
410 | + struct file *file = vma_pr_or_file(vma); | |
076b876e | 411 | struct mm_struct *mm = vma->vm_mm; |
7e9cd9fe AM |
412 | struct mm_walk walk = { |
413 | .hugetlb_entry = gather_hugetlb_stats, | |
fb47a38f | 414 | diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c |
2121bcd9 | 415 | index 5b62f57..dfb4a3b 100644 |
fb47a38f JR |
416 | --- a/fs/proc/task_nommu.c |
417 | +++ b/fs/proc/task_nommu.c | |
2121bcd9 | 418 | @@ -156,7 +156,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma, |
fb47a38f JR |
419 | file = vma->vm_file; |
420 | ||
421 | if (file) { | |
422 | - struct inode *inode = file_inode(vma->vm_file); | |
423 | + struct inode *inode; | |
076b876e | 424 | + |
b912730e | 425 | + file = vma_pr_or_file(vma); |
fb47a38f JR |
426 | + inode = file_inode(file); |
427 | dev = inode->i_sb->s_dev; | |
428 | ino = inode->i_ino; | |
429 | pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; | |
430 | diff --git a/include/linux/mm.h b/include/linux/mm.h | |
2121bcd9 | 431 | index ea818ff..fbd4799 100644 |
fb47a38f JR |
432 | --- a/include/linux/mm.h |
433 | +++ b/include/linux/mm.h | |
2121bcd9 | 434 | @@ -1362,6 +1362,28 @@ static inline int fixup_user_fault(struct task_struct *tsk, |
fb47a38f JR |
435 | } |
436 | #endif | |
437 | ||
076b876e AM |
438 | +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int); |
439 | +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[], | |
f2c43d5f | 440 | + int); |
076b876e AM |
441 | +extern void vma_do_get_file(struct vm_area_struct *, const char[], int); |
442 | +extern void vma_do_fput(struct vm_area_struct *, const char[], int); | |
fb47a38f | 443 | + |
f2c43d5f AM |
444 | +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \ |
445 | + __LINE__) | |
446 | +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \ | |
447 | + __LINE__) | |
448 | +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__) | |
449 | +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__) | |
b912730e AM |
450 | + |
451 | +#ifndef CONFIG_MMU | |
076b876e AM |
452 | +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int); |
453 | +extern void vmr_do_fput(struct vm_region *, const char[], int); | |
454 | + | |
f2c43d5f AM |
455 | +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \ |
456 | + __LINE__) | |
457 | +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__) | |
b912730e | 458 | +#endif /* !CONFIG_MMU */ |
fb47a38f | 459 | + |
106341ce AM |
460 | extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, |
461 | unsigned int gup_flags); | |
fb47a38f | 462 | extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, |
fb47a38f | 463 | diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h |
2121bcd9 | 464 | index cfd0ac4..135e11c 100644 |
fb47a38f JR |
465 | --- a/include/linux/mm_types.h |
466 | +++ b/include/linux/mm_types.h | |
2121bcd9 | 467 | @@ -255,6 +255,7 @@ struct vm_region { |
fb47a38f JR |
468 | unsigned long vm_top; /* region allocated to here */ |
469 | unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */ | |
470 | struct file *vm_file; /* the backing file or NULL */ | |
471 | + struct file *vm_prfile; /* the virtual backing file or NULL */ | |
472 | ||
473 | int vm_usage; /* region usage count (access under nommu_region_sem) */ | |
474 | bool vm_icache_flushed : 1; /* true if the icache has been flushed for | |
2121bcd9 | 475 | @@ -329,6 +330,7 @@ struct vm_area_struct { |
fb47a38f | 476 | unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE |
5afbbe0d | 477 | units */ |
fb47a38f JR |
478 | struct file * vm_file; /* File we map to (can be NULL). */ |
479 | + struct file *vm_prfile; /* shadow of vm_file */ | |
480 | void * vm_private_data; /* was vm_pte (shared mem) */ | |
481 | ||
8b6a4947 | 482 | atomic_long_t swap_readahead_info; |
fb47a38f | 483 | diff --git a/kernel/fork.c b/kernel/fork.c |
2121bcd9 | 484 | index 432eadf..8b2ba5b 100644 |
fb47a38f JR |
485 | --- a/kernel/fork.c |
486 | +++ b/kernel/fork.c | |
8b6a4947 | 487 | @@ -676,7 +676,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, |
fb47a38f JR |
488 | struct inode *inode = file_inode(file); |
489 | struct address_space *mapping = file->f_mapping; | |
490 | ||
491 | - get_file(file); | |
492 | + vma_get_file(tmp); | |
493 | if (tmp->vm_flags & VM_DENYWRITE) | |
494 | atomic_dec(&inode->i_writecount); | |
2000de60 | 495 | i_mmap_lock_write(mapping); |
076b876e | 496 | diff --git a/mm/Makefile b/mm/Makefile |
2121bcd9 | 497 | index e669f02..9c36567 100644 |
076b876e AM |
498 | --- a/mm/Makefile |
499 | +++ b/mm/Makefile | |
521ced18 | 500 | @@ -39,7 +39,7 @@ obj-y := filemap.o mempool.o oom_kill.o \ |
076b876e | 501 | mm_init.o mmu_context.o percpu.o slab_common.o \ |
521ced18 | 502 | compaction.o vmacache.o swap_slots.o \ |
076b876e | 503 | interval_tree.o list_lru.o workingset.o \ |
7e9cd9fe AM |
504 | - debug.o $(mmu-y) |
505 | + prfile.o debug.o $(mmu-y) | |
076b876e AM |
506 | |
507 | obj-y += init-mm.o | |
508 | ||
fb47a38f | 509 | diff --git a/mm/filemap.c b/mm/filemap.c |
2121bcd9 | 510 | index ee83baa..7677d13 100644 |
fb47a38f JR |
511 | --- a/mm/filemap.c |
512 | +++ b/mm/filemap.c | |
2121bcd9 | 513 | @@ -2704,7 +2704,7 @@ int filemap_page_mkwrite(struct vm_fault *vmf) |
fb47a38f JR |
514 | int ret = VM_FAULT_LOCKED; |
515 | ||
516 | sb_start_pagefault(inode->i_sb); | |
521ced18 JR |
517 | - file_update_time(vmf->vma->vm_file); |
518 | + vma_file_update_time(vmf->vma); | |
fb47a38f JR |
519 | lock_page(page); |
520 | if (page->mapping != inode->i_mapping) { | |
521 | unlock_page(page); | |
fb47a38f | 522 | diff --git a/mm/mmap.c b/mm/mmap.c |
2121bcd9 | 523 | index a4d5468..cb06cbd 100644 |
fb47a38f JR |
524 | --- a/mm/mmap.c |
525 | +++ b/mm/mmap.c | |
8b6a4947 | 526 | @@ -171,7 +171,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) |
fb47a38f JR |
527 | if (vma->vm_ops && vma->vm_ops->close) |
528 | vma->vm_ops->close(vma); | |
529 | if (vma->vm_file) | |
530 | - fput(vma->vm_file); | |
531 | + vma_fput(vma); | |
532 | mpol_put(vma_policy(vma)); | |
533 | kmem_cache_free(vm_area_cachep, vma); | |
534 | return next; | |
8b6a4947 | 535 | @@ -896,7 +896,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, |
fb47a38f JR |
536 | if (remove_next) { |
537 | if (file) { | |
538 | uprobe_munmap(next, next->vm_start, next->vm_end); | |
539 | - fput(file); | |
540 | + vma_fput(vma); | |
541 | } | |
542 | if (next->anon_vma) | |
543 | anon_vma_merge(vma, next); | |
2121bcd9 | 544 | @@ -1761,8 +1761,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, |
35939ee7 JR |
545 | return addr; |
546 | ||
fb47a38f | 547 | unmap_and_free_vma: |
fb47a38f JR |
548 | + vma_fput(vma); |
549 | vma->vm_file = NULL; | |
550 | - fput(file); | |
551 | ||
552 | /* Undo any partial mapping done by a device driver. */ | |
553 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); | |
2121bcd9 | 554 | @@ -2586,7 +2586,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
555 | goto out_free_mpol; |
556 | ||
557 | if (new->vm_file) | |
558 | - get_file(new->vm_file); | |
559 | + vma_get_file(new); | |
560 | ||
561 | if (new->vm_ops && new->vm_ops->open) | |
562 | new->vm_ops->open(new); | |
2121bcd9 | 563 | @@ -2605,7 +2605,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
564 | if (new->vm_ops && new->vm_ops->close) |
565 | new->vm_ops->close(new); | |
566 | if (new->vm_file) | |
567 | - fput(new->vm_file); | |
568 | + vma_fput(new); | |
569 | unlink_anon_vmas(new); | |
570 | out_free_mpol: | |
571 | mpol_put(vma_policy(new)); | |
2121bcd9 | 572 | @@ -2767,7 +2767,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
7e9cd9fe AM |
573 | struct vm_area_struct *vma; |
574 | unsigned long populate = 0; | |
575 | unsigned long ret = -EINVAL; | |
576 | - struct file *file; | |
5afbbe0d | 577 | + struct file *file, *prfile; |
7e9cd9fe | 578 | |
5afbbe0d AM |
579 | pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n", |
580 | current->comm, current->pid); | |
2121bcd9 | 581 | @@ -2842,10 +2842,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
febd17d6 | 582 | } |
7e9cd9fe AM |
583 | } |
584 | ||
585 | - file = get_file(vma->vm_file); | |
586 | + vma_get_file(vma); | |
5afbbe0d AM |
587 | + file = vma->vm_file; |
588 | + prfile = vma->vm_prfile; | |
7e9cd9fe | 589 | ret = do_mmap_pgoff(vma->vm_file, start, size, |
521ced18 | 590 | prot, flags, pgoff, &populate, NULL); |
5afbbe0d AM |
591 | + if (!IS_ERR_VALUE(ret) && file && prfile) { |
592 | + struct vm_area_struct *new_vma; | |
593 | + | |
594 | + new_vma = find_vma(mm, ret); | |
595 | + if (!new_vma->vm_prfile) | |
596 | + new_vma->vm_prfile = prfile; | |
597 | + if (new_vma != vma) | |
598 | + get_file(prfile); | |
599 | + } | |
600 | + /* | |
601 | + * two fput()s instead of vma_fput(vma), | |
602 | + * coz vma may not be available anymore. | |
603 | + */ | |
604 | fput(file); | |
605 | + if (prfile) | |
606 | + fput(prfile); | |
7e9cd9fe AM |
607 | out: |
608 | up_write(&mm->mmap_sem); | |
609 | if (populate) | |
2121bcd9 | 610 | @@ -3153,7 +3170,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, |
79b8bda9 AM |
611 | if (anon_vma_clone(new_vma, vma)) |
612 | goto out_free_mempol; | |
613 | if (new_vma->vm_file) | |
614 | - get_file(new_vma->vm_file); | |
615 | + vma_get_file(new_vma); | |
616 | if (new_vma->vm_ops && new_vma->vm_ops->open) | |
617 | new_vma->vm_ops->open(new_vma); | |
618 | vma_link(mm, new_vma, prev, rb_link, rb_parent); | |
fb47a38f | 619 | diff --git a/mm/nommu.c b/mm/nommu.c |
8b6a4947 | 620 | index 17c00d9..4bcdf94 100644 |
fb47a38f JR |
621 | --- a/mm/nommu.c |
622 | +++ b/mm/nommu.c | |
ffa93bbd | 623 | @@ -641,7 +641,7 @@ static void __put_nommu_region(struct vm_region *region) |
fb47a38f JR |
624 | up_write(&nommu_region_sem); |
625 | ||
626 | if (region->vm_file) | |
627 | - fput(region->vm_file); | |
628 | + vmr_fput(region); | |
629 | ||
630 | /* IO memory and memory shared directly out of the pagecache | |
631 | * from ramfs/tmpfs mustn't be released here */ | |
ffa93bbd | 632 | @@ -799,7 +799,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
fb47a38f JR |
633 | if (vma->vm_ops && vma->vm_ops->close) |
634 | vma->vm_ops->close(vma); | |
635 | if (vma->vm_file) | |
636 | - fput(vma->vm_file); | |
637 | + vma_fput(vma); | |
638 | put_nommu_region(vma->vm_region); | |
639 | kmem_cache_free(vm_area_cachep, vma); | |
640 | } | |
8b6a4947 | 641 | @@ -1321,7 +1321,7 @@ unsigned long do_mmap(struct file *file, |
fb47a38f JR |
642 | goto error_just_free; |
643 | } | |
644 | } | |
645 | - fput(region->vm_file); | |
646 | + vmr_fput(region); | |
647 | kmem_cache_free(vm_region_jar, region); | |
648 | region = pregion; | |
649 | result = start; | |
8b6a4947 | 650 | @@ -1396,10 +1396,10 @@ unsigned long do_mmap(struct file *file, |
fb47a38f JR |
651 | up_write(&nommu_region_sem); |
652 | error: | |
653 | if (region->vm_file) | |
654 | - fput(region->vm_file); | |
655 | + vmr_fput(region); | |
656 | kmem_cache_free(vm_region_jar, region); | |
657 | if (vma->vm_file) | |
658 | - fput(vma->vm_file); | |
659 | + vma_fput(vma); | |
660 | kmem_cache_free(vm_area_cachep, vma); | |
fb47a38f | 661 | return ret; |
c2c0f25c | 662 | |
076b876e AM |
663 | diff --git a/mm/prfile.c b/mm/prfile.c |
664 | new file mode 100644 | |
2121bcd9 | 665 | index 0000000..3f56669 |
076b876e AM |
666 | --- /dev/null |
667 | +++ b/mm/prfile.c | |
2121bcd9 | 668 | @@ -0,0 +1,86 @@ |
076b876e | 669 | +/* |
2121bcd9 | 670 | + * SPDX-License-Identifier: GPL-2.0 |
1c60b727 AM |
671 | + * Mainly for aufs which mmap(2) different file and wants to print different |
672 | + * path in /proc/PID/maps. | |
076b876e AM |
673 | + * Call these functions via macros defined in linux/mm.h. |
674 | + * | |
675 | + * See Documentation/filesystems/aufs/design/06mmap.txt | |
676 | + * | |
1c60b727 | 677 | + * Copyright (c) 2014-2017 Junjro R. Okajima |
076b876e AM |
678 | + * Copyright (c) 2014 Ian Campbell |
679 | + */ | |
680 | + | |
681 | +#include <linux/mm.h> | |
682 | +#include <linux/file.h> | |
683 | +#include <linux/fs.h> | |
684 | + | |
685 | +/* #define PRFILE_TRACE */ | |
686 | +static inline void prfile_trace(struct file *f, struct file *pr, | |
687 | + const char func[], int line, const char func2[]) | |
688 | +{ | |
689 | +#ifdef PRFILE_TRACE | |
690 | + if (pr) | |
1c60b727 | 691 | + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f); |
076b876e AM |
692 | +#endif |
693 | +} | |
694 | + | |
076b876e AM |
695 | +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[], |
696 | + int line) | |
697 | +{ | |
698 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
699 | + | |
700 | + prfile_trace(f, pr, func, line, __func__); | |
701 | + file_update_time(f); | |
702 | + if (f && pr) | |
703 | + file_update_time(pr); | |
704 | +} | |
705 | + | |
706 | +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[], | |
707 | + int line) | |
708 | +{ | |
709 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
710 | + | |
711 | + prfile_trace(f, pr, func, line, __func__); | |
712 | + return (f && pr) ? pr : f; | |
713 | +} | |
714 | + | |
715 | +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line) | |
716 | +{ | |
717 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
718 | + | |
719 | + prfile_trace(f, pr, func, line, __func__); | |
720 | + get_file(f); | |
721 | + if (f && pr) | |
722 | + get_file(pr); | |
723 | +} | |
724 | + | |
725 | +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line) | |
726 | +{ | |
727 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
728 | + | |
729 | + prfile_trace(f, pr, func, line, __func__); | |
730 | + fput(f); | |
731 | + if (f && pr) | |
732 | + fput(pr); | |
733 | +} | |
b912730e AM |
734 | + |
735 | +#ifndef CONFIG_MMU | |
076b876e AM |
736 | +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[], |
737 | + int line) | |
738 | +{ | |
739 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
740 | + | |
741 | + prfile_trace(f, pr, func, line, __func__); | |
742 | + return (f && pr) ? pr : f; | |
743 | +} | |
744 | + | |
745 | +void vmr_do_fput(struct vm_region *region, const char func[], int line) | |
746 | +{ | |
747 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
748 | + | |
749 | + prfile_trace(f, pr, func, line, __func__); | |
750 | + fput(f); | |
751 | + if (f && pr) | |
752 | + fput(pr); | |
753 | +} | |
b912730e | 754 | +#endif /* !CONFIG_MMU */ |
2121bcd9 | 755 | SPDX-License-Identifier: GPL-2.0 |
ffa93bbd | 756 | aufs4.x-rcN standalone patch |
7f207e10 | 757 | |
c1595e42 | 758 | diff --git a/fs/dcache.c b/fs/dcache.c |
2121bcd9 | 759 | index 019f14b..10c1a6d 100644 |
c1595e42 JR |
760 | --- a/fs/dcache.c |
761 | +++ b/fs/dcache.c | |
3c1bdaff | 762 | @@ -1305,6 +1305,7 @@ void d_walk(struct dentry *parent, void *data, |
c1595e42 JR |
763 | seq = 1; |
764 | goto again; | |
765 | } | |
febd17d6 | 766 | +EXPORT_SYMBOL_GPL(d_walk); |
c1595e42 | 767 | |
a2654f78 AM |
768 | struct check_mount { |
769 | struct vfsmount *mnt; | |
2121bcd9 | 770 | @@ -2892,6 +2893,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2) |
f2c43d5f AM |
771 | |
772 | write_sequnlock(&rename_lock); | |
773 | } | |
774 | +EXPORT_SYMBOL_GPL(d_exchange); | |
775 | ||
776 | /** | |
777 | * d_ancestor - search for an ancestor | |
79b8bda9 | 778 | diff --git a/fs/exec.c b/fs/exec.c |
2121bcd9 | 779 | index 6be2aa0..1e003f9 100644 |
79b8bda9 AM |
780 | --- a/fs/exec.c |
781 | +++ b/fs/exec.c | |
521ced18 | 782 | @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path) |
79b8bda9 AM |
783 | return (path->mnt->mnt_flags & MNT_NOEXEC) || |
784 | (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC); | |
785 | } | |
febd17d6 | 786 | +EXPORT_SYMBOL_GPL(path_noexec); |
79b8bda9 AM |
787 | |
788 | #ifdef CONFIG_USELIB | |
789 | /* | |
febd17d6 | 790 | diff --git a/fs/fcntl.c b/fs/fcntl.c |
2121bcd9 | 791 | index 74c255d..ec53ee1 100644 |
febd17d6 JR |
792 | --- a/fs/fcntl.c |
793 | +++ b/fs/fcntl.c | |
2121bcd9 | 794 | @@ -85,6 +85,7 @@ int setfl(int fd, struct file * filp, unsigned long arg) |
febd17d6 JR |
795 | out: |
796 | return error; | |
797 | } | |
798 | +EXPORT_SYMBOL_GPL(setfl); | |
799 | ||
800 | static void f_modown(struct file *filp, struct pid *pid, enum pid_type type, | |
801 | int force) | |
b912730e | 802 | diff --git a/fs/file_table.c b/fs/file_table.c |
2121bcd9 | 803 | index 2dc9f38..7bf57df 100644 |
b912730e AM |
804 | --- a/fs/file_table.c |
805 | +++ b/fs/file_table.c | |
521ced18 | 806 | @@ -148,6 +148,7 @@ struct file *get_empty_filp(void) |
b912730e AM |
807 | } |
808 | return ERR_PTR(-ENFILE); | |
809 | } | |
febd17d6 | 810 | +EXPORT_SYMBOL_GPL(get_empty_filp); |
b912730e AM |
811 | |
812 | /** | |
813 | * alloc_file - allocate and initialize a 'struct file' | |
8b6a4947 | 814 | @@ -258,6 +259,7 @@ void flush_delayed_fput(void) |
8cdd5066 JR |
815 | { |
816 | delayed_fput(NULL); | |
817 | } | |
febd17d6 | 818 | +EXPORT_SYMBOL_GPL(flush_delayed_fput); |
8cdd5066 JR |
819 | |
820 | static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput); | |
821 | ||
8b6a4947 | 822 | @@ -300,6 +302,7 @@ void __fput_sync(struct file *file) |
8cdd5066 JR |
823 | } |
824 | ||
825 | EXPORT_SYMBOL(fput); | |
febd17d6 | 826 | +EXPORT_SYMBOL_GPL(__fput_sync); |
8cdd5066 JR |
827 | |
828 | void put_filp(struct file *file) | |
829 | { | |
8b6a4947 | 830 | @@ -308,6 +311,7 @@ void put_filp(struct file *file) |
b912730e AM |
831 | file_free(file); |
832 | } | |
833 | } | |
febd17d6 | 834 | +EXPORT_SYMBOL_GPL(put_filp); |
b912730e | 835 | |
79b8bda9 | 836 | void __init files_init(void) |
8b6a4947 | 837 | { |
5afbbe0d | 838 | diff --git a/fs/inode.c b/fs/inode.c |
2121bcd9 | 839 | index 517883c..5cece5e 100644 |
5afbbe0d AM |
840 | --- a/fs/inode.c |
841 | +++ b/fs/inode.c | |
8b6a4947 | 842 | @@ -1664,6 +1664,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags) |
5afbbe0d AM |
843 | |
844 | return update_time(inode, time, flags); | |
845 | } | |
846 | +EXPORT_SYMBOL_GPL(update_time); | |
847 | ||
848 | /** | |
849 | * touch_atime - update the access time | |
7f207e10 | 850 | diff --git a/fs/namespace.c b/fs/namespace.c |
2121bcd9 | 851 | index 312bdbd8..a5baeb5 100644 |
7f207e10 AM |
852 | --- a/fs/namespace.c |
853 | +++ b/fs/namespace.c | |
8b6a4947 | 854 | @@ -517,6 +517,7 @@ void __mnt_drop_write(struct vfsmount *mnt) |
c06a8ce3 AM |
855 | mnt_dec_writers(real_mount(mnt)); |
856 | preempt_enable(); | |
857 | } | |
858 | +EXPORT_SYMBOL_GPL(__mnt_drop_write); | |
859 | ||
860 | /** | |
861 | * mnt_drop_write - give up write access to a mount | |
8b6a4947 AM |
862 | @@ -851,6 +852,7 @@ int is_current_mnt_ns(struct vfsmount *mnt) |
863 | { | |
864 | return check_mnt(real_mount(mnt)); | |
865 | } | |
866 | +EXPORT_SYMBOL_GPL(is_current_mnt_ns); | |
867 | ||
868 | /* | |
869 | * vfsmount lock must be held for write | |
870 | @@ -1887,6 +1889,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, | |
7f207e10 AM |
871 | } |
872 | return 0; | |
873 | } | |
febd17d6 | 874 | +EXPORT_SYMBOL_GPL(iterate_mounts); |
7f207e10 | 875 | |
7eafdf33 | 876 | static void cleanup_group_ids(struct mount *mnt, struct mount *end) |
7f207e10 AM |
877 | { |
878 | diff --git a/fs/notify/group.c b/fs/notify/group.c | |
2121bcd9 | 879 | index b7a4b6a..5a69d60 100644 |
7f207e10 AM |
880 | --- a/fs/notify/group.c |
881 | +++ b/fs/notify/group.c | |
882 | @@ -22,6 +22,7 @@ | |
883 | #include <linux/srcu.h> | |
884 | #include <linux/rculist.h> | |
885 | #include <linux/wait.h> | |
886 | +#include <linux/module.h> | |
887 | ||
888 | #include <linux/fsnotify_backend.h> | |
889 | #include "fsnotify.h" | |
ffa93bbd | 890 | @@ -109,6 +110,7 @@ void fsnotify_get_group(struct fsnotify_group *group) |
1716fcea | 891 | { |
2121bcd9 | 892 | refcount_inc(&group->refcnt); |
1716fcea | 893 | } |
febd17d6 | 894 | +EXPORT_SYMBOL_GPL(fsnotify_get_group); |
1716fcea AM |
895 | |
896 | /* | |
897 | * Drop a reference to a group. Free it if it's through. | |
ffa93bbd | 898 | @@ -118,6 +120,7 @@ void fsnotify_put_group(struct fsnotify_group *group) |
2121bcd9 | 899 | if (refcount_dec_and_test(&group->refcnt)) |
1716fcea | 900 | fsnotify_final_destroy_group(group); |
7f207e10 | 901 | } |
febd17d6 | 902 | +EXPORT_SYMBOL_GPL(fsnotify_put_group); |
7f207e10 AM |
903 | |
904 | /* | |
905 | * Create a new fsnotify_group and hold a reference for the group returned. | |
ffa93bbd | 906 | @@ -147,6 +150,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops) |
7f207e10 AM |
907 | |
908 | return group; | |
909 | } | |
febd17d6 | 910 | +EXPORT_SYMBOL_GPL(fsnotify_alloc_group); |
1716fcea AM |
911 | |
912 | int fsnotify_fasync(int fd, struct file *file, int on) | |
913 | { | |
7f207e10 | 914 | diff --git a/fs/notify/mark.c b/fs/notify/mark.c |
2121bcd9 | 915 | index e9191b4..1f8ccfa 100644 |
7f207e10 AM |
916 | --- a/fs/notify/mark.c |
917 | +++ b/fs/notify/mark.c | |
2121bcd9 AM |
918 | @@ -108,6 +108,7 @@ void fsnotify_get_mark(struct fsnotify_mark *mark) |
919 | WARN_ON_ONCE(!refcount_read(&mark->refcnt)); | |
920 | refcount_inc(&mark->refcnt); | |
7f207e10 | 921 | } |
febd17d6 | 922 | +EXPORT_SYMBOL_GPL(fsnotify_put_mark); |
7f207e10 | 923 | |
ffa93bbd AM |
924 | static void __fsnotify_recalc_mask(struct fsnotify_mark_connector *conn) |
925 | { | |
2121bcd9 | 926 | @@ -392,6 +393,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark, |
1716fcea | 927 | mutex_unlock(&group->mark_mutex); |
79b8bda9 | 928 | fsnotify_free_mark(mark); |
7f207e10 | 929 | } |
febd17d6 | 930 | +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark); |
7f207e10 | 931 | |
ffa93bbd AM |
932 | /* |
933 | * Sorting function for lists of fsnotify marks. | |
2121bcd9 | 934 | @@ -606,6 +608,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark, struct inode *inode, |
ffa93bbd | 935 | fsnotify_put_mark(mark); |
7f207e10 AM |
936 | return ret; |
937 | } | |
febd17d6 | 938 | +EXPORT_SYMBOL_GPL(fsnotify_add_mark); |
7f207e10 | 939 | |
ffa93bbd AM |
940 | int fsnotify_add_mark(struct fsnotify_mark *mark, struct inode *inode, |
941 | struct vfsmount *mnt, int allow_dups) | |
2121bcd9 | 942 | @@ -741,6 +744,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark, |
ffa93bbd AM |
943 | fsnotify_get_group(group); |
944 | mark->group = group; | |
7f207e10 | 945 | } |
febd17d6 | 946 | +EXPORT_SYMBOL_GPL(fsnotify_init_mark); |
7f207e10 | 947 | |
5afbbe0d AM |
948 | /* |
949 | * Destroy all marks in destroy_list, waits for SRCU period to finish before | |
7f207e10 | 950 | diff --git a/fs/open.c b/fs/open.c |
8b6a4947 | 951 | index 7ea1184..6e2e241 100644 |
7f207e10 AM |
952 | --- a/fs/open.c |
953 | +++ b/fs/open.c | |
c2c0f25c | 954 | @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
febd17d6 | 955 | inode_unlock(dentry->d_inode); |
7f207e10 AM |
956 | return ret; |
957 | } | |
febd17d6 | 958 | +EXPORT_SYMBOL_GPL(do_truncate); |
7f207e10 | 959 | |
5afbbe0d | 960 | long vfs_truncate(const struct path *path, loff_t length) |
7f207e10 | 961 | { |
ffa93bbd | 962 | @@ -691,6 +692,7 @@ int open_check_o_direct(struct file *f) |
b912730e AM |
963 | } |
964 | return 0; | |
965 | } | |
febd17d6 | 966 | +EXPORT_SYMBOL_GPL(open_check_o_direct); |
b912730e AM |
967 | |
968 | static int do_dentry_open(struct file *f, | |
c2c0f25c | 969 | struct inode *inode, |
5527c038 | 970 | diff --git a/fs/read_write.c b/fs/read_write.c |
2121bcd9 | 971 | index 0a5c47b..d423a5f 100644 |
5527c038 JR |
972 | --- a/fs/read_write.c |
973 | +++ b/fs/read_write.c | |
2121bcd9 | 974 | @@ -454,6 +454,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) |
8b6a4947 AM |
975 | |
976 | return ret; | |
977 | } | |
978 | +EXPORT_SYMBOL_GPL(vfs_read); | |
979 | ||
980 | static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos) | |
981 | { | |
2121bcd9 | 982 | @@ -494,6 +495,7 @@ vfs_readf_t vfs_readf(struct file *file) |
5527c038 JR |
983 | return new_sync_read; |
984 | return ERR_PTR(-ENOSYS); | |
985 | } | |
febd17d6 | 986 | +EXPORT_SYMBOL_GPL(vfs_readf); |
5527c038 JR |
987 | |
988 | vfs_writef_t vfs_writef(struct file *file) | |
989 | { | |
2121bcd9 | 990 | @@ -505,6 +507,7 @@ vfs_writef_t vfs_writef(struct file *file) |
5527c038 JR |
991 | return new_sync_write; |
992 | return ERR_PTR(-ENOSYS); | |
993 | } | |
febd17d6 | 994 | +EXPORT_SYMBOL_GPL(vfs_writef); |
5527c038 | 995 | |
8b6a4947 AM |
996 | ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) |
997 | { | |
2121bcd9 | 998 | @@ -574,6 +577,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ |
8b6a4947 AM |
999 | |
1000 | return ret; | |
1001 | } | |
1002 | +EXPORT_SYMBOL_GPL(vfs_write); | |
1003 | ||
1004 | static inline loff_t file_pos_read(struct file *file) | |
5527c038 | 1005 | { |
7f207e10 | 1006 | diff --git a/fs/splice.c b/fs/splice.c |
2121bcd9 | 1007 | index c5fb195..ce01a74 100644 |
7f207e10 AM |
1008 | --- a/fs/splice.c |
1009 | +++ b/fs/splice.c | |
8b6a4947 | 1010 | @@ -850,6 +850,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
392086de AM |
1011 | |
1012 | return splice_write(pipe, out, ppos, len, flags); | |
7f207e10 | 1013 | } |
febd17d6 | 1014 | +EXPORT_SYMBOL_GPL(do_splice_from); |
7f207e10 AM |
1015 | |
1016 | /* | |
1017 | * Attempt to initiate a splice from a file to a pipe. | |
8b6a4947 | 1018 | @@ -879,6 +880,7 @@ long do_splice_to(struct file *in, loff_t *ppos, |
7f207e10 AM |
1019 | |
1020 | return splice_read(in, ppos, pipe, len, flags); | |
1021 | } | |
febd17d6 | 1022 | +EXPORT_SYMBOL_GPL(do_splice_to); |
7f207e10 AM |
1023 | |
1024 | /** | |
1025 | * splice_direct_to_actor - splices data directly between two non-pipes | |
a2654f78 | 1026 | diff --git a/fs/sync.c b/fs/sync.c |
2121bcd9 | 1027 | index a6891ee..47a78bd 100644 |
a2654f78 AM |
1028 | --- a/fs/sync.c |
1029 | +++ b/fs/sync.c | |
2121bcd9 | 1030 | @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait) |
a2654f78 AM |
1031 | sb->s_op->sync_fs(sb, wait); |
1032 | return __sync_blockdev(sb->s_bdev, wait); | |
1033 | } | |
1034 | +EXPORT_SYMBOL_GPL(__sync_filesystem); | |
1035 | ||
1036 | /* | |
1037 | * Write out and wait upon all dirty data associated with this | |
c1595e42 | 1038 | diff --git a/fs/xattr.c b/fs/xattr.c |
8b6a4947 | 1039 | index 61cd28b..35570cd 100644 |
c1595e42 JR |
1040 | --- a/fs/xattr.c |
1041 | +++ b/fs/xattr.c | |
8b6a4947 | 1042 | @@ -297,6 +297,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, |
c1595e42 JR |
1043 | *xattr_value = value; |
1044 | return error; | |
1045 | } | |
febd17d6 | 1046 | +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc); |
c1595e42 | 1047 | |
febd17d6 | 1048 | ssize_t |
f2c43d5f | 1049 | __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name, |
8b6a4947 | 1050 | diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c |
2121bcd9 | 1051 | index 2cd0282..af59768 100644 |
8b6a4947 AM |
1052 | --- a/kernel/locking/lockdep.c |
1053 | +++ b/kernel/locking/lockdep.c | |
2121bcd9 | 1054 | @@ -167,6 +167,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock) |
8b6a4947 AM |
1055 | } |
1056 | return lock_classes + hlock->class_idx - 1; | |
1057 | } | |
1058 | +EXPORT_SYMBOL_GPL(lockdep_hlock_class); | |
1059 | #define hlock_class(hlock) lockdep_hlock_class(hlock) | |
1060 | ||
1061 | #ifdef CONFIG_LOCK_STAT | |
8cdd5066 | 1062 | diff --git a/kernel/task_work.c b/kernel/task_work.c |
2121bcd9 | 1063 | index 0fef395..83fb1ec 100644 |
8cdd5066 JR |
1064 | --- a/kernel/task_work.c |
1065 | +++ b/kernel/task_work.c | |
2121bcd9 | 1066 | @@ -116,3 +116,4 @@ void task_work_run(void) |
8cdd5066 JR |
1067 | } while (work); |
1068 | } | |
1069 | } | |
febd17d6 | 1070 | +EXPORT_SYMBOL_GPL(task_work_run); |
7f207e10 | 1071 | diff --git a/security/commoncap.c b/security/commoncap.c |
2121bcd9 | 1072 | index 4f8e093..f1e0544 100644 |
7f207e10 AM |
1073 | --- a/security/commoncap.c |
1074 | +++ b/security/commoncap.c | |
2121bcd9 | 1075 | @@ -1333,12 +1333,14 @@ int cap_mmap_addr(unsigned long addr) |
94337f0d | 1076 | } |
7f207e10 AM |
1077 | return ret; |
1078 | } | |
febd17d6 | 1079 | +EXPORT_SYMBOL_GPL(cap_mmap_addr); |
0c3ec466 AM |
1080 | |
1081 | int cap_mmap_file(struct file *file, unsigned long reqprot, | |
1082 | unsigned long prot, unsigned long flags) | |
1083 | { | |
1084 | return 0; | |
1085 | } | |
febd17d6 | 1086 | +EXPORT_SYMBOL_GPL(cap_mmap_file); |
c2c0f25c AM |
1087 | |
1088 | #ifdef CONFIG_SECURITY | |
1089 | ||
7f207e10 | 1090 | diff --git a/security/device_cgroup.c b/security/device_cgroup.c |
2121bcd9 | 1091 | index c65b39b..e363d22 100644 |
7f207e10 AM |
1092 | --- a/security/device_cgroup.c |
1093 | +++ b/security/device_cgroup.c | |
2121bcd9 | 1094 | @@ -8,6 +8,7 @@ |
f6c5ef8b AM |
1095 | #include <linux/device_cgroup.h> |
1096 | #include <linux/cgroup.h> | |
1097 | #include <linux/ctype.h> | |
1098 | +#include <linux/export.h> | |
1099 | #include <linux/list.h> | |
1100 | #include <linux/uaccess.h> | |
1101 | #include <linux/seq_file.h> | |
2121bcd9 | 1102 | @@ -824,3 +825,4 @@ int __devcgroup_check_permission(short type, u32 major, u32 minor, |
7f207e10 | 1103 | |
2121bcd9 AM |
1104 | return 0; |
1105 | } | |
1106 | +EXPORT_SYMBOL_GPL(__devcgroup_check_permission); | |
7f207e10 | 1107 | diff --git a/security/security.c b/security/security.c |
2121bcd9 | 1108 | index 1cd8526..f2e4736 100644 |
7f207e10 AM |
1109 | --- a/security/security.c |
1110 | +++ b/security/security.c | |
2121bcd9 | 1111 | @@ -531,6 +531,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
7f207e10 | 1112 | return 0; |
c2c0f25c | 1113 | return call_int_hook(path_rmdir, 0, dir, dentry); |
7f207e10 | 1114 | } |
febd17d6 | 1115 | +EXPORT_SYMBOL_GPL(security_path_rmdir); |
7f207e10 | 1116 | |
5afbbe0d | 1117 | int security_path_unlink(const struct path *dir, struct dentry *dentry) |
7f207e10 | 1118 | { |
2121bcd9 | 1119 | @@ -547,6 +548,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry, |
7f207e10 | 1120 | return 0; |
c2c0f25c | 1121 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
7f207e10 | 1122 | } |
febd17d6 | 1123 | +EXPORT_SYMBOL_GPL(security_path_symlink); |
7f207e10 | 1124 | |
5afbbe0d | 1125 | int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
7f207e10 | 1126 | struct dentry *new_dentry) |
2121bcd9 | 1127 | @@ -555,6 +557,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
7f207e10 | 1128 | return 0; |
c2c0f25c | 1129 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
7f207e10 | 1130 | } |
febd17d6 | 1131 | +EXPORT_SYMBOL_GPL(security_path_link); |
7f207e10 | 1132 | |
5afbbe0d AM |
1133 | int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
1134 | const struct path *new_dir, struct dentry *new_dentry, | |
2121bcd9 | 1135 | @@ -582,6 +585,7 @@ int security_path_truncate(const struct path *path) |
7f207e10 | 1136 | return 0; |
c2c0f25c | 1137 | return call_int_hook(path_truncate, 0, path); |
7f207e10 | 1138 | } |
febd17d6 | 1139 | +EXPORT_SYMBOL_GPL(security_path_truncate); |
7f207e10 | 1140 | |
5afbbe0d | 1141 | int security_path_chmod(const struct path *path, umode_t mode) |
7eafdf33 | 1142 | { |
2121bcd9 | 1143 | @@ -589,6 +593,7 @@ int security_path_chmod(const struct path *path, umode_t mode) |
7f207e10 | 1144 | return 0; |
c2c0f25c | 1145 | return call_int_hook(path_chmod, 0, path, mode); |
7f207e10 | 1146 | } |
febd17d6 | 1147 | +EXPORT_SYMBOL_GPL(security_path_chmod); |
7f207e10 | 1148 | |
5afbbe0d | 1149 | int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 1150 | { |
2121bcd9 | 1151 | @@ -596,6 +601,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 1152 | return 0; |
c2c0f25c | 1153 | return call_int_hook(path_chown, 0, path, uid, gid); |
7f207e10 | 1154 | } |
febd17d6 | 1155 | +EXPORT_SYMBOL_GPL(security_path_chown); |
7f207e10 | 1156 | |
5afbbe0d | 1157 | int security_path_chroot(const struct path *path) |
7f207e10 | 1158 | { |
2121bcd9 | 1159 | @@ -681,6 +687,7 @@ int security_inode_readlink(struct dentry *dentry) |
7f207e10 | 1160 | return 0; |
c2c0f25c | 1161 | return call_int_hook(inode_readlink, 0, dentry); |
7f207e10 | 1162 | } |
febd17d6 | 1163 | +EXPORT_SYMBOL_GPL(security_inode_readlink); |
7f207e10 | 1164 | |
c2c0f25c AM |
1165 | int security_inode_follow_link(struct dentry *dentry, struct inode *inode, |
1166 | bool rcu) | |
2121bcd9 | 1167 | @@ -696,6 +703,7 @@ int security_inode_permission(struct inode *inode, int mask) |
7f207e10 | 1168 | return 0; |
c2c0f25c | 1169 | return call_int_hook(inode_permission, 0, inode, mask); |
7f207e10 | 1170 | } |
febd17d6 | 1171 | +EXPORT_SYMBOL_GPL(security_inode_permission); |
7f207e10 | 1172 | |
1e00d052 | 1173 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
7f207e10 | 1174 | { |
2121bcd9 | 1175 | @@ -867,6 +875,7 @@ int security_file_permission(struct file *file, int mask) |
7f207e10 AM |
1176 | |
1177 | return fsnotify_perm(file, mask); | |
1178 | } | |
febd17d6 | 1179 | +EXPORT_SYMBOL_GPL(security_file_permission); |
7f207e10 AM |
1180 | |
1181 | int security_file_alloc(struct file *file) | |
1182 | { | |
2121bcd9 | 1183 | @@ -926,6 +935,7 @@ int security_mmap_file(struct file *file, unsigned long prot, |
7f207e10 AM |
1184 | return ret; |
1185 | return ima_file_mmap(file, prot); | |
1186 | } | |
febd17d6 | 1187 | +EXPORT_SYMBOL_GPL(security_mmap_file); |
7f207e10 | 1188 | |
0c3ec466 AM |
1189 | int security_mmap_addr(unsigned long addr) |
1190 | { | |
7f207e10 AM |
1191 | diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs |
1192 | --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1193 | +++ linux/Documentation/ABI/testing/debugfs-aufs 2016-01-13 20:11:11.663093444 +0100 |
86dc4139 | 1194 | @@ -0,0 +1,50 @@ |
7f207e10 AM |
1195 | +What: /debug/aufs/si_<id>/ |
1196 | +Date: March 2009 | |
f6b6e03d | 1197 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1198 | +Description: |
1199 | + Under /debug/aufs, a directory named si_<id> is created | |
1200 | + per aufs mount, where <id> is a unique id generated | |
1201 | + internally. | |
1facf9fc | 1202 | + |
86dc4139 AM |
1203 | +What: /debug/aufs/si_<id>/plink |
1204 | +Date: Apr 2013 | |
f6b6e03d | 1205 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
86dc4139 AM |
1206 | +Description: |
1207 | + It has three lines and shows the information about the | |
1208 | + pseudo-link. The first line is a single number | |
1209 | + representing a number of buckets. The second line is a | |
1210 | + number of pseudo-links per buckets (separated by a | |
1211 | + blank). The last line is a single number representing a | |
1212 | + total number of psedo-links. | |
1213 | + When the aufs mount option 'noplink' is specified, it | |
1214 | + will show "1\n0\n0\n". | |
1215 | + | |
7f207e10 AM |
1216 | +What: /debug/aufs/si_<id>/xib |
1217 | +Date: March 2009 | |
f6b6e03d | 1218 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1219 | +Description: |
1220 | + It shows the consumed blocks by xib (External Inode Number | |
1221 | + Bitmap), its block size and file size. | |
1222 | + When the aufs mount option 'noxino' is specified, it | |
1223 | + will be empty. About XINO files, see the aufs manual. | |
1224 | + | |
1225 | +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN | |
1226 | +Date: March 2009 | |
f6b6e03d | 1227 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1228 | +Description: |
1229 | + It shows the consumed blocks by xino (External Inode Number | |
1230 | + Translation Table), its link count, block size and file | |
1231 | + size. | |
1232 | + When the aufs mount option 'noxino' is specified, it | |
1233 | + will be empty. About XINO files, see the aufs manual. | |
1234 | + | |
1235 | +What: /debug/aufs/si_<id>/xigen | |
1236 | +Date: March 2009 | |
f6b6e03d | 1237 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1238 | +Description: |
1239 | + It shows the consumed blocks by xigen (External Inode | |
1240 | + Generation Table), its block size and file size. | |
1241 | + If CONFIG_AUFS_EXPORT is disabled, this entry will not | |
1242 | + be created. | |
1243 | + When the aufs mount option 'noxino' is specified, it | |
1244 | + will be empty. About XINO files, see the aufs manual. | |
1245 | diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs | |
1246 | --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1247 | +++ linux/Documentation/ABI/testing/sysfs-aufs 2016-01-13 20:11:11.663093444 +0100 |
392086de | 1248 | @@ -0,0 +1,31 @@ |
7f207e10 AM |
1249 | +What: /sys/fs/aufs/si_<id>/ |
1250 | +Date: March 2009 | |
f6b6e03d | 1251 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1252 | +Description: |
1253 | + Under /sys/fs/aufs, a directory named si_<id> is created | |
1254 | + per aufs mount, where <id> is a unique id generated | |
1255 | + internally. | |
1256 | + | |
1257 | +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN | |
1258 | +Date: March 2009 | |
f6b6e03d | 1259 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1260 | +Description: |
1261 | + It shows the abolute path of a member directory (which | |
1262 | + is called branch) in aufs, and its permission. | |
1263 | + | |
392086de AM |
1264 | +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN |
1265 | +Date: July 2013 | |
f6b6e03d | 1266 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
392086de AM |
1267 | +Description: |
1268 | + It shows the id of a member directory (which is called | |
1269 | + branch) in aufs. | |
1270 | + | |
7f207e10 AM |
1271 | +What: /sys/fs/aufs/si_<id>/xi_path |
1272 | +Date: March 2009 | |
f6b6e03d | 1273 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1274 | +Description: |
1275 | + It shows the abolute path of XINO (External Inode Number | |
1276 | + Bitmap, Translation Table and Generation Table) file | |
1277 | + even if it is the default path. | |
1278 | + When the aufs mount option 'noxino' is specified, it | |
1279 | + will be empty. About XINO files, see the aufs manual. | |
53392da6 AM |
1280 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt |
1281 | --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1282 | +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2018-01-29 07:56:20.046658203 +0100 |
1c60b727 | 1283 | @@ -0,0 +1,171 @@ |
53392da6 | 1284 | + |
a2654f78 | 1285 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1286 | +# |
1287 | +# This program is free software; you can redistribute it and/or modify | |
1288 | +# it under the terms of the GNU General Public License as published by | |
1289 | +# the Free Software Foundation; either version 2 of the License, or | |
1290 | +# (at your option) any later version. | |
1291 | +# | |
1292 | +# This program is distributed in the hope that it will be useful, | |
1293 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1294 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1295 | +# GNU General Public License for more details. | |
1296 | +# | |
1297 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1298 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1299 | + |
1300 | +Introduction | |
1301 | +---------------------------------------- | |
1302 | + | |
3c1bdaff | 1303 | +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s] |
53392da6 AM |
1304 | +1. abbrev. for "advanced multi-layered unification filesystem". |
1305 | +2. abbrev. for "another unionfs". | |
1306 | +3. abbrev. for "auf das" in German which means "on the" in English. | |
1307 | + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E). | |
1308 | + But "Filesystem aufs Filesystem" is hard to understand. | |
1c60b727 | 1309 | +4. abbrev. for "African Urban Fashion Show". |
53392da6 AM |
1310 | + |
1311 | +AUFS is a filesystem with features: | |
1312 | +- multi layered stackable unification filesystem, the member directory | |
1313 | + is called as a branch. | |
1314 | +- branch permission and attribute, 'readonly', 'real-readonly', | |
7e9cd9fe | 1315 | + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their |
53392da6 AM |
1316 | + combination. |
1317 | +- internal "file copy-on-write". | |
1318 | +- logical deletion, whiteout. | |
1319 | +- dynamic branch manipulation, adding, deleting and changing permission. | |
1320 | +- allow bypassing aufs, user's direct branch access. | |
1321 | +- external inode number translation table and bitmap which maintains the | |
1322 | + persistent aufs inode number. | |
1323 | +- seekable directory, including NFS readdir. | |
1324 | +- file mapping, mmap and sharing pages. | |
1325 | +- pseudo-link, hardlink over branches. | |
1326 | +- loopback mounted filesystem as a branch. | |
1327 | +- several policies to select one among multiple writable branches. | |
1328 | +- revert a single systemcall when an error occurs in aufs. | |
1329 | +- and more... | |
1330 | + | |
1331 | + | |
1332 | +Multi Layered Stackable Unification Filesystem | |
1333 | +---------------------------------------------------------------------- | |
1334 | +Most people already knows what it is. | |
1335 | +It is a filesystem which unifies several directories and provides a | |
1336 | +merged single directory. When users access a file, the access will be | |
1337 | +passed/re-directed/converted (sorry, I am not sure which English word is | |
1338 | +correct) to the real file on the member filesystem. The member | |
1339 | +filesystem is called 'lower filesystem' or 'branch' and has a mode | |
1340 | +'readonly' and 'readwrite.' And the deletion for a file on the lower | |
1341 | +readonly branch is handled by creating 'whiteout' on the upper writable | |
1342 | +branch. | |
1343 | + | |
1344 | +On LKML, there have been discussions about UnionMount (Jan Blunck, | |
1345 | +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took | |
1346 | +different approaches to implement the merged-view. | |
1347 | +The former tries putting it into VFS, and the latter implements as a | |
1348 | +separate filesystem. | |
1349 | +(If I misunderstand about these implementations, please let me know and | |
1350 | +I shall correct it. Because it is a long time ago when I read their | |
1351 | +source files last time). | |
1352 | + | |
1353 | +UnionMount's approach will be able to small, but may be hard to share | |
1354 | +branches between several UnionMount since the whiteout in it is | |
1355 | +implemented in the inode on branch filesystem and always | |
1356 | +shared. According to Bharata's post, readdir does not seems to be | |
1357 | +finished yet. | |
1358 | +There are several missing features known in this implementations such as | |
1359 | +- for users, the inode number may change silently. eg. copy-up. | |
1360 | +- link(2) may break by copy-up. | |
1361 | +- read(2) may get an obsoleted filedata (fstat(2) too). | |
1362 | +- fcntl(F_SETLK) may be broken by copy-up. | |
1363 | +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after | |
1364 | + open(O_RDWR). | |
1365 | + | |
7e9cd9fe AM |
1366 | +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was |
1367 | +merged into mainline. This is another implementation of UnionMount as a | |
1368 | +separated filesystem. All the limitations and known problems which | |
1369 | +UnionMount are equally inherited to "overlay" filesystem. | |
1370 | + | |
1371 | +Unionfs has a longer history. When I started implementing a stackable | |
1372 | +filesystem (Aug 2005), it already existed. It has virtual super_block, | |
1373 | +inode, dentry and file objects and they have an array pointing lower | |
1374 | +same kind objects. After contributing many patches for Unionfs, I | |
1375 | +re-started my project AUFS (Jun 2006). | |
53392da6 AM |
1376 | + |
1377 | +In AUFS, the structure of filesystem resembles to Unionfs, but I | |
1378 | +implemented my own ideas, approaches and enhancements and it became | |
1379 | +totally different one. | |
1380 | + | |
1381 | +Comparing DM snapshot and fs based implementation | |
1382 | +- the number of bytes to be copied between devices is much smaller. | |
1383 | +- the type of filesystem must be one and only. | |
1384 | +- the fs must be writable, no readonly fs, even for the lower original | |
1385 | + device. so the compression fs will not be usable. but if we use | |
1386 | + loopback mount, we may address this issue. | |
1387 | + for instance, | |
1388 | + mount /cdrom/squashfs.img /sq | |
1389 | + losetup /sq/ext2.img | |
1390 | + losetup /somewhere/cow | |
1391 | + dmsetup "snapshot /dev/loop0 /dev/loop1 ..." | |
1392 | +- it will be difficult (or needs more operations) to extract the | |
1393 | + difference between the original device and COW. | |
1394 | +- DM snapshot-merge may help a lot when users try merging. in the | |
1395 | + fs-layer union, users will use rsync(1). | |
1396 | + | |
7e9cd9fe AM |
1397 | +You may want to read my old paper "Filesystems in LiveCD" |
1398 | +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf). | |
53392da6 | 1399 | + |
7e9cd9fe AM |
1400 | + |
1401 | +Several characters/aspects/persona of aufs | |
53392da6 AM |
1402 | +---------------------------------------------------------------------- |
1403 | + | |
7e9cd9fe | 1404 | +Aufs has several characters, aspects or persona. |
53392da6 AM |
1405 | +1. a filesystem, callee of VFS helper |
1406 | +2. sub-VFS, caller of VFS helper for branches | |
1407 | +3. a virtual filesystem which maintains persistent inode number | |
1408 | +4. reader/writer of files on branches such like an application | |
1409 | + | |
1410 | +1. Callee of VFS Helper | |
1411 | +As an ordinary linux filesystem, aufs is a callee of VFS. For instance, | |
1412 | +unlink(2) from an application reaches sys_unlink() kernel function and | |
1413 | +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it | |
1414 | +calls filesystem specific unlink operation. Actually aufs implements the | |
1415 | +unlink operation but it behaves like a redirector. | |
1416 | + | |
1417 | +2. Caller of VFS Helper for Branches | |
1418 | +aufs_unlink() passes the unlink request to the branch filesystem as if | |
1419 | +it were called from VFS. So the called unlink operation of the branch | |
1420 | +filesystem acts as usual. As a caller of VFS helper, aufs should handle | |
1421 | +every necessary pre/post operation for the branch filesystem. | |
1422 | +- acquire the lock for the parent dir on a branch | |
1423 | +- lookup in a branch | |
1424 | +- revalidate dentry on a branch | |
1425 | +- mnt_want_write() for a branch | |
1426 | +- vfs_unlink() for a branch | |
1427 | +- mnt_drop_write() for a branch | |
1428 | +- release the lock on a branch | |
1429 | + | |
1430 | +3. Persistent Inode Number | |
1431 | +One of the most important issue for a filesystem is to maintain inode | |
1432 | +numbers. This is particularly important to support exporting a | |
1433 | +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a | |
1434 | +backend block device for its own. But some storage is necessary to | |
7e9cd9fe AM |
1435 | +keep and maintain the inode numbers. It may be a large space and may not |
1436 | +suit to keep in memory. Aufs rents some space from its first writable | |
1437 | +branch filesystem (by default) and creates file(s) on it. These files | |
1438 | +are created by aufs internally and removed soon (currently) keeping | |
1439 | +opened. | |
53392da6 AM |
1440 | +Note: Because these files are removed, they are totally gone after |
1441 | + unmounting aufs. It means the inode numbers are not persistent | |
1442 | + across unmount or reboot. I have a plan to make them really | |
1443 | + persistent which will be important for aufs on NFS server. | |
1444 | + | |
1445 | +4. Read/Write Files Internally (copy-on-write) | |
1446 | +Because a branch can be readonly, when you write a file on it, aufs will | |
1447 | +"copy-up" it to the upper writable branch internally. And then write the | |
1448 | +originally requested thing to the file. Generally kernel doesn't | |
1449 | +open/read/write file actively. In aufs, even a single write may cause a | |
1450 | +internal "file copy". This behaviour is very similar to cp(1) command. | |
1451 | + | |
1452 | +Some people may think it is better to pass such work to user space | |
1453 | +helper, instead of doing in kernel space. Actually I am still thinking | |
1454 | +about it. But currently I have implemented it in kernel space. | |
1455 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt | |
1456 | --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1457 | +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2018-01-29 07:56:20.049991637 +0100 |
7e9cd9fe | 1458 | @@ -0,0 +1,258 @@ |
53392da6 | 1459 | + |
a2654f78 | 1460 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1461 | +# |
1462 | +# This program is free software; you can redistribute it and/or modify | |
1463 | +# it under the terms of the GNU General Public License as published by | |
1464 | +# the Free Software Foundation; either version 2 of the License, or | |
1465 | +# (at your option) any later version. | |
1466 | +# | |
1467 | +# This program is distributed in the hope that it will be useful, | |
1468 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1469 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1470 | +# GNU General Public License for more details. | |
1471 | +# | |
1472 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1473 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1474 | + |
1475 | +Basic Aufs Internal Structure | |
1476 | + | |
1477 | +Superblock/Inode/Dentry/File Objects | |
1478 | +---------------------------------------------------------------------- | |
1479 | +As like an ordinary filesystem, aufs has its own | |
1480 | +superblock/inode/dentry/file objects. All these objects have a | |
1481 | +dynamically allocated array and store the same kind of pointers to the | |
1482 | +lower filesystem, branch. | |
1483 | +For example, when you build a union with one readwrite branch and one | |
1484 | +readonly, mounted /au, /rw and /ro respectively. | |
1485 | +- /au = /rw + /ro | |
1486 | +- /ro/fileA exists but /rw/fileA | |
1487 | + | |
1488 | +Aufs lookup operation finds /ro/fileA and gets dentry for that. These | |
1489 | +pointers are stored in a aufs dentry. The array in aufs dentry will be, | |
7e9cd9fe | 1490 | +- [0] = NULL (because /rw/fileA doesn't exist) |
53392da6 AM |
1491 | +- [1] = /ro/fileA |
1492 | + | |
1493 | +This style of an array is essentially same to the aufs | |
1494 | +superblock/inode/dentry/file objects. | |
1495 | + | |
1496 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1497 | +branches dynamically, these objects has its own generation. When |
1498 | +branches are changed, the generation in aufs superblock is | |
1499 | +incremented. And a generation in other object are compared when it is | |
1500 | +accessed. When a generation in other objects are obsoleted, aufs | |
1501 | +refreshes the internal array. | |
53392da6 AM |
1502 | + |
1503 | + | |
1504 | +Superblock | |
1505 | +---------------------------------------------------------------------- | |
1506 | +Additionally aufs superblock has some data for policies to select one | |
1507 | +among multiple writable branches, XIB files, pseudo-links and kobject. | |
1508 | +See below in detail. | |
7e9cd9fe AM |
1509 | +About the policies which supports copy-down a directory, see |
1510 | +wbr_policy.txt too. | |
53392da6 AM |
1511 | + |
1512 | + | |
1513 | +Branch and XINO(External Inode Number Translation Table) | |
1514 | +---------------------------------------------------------------------- | |
1515 | +Every branch has its own xino (external inode number translation table) | |
1516 | +file. The xino file is created and unlinked by aufs internally. When two | |
1517 | +members of a union exist on the same filesystem, they share the single | |
1518 | +xino file. | |
1519 | +The struct of a xino file is simple, just a sequence of aufs inode | |
1520 | +numbers which is indexed by the lower inode number. | |
1521 | +In the above sample, assume the inode number of /ro/fileA is i111 and | |
1522 | +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as | |
1523 | +4(8) bytes at 111 * 4(8) bytes offset in the xino file. | |
1524 | + | |
1525 | +When the inode numbers are not contiguous, the xino file will be sparse | |
1526 | +which has a hole in it and doesn't consume as much disk space as it | |
1527 | +might appear. If your branch filesystem consumes disk space for such | |
1528 | +holes, then you should specify 'xino=' option at mounting aufs. | |
1529 | + | |
7e9cd9fe AM |
1530 | +Aufs has a mount option to free the disk blocks for such holes in XINO |
1531 | +files on tmpfs or ramdisk. But it is not so effective actually. If you | |
1532 | +meet a problem of disk shortage due to XINO files, then you should try | |
1533 | +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git. | |
1534 | +The patch localizes the assignment inumbers per tmpfs-mount and avoid | |
1535 | +the holes in XINO files. | |
1536 | + | |
53392da6 | 1537 | +Also a writable branch has three kinds of "whiteout bases". All these |
7e9cd9fe | 1538 | +are existed when the branch is joined to aufs, and their names are |
53392da6 AM |
1539 | +whiteout-ed doubly, so that users will never see their names in aufs |
1540 | +hierarchy. | |
7e9cd9fe | 1541 | +1. a regular file which will be hardlinked to all whiteouts. |
53392da6 | 1542 | +2. a directory to store a pseudo-link. |
7e9cd9fe | 1543 | +3. a directory to store an "orphan"-ed file temporary. |
53392da6 AM |
1544 | + |
1545 | +1. Whiteout Base | |
1546 | + When you remove a file on a readonly branch, aufs handles it as a | |
1547 | + logical deletion and creates a whiteout on the upper writable branch | |
1548 | + as a hardlink of this file in order not to consume inode on the | |
1549 | + writable branch. | |
1550 | +2. Pseudo-link Dir | |
1551 | + See below, Pseudo-link. | |
1552 | +3. Step-Parent Dir | |
1553 | + When "fileC" exists on the lower readonly branch only and it is | |
1554 | + opened and removed with its parent dir, and then user writes | |
1555 | + something into it, then aufs copies-up fileC to this | |
1556 | + directory. Because there is no other dir to store fileC. After | |
1557 | + creating a file under this dir, the file is unlinked. | |
1558 | + | |
1559 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1560 | +dynamically, a branch has its own id. When the branch order changes, |
1561 | +aufs finds the new index by searching the branch id. | |
53392da6 AM |
1562 | + |
1563 | + | |
1564 | +Pseudo-link | |
1565 | +---------------------------------------------------------------------- | |
1566 | +Assume "fileA" exists on the lower readonly branch only and it is | |
1567 | +hardlinked to "fileB" on the branch. When you write something to fileA, | |
1568 | +aufs copies-up it to the upper writable branch. Additionally aufs | |
1569 | +creates a hardlink under the Pseudo-link Directory of the writable | |
1570 | +branch. The inode of a pseudo-link is kept in aufs super_block as a | |
1571 | +simple list. If fileB is read after unlinking fileA, aufs returns | |
1572 | +filedata from the pseudo-link instead of the lower readonly | |
1573 | +branch. Because the pseudo-link is based upon the inode, to keep the | |
7e9cd9fe | 1574 | +inode number by xino (see above) is essentially necessary. |
53392da6 AM |
1575 | + |
1576 | +All the hardlinks under the Pseudo-link Directory of the writable branch | |
1577 | +should be restored in a proper location later. Aufs provides a utility | |
1578 | +to do this. The userspace helpers executed at remounting and unmounting | |
1579 | +aufs by default. | |
1580 | +During this utility is running, it puts aufs into the pseudo-link | |
1581 | +maintenance mode. In this mode, only the process which began the | |
1582 | +maintenance mode (and its child processes) is allowed to operate in | |
1583 | +aufs. Some other processes which are not related to the pseudo-link will | |
1584 | +be allowed to run too, but the rest have to return an error or wait | |
1585 | +until the maintenance mode ends. If a process already acquires an inode | |
1586 | +mutex (in VFS), it has to return an error. | |
1587 | + | |
1588 | + | |
1589 | +XIB(external inode number bitmap) | |
1590 | +---------------------------------------------------------------------- | |
1591 | +Addition to the xino file per a branch, aufs has an external inode number | |
7e9cd9fe AM |
1592 | +bitmap in a superblock object. It is also an internal file such like a |
1593 | +xino file. | |
53392da6 AM |
1594 | +It is a simple bitmap to mark whether the aufs inode number is in-use or |
1595 | +not. | |
1596 | +To reduce the file I/O, aufs prepares a single memory page to cache xib. | |
1597 | + | |
7e9cd9fe | 1598 | +As well as XINO files, aufs has a feature to truncate/refresh XIB to |
53392da6 AM |
1599 | +reduce the number of consumed disk blocks for these files. |
1600 | + | |
1601 | + | |
1602 | +Virtual or Vertical Dir, and Readdir in Userspace | |
1603 | +---------------------------------------------------------------------- | |
1604 | +In order to support multiple layers (branches), aufs readdir operation | |
1605 | +constructs a virtual dir block on memory. For readdir, aufs calls | |
1606 | +vfs_readdir() internally for each dir on branches, merges their entries | |
1607 | +with eliminating the whiteout-ed ones, and sets it to file (dir) | |
1608 | +object. So the file object has its entry list until it is closed. The | |
1609 | +entry list will be updated when the file position is zero and becomes | |
7e9cd9fe | 1610 | +obsoleted. This decision is made in aufs automatically. |
53392da6 AM |
1611 | + |
1612 | +The dynamically allocated memory block for the name of entries has a | |
1613 | +unit of 512 bytes (by default) and stores the names contiguously (no | |
1614 | +padding). Another block for each entry is handled by kmem_cache too. | |
1615 | +During building dir blocks, aufs creates hash list and judging whether | |
1616 | +the entry is whiteouted by its upper branch or already listed. | |
1617 | +The merged result is cached in the corresponding inode object and | |
1618 | +maintained by a customizable life-time option. | |
1619 | + | |
1620 | +Some people may call it can be a security hole or invite DoS attack | |
1621 | +since the opened and once readdir-ed dir (file object) holds its entry | |
1622 | +list and becomes a pressure for system memory. But I'd say it is similar | |
1623 | +to files under /proc or /sys. The virtual files in them also holds a | |
1624 | +memory page (generally) while they are opened. When an idea to reduce | |
1625 | +memory for them is introduced, it will be applied to aufs too. | |
1626 | +For those who really hate this situation, I've developed readdir(3) | |
1627 | +library which operates this merging in userspace. You just need to set | |
1628 | +LD_PRELOAD environment variable, and aufs will not consume no memory in | |
1629 | +kernel space for readdir(3). | |
1630 | + | |
1631 | + | |
1632 | +Workqueue | |
1633 | +---------------------------------------------------------------------- | |
1634 | +Aufs sometimes requires privilege access to a branch. For instance, | |
1635 | +in copy-up/down operation. When a user process is going to make changes | |
1636 | +to a file which exists in the lower readonly branch only, and the mode | |
1637 | +of one of ancestor directories may not be writable by a user | |
1638 | +process. Here aufs copy-up the file with its ancestors and they may | |
1639 | +require privilege to set its owner/group/mode/etc. | |
1640 | +This is a typical case of a application character of aufs (see | |
1641 | +Introduction). | |
1642 | + | |
1643 | +Aufs uses workqueue synchronously for this case. It creates its own | |
1644 | +workqueue. The workqueue is a kernel thread and has privilege. Aufs | |
1645 | +passes the request to call mkdir or write (for example), and wait for | |
1646 | +its completion. This approach solves a problem of a signal handler | |
1647 | +simply. | |
1648 | +If aufs didn't adopt the workqueue and changed the privilege of the | |
7e9cd9fe AM |
1649 | +process, then the process may receive the unexpected SIGXFSZ or other |
1650 | +signals. | |
53392da6 AM |
1651 | + |
1652 | +Also aufs uses the system global workqueue ("events" kernel thread) too | |
1653 | +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a | |
1654 | +whiteout base and etc. This is unrelated to a privilege. | |
1655 | +Most of aufs operation tries acquiring a rw_semaphore for aufs | |
1656 | +superblock at the beginning, at the same time waits for the completion | |
1657 | +of all queued asynchronous tasks. | |
1658 | + | |
1659 | + | |
1660 | +Whiteout | |
1661 | +---------------------------------------------------------------------- | |
1662 | +The whiteout in aufs is very similar to Unionfs's. That is represented | |
1663 | +by its filename. UnionMount takes an approach of a file mode, but I am | |
1664 | +afraid several utilities (find(1) or something) will have to support it. | |
1665 | + | |
1666 | +Basically the whiteout represents "logical deletion" which stops aufs to | |
1667 | +lookup further, but also it represents "dir is opaque" which also stop | |
7e9cd9fe | 1668 | +further lookup. |
53392da6 AM |
1669 | + |
1670 | +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively. | |
1671 | +In order to make several functions in a single systemcall to be | |
1672 | +revertible, aufs adopts an approach to rename a directory to a temporary | |
1673 | +unique whiteouted name. | |
1674 | +For example, in rename(2) dir where the target dir already existed, aufs | |
1675 | +renames the target dir to a temporary unique whiteouted name before the | |
7e9cd9fe | 1676 | +actual rename on a branch, and then handles other actions (make it opaque, |
53392da6 AM |
1677 | +update the attributes, etc). If an error happens in these actions, aufs |
1678 | +simply renames the whiteouted name back and returns an error. If all are | |
1679 | +succeeded, aufs registers a function to remove the whiteouted unique | |
1680 | +temporary name completely and asynchronously to the system global | |
1681 | +workqueue. | |
1682 | + | |
1683 | + | |
1684 | +Copy-up | |
1685 | +---------------------------------------------------------------------- | |
1686 | +It is a well-known feature or concept. | |
1687 | +When user modifies a file on a readonly branch, aufs operate "copy-up" | |
1688 | +internally and makes change to the new file on the upper writable branch. | |
1689 | +When the trigger systemcall does not update the timestamps of the parent | |
1690 | +dir, aufs reverts it after copy-up. | |
c2b27bf2 AM |
1691 | + |
1692 | + | |
1693 | +Move-down (aufs3.9 and later) | |
1694 | +---------------------------------------------------------------------- | |
1695 | +"Copy-up" is one of the essential feature in aufs. It copies a file from | |
1696 | +the lower readonly branch to the upper writable branch when a user | |
1697 | +changes something about the file. | |
1698 | +"Move-down" is an opposite action of copy-up. Basically this action is | |
1699 | +ran manually instead of automatically and internally. | |
076b876e AM |
1700 | +For desgin and implementation, aufs has to consider these issues. |
1701 | +- whiteout for the file may exist on the lower branch. | |
1702 | +- ancestor directories may not exist on the lower branch. | |
1703 | +- diropq for the ancestor directories may exist on the upper branch. | |
1704 | +- free space on the lower branch will reduce. | |
1705 | +- another access to the file may happen during moving-down, including | |
7e9cd9fe | 1706 | + UDBA (see "Revalidate Dentry and UDBA"). |
076b876e AM |
1707 | +- the file should not be hard-linked nor pseudo-linked. they should be |
1708 | + handled by auplink utility later. | |
c2b27bf2 AM |
1709 | + |
1710 | +Sometimes users want to move-down a file from the upper writable branch | |
1711 | +to the lower readonly or writable branch. For instance, | |
1712 | +- the free space of the upper writable branch is going to run out. | |
1713 | +- create a new intermediate branch between the upper and lower branch. | |
1714 | +- etc. | |
1715 | + | |
1716 | +For this purpose, use "aumvdown" command in aufs-util.git. | |
b912730e AM |
1717 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt |
1718 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1719 | +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2018-01-29 07:56:20.049991637 +0100 |
b912730e AM |
1720 | @@ -0,0 +1,85 @@ |
1721 | + | |
a2654f78 | 1722 | +# Copyright (C) 2015-2017 Junjiro R. Okajima |
b912730e AM |
1723 | +# |
1724 | +# This program is free software; you can redistribute it and/or modify | |
1725 | +# it under the terms of the GNU General Public License as published by | |
1726 | +# the Free Software Foundation; either version 2 of the License, or | |
1727 | +# (at your option) any later version. | |
1728 | +# | |
1729 | +# This program is distributed in the hope that it will be useful, | |
1730 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1731 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1732 | +# GNU General Public License for more details. | |
1733 | +# | |
1734 | +# You should have received a copy of the GNU General Public License | |
1735 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1736 | + | |
1737 | +Support for a branch who has its ->atomic_open() | |
1738 | +---------------------------------------------------------------------- | |
1739 | +The filesystems who implement its ->atomic_open() are not majority. For | |
1740 | +example NFSv4 does, and aufs should call NFSv4 ->atomic_open, | |
1741 | +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than | |
1742 | +->atomic_open(), NFSv4 returns an error for this open(2). While I am not | |
1743 | +sure whether all filesystems who have ->atomic_open() behave like this, | |
1744 | +but NFSv4 surely returns the error. | |
1745 | + | |
1746 | +In order to support ->atomic_open() for aufs, there are a few | |
1747 | +approaches. | |
1748 | + | |
1749 | +A. Introduce aufs_atomic_open() | |
1750 | + - calls one of VFS:do_last(), lookup_open() or atomic_open() for | |
1751 | + branch fs. | |
1752 | +B. Introduce aufs_atomic_open() calling create, open and chmod. this is | |
1753 | + an aufs user Pip Cet's approach | |
1754 | + - calls aufs_create(), VFS finish_open() and notify_change(). | |
1755 | + - pass fake-mode to finish_open(), and then correct the mode by | |
1756 | + notify_change(). | |
1757 | +C. Extend aufs_open() to call branch fs's ->atomic_open() | |
1758 | + - no aufs_atomic_open(). | |
1759 | + - aufs_lookup() registers the TID to an aufs internal object. | |
1760 | + - aufs_create() does nothing when the matching TID is registered, but | |
1761 | + registers the mode. | |
1762 | + - aufs_open() calls branch fs's ->atomic_open() when the matching | |
1763 | + TID is registered. | |
1764 | +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's | |
1765 | + credential | |
1766 | + - no aufs_atomic_open(). | |
1767 | + - aufs_create() registers the TID to an internal object. this info | |
1768 | + represents "this process created this file just now." | |
1769 | + - when aufs gets EACCES from branch fs's ->open(), then confirm the | |
1770 | + registered TID and re-try open() with superuser's credential. | |
1771 | + | |
1772 | +Pros and cons for each approach. | |
1773 | + | |
1774 | +A. | |
1775 | + - straightforward but highly depends upon VFS internal. | |
1776 | + - the atomic behavaiour is kept. | |
1777 | + - some of parameters such as nameidata are hard to reproduce for | |
1778 | + branch fs. | |
1779 | + - large overhead. | |
1780 | +B. | |
1781 | + - easy to implement. | |
1782 | + - the atomic behavaiour is lost. | |
1783 | +C. | |
1784 | + - the atomic behavaiour is kept. | |
1785 | + - dirty and tricky. | |
1786 | + - VFS checks whether the file is created correctly after calling | |
1787 | + ->create(), which means this approach doesn't work. | |
1788 | +D. | |
1789 | + - easy to implement. | |
1790 | + - the atomic behavaiour is lost. | |
1791 | + - to open a file with superuser's credential and give it to a user | |
1792 | + process is a bad idea, since the file object keeps the credential | |
1793 | + in it. It may affect LSM or something. This approach doesn't work | |
1794 | + either. | |
1795 | + | |
1796 | +The approach A is ideal, but it hard to implement. So here is a | |
1797 | +variation of A, which is to be implemented. | |
1798 | + | |
1799 | +A-1. Introduce aufs_atomic_open() | |
1800 | + - calls branch fs ->atomic_open() if exists. otherwise calls | |
1801 | + vfs_create() and finish_open(). | |
1802 | + - the demerit is that the several checks after branch fs | |
1803 | + ->atomic_open() are lost. in the ordinary case, the checks are | |
1804 | + done by VFS:do_last(), lookup_open() and atomic_open(). some can | |
1805 | + be implemented in aufs, but not all I am afraid. | |
53392da6 AM |
1806 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt |
1807 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1808 | +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2018-01-29 07:56:20.049991637 +0100 |
7e9cd9fe | 1809 | @@ -0,0 +1,113 @@ |
53392da6 | 1810 | + |
a2654f78 | 1811 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1812 | +# |
1813 | +# This program is free software; you can redistribute it and/or modify | |
1814 | +# it under the terms of the GNU General Public License as published by | |
1815 | +# the Free Software Foundation; either version 2 of the License, or | |
1816 | +# (at your option) any later version. | |
1817 | +# | |
1818 | +# This program is distributed in the hope that it will be useful, | |
1819 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1820 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1821 | +# GNU General Public License for more details. | |
1822 | +# | |
1823 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1824 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1825 | + |
1826 | +Lookup in a Branch | |
1827 | +---------------------------------------------------------------------- | |
1828 | +Since aufs has a character of sub-VFS (see Introduction), it operates | |
7e9cd9fe AM |
1829 | +lookup for branches as VFS does. It may be a heavy work. But almost all |
1830 | +lookup operation in aufs is the simplest case, ie. lookup only an entry | |
1831 | +directly connected to its parent. Digging down the directory hierarchy | |
1832 | +is unnecessary. VFS has a function lookup_one_len() for that use, and | |
1833 | +aufs calls it. | |
1834 | + | |
1835 | +When a branch is a remote filesystem, aufs basically relies upon its | |
53392da6 AM |
1836 | +->d_revalidate(), also aufs forces the hardest revalidate tests for |
1837 | +them. | |
1838 | +For d_revalidate, aufs implements three levels of revalidate tests. See | |
1839 | +"Revalidate Dentry and UDBA" in detail. | |
1840 | + | |
1841 | + | |
076b876e AM |
1842 | +Test Only the Highest One for the Directory Permission (dirperm1 option) |
1843 | +---------------------------------------------------------------------- | |
1844 | +Let's try case study. | |
1845 | +- aufs has two branches, upper readwrite and lower readonly. | |
1846 | + /au = /rw + /ro | |
1847 | +- "dirA" exists under /ro, but /rw. and its mode is 0700. | |
1848 | +- user invoked "chmod a+rx /au/dirA" | |
1849 | +- the internal copy-up is activated and "/rw/dirA" is created and its | |
7e9cd9fe | 1850 | + permission bits are set to world readable. |
076b876e AM |
1851 | +- then "/au/dirA" becomes world readable? |
1852 | + | |
1853 | +In this case, /ro/dirA is still 0700 since it exists in readonly branch, | |
1854 | +or it may be a natively readonly filesystem. If aufs respects the lower | |
1855 | +branch, it should not respond readdir request from other users. But user | |
1856 | +allowed it by chmod. Should really aufs rejects showing the entries | |
1857 | +under /ro/dirA? | |
1858 | + | |
7e9cd9fe AM |
1859 | +To be honest, I don't have a good solution for this case. So aufs |
1860 | +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to | |
1861 | +users. | |
076b876e AM |
1862 | +When dirperm1 is specified, aufs checks only the highest one for the |
1863 | +directory permission, and shows the entries. Otherwise, as usual, checks | |
1864 | +every dir existing on all branches and rejects the request. | |
1865 | + | |
1866 | +As a side effect, dirperm1 option improves the performance of aufs | |
1867 | +because the number of permission check is reduced when the number of | |
1868 | +branch is many. | |
1869 | + | |
1870 | + | |
53392da6 AM |
1871 | +Revalidate Dentry and UDBA (User's Direct Branch Access) |
1872 | +---------------------------------------------------------------------- | |
1873 | +Generally VFS helpers re-validate a dentry as a part of lookup. | |
1874 | +0. digging down the directory hierarchy. | |
1875 | +1. lock the parent dir by its i_mutex. | |
1876 | +2. lookup the final (child) entry. | |
1877 | +3. revalidate it. | |
1878 | +4. call the actual operation (create, unlink, etc.) | |
1879 | +5. unlock the parent dir | |
1880 | + | |
1881 | +If the filesystem implements its ->d_revalidate() (step 3), then it is | |
1882 | +called. Actually aufs implements it and checks the dentry on a branch is | |
1883 | +still valid. | |
1884 | +But it is not enough. Because aufs has to release the lock for the | |
1885 | +parent dir on a branch at the end of ->lookup() (step 2) and | |
1886 | +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still | |
1887 | +held by VFS. | |
1888 | +If the file on a branch is changed directly, eg. bypassing aufs, after | |
1889 | +aufs released the lock, then the subsequent operation may cause | |
1890 | +something unpleasant result. | |
1891 | + | |
1892 | +This situation is a result of VFS architecture, ->lookup() and | |
1893 | +->d_revalidate() is separated. But I never say it is wrong. It is a good | |
1894 | +design from VFS's point of view. It is just not suitable for sub-VFS | |
1895 | +character in aufs. | |
1896 | + | |
1897 | +Aufs supports such case by three level of revalidation which is | |
1898 | +selectable by user. | |
1899 | +1. Simple Revalidate | |
1900 | + Addition to the native flow in VFS's, confirm the child-parent | |
1901 | + relationship on the branch just after locking the parent dir on the | |
1902 | + branch in the "actual operation" (step 4). When this validation | |
1903 | + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still | |
1904 | + checks the validation of the dentry on branches. | |
1905 | +2. Monitor Changes Internally by Inotify/Fsnotify | |
1906 | + Addition to above, in the "actual operation" (step 4) aufs re-lookup | |
1907 | + the dentry on the branch, and returns EBUSY if it finds different | |
1908 | + dentry. | |
1909 | + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches | |
1910 | + during it is in cache. When the event is notified, aufs registers a | |
1911 | + function to kernel 'events' thread by schedule_work(). And the | |
1912 | + function sets some special status to the cached aufs dentry and inode | |
1913 | + private data. If they are not cached, then aufs has nothing to | |
1914 | + do. When the same file is accessed through aufs (step 0-3) later, | |
1915 | + aufs will detect the status and refresh all necessary data. | |
1916 | + In this mode, aufs has to ignore the event which is fired by aufs | |
1917 | + itself. | |
1918 | +3. No Extra Validation | |
1919 | + This is the simplest test and doesn't add any additional revalidation | |
7e9cd9fe | 1920 | + test, and skip the revalidation in step 4. It is useful and improves |
53392da6 AM |
1921 | + aufs performance when system surely hide the aufs branches from user, |
1922 | + by over-mounting something (or another method). | |
1923 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt | |
1924 | --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 1925 | +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2018-01-29 07:56:20.049991637 +0100 |
7e9cd9fe | 1926 | @@ -0,0 +1,74 @@ |
53392da6 | 1927 | + |
a2654f78 | 1928 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
1929 | +# |
1930 | +# This program is free software; you can redistribute it and/or modify | |
1931 | +# it under the terms of the GNU General Public License as published by | |
1932 | +# the Free Software Foundation; either version 2 of the License, or | |
1933 | +# (at your option) any later version. | |
1934 | +# | |
1935 | +# This program is distributed in the hope that it will be useful, | |
1936 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1937 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1938 | +# GNU General Public License for more details. | |
1939 | +# | |
1940 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1941 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1942 | + |
1943 | +Branch Manipulation | |
1944 | + | |
1945 | +Since aufs supports dynamic branch manipulation, ie. add/remove a branch | |
1946 | +and changing its permission/attribute, there are a lot of works to do. | |
1947 | + | |
1948 | + | |
1949 | +Add a Branch | |
1950 | +---------------------------------------------------------------------- | |
1951 | +o Confirm the adding dir exists outside of aufs, including loopback | |
7e9cd9fe | 1952 | + mount, and its various attributes. |
53392da6 AM |
1953 | +o Initialize the xino file and whiteout bases if necessary. |
1954 | + See struct.txt. | |
1955 | + | |
1956 | +o Check the owner/group/mode of the directory | |
1957 | + When the owner/group/mode of the adding directory differs from the | |
1958 | + existing branch, aufs issues a warning because it may impose a | |
1959 | + security risk. | |
1960 | + For example, when a upper writable branch has a world writable empty | |
1961 | + top directory, a malicious user can create any files on the writable | |
1962 | + branch directly, like copy-up and modify manually. If something like | |
1963 | + /etc/{passwd,shadow} exists on the lower readonly branch but the upper | |
1964 | + writable branch, and the writable branch is world-writable, then a | |
1965 | + malicious guy may create /etc/passwd on the writable branch directly | |
1966 | + and the infected file will be valid in aufs. | |
7e9cd9fe | 1967 | + I am afraid it can be a security issue, but aufs can do nothing except |
53392da6 AM |
1968 | + producing a warning. |
1969 | + | |
1970 | + | |
1971 | +Delete a Branch | |
1972 | +---------------------------------------------------------------------- | |
1973 | +o Confirm the deleting branch is not busy | |
1974 | + To be general, there is one merit to adopt "remount" interface to | |
1975 | + manipulate branches. It is to discard caches. At deleting a branch, | |
1976 | + aufs checks the still cached (and connected) dentries and inodes. If | |
1977 | + there are any, then they are all in-use. An inode without its | |
1978 | + corresponding dentry can be alive alone (for example, inotify/fsnotify case). | |
1979 | + | |
1980 | + For the cached one, aufs checks whether the same named entry exists on | |
1981 | + other branches. | |
1982 | + If the cached one is a directory, because aufs provides a merged view | |
1983 | + to users, as long as one dir is left on any branch aufs can show the | |
1984 | + dir to users. In this case, the branch can be removed from aufs. | |
1985 | + Otherwise aufs rejects deleting the branch. | |
1986 | + | |
1987 | + If any file on the deleting branch is opened by aufs, then aufs | |
1988 | + rejects deleting. | |
1989 | + | |
1990 | + | |
1991 | +Modify the Permission of a Branch | |
1992 | +---------------------------------------------------------------------- | |
1993 | +o Re-initialize or remove the xino file and whiteout bases if necessary. | |
1994 | + See struct.txt. | |
1995 | + | |
1996 | +o rw --> ro: Confirm the modifying branch is not busy | |
1997 | + Aufs rejects the request if any of these conditions are true. | |
1998 | + - a file on the branch is mmap-ed. | |
1999 | + - a regular file on the branch is opened for write and there is no | |
2000 | + same named entry on the upper branch. | |
2001 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt | |
2002 | --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2003 | +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2018-01-29 07:56:20.049991637 +0100 |
523b37e3 | 2004 | @@ -0,0 +1,64 @@ |
53392da6 | 2005 | + |
a2654f78 | 2006 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2007 | +# |
2008 | +# This program is free software; you can redistribute it and/or modify | |
2009 | +# it under the terms of the GNU General Public License as published by | |
2010 | +# the Free Software Foundation; either version 2 of the License, or | |
2011 | +# (at your option) any later version. | |
2012 | +# | |
2013 | +# This program is distributed in the hope that it will be useful, | |
2014 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2015 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2016 | +# GNU General Public License for more details. | |
2017 | +# | |
2018 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2019 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2020 | + |
2021 | +Policies to Select One among Multiple Writable Branches | |
2022 | +---------------------------------------------------------------------- | |
2023 | +When the number of writable branch is more than one, aufs has to decide | |
2024 | +the target branch for file creation or copy-up. By default, the highest | |
2025 | +writable branch which has the parent (or ancestor) dir of the target | |
2026 | +file is chosen (top-down-parent policy). | |
2027 | +By user's request, aufs implements some other policies to select the | |
7e9cd9fe AM |
2028 | +writable branch, for file creation several policies, round-robin, |
2029 | +most-free-space, and other policies. For copy-up, top-down-parent, | |
2030 | +bottom-up-parent, bottom-up and others. | |
53392da6 AM |
2031 | + |
2032 | +As expected, the round-robin policy selects the branch in circular. When | |
2033 | +you have two writable branches and creates 10 new files, 5 files will be | |
2034 | +created for each branch. mkdir(2) systemcall is an exception. When you | |
2035 | +create 10 new directories, all will be created on the same branch. | |
2036 | +And the most-free-space policy selects the one which has most free | |
2037 | +space among the writable branches. The amount of free space will be | |
2038 | +checked by aufs internally, and users can specify its time interval. | |
2039 | + | |
2040 | +The policies for copy-up is more simple, | |
2041 | +top-down-parent is equivalent to the same named on in create policy, | |
2042 | +bottom-up-parent selects the writable branch where the parent dir | |
2043 | +exists and the nearest upper one from the copyup-source, | |
2044 | +bottom-up selects the nearest upper writable branch from the | |
2045 | +copyup-source, regardless the existence of the parent dir. | |
2046 | + | |
2047 | +There are some rules or exceptions to apply these policies. | |
2048 | +- If there is a readonly branch above the policy-selected branch and | |
2049 | + the parent dir is marked as opaque (a variation of whiteout), or the | |
2050 | + target (creating) file is whiteout-ed on the upper readonly branch, | |
2051 | + then the result of the policy is ignored and the target file will be | |
2052 | + created on the nearest upper writable branch than the readonly branch. | |
2053 | +- If there is a writable branch above the policy-selected branch and | |
2054 | + the parent dir is marked as opaque or the target file is whiteouted | |
2055 | + on the branch, then the result of the policy is ignored and the target | |
2056 | + file will be created on the highest one among the upper writable | |
2057 | + branches who has diropq or whiteout. In case of whiteout, aufs removes | |
2058 | + it as usual. | |
2059 | +- link(2) and rename(2) systemcalls are exceptions in every policy. | |
2060 | + They try selecting the branch where the source exists as possible | |
2061 | + since copyup a large file will take long time. If it can't be, | |
2062 | + ie. the branch where the source exists is readonly, then they will | |
2063 | + follow the copyup policy. | |
2064 | +- There is an exception for rename(2) when the target exists. | |
2065 | + If the rename target exists, aufs compares the index of the branches | |
2066 | + where the source and the target exists and selects the higher | |
2067 | + one. If the selected branch is readonly, then aufs follows the | |
2068 | + copyup policy. | |
8b6a4947 AM |
2069 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot |
2070 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2071 | +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2018-01-29 07:56:20.049991637 +0100 |
8b6a4947 AM |
2072 | @@ -0,0 +1,31 @@ |
2073 | + | |
2074 | +// to view this graph, run dot(1) command in GRAPHVIZ. | |
2075 | + | |
2076 | +digraph G { | |
2077 | +node [shape=box]; | |
2078 | +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"]; | |
2079 | + | |
2080 | +node [shape=oval]; | |
2081 | + | |
2082 | +aufs_rename -> whinfo [label="store/remove"]; | |
2083 | + | |
2084 | +node [shape=oval]; | |
2085 | +inode_list [label="h_inum list in branch\ncache"]; | |
2086 | + | |
2087 | +node [shape=box]; | |
2088 | +whinode [label="h_inum list file"]; | |
2089 | + | |
2090 | +node [shape=oval]; | |
2091 | +brmgmt [label="br_add/del/mod/umount"]; | |
2092 | + | |
2093 | +brmgmt -> inode_list [label="create/remove"]; | |
2094 | +brmgmt -> whinode [label="load/store"]; | |
2095 | + | |
2096 | +inode_list -> whinode [style=dashed,dir=both]; | |
2097 | + | |
2098 | +aufs_rename -> inode_list [label="add/del"]; | |
2099 | + | |
2100 | +aufs_lookup -> inode_list [label="search"]; | |
2101 | + | |
2102 | +aufs_lookup -> whinfo [label="load/remove"]; | |
2103 | +} | |
2104 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt | |
2105 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2106 | +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2018-01-29 07:56:20.049991637 +0100 |
8b6a4947 AM |
2107 | @@ -0,0 +1,102 @@ |
2108 | + | |
2109 | +# Copyright (C) 2017 Junjiro R. Okajima | |
2110 | +# | |
2111 | +# This program is free software; you can redistribute it and/or modify | |
2112 | +# it under the terms of the GNU General Public License as published by | |
2113 | +# the Free Software Foundation; either version 2 of the License, or | |
2114 | +# (at your option) any later version. | |
2115 | +# | |
2116 | +# This program is distributed in the hope that it will be useful, | |
2117 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2118 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2119 | +# GNU General Public License for more details. | |
2120 | +# | |
2121 | +# You should have received a copy of the GNU General Public License | |
2122 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
2123 | + | |
2124 | +Special handling for renaming a directory (DIRREN) | |
2125 | +---------------------------------------------------------------------- | |
2126 | +First, let's assume we have a simple usecase. | |
2127 | + | |
2128 | +- /u = /rw + /ro | |
2129 | +- /rw/dirA exists | |
2130 | +- /ro/dirA and /ro/dirA/file exist too | |
2131 | +- there is no dirB on both branches | |
2132 | +- a user issues rename("dirA", "dirB") | |
2133 | + | |
2134 | +Now, what should aufs behave against this rename(2)? | |
2135 | +There are a few possible cases. | |
2136 | + | |
2137 | +A. returns EROFS. | |
2138 | + since dirA exists on a readonly branch which cannot be renamed. | |
2139 | +B. returns EXDEV. | |
2140 | + it is possible to copy-up dirA (only the dir itself), but the child | |
2141 | + entries ("file" in this case) should not be. it must be a bad | |
2142 | + approach to copy-up recursively. | |
2143 | +C. returns a success. | |
2144 | + even the branch /ro is readonly, aufs tries renaming it. Obviously it | |
2145 | + is a violation of aufs' policy. | |
2146 | +D. construct an extra information which indicates that /ro/dirA should | |
2147 | + be handled as the name of dirB. | |
2148 | + overlayfs has a similar feature called REDIRECT. | |
2149 | + | |
2150 | +Until now, aufs implements the case B only which returns EXDEV, and | |
2151 | +expects the userspace application behaves like mv(1) which tries | |
2152 | +issueing rename(2) recursively. | |
2153 | + | |
2154 | +A new aufs feature called DIRREN is introduced which implements the case | |
2155 | +D. There are several "extra information" added. | |
2156 | + | |
2157 | +1. detailed info per renamed directory | |
2158 | + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id> | |
2159 | +2. the inode-number list of directories on a branch | |
2160 | + path: /rw/dirB/$AUFS_WH_DR_BRHINO | |
2161 | + | |
2162 | +The filename of "detailed info per directory" represents the lower | |
2163 | +branch, and its format is | |
2164 | +- a type of the branch id | |
2165 | + one of these. | |
2166 | + + uuid (not implemented yet) | |
2167 | + + fsid | |
2168 | + + dev | |
2169 | +- the inode-number of the branch root dir | |
2170 | + | |
2171 | +And it contains these info in a single regular file. | |
2172 | +- magic number | |
2173 | +- branch's inode-number of the logically renamed dir | |
2174 | +- the name of the before-renamed dir | |
2175 | + | |
2176 | +The "detailed info per directory" file is created in aufs rename(2), and | |
2177 | +loaded in any lookup. | |
2178 | +The info is considered in lookup for the matching case only. Here | |
2179 | +"matching" means that the root of branch (in the info filename) is same | |
2180 | +to the current looking-up branch. After looking-up the before-renamed | |
2181 | +name, the inode-number is compared. And the matched dentry is used. | |
2182 | + | |
2183 | +The "inode-number list of directories" is a regular file which contains | |
2184 | +simply the inode-numbers on the branch. The file is created or updated | |
2185 | +in removing the branch, and loaded in adding the branch. Its lifetime is | |
2186 | +equal to the branch. | |
2187 | +The list is refered in lookup, and when the current target inode is | |
2188 | +found in the list, the aufs tries loading the "detailed info per | |
2189 | +directory" and get the changed and valid name of the dir. | |
2190 | + | |
2191 | +Theoretically these "extra informaiton" may be able to be put into XATTR | |
2192 | +in the dir inode. But aufs doesn't choose this way because | |
2193 | +1. XATTR may not be supported by the branch (or its configuration) | |
2194 | +2. XATTR may have its size limit. | |
2195 | +3. XATTR may be less easy to convert than a regular file, when the | |
2196 | + format of the info is changed in the future. | |
2197 | +At the same time, I agree that the regular file approach is much slower | |
2198 | +than XATTR approach. So, in the future, aufs may take the XATTR or other | |
2199 | +better approach. | |
2200 | + | |
2201 | +This DIRREN feature is enabled by aufs configuration, and is activated | |
2202 | +by a new mount option. | |
2203 | + | |
2204 | +For the more complicated case, there is a work with UDBA option, which | |
2205 | +is to dected the direct access to the branches (by-passing aufs) and to | |
2206 | +maintain the cashes in aufs. Since a single cached aufs dentry may | |
2207 | +contains two names, before- and after-rename, the name comparision in | |
2208 | +UDBA handler may not work correctly. In this case, the behaviour will be | |
2209 | +equivalen to udba=reval case. | |
076b876e AM |
2210 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt |
2211 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2212 | +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2018-01-29 07:56:20.049991637 +0100 |
076b876e AM |
2213 | @@ -0,0 +1,120 @@ |
2214 | + | |
a2654f78 | 2215 | +# Copyright (C) 2011-2017 Junjiro R. Okajima |
076b876e AM |
2216 | +# |
2217 | +# This program is free software; you can redistribute it and/or modify | |
2218 | +# it under the terms of the GNU General Public License as published by | |
2219 | +# the Free Software Foundation; either version 2 of the License, or | |
2220 | +# (at your option) any later version. | |
2221 | +# | |
2222 | +# This program is distributed in the hope that it will be useful, | |
2223 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2224 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2225 | +# GNU General Public License for more details. | |
2226 | +# | |
2227 | +# You should have received a copy of the GNU General Public License | |
2228 | +# along with this program; if not, write to the Free Software | |
2229 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2230 | + | |
2231 | + | |
2232 | +File-based Hierarchical Storage Management (FHSM) | |
2233 | +---------------------------------------------------------------------- | |
2234 | +Hierarchical Storage Management (or HSM) is a well-known feature in the | |
2235 | +storage world. Aufs provides this feature as file-based with multiple | |
7e9cd9fe | 2236 | +writable branches, based upon the principle of "Colder, the Lower". |
076b876e | 2237 | +Here the word "colder" means that the less used files, and "lower" means |
7e9cd9fe | 2238 | +that the position in the order of the stacked branches vertically. |
076b876e AM |
2239 | +These multiple writable branches are prioritized, ie. the topmost one |
2240 | +should be the fastest drive and be used heavily. | |
2241 | + | |
2242 | +o Characters in aufs FHSM story | |
2243 | +- aufs itself and a new branch attribute. | |
2244 | +- a new ioctl interface to move-down and to establish a connection with | |
2245 | + the daemon ("move-down" is a converse of "copy-up"). | |
2246 | +- userspace tool and daemon. | |
2247 | + | |
2248 | +The userspace daemon establishes a connection with aufs and waits for | |
2249 | +the notification. The notified information is very similar to struct | |
2250 | +statfs containing the number of consumed blocks and inodes. | |
2251 | +When the consumed blocks/inodes of a branch exceeds the user-specified | |
2252 | +upper watermark, the daemon activates its move-down process until the | |
2253 | +consumed blocks/inodes reaches the user-specified lower watermark. | |
2254 | + | |
2255 | +The actual move-down is done by aufs based upon the request from | |
2256 | +user-space since we need to maintain the inode number and the internal | |
2257 | +pointer arrays in aufs. | |
2258 | + | |
2259 | +Currently aufs FHSM handles the regular files only. Additionally they | |
2260 | +must not be hard-linked nor pseudo-linked. | |
2261 | + | |
2262 | + | |
2263 | +o Cowork of aufs and the user-space daemon | |
2264 | + During the userspace daemon established the connection, aufs sends a | |
2265 | + small notification to it whenever aufs writes something into the | |
2266 | + writable branch. But it may cost high since aufs issues statfs(2) | |
2267 | + internally. So user can specify a new option to cache the | |
2268 | + info. Actually the notification is controlled by these factors. | |
2269 | + + the specified cache time. | |
2270 | + + classified as "force" by aufs internally. | |
2271 | + Until the specified time expires, aufs doesn't send the info | |
2272 | + except the forced cases. When aufs decide forcing, the info is always | |
2273 | + notified to userspace. | |
2274 | + For example, the number of free inodes is generally large enough and | |
2275 | + the shortage of it happens rarely. So aufs doesn't force the | |
2276 | + notification when creating a new file, directory and others. This is | |
2277 | + the typical case which aufs doesn't force. | |
2278 | + When aufs writes the actual filedata and the files consumes any of new | |
2279 | + blocks, the aufs forces notifying. | |
2280 | + | |
2281 | + | |
2282 | +o Interfaces in aufs | |
2283 | +- New branch attribute. | |
2284 | + + fhsm | |
2285 | + Specifies that the branch is managed by FHSM feature. In other word, | |
2286 | + participant in the FHSM. | |
2287 | + When nofhsm is set to the branch, it will not be the source/target | |
2288 | + branch of the move-down operation. This attribute is set | |
2289 | + independently from coo and moo attributes, and if you want full | |
2290 | + FHSM, you should specify them as well. | |
2291 | +- New mount option. | |
2292 | + + fhsm_sec | |
2293 | + Specifies a second to suppress many less important info to be | |
2294 | + notified. | |
2295 | +- New ioctl. | |
2296 | + + AUFS_CTL_FHSM_FD | |
2297 | + create a new file descriptor which userspace can read the notification | |
2298 | + (a subset of struct statfs) from aufs. | |
2299 | +- Module parameter 'brs' | |
2300 | + It has to be set to 1. Otherwise the new mount option 'fhsm' will not | |
2301 | + be set. | |
2302 | +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs | |
2303 | + When there are two or more branches with fhsm attributes, | |
2304 | + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs | |
2305 | + terminates it. As a result of remounting and branch-manipulation, the | |
2306 | + number of branches with fhsm attribute can be one. In this case, | |
2307 | + /sbin/mount.aufs will terminate the user-space daemon. | |
2308 | + | |
2309 | + | |
2310 | +Finally the operation is done as these steps in kernel-space. | |
2311 | +- make sure that, | |
2312 | + + no one else is using the file. | |
2313 | + + the file is not hard-linked. | |
2314 | + + the file is not pseudo-linked. | |
2315 | + + the file is a regular file. | |
2316 | + + the parent dir is not opaqued. | |
2317 | +- find the target writable branch. | |
2318 | +- make sure the file is not whiteout-ed by the upper (than the target) | |
2319 | + branch. | |
2320 | +- make the parent dir on the target branch. | |
2321 | +- mutex lock the inode on the branch. | |
2322 | +- unlink the whiteout on the target branch (if exists). | |
2323 | +- lookup and create the whiteout-ed temporary name on the target branch. | |
2324 | +- copy the file as the whiteout-ed temporary name on the target branch. | |
2325 | +- rename the whiteout-ed temporary name to the original name. | |
2326 | +- unlink the file on the source branch. | |
2327 | +- maintain the internal pointer array and the external inode number | |
2328 | + table (XINO). | |
2329 | +- maintain the timestamps and other attributes of the parent dir and the | |
2330 | + file. | |
2331 | + | |
2332 | +And of course, in every step, an error may happen. So the operation | |
2333 | +should restore the original file state after an error happens. | |
53392da6 AM |
2334 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt |
2335 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2336 | +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2018-01-29 07:56:20.049991637 +0100 |
b912730e | 2337 | @@ -0,0 +1,72 @@ |
53392da6 | 2338 | + |
a2654f78 | 2339 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2340 | +# |
2341 | +# This program is free software; you can redistribute it and/or modify | |
2342 | +# it under the terms of the GNU General Public License as published by | |
2343 | +# the Free Software Foundation; either version 2 of the License, or | |
2344 | +# (at your option) any later version. | |
2345 | +# | |
2346 | +# This program is distributed in the hope that it will be useful, | |
2347 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2348 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2349 | +# GNU General Public License for more details. | |
2350 | +# | |
2351 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2352 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2353 | + |
2354 | +mmap(2) -- File Memory Mapping | |
2355 | +---------------------------------------------------------------------- | |
2356 | +In aufs, the file-mapped pages are handled by a branch fs directly, no | |
2357 | +interaction with aufs. It means aufs_mmap() calls the branch fs's | |
2358 | +->mmap(). | |
2359 | +This approach is simple and good, but there is one problem. | |
7e9cd9fe | 2360 | +Under /proc, several entries show the mmapped files by its path (with |
53392da6 AM |
2361 | +device and inode number), and the printed path will be the path on the |
2362 | +branch fs's instead of virtual aufs's. | |
2363 | +This is not a problem in most cases, but some utilities lsof(1) (and its | |
2364 | +user) may expect the path on aufs. | |
2365 | + | |
2366 | +To address this issue, aufs adds a new member called vm_prfile in struct | |
2367 | +vm_area_struct (and struct vm_region). The original vm_file points to | |
2368 | +the file on the branch fs in order to handle everything correctly as | |
2369 | +usual. The new vm_prfile points to a virtual file in aufs, and the | |
2370 | +show-functions in procfs refers to vm_prfile if it is set. | |
2371 | +Also we need to maintain several other places where touching vm_file | |
2372 | +such like | |
2373 | +- fork()/clone() copies vma and the reference count of vm_file is | |
2374 | + incremented. | |
2375 | +- merging vma maintains the ref count too. | |
2376 | + | |
7e9cd9fe | 2377 | +This is not a good approach. It just fakes the printed path. But it |
53392da6 AM |
2378 | +leaves all behaviour around f_mapping unchanged. This is surely an |
2379 | +advantage. | |
2380 | +Actually aufs had adopted another complicated approach which calls | |
2381 | +generic_file_mmap() and handles struct vm_operations_struct. In this | |
2382 | +approach, aufs met a hard problem and I could not solve it without | |
2383 | +switching the approach. | |
b912730e AM |
2384 | + |
2385 | +There may be one more another approach which is | |
2386 | +- bind-mount the branch-root onto the aufs-root internally | |
2387 | +- grab the new vfsmount (ie. struct mount) | |
2388 | +- lazy-umount the branch-root internally | |
2389 | +- in open(2) the aufs-file, open the branch-file with the hidden | |
2390 | + vfsmount (instead of the original branch's vfsmount) | |
2391 | +- ideally this "bind-mount and lazy-umount" should be done atomically, | |
2392 | + but it may be possible from userspace by the mount helper. | |
2393 | + | |
2394 | +Adding the internal hidden vfsmount and using it in opening a file, the | |
2395 | +file path under /proc will be printed correctly. This approach looks | |
2396 | +smarter, but is not possible I am afraid. | |
2397 | +- aufs-root may be bind-mount later. when it happens, another hidden | |
2398 | + vfsmount will be required. | |
2399 | +- it is hard to get the chance to bind-mount and lazy-umount | |
2400 | + + in kernel-space, FS can have vfsmount in open(2) via | |
2401 | + file->f_path, and aufs can know its vfsmount. But several locks are | |
2402 | + already acquired, and if aufs tries to bind-mount and lazy-umount | |
2403 | + here, then it may cause a deadlock. | |
2404 | + + in user-space, bind-mount doesn't invoke the mount helper. | |
2405 | +- since /proc shows dev and ino, aufs has to give vma these info. it | |
2406 | + means a new member vm_prinode will be necessary. this is essentially | |
2407 | + equivalent to vm_prfile described above. | |
2408 | + | |
2409 | +I have to give up this "looks-smater" approach. | |
c1595e42 JR |
2410 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt |
2411 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2412 | +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2018-01-29 07:56:20.049991637 +0100 |
c1595e42 JR |
2413 | @@ -0,0 +1,96 @@ |
2414 | + | |
a2654f78 | 2415 | +# Copyright (C) 2014-2017 Junjiro R. Okajima |
c1595e42 JR |
2416 | +# |
2417 | +# This program is free software; you can redistribute it and/or modify | |
2418 | +# it under the terms of the GNU General Public License as published by | |
2419 | +# the Free Software Foundation; either version 2 of the License, or | |
2420 | +# (at your option) any later version. | |
2421 | +# | |
2422 | +# This program is distributed in the hope that it will be useful, | |
2423 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2424 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2425 | +# GNU General Public License for more details. | |
2426 | +# | |
2427 | +# You should have received a copy of the GNU General Public License | |
2428 | +# along with this program; if not, write to the Free Software | |
2429 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2430 | + | |
2431 | + | |
2432 | +Listing XATTR/EA and getting the value | |
2433 | +---------------------------------------------------------------------- | |
2434 | +For the inode standard attributes (owner, group, timestamps, etc.), aufs | |
2435 | +shows the values from the topmost existing file. This behaviour is good | |
7e9cd9fe | 2436 | +for the non-dir entries since the bahaviour exactly matches the shown |
c1595e42 JR |
2437 | +information. But for the directories, aufs considers all the same named |
2438 | +entries on the lower branches. Which means, if one of the lower entry | |
2439 | +rejects readdir call, then aufs returns an error even if the topmost | |
2440 | +entry allows it. This behaviour is necessary to respect the branch fs's | |
2441 | +security, but can make users confused since the user-visible standard | |
2442 | +attributes don't match the behaviour. | |
2443 | +To address this issue, aufs has a mount option called dirperm1 which | |
2444 | +checks the permission for the topmost entry only, and ignores the lower | |
2445 | +entry's permission. | |
2446 | + | |
2447 | +A similar issue can happen around XATTR. | |
2448 | +getxattr(2) and listxattr(2) families behave as if dirperm1 option is | |
7e9cd9fe AM |
2449 | +always set. Otherwise these very unpleasant situation would happen. |
2450 | +- listxattr(2) may return the duplicated entries. | |
c1595e42 JR |
2451 | +- users may not be able to remove or reset the XATTR forever, |
2452 | + | |
2453 | + | |
2454 | +XATTR/EA support in the internal (copy,move)-(up,down) | |
2455 | +---------------------------------------------------------------------- | |
7e9cd9fe | 2456 | +Generally the extended attributes of inode are categorized as these. |
c1595e42 JR |
2457 | +- "security" for LSM and capability. |
2458 | +- "system" for posix ACL, 'acl' mount option is required for the branch | |
2459 | + fs generally. | |
2460 | +- "trusted" for userspace, CAP_SYS_ADMIN is required. | |
2461 | +- "user" for userspace, 'user_xattr' mount option is required for the | |
2462 | + branch fs generally. | |
2463 | + | |
2464 | +Moreover there are some other categories. Aufs handles these rather | |
2465 | +unpopular categories as the ordinary ones, ie. there is no special | |
2466 | +condition nor exception. | |
2467 | + | |
2468 | +In copy-up, the support for XATTR on the dst branch may differ from the | |
2469 | +src branch. In this case, the copy-up operation will get an error and | |
7e9cd9fe AM |
2470 | +the original user operation which triggered the copy-up will fail. It |
2471 | +can happen that even all copy-up will fail. | |
c1595e42 JR |
2472 | +When both of src and dst branches support XATTR and if an error occurs |
2473 | +during copying XATTR, then the copy-up should fail obviously. That is a | |
2474 | +good reason and aufs should return an error to userspace. But when only | |
7e9cd9fe | 2475 | +the src branch support that XATTR, aufs should not return an error. |
c1595e42 JR |
2476 | +For example, the src branch supports ACL but the dst branch doesn't |
2477 | +because the dst branch may natively un-support it or temporary | |
2478 | +un-support it due to "noacl" mount option. Of course, the dst branch fs | |
2479 | +may NOT return an error even if the XATTR is not supported. It is | |
2480 | +totally up to the branch fs. | |
2481 | + | |
2482 | +Anyway when the aufs internal copy-up gets an error from the dst branch | |
2483 | +fs, then aufs tries removing the just copied entry and returns the error | |
2484 | +to the userspace. The worst case of this situation will be all copy-up | |
2485 | +will fail. | |
2486 | + | |
2487 | +For the copy-up operation, there two basic approaches. | |
2488 | +- copy the specified XATTR only (by category above), and return the | |
7e9cd9fe | 2489 | + error unconditionally if it happens. |
c1595e42 JR |
2490 | +- copy all XATTR, and ignore the error on the specified category only. |
2491 | + | |
2492 | +In order to support XATTR and to implement the correct behaviour, aufs | |
7e9cd9fe AM |
2493 | +chooses the latter approach and introduces some new branch attributes, |
2494 | +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth". | |
c1595e42 | 2495 | +They correspond to the XATTR namespaces (see above). Additionally, to be |
7e9cd9fe AM |
2496 | +convenient, "icex" is also provided which means all "icex*" attributes |
2497 | +are set (here the word "icex" stands for "ignore copy-error on XATTR"). | |
c1595e42 JR |
2498 | + |
2499 | +The meaning of these attributes is to ignore the error from setting | |
2500 | +XATTR on that branch. | |
2501 | +Note that aufs tries copying all XATTR unconditionally, and ignores the | |
2502 | +error from the dst branch according to the specified attributes. | |
2503 | + | |
2504 | +Some XATTR may have its default value. The default value may come from | |
2505 | +the parent dir or the environment. If the default value is set at the | |
2506 | +file creating-time, it will be overwritten by copy-up. | |
2507 | +Some contradiction may happen I am afraid. | |
2508 | +Do we need another attribute to stop copying XATTR? I am unsure. For | |
2509 | +now, aufs implements the branch attributes to ignore the error. | |
53392da6 AM |
2510 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt |
2511 | --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2512 | +++ linux/Documentation/filesystems/aufs/design/07export.txt 2018-01-29 07:56:20.049991637 +0100 |
523b37e3 | 2513 | @@ -0,0 +1,58 @@ |
53392da6 | 2514 | + |
a2654f78 | 2515 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2516 | +# |
2517 | +# This program is free software; you can redistribute it and/or modify | |
2518 | +# it under the terms of the GNU General Public License as published by | |
2519 | +# the Free Software Foundation; either version 2 of the License, or | |
2520 | +# (at your option) any later version. | |
2521 | +# | |
2522 | +# This program is distributed in the hope that it will be useful, | |
2523 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2524 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2525 | +# GNU General Public License for more details. | |
2526 | +# | |
2527 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2528 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2529 | + |
2530 | +Export Aufs via NFS | |
2531 | +---------------------------------------------------------------------- | |
2532 | +Here is an approach. | |
2533 | +- like xino/xib, add a new file 'xigen' which stores aufs inode | |
2534 | + generation. | |
2535 | +- iget_locked(): initialize aufs inode generation for a new inode, and | |
2536 | + store it in xigen file. | |
2537 | +- destroy_inode(): increment aufs inode generation and store it in xigen | |
2538 | + file. it is necessary even if it is not unlinked, because any data of | |
2539 | + inode may be changed by UDBA. | |
2540 | +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise | |
2541 | + build file handle by | |
2542 | + + branch id (4 bytes) | |
2543 | + + superblock generation (4 bytes) | |
2544 | + + inode number (4 or 8 bytes) | |
2545 | + + parent dir inode number (4 or 8 bytes) | |
2546 | + + inode generation (4 bytes)) | |
2547 | + + return value of exportfs_encode_fh() for the parent on a branch (4 | |
2548 | + bytes) | |
2549 | + + file handle for a branch (by exportfs_encode_fh()) | |
2550 | +- fh_to_dentry(): | |
2551 | + + find the index of a branch from its id in handle, and check it is | |
2552 | + still exist in aufs. | |
2553 | + + 1st level: get the inode number from handle and search it in cache. | |
7e9cd9fe AM |
2554 | + + 2nd level: if not found in cache, get the parent inode number from |
2555 | + the handle and search it in cache. and then open the found parent | |
2556 | + dir, find the matching inode number by vfs_readdir() and get its | |
2557 | + name, and call lookup_one_len() for the target dentry. | |
53392da6 AM |
2558 | + + 3rd level: if the parent dir is not cached, call |
2559 | + exportfs_decode_fh() for a branch and get the parent on a branch, | |
2560 | + build a pathname of it, convert it a pathname in aufs, call | |
2561 | + path_lookup(). now aufs gets a parent dir dentry, then handle it as | |
2562 | + the 2nd level. | |
2563 | + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount | |
2564 | + for every branch, but not itself. to get this, (currently) aufs | |
2565 | + searches in current->nsproxy->mnt_ns list. it may not be a good | |
2566 | + idea, but I didn't get other approach. | |
2567 | + + test the generation of the gotten inode. | |
2568 | +- every inode operation: they may get EBUSY due to UDBA. in this case, | |
2569 | + convert it into ESTALE for NFSD. | |
2570 | +- readdir(): call lockdep_on/off() because filldir in NFSD calls | |
2571 | + lookup_one_len(), vfs_getattr(), encode_fh() and others. | |
2572 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt | |
2573 | --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2574 | +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2018-01-29 07:56:20.049991637 +0100 |
523b37e3 | 2575 | @@ -0,0 +1,52 @@ |
53392da6 | 2576 | + |
a2654f78 | 2577 | +# Copyright (C) 2005-2017 Junjiro R. Okajima |
53392da6 AM |
2578 | +# |
2579 | +# This program is free software; you can redistribute it and/or modify | |
2580 | +# it under the terms of the GNU General Public License as published by | |
2581 | +# the Free Software Foundation; either version 2 of the License, or | |
2582 | +# (at your option) any later version. | |
2583 | +# | |
2584 | +# This program is distributed in the hope that it will be useful, | |
2585 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2586 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2587 | +# GNU General Public License for more details. | |
2588 | +# | |
2589 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2590 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2591 | + |
2592 | +Show Whiteout Mode (shwh) | |
2593 | +---------------------------------------------------------------------- | |
2594 | +Generally aufs hides the name of whiteouts. But in some cases, to show | |
2595 | +them is very useful for users. For instance, creating a new middle layer | |
2596 | +(branch) by merging existing layers. | |
2597 | + | |
2598 | +(borrowing aufs1 HOW-TO from a user, Michael Towers) | |
2599 | +When you have three branches, | |
2600 | +- Bottom: 'system', squashfs (underlying base system), read-only | |
2601 | +- Middle: 'mods', squashfs, read-only | |
2602 | +- Top: 'overlay', ram (tmpfs), read-write | |
2603 | + | |
2604 | +The top layer is loaded at boot time and saved at shutdown, to preserve | |
2605 | +the changes made to the system during the session. | |
2606 | +When larger changes have been made, or smaller changes have accumulated, | |
2607 | +the size of the saved top layer data grows. At this point, it would be | |
2608 | +nice to be able to merge the two overlay branches ('mods' and 'overlay') | |
2609 | +and rewrite the 'mods' squashfs, clearing the top layer and thus | |
2610 | +restoring save and load speed. | |
2611 | + | |
2612 | +This merging is simplified by the use of another aufs mount, of just the | |
2613 | +two overlay branches using the 'shwh' option. | |
2614 | +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \ | |
2615 | + aufs /livesys/merge_union | |
2616 | + | |
2617 | +A merged view of these two branches is then available at | |
2618 | +/livesys/merge_union, and the new feature is that the whiteouts are | |
2619 | +visible! | |
2620 | +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable | |
2621 | +writing to all branches. Also the default mode for all branches is 'ro'. | |
2622 | +It is now possible to save the combined contents of the two overlay | |
2623 | +branches to a new squashfs, e.g.: | |
2624 | +# mksquashfs /livesys/merge_union /path/to/newmods.squash | |
2625 | + | |
2626 | +This new squashfs archive can be stored on the boot device and the | |
2627 | +initramfs will use it to replace the old one at the next boot. | |
2628 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt | |
2629 | --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2630 | +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2018-01-29 07:56:20.049991637 +0100 |
7e9cd9fe | 2631 | @@ -0,0 +1,47 @@ |
53392da6 | 2632 | + |
a2654f78 | 2633 | +# Copyright (C) 2010-2017 Junjiro R. Okajima |
53392da6 AM |
2634 | +# |
2635 | +# This program is free software; you can redistribute it and/or modify | |
2636 | +# it under the terms of the GNU General Public License as published by | |
2637 | +# the Free Software Foundation; either version 2 of the License, or | |
2638 | +# (at your option) any later version. | |
2639 | +# | |
2640 | +# This program is distributed in the hope that it will be useful, | |
2641 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2642 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2643 | +# GNU General Public License for more details. | |
2644 | +# | |
2645 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2646 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2647 | + |
2648 | +Dynamically customizable FS operations | |
2649 | +---------------------------------------------------------------------- | |
2650 | +Generally FS operations (struct inode_operations, struct | |
2651 | +address_space_operations, struct file_operations, etc.) are defined as | |
2652 | +"static const", but it never means that FS have only one set of | |
2653 | +operation. Some FS have multiple sets of them. For instance, ext2 has | |
2654 | +three sets, one for XIP, for NOBH, and for normal. | |
2655 | +Since aufs overrides and redirects these operations, sometimes aufs has | |
7e9cd9fe | 2656 | +to change its behaviour according to the branch FS type. More importantly |
53392da6 AM |
2657 | +VFS acts differently if a function (member in the struct) is set or |
2658 | +not. It means aufs should have several sets of operations and select one | |
2659 | +among them according to the branch FS definition. | |
2660 | + | |
7e9cd9fe | 2661 | +In order to solve this problem and not to affect the behaviour of VFS, |
53392da6 | 2662 | +aufs defines these operations dynamically. For instance, aufs defines |
7e9cd9fe AM |
2663 | +dummy direct_IO function for struct address_space_operations, but it may |
2664 | +not be set to the address_space_operations actually. When the branch FS | |
2665 | +doesn't have it, aufs doesn't set it to its address_space_operations | |
2666 | +while the function definition itself is still alive. So the behaviour | |
2667 | +itself will not change, and it will return an error when direct_IO is | |
2668 | +not set. | |
53392da6 AM |
2669 | + |
2670 | +The lifetime of these dynamically generated operation object is | |
2671 | +maintained by aufs branch object. When the branch is removed from aufs, | |
2672 | +the reference counter of the object is decremented. When it reaches | |
2673 | +zero, the dynamically generated operation object will be freed. | |
2674 | + | |
7e9cd9fe AM |
2675 | +This approach is designed to support AIO (io_submit), Direct I/O and |
2676 | +XIP (DAX) mainly. | |
2677 | +Currently this approach is applied to address_space_operations for | |
2678 | +regular files only. | |
53392da6 AM |
2679 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README |
2680 | --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 2681 | +++ linux/Documentation/filesystems/aufs/README 2018-01-29 07:56:20.046658203 +0100 |
f2c43d5f | 2682 | @@ -0,0 +1,393 @@ |
53392da6 | 2683 | + |
5527c038 | 2684 | +Aufs4 -- advanced multi layered unification filesystem version 4.x |
53392da6 AM |
2685 | +http://aufs.sf.net |
2686 | +Junjiro R. Okajima | |
2687 | + | |
2688 | + | |
2689 | +0. Introduction | |
2690 | +---------------------------------------- | |
2691 | +In the early days, aufs was entirely re-designed and re-implemented | |
7e9cd9fe | 2692 | +Unionfs Version 1.x series. Adding many original ideas, approaches, |
53392da6 AM |
2693 | +improvements and implementations, it becomes totally different from |
2694 | +Unionfs while keeping the basic features. | |
2695 | +Recently, Unionfs Version 2.x series begin taking some of the same | |
2696 | +approaches to aufs1's. | |
2697 | +Unionfs is being developed by Professor Erez Zadok at Stony Brook | |
2698 | +University and his team. | |
2699 | + | |
5527c038 | 2700 | +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3. |
53392da6 AM |
2701 | +If you want older kernel version support, try aufs2-2.6.git or |
2702 | +aufs2-standalone.git repository, aufs1 from CVS on SourceForge. | |
2703 | + | |
2704 | +Note: it becomes clear that "Aufs was rejected. Let's give it up." | |
38d290e6 JR |
2705 | + According to Christoph Hellwig, linux rejects all union-type |
2706 | + filesystems but UnionMount. | |
53392da6 AM |
2707 | +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2> |
2708 | + | |
38d290e6 JR |
2709 | +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and |
2710 | + UnionMount, and he pointed out an issue around a directory mutex | |
2711 | + lock and aufs addressed it. But it is still unsure whether aufs will | |
2712 | + be merged (or any other union solution). | |
076b876e | 2713 | +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1> |
38d290e6 | 2714 | + |
53392da6 AM |
2715 | + |
2716 | +1. Features | |
2717 | +---------------------------------------- | |
2718 | +- unite several directories into a single virtual filesystem. The member | |
2719 | + directory is called as a branch. | |
2720 | +- you can specify the permission flags to the branch, which are 'readonly', | |
2721 | + 'readwrite' and 'whiteout-able.' | |
2722 | +- by upper writable branch, internal copyup and whiteout, files/dirs on | |
2723 | + readonly branch are modifiable logically. | |
2724 | +- dynamic branch manipulation, add, del. | |
2725 | +- etc... | |
2726 | + | |
7e9cd9fe AM |
2727 | +Also there are many enhancements in aufs, such as: |
2728 | +- test only the highest one for the directory permission (dirperm1) | |
2729 | +- copyup on open (coo=) | |
2730 | +- 'move' policy for copy-up between two writable branches, after | |
2731 | + checking free space. | |
2732 | +- xattr, acl | |
53392da6 AM |
2733 | +- readdir(3) in userspace. |
2734 | +- keep inode number by external inode number table | |
2735 | +- keep the timestamps of file/dir in internal copyup operation | |
2736 | +- seekable directory, supporting NFS readdir. | |
2737 | +- whiteout is hardlinked in order to reduce the consumption of inodes | |
2738 | + on branch | |
2739 | +- do not copyup, nor create a whiteout when it is unnecessary | |
2740 | +- revert a single systemcall when an error occurs in aufs | |
2741 | +- remount interface instead of ioctl | |
2742 | +- maintain /etc/mtab by an external command, /sbin/mount.aufs. | |
2743 | +- loopback mounted filesystem as a branch | |
2744 | +- kernel thread for removing the dir who has a plenty of whiteouts | |
2745 | +- support copyup sparse file (a file which has a 'hole' in it) | |
2746 | +- default permission flags for branches | |
2747 | +- selectable permission flags for ro branch, whether whiteout can | |
2748 | + exist or not | |
2749 | +- export via NFS. | |
2750 | +- support <sysfs>/fs/aufs and <debugfs>/aufs. | |
2751 | +- support multiple writable branches, some policies to select one | |
2752 | + among multiple writable branches. | |
2753 | +- a new semantics for link(2) and rename(2) to support multiple | |
2754 | + writable branches. | |
2755 | +- no glibc changes are required. | |
2756 | +- pseudo hardlink (hardlink over branches) | |
2757 | +- allow a direct access manually to a file on branch, e.g. bypassing aufs. | |
2758 | + including NFS or remote filesystem branch. | |
2759 | +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX. | |
2760 | +- and more... | |
2761 | + | |
5527c038 | 2762 | +Currently these features are dropped temporary from aufs4. |
53392da6 | 2763 | +See design/08plan.txt in detail. |
53392da6 AM |
2764 | +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs |
2765 | + (robr) | |
2766 | +- statistics of aufs thread (/sys/fs/aufs/stat) | |
53392da6 AM |
2767 | + |
2768 | +Features or just an idea in the future (see also design/*.txt), | |
2769 | +- reorder the branch index without del/re-add. | |
2770 | +- permanent xino files for NFSD | |
2771 | +- an option for refreshing the opened files after add/del branches | |
53392da6 AM |
2772 | +- light version, without branch manipulation. (unnecessary?) |
2773 | +- copyup in userspace | |
2774 | +- inotify in userspace | |
2775 | +- readv/writev | |
53392da6 AM |
2776 | + |
2777 | + | |
2778 | +2. Download | |
2779 | +---------------------------------------- | |
5527c038 JR |
2780 | +There are three GIT trees for aufs4, aufs4-linux.git, |
2781 | +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in | |
1e00d052 | 2782 | +"aufs-util.git." |
5527c038 JR |
2783 | +While the aufs-util is always necessary, you need either of aufs4-linux |
2784 | +or aufs4-standalone. | |
1e00d052 | 2785 | + |
5527c038 | 2786 | +The aufs4-linux tree includes the whole linux mainline GIT tree, |
1e00d052 AM |
2787 | +git://git.kernel.org/.../torvalds/linux.git. |
2788 | +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot | |
5527c038 | 2789 | +build aufs4 as an external kernel module. |
2000de60 | 2790 | +Several extra patches are not included in this tree. Only |
be52b249 | 2791 | +aufs4-standalone tree contains them. They are described in the later |
2000de60 | 2792 | +section "Configuration and Compilation." |
1e00d052 | 2793 | + |
5527c038 | 2794 | +On the other hand, the aufs4-standalone tree has only aufs source files |
53392da6 | 2795 | +and necessary patches, and you can select CONFIG_AUFS_FS=m. |
2000de60 | 2796 | +But you need to apply all aufs patches manually. |
53392da6 | 2797 | + |
5527c038 JR |
2798 | +You will find GIT branches whose name is in form of "aufs4.x" where "x" |
2799 | +represents the linux kernel version, "linux-4.x". For instance, | |
2800 | +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use | |
2801 | +"aufs4.x-rcN" branch. | |
1e00d052 | 2802 | + |
5527c038 | 2803 | +o aufs4-linux tree |
1e00d052 | 2804 | +$ git clone --reference /your/linux/git/tree \ |
5527c038 | 2805 | + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git |
1e00d052 | 2806 | +- if you don't have linux GIT tree, then remove "--reference ..." |
5527c038 JR |
2807 | +$ cd aufs4-linux.git |
2808 | +$ git checkout origin/aufs4.0 | |
53392da6 | 2809 | + |
2000de60 JR |
2810 | +Or You may want to directly git-pull aufs into your linux GIT tree, and |
2811 | +leave the patch-work to GIT. | |
2812 | +$ cd /your/linux/git/tree | |
5527c038 JR |
2813 | +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git |
2814 | +$ git fetch aufs4 | |
2815 | +$ git checkout -b my4.0 v4.0 | |
2816 | +$ (add your local change...) | |
2817 | +$ git pull aufs4 aufs4.0 | |
2818 | +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch. | |
2000de60 | 2819 | +- you may need to solve some conflicts between your_changes and |
5527c038 JR |
2820 | + aufs4.0. in this case, git-rerere is recommended so that you can |
2821 | + solve the similar conflicts automatically when you upgrade to 4.1 or | |
2000de60 JR |
2822 | + later in the future. |
2823 | + | |
5527c038 JR |
2824 | +o aufs4-standalone tree |
2825 | +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git | |
2826 | +$ cd aufs4-standalone.git | |
2827 | +$ git checkout origin/aufs4.0 | |
53392da6 AM |
2828 | + |
2829 | +o aufs-util tree | |
5527c038 JR |
2830 | +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git |
2831 | +- note that the public aufs-util.git is on SourceForge instead of | |
2832 | + GitHUB. | |
53392da6 | 2833 | +$ cd aufs-util.git |
5527c038 | 2834 | +$ git checkout origin/aufs4.0 |
53392da6 | 2835 | + |
5527c038 JR |
2836 | +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY. |
2837 | +The minor version number, 'x' in '4.x', of aufs may not always | |
9dbd164d AM |
2838 | +follow the minor version number of the kernel. |
2839 | +Because changes in the kernel that cause the use of a new | |
2840 | +minor version number do not always require changes to aufs-util. | |
2841 | + | |
2842 | +Since aufs-util has its own minor version number, you may not be | |
2843 | +able to find a GIT branch in aufs-util for your kernel's | |
2844 | +exact minor version number. | |
2845 | +In this case, you should git-checkout the branch for the | |
53392da6 | 2846 | +nearest lower number. |
9dbd164d AM |
2847 | + |
2848 | +For (an unreleased) example: | |
5527c038 JR |
2849 | +If you are using "linux-4.10" and the "aufs4.10" branch |
2850 | +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8" | |
9dbd164d AM |
2851 | +or something numerically smaller is the branch for your kernel. |
2852 | + | |
53392da6 AM |
2853 | +Also you can view all branches by |
2854 | + $ git branch -a | |
2855 | + | |
2856 | + | |
2857 | +3. Configuration and Compilation | |
2858 | +---------------------------------------- | |
2859 | +Make sure you have git-checkout'ed the correct branch. | |
2860 | + | |
5527c038 | 2861 | +For aufs4-linux tree, |
c06a8ce3 | 2862 | +- enable CONFIG_AUFS_FS. |
1e00d052 AM |
2863 | +- set other aufs configurations if necessary. |
2864 | + | |
5527c038 | 2865 | +For aufs4-standalone tree, |
53392da6 AM |
2866 | +There are several ways to build. |
2867 | + | |
2868 | +1. | |
5527c038 JR |
2869 | +- apply ./aufs4-kbuild.patch to your kernel source files. |
2870 | +- apply ./aufs4-base.patch too. | |
2871 | +- apply ./aufs4-mmap.patch too. | |
2872 | +- apply ./aufs4-standalone.patch too, if you have a plan to set | |
2873 | + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch. | |
537831f9 AM |
2874 | +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your |
2875 | + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild. | |
c06a8ce3 | 2876 | +- enable CONFIG_AUFS_FS, you can select either |
53392da6 AM |
2877 | + =m or =y. |
2878 | +- and build your kernel as usual. | |
2879 | +- install the built kernel. | |
c06a8ce3 AM |
2880 | + Note: Since linux-3.9, every filesystem module requires an alias |
2881 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2882 | + modules.aliases file if you set CONFIG_AUFS_FS=m. | |
7eafdf33 AM |
2883 | +- install the header files too by "make headers_install" to the |
2884 | + directory where you specify. By default, it is $PWD/usr. | |
b4510431 | 2885 | + "make help" shows a brief note for headers_install. |
53392da6 AM |
2886 | +- and reboot your system. |
2887 | + | |
2888 | +2. | |
2889 | +- module only (CONFIG_AUFS_FS=m). | |
5527c038 JR |
2890 | +- apply ./aufs4-base.patch to your kernel source files. |
2891 | +- apply ./aufs4-mmap.patch too. | |
2892 | +- apply ./aufs4-standalone.patch too. | |
53392da6 AM |
2893 | +- build your kernel, don't forget "make headers_install", and reboot. |
2894 | +- edit ./config.mk and set other aufs configurations if necessary. | |
b4510431 | 2895 | + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes |
53392da6 AM |
2896 | + every aufs configurations. |
2897 | +- build the module by simple "make". | |
c06a8ce3 AM |
2898 | + Note: Since linux-3.9, every filesystem module requires an alias |
2899 | + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your | |
2900 | + modules.aliases file. | |
53392da6 AM |
2901 | +- you can specify ${KDIR} make variable which points to your kernel |
2902 | + source tree. | |
2903 | +- install the files | |
2904 | + + run "make install" to install the aufs module, or copy the built | |
b4510431 AM |
2905 | + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply). |
2906 | + + run "make install_headers" (instead of headers_install) to install | |
2907 | + the modified aufs header file (you can specify DESTDIR which is | |
2908 | + available in aufs standalone version's Makefile only), or copy | |
2909 | + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever | |
2910 | + you like manually. By default, the target directory is $PWD/usr. | |
5527c038 | 2911 | +- no need to apply aufs4-kbuild.patch, nor copying source files to your |
53392da6 AM |
2912 | + kernel source tree. |
2913 | + | |
b4510431 | 2914 | +Note: The header file aufs_type.h is necessary to build aufs-util |
53392da6 AM |
2915 | + as well as "make headers_install" in the kernel source tree. |
2916 | + headers_install is subject to be forgotten, but it is essentially | |
2917 | + necessary, not only for building aufs-util. | |
2918 | + You may not meet problems without headers_install in some older | |
2919 | + version though. | |
2920 | + | |
2921 | +And then, | |
2922 | +- read README in aufs-util, build and install it | |
9dbd164d AM |
2923 | +- note that your distribution may contain an obsoleted version of |
2924 | + aufs_type.h in /usr/include/linux or something. When you build aufs | |
2925 | + utilities, make sure that your compiler refers the correct aufs header | |
2926 | + file which is built by "make headers_install." | |
53392da6 AM |
2927 | +- if you want to use readdir(3) in userspace or pathconf(3) wrapper, |
2928 | + then run "make install_ulib" too. And refer to the aufs manual in | |
2929 | + detail. | |
2930 | + | |
5527c038 | 2931 | +There several other patches in aufs4-standalone.git. They are all |
38d290e6 | 2932 | +optional. When you meet some problems, they will help you. |
5527c038 | 2933 | +- aufs4-loopback.patch |
38d290e6 JR |
2934 | + Supports a nested loopback mount in a branch-fs. This patch is |
2935 | + unnecessary until aufs produces a message like "you may want to try | |
2936 | + another patch for loopback file". | |
2937 | +- vfs-ino.patch | |
2938 | + Modifies a system global kernel internal function get_next_ino() in | |
2939 | + order to stop assigning 0 for an inode-number. Not directly related to | |
2940 | + aufs, but recommended generally. | |
2941 | +- tmpfs-idr.patch | |
2942 | + Keeps the tmpfs inode number as the lowest value. Effective to reduce | |
2943 | + the size of aufs XINO files for tmpfs branch. Also it prevents the | |
2944 | + duplication of inode number, which is important for backup tools and | |
2945 | + other utilities. When you find aufs XINO files for tmpfs branch | |
2946 | + growing too much, try this patch. | |
be52b249 AM |
2947 | +- lockdep-debug.patch |
2948 | + Because aufs is not only an ordinary filesystem (callee of VFS), but | |
2949 | + also a caller of VFS functions for branch filesystems, subclassing of | |
2950 | + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging | |
2951 | + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will | |
2952 | + need to apply this debug patch to expand several constant values. | |
2953 | + If don't know what LOCKDEP, then you don't have apply this patch. | |
38d290e6 | 2954 | + |
53392da6 AM |
2955 | + |
2956 | +4. Usage | |
2957 | +---------------------------------------- | |
2958 | +At first, make sure aufs-util are installed, and please read the aufs | |
2959 | +manual, aufs.5 in aufs-util.git tree. | |
2960 | +$ man -l aufs.5 | |
2961 | + | |
2962 | +And then, | |
2963 | +$ mkdir /tmp/rw /tmp/aufs | |
2964 | +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs | |
2965 | + | |
2966 | +Here is another example. The result is equivalent. | |
2967 | +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs | |
2968 | + Or | |
2969 | +# mount -t aufs -o br:/tmp/rw none /tmp/aufs | |
2970 | +# mount -o remount,append:${HOME} /tmp/aufs | |
2971 | + | |
2972 | +Then, you can see whole tree of your home dir through /tmp/aufs. If | |
2973 | +you modify a file under /tmp/aufs, the one on your home directory is | |
2974 | +not affected, instead the same named file will be newly created under | |
2975 | +/tmp/rw. And all of your modification to a file will be applied to | |
2976 | +the one under /tmp/rw. This is called the file based Copy on Write | |
2977 | +(COW) method. | |
2978 | +Aufs mount options are described in aufs.5. | |
2979 | +If you run chroot or something and make your aufs as a root directory, | |
2980 | +then you need to customize the shutdown script. See the aufs manual in | |
2981 | +detail. | |
2982 | + | |
2983 | +Additionally, there are some sample usages of aufs which are a | |
2984 | +diskless system with network booting, and LiveCD over NFS. | |
2985 | +See sample dir in CVS tree on SourceForge. | |
2986 | + | |
2987 | + | |
2988 | +5. Contact | |
2989 | +---------------------------------------- | |
2990 | +When you have any problems or strange behaviour in aufs, please let me | |
2991 | +know with: | |
2992 | +- /proc/mounts (instead of the output of mount(8)) | |
2993 | +- /sys/module/aufs/* | |
2994 | +- /sys/fs/aufs/* (if you have them) | |
2995 | +- /debug/aufs/* (if you have them) | |
2996 | +- linux kernel version | |
2997 | + if your kernel is not plain, for example modified by distributor, | |
2998 | + the url where i can download its source is necessary too. | |
2999 | +- aufs version which was printed at loading the module or booting the | |
3000 | + system, instead of the date you downloaded. | |
3001 | +- configuration (define/undefine CONFIG_AUFS_xxx) | |
3002 | +- kernel configuration or /proc/config.gz (if you have it) | |
3003 | +- behaviour which you think to be incorrect | |
3004 | +- actual operation, reproducible one is better | |
3005 | +- mailto: aufs-users at lists.sourceforge.net | |
3006 | + | |
3007 | +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches, | |
3008 | +and Feature Requests) on SourceForge. Please join and write to | |
3009 | +aufs-users ML. | |
3010 | + | |
3011 | + | |
3012 | +6. Acknowledgements | |
3013 | +---------------------------------------- | |
3014 | +Thanks to everyone who have tried and are using aufs, whoever | |
3015 | +have reported a bug or any feedback. | |
3016 | + | |
3017 | +Especially donators: | |
3018 | +Tomas Matejicek(slax.org) made a donation (much more than once). | |
3019 | + Since Apr 2010, Tomas M (the author of Slax and Linux Live | |
3020 | + scripts) is making "doubling" donations. | |
3021 | + Unfortunately I cannot list all of the donators, but I really | |
b4510431 | 3022 | + appreciate. |
53392da6 AM |
3023 | + It ends Aug 2010, but the ordinary donation URL is still available. |
3024 | + <http://sourceforge.net/donate/index.php?group_id=167503> | |
3025 | +Dai Itasaka made a donation (2007/8). | |
3026 | +Chuck Smith made a donation (2008/4, 10 and 12). | |
3027 | +Henk Schoneveld made a donation (2008/9). | |
3028 | +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10). | |
3029 | +Francois Dupoux made a donation (2008/11). | |
3030 | +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public | |
3031 | + aufs2 GIT tree (2009/2). | |
3032 | +William Grant made a donation (2009/3). | |
3033 | +Patrick Lane made a donation (2009/4). | |
3034 | +The Mail Archive (mail-archive.com) made donations (2009/5). | |
3035 | +Nippy Networks (Ed Wildgoose) made a donation (2009/7). | |
3036 | +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11). | |
3037 | +Pavel Pronskiy made a donation (2011/2). | |
3038 | +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy | |
3039 | + Networks (Ed Wildgoose) made a donation for hardware (2011/3). | |
537831f9 AM |
3040 | +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and |
3041 | +11). | |
1e00d052 | 3042 | +Sam Liddicott made a donation (2011/9). |
86dc4139 AM |
3043 | +Era Scarecrow made a donation (2013/4). |
3044 | +Bor Ratajc made a donation (2013/4). | |
3045 | +Alessandro Gorreta made a donation (2013/4). | |
3046 | +POIRETTE Marc made a donation (2013/4). | |
3047 | +Alessandro Gorreta made a donation (2013/4). | |
3048 | +lauri kasvandik made a donation (2013/5). | |
392086de | 3049 | +"pemasu from Finland" made a donation (2013/7). |
523b37e3 AM |
3050 | +The Parted Magic Project made a donation (2013/9 and 11). |
3051 | +Pavel Barta made a donation (2013/10). | |
38d290e6 | 3052 | +Nikolay Pertsev made a donation (2014/5). |
c2c0f25c | 3053 | +James B made a donation (2014/7 and 2015/7). |
076b876e | 3054 | +Stefano Di Biase made a donation (2014/8). |
2000de60 | 3055 | +Daniel Epellei made a donation (2015/1). |
8cdd5066 | 3056 | +OmegaPhil made a donation (2016/1). |
5afbbe0d | 3057 | +Tomasz Szewczyk made a donation (2016/4). |
f2c43d5f | 3058 | +James Burry made a donation (2016/12). |
53392da6 AM |
3059 | + |
3060 | +Thank you very much. | |
3061 | +Donations are always, including future donations, very important and | |
3062 | +helpful for me to keep on developing aufs. | |
3063 | + | |
3064 | + | |
3065 | +7. | |
3066 | +---------------------------------------- | |
3067 | +If you are an experienced user, no explanation is needed. Aufs is | |
3068 | +just a linux filesystem. | |
3069 | + | |
3070 | + | |
3071 | +Enjoy! | |
3072 | + | |
3073 | +# Local variables: ; | |
3074 | +# mode: text; | |
3075 | +# End: ; | |
7f207e10 AM |
3076 | diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h |
3077 | --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 3078 | +++ linux/fs/aufs/aufs.h 2018-01-29 07:56:20.049991637 +0100 |
8b6a4947 | 3079 | @@ -0,0 +1,60 @@ |
7f207e10 | 3080 | +/* |
a2654f78 | 3081 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
7f207e10 AM |
3082 | + * |
3083 | + * This program, aufs is free software; you can redistribute it and/or modify | |
3084 | + * it under the terms of the GNU General Public License as published by | |
3085 | + * the Free Software Foundation; either version 2 of the License, or | |
3086 | + * (at your option) any later version. | |
3087 | + * | |
3088 | + * This program is distributed in the hope that it will be useful, | |
3089 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
3090 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
3091 | + * GNU General Public License for more details. | |
3092 | + * | |
3093 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 3094 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
3095 | + */ |
3096 | + | |
3097 | +/* | |
3098 | + * all header files | |
3099 | + */ | |
3100 | + | |
3101 | +#ifndef __AUFS_H__ | |
3102 | +#define __AUFS_H__ | |
3103 | + | |
3104 | +#ifdef __KERNEL__ | |
3105 | + | |
3106 | +#define AuStub(type, name, body, ...) \ | |
3107 | + static inline type name(__VA_ARGS__) { body; } | |
3108 | + | |
3109 | +#define AuStubVoid(name, ...) \ | |
3110 | + AuStub(void, name, , __VA_ARGS__) | |
3111 | +#define AuStubInt0(name, ...) \ | |
3112 | + AuStub(int, name, return 0, __VA_ARGS__) | |
3113 | + | |
3114 | +#include "debug.h" | |
3115 | + | |
3116 | +#include "branch.h" | |
3117 | +#include "cpup.h" | |
3118 | +#include "dcsub.h" | |
3119 | +#include "dbgaufs.h" | |
3120 | +#include "dentry.h" | |
3121 | +#include "dir.h" | |
8b6a4947 | 3122 | +#include "dirren.h" |
7f207e10 AM |
3123 | +#include "dynop.h" |
3124 | +#include "file.h" | |
3125 | +#include "fstype.h" | |
8b6a4947 | 3126 | +#include "hbl.h" |
7f207e10 AM |
3127 | +#include "inode.h" |
3128 | +#include "loop.h" | |
3129 | +#include "module.h" | |
7f207e10 AM |
3130 | +#include "opts.h" |
3131 | +#include "rwsem.h" | |
7f207e10 AM |
3132 | +#include "super.h" |
3133 | +#include "sysaufs.h" | |
3134 | +#include "vfsub.h" | |
3135 | +#include "whout.h" | |
3136 | +#include "wkq.h" | |
3137 | + | |
3138 | +#endif /* __KERNEL__ */ | |
3139 | +#endif /* __AUFS_H__ */ | |
3140 | diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c | |
3141 | --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 3142 | +++ linux/fs/aufs/branch.c 2018-01-29 07:56:20.049991637 +0100 |
8b6a4947 | 3143 | @@ -0,0 +1,1432 @@ |
7f207e10 | 3144 | +/* |
a2654f78 | 3145 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
7f207e10 AM |
3146 | + * |
3147 | + * This program, aufs is free software; you can redistribute it and/or modify | |
3148 | + * it under the terms of the GNU General Public License as published by | |
3149 | + * the Free Software Foundation; either version 2 of the License, or | |
3150 | + * (at your option) any later version. | |
3151 | + * | |
3152 | + * This program is distributed in the hope that it will be useful, | |
3153 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
3154 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
3155 | + * GNU General Public License for more details. | |
3156 | + * | |
3157 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 3158 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
3159 | + */ |
3160 | + | |
3161 | +/* | |
3162 | + * branch management | |
3163 | + */ | |
3164 | + | |
027c5e7a | 3165 | +#include <linux/compat.h> |
7f207e10 AM |
3166 | +#include <linux/statfs.h> |
3167 | +#include "aufs.h" | |
3168 | + | |
3169 | +/* | |
3170 | + * free a single branch | |
1facf9fc | 3171 | + */ |
3172 | +static void au_br_do_free(struct au_branch *br) | |
3173 | +{ | |
3174 | + int i; | |
3175 | + struct au_wbr *wbr; | |
4a4d8108 | 3176 | + struct au_dykey **key; |
1facf9fc | 3177 | + |
027c5e7a | 3178 | + au_hnotify_fin_br(br); |
8b6a4947 AM |
3179 | + /* always, regardless the mount option */ |
3180 | + au_dr_hino_free(&br->br_dirren); | |
027c5e7a | 3181 | + |
1facf9fc | 3182 | + if (br->br_xino.xi_file) |
3183 | + fput(br->br_xino.xi_file); | |
521ced18 JR |
3184 | + for (i = br->br_xino.xi_nondir.total - 1; i >= 0; i--) |
3185 | + AuDebugOn(br->br_xino.xi_nondir.array[i]); | |
1c60b727 | 3186 | + kfree(br->br_xino.xi_nondir.array); |
1facf9fc | 3187 | + |
5afbbe0d AM |
3188 | + AuDebugOn(au_br_count(br)); |
3189 | + au_br_count_fin(br); | |
1facf9fc | 3190 | + |
3191 | + wbr = br->br_wbr; | |
3192 | + if (wbr) { | |
3193 | + for (i = 0; i < AuBrWh_Last; i++) | |
3194 | + dput(wbr->wbr_wh[i]); | |
3195 | + AuDebugOn(atomic_read(&wbr->wbr_wh_running)); | |
dece6358 | 3196 | + AuRwDestroy(&wbr->wbr_wh_rwsem); |
1facf9fc | 3197 | + } |
3198 | + | |
076b876e AM |
3199 | + if (br->br_fhsm) { |
3200 | + au_br_fhsm_fin(br->br_fhsm); | |
1c60b727 | 3201 | + kfree(br->br_fhsm); |
076b876e AM |
3202 | + } |
3203 | + | |
4a4d8108 AM |
3204 | + key = br->br_dykey; |
3205 | + for (i = 0; i < AuBrDynOp; i++, key++) | |
3206 | + if (*key) | |
3207 | + au_dy_put(*key); | |
3208 | + else | |
3209 | + break; | |
3210 | + | |
537831f9 AM |
3211 | + /* recursive lock, s_umount of branch's */ |
3212 | + lockdep_off(); | |
86dc4139 | 3213 | + path_put(&br->br_path); |
537831f9 | 3214 | + lockdep_on(); |
1c60b727 AM |
3215 | + kfree(wbr); |
3216 | + kfree(br); | |
1facf9fc | 3217 | +} |
3218 | + | |
3219 | +/* | |
3220 | + * frees all branches | |
3221 | + */ | |
3222 | +void au_br_free(struct au_sbinfo *sbinfo) | |
3223 | +{ | |
3224 | + aufs_bindex_t bmax; | |
3225 | + struct au_branch **br; | |
3226 | + | |
dece6358 AM |
3227 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3228 | + | |
5afbbe0d | 3229 | + bmax = sbinfo->si_bbot + 1; |
1facf9fc | 3230 | + br = sbinfo->si_branch; |
3231 | + while (bmax--) | |
3232 | + au_br_do_free(*br++); | |
3233 | +} | |
3234 | + | |
3235 | +/* | |
3236 | + * find the index of a branch which is specified by @br_id. | |
3237 | + */ | |
3238 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id) | |
3239 | +{ | |
5afbbe0d | 3240 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 3241 | + |
5afbbe0d AM |
3242 | + bbot = au_sbbot(sb); |
3243 | + for (bindex = 0; bindex <= bbot; bindex++) | |
1facf9fc | 3244 | + if (au_sbr_id(sb, bindex) == br_id) |
3245 | + return bindex; | |
3246 | + return -1; | |
3247 | +} | |
3248 | + | |
3249 | +/* ---------------------------------------------------------------------- */ | |
3250 | + | |
3251 | +/* | |
3252 | + * add a branch | |
3253 | + */ | |
3254 | + | |
b752ccd1 AM |
3255 | +static int test_overlap(struct super_block *sb, struct dentry *h_adding, |
3256 | + struct dentry *h_root) | |
1facf9fc | 3257 | +{ |
b752ccd1 AM |
3258 | + if (unlikely(h_adding == h_root |
3259 | + || au_test_loopback_overlap(sb, h_adding))) | |
1facf9fc | 3260 | + return 1; |
b752ccd1 AM |
3261 | + if (h_adding->d_sb != h_root->d_sb) |
3262 | + return 0; | |
3263 | + return au_test_subdir(h_adding, h_root) | |
3264 | + || au_test_subdir(h_root, h_adding); | |
1facf9fc | 3265 | +} |
3266 | + | |
3267 | +/* | |
3268 | + * returns a newly allocated branch. @new_nbranch is a number of branches | |
3269 | + * after adding a branch. | |
3270 | + */ | |
3271 | +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch, | |
3272 | + int perm) | |
3273 | +{ | |
3274 | + struct au_branch *add_branch; | |
3275 | + struct dentry *root; | |
5527c038 | 3276 | + struct inode *inode; |
4a4d8108 | 3277 | + int err; |
1facf9fc | 3278 | + |
4a4d8108 | 3279 | + err = -ENOMEM; |
be52b249 | 3280 | + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS); |
1facf9fc | 3281 | + if (unlikely(!add_branch)) |
3282 | + goto out; | |
521ced18 JR |
3283 | + add_branch->br_xino.xi_nondir.total = 8; /* initial size */ |
3284 | + add_branch->br_xino.xi_nondir.array | |
8b6a4947 | 3285 | + = kcalloc(add_branch->br_xino.xi_nondir.total, sizeof(ino_t), |
521ced18 JR |
3286 | + GFP_NOFS); |
3287 | + if (unlikely(!add_branch->br_xino.xi_nondir.array)) | |
3288 | + goto out_br; | |
1facf9fc | 3289 | + |
027c5e7a AM |
3290 | + err = au_hnotify_init_br(add_branch, perm); |
3291 | + if (unlikely(err)) | |
521ced18 | 3292 | + goto out_xinondir; |
027c5e7a | 3293 | + |
1facf9fc | 3294 | + if (au_br_writable(perm)) { |
3295 | + /* may be freed separately at changing the branch permission */ | |
be52b249 | 3296 | + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr), |
1facf9fc | 3297 | + GFP_NOFS); |
3298 | + if (unlikely(!add_branch->br_wbr)) | |
027c5e7a | 3299 | + goto out_hnotify; |
1facf9fc | 3300 | + } |
3301 | + | |
076b876e AM |
3302 | + if (au_br_fhsm(perm)) { |
3303 | + err = au_fhsm_br_alloc(add_branch); | |
3304 | + if (unlikely(err)) | |
3305 | + goto out_wbr; | |
3306 | + } | |
3307 | + | |
521ced18 | 3308 | + root = sb->s_root; |
e2f27e51 | 3309 | + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0); |
4a4d8108 | 3310 | + if (!err) |
e2f27e51 | 3311 | + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0); |
5527c038 JR |
3312 | + if (!err) { |
3313 | + inode = d_inode(root); | |
1c60b727 AM |
3314 | + err = au_hinode_realloc(au_ii(inode), new_nbranch, |
3315 | + /*may_shrink*/0); | |
5527c038 | 3316 | + } |
4a4d8108 AM |
3317 | + if (!err) |
3318 | + return add_branch; /* success */ | |
1facf9fc | 3319 | + |
076b876e | 3320 | +out_wbr: |
1c60b727 | 3321 | + kfree(add_branch->br_wbr); |
027c5e7a AM |
3322 | +out_hnotify: |
3323 | + au_hnotify_fin_br(add_branch); | |
521ced18 | 3324 | +out_xinondir: |
1c60b727 | 3325 | + kfree(add_branch->br_xino.xi_nondir.array); |
4f0767ce | 3326 | +out_br: |
1c60b727 | 3327 | + kfree(add_branch); |
4f0767ce | 3328 | +out: |
4a4d8108 | 3329 | + return ERR_PTR(err); |
1facf9fc | 3330 | +} |
3331 | + | |
3332 | +/* | |
3333 | + * test if the branch permission is legal or not. | |
3334 | + */ | |
3335 | +static int test_br(struct inode *inode, int brperm, char *path) | |
3336 | +{ | |
3337 | + int err; | |
3338 | + | |
4a4d8108 AM |
3339 | + err = (au_br_writable(brperm) && IS_RDONLY(inode)); |
3340 | + if (!err) | |
3341 | + goto out; | |
1facf9fc | 3342 | + |
4a4d8108 AM |
3343 | + err = -EINVAL; |
3344 | + pr_err("write permission for readonly mount or inode, %s\n", path); | |
3345 | + | |
4f0767ce | 3346 | +out: |
1facf9fc | 3347 | + return err; |
3348 | +} | |
3349 | + | |
3350 | +/* | |
3351 | + * returns: | |
3352 | + * 0: success, the caller will add it | |
3353 | + * plus: success, it is already unified, the caller should ignore it | |
3354 | + * minus: error | |
3355 | + */ | |
3356 | +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3357 | +{ | |
3358 | + int err; | |
5afbbe0d | 3359 | + aufs_bindex_t bbot, bindex; |
5527c038 | 3360 | + struct dentry *root, *h_dentry; |
1facf9fc | 3361 | + struct inode *inode, *h_inode; |
3362 | + | |
3363 | + root = sb->s_root; | |
5afbbe0d AM |
3364 | + bbot = au_sbbot(sb); |
3365 | + if (unlikely(bbot >= 0 | |
1facf9fc | 3366 | + && au_find_dbindex(root, add->path.dentry) >= 0)) { |
3367 | + err = 1; | |
3368 | + if (!remount) { | |
3369 | + err = -EINVAL; | |
4a4d8108 | 3370 | + pr_err("%s duplicated\n", add->pathname); |
1facf9fc | 3371 | + } |
3372 | + goto out; | |
3373 | + } | |
3374 | + | |
3375 | + err = -ENOSPC; /* -E2BIG; */ | |
3376 | + if (unlikely(AUFS_BRANCH_MAX <= add->bindex | |
5afbbe0d | 3377 | + || AUFS_BRANCH_MAX - 1 <= bbot)) { |
4a4d8108 | 3378 | + pr_err("number of branches exceeded %s\n", add->pathname); |
1facf9fc | 3379 | + goto out; |
3380 | + } | |
3381 | + | |
3382 | + err = -EDOM; | |
5afbbe0d | 3383 | + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) { |
4a4d8108 | 3384 | + pr_err("bad index %d\n", add->bindex); |
1facf9fc | 3385 | + goto out; |
3386 | + } | |
3387 | + | |
5527c038 | 3388 | + inode = d_inode(add->path.dentry); |
1facf9fc | 3389 | + err = -ENOENT; |
3390 | + if (unlikely(!inode->i_nlink)) { | |
4a4d8108 | 3391 | + pr_err("no existence %s\n", add->pathname); |
1facf9fc | 3392 | + goto out; |
3393 | + } | |
3394 | + | |
3395 | + err = -EINVAL; | |
3396 | + if (unlikely(inode->i_sb == sb)) { | |
4a4d8108 | 3397 | + pr_err("%s must be outside\n", add->pathname); |
1facf9fc | 3398 | + goto out; |
3399 | + } | |
3400 | + | |
3401 | + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) { | |
4a4d8108 AM |
3402 | + pr_err("unsupported filesystem, %s (%s)\n", |
3403 | + add->pathname, au_sbtype(inode->i_sb)); | |
1facf9fc | 3404 | + goto out; |
3405 | + } | |
3406 | + | |
c1595e42 JR |
3407 | + if (unlikely(inode->i_sb->s_stack_depth)) { |
3408 | + pr_err("already stacked, %s (%s)\n", | |
3409 | + add->pathname, au_sbtype(inode->i_sb)); | |
3410 | + goto out; | |
3411 | + } | |
3412 | + | |
5527c038 | 3413 | + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname); |
1facf9fc | 3414 | + if (unlikely(err)) |
3415 | + goto out; | |
3416 | + | |
5afbbe0d | 3417 | + if (bbot < 0) |
1facf9fc | 3418 | + return 0; /* success */ |
3419 | + | |
3420 | + err = -EINVAL; | |
5afbbe0d | 3421 | + for (bindex = 0; bindex <= bbot; bindex++) |
1facf9fc | 3422 | + if (unlikely(test_overlap(sb, add->path.dentry, |
3423 | + au_h_dptr(root, bindex)))) { | |
4a4d8108 | 3424 | + pr_err("%s is overlapped\n", add->pathname); |
1facf9fc | 3425 | + goto out; |
3426 | + } | |
3427 | + | |
3428 | + err = 0; | |
3429 | + if (au_opt_test(au_mntflags(sb), WARN_PERM)) { | |
5527c038 JR |
3430 | + h_dentry = au_h_dptr(root, 0); |
3431 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 3432 | + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO) |
0c3ec466 AM |
3433 | + || !uid_eq(h_inode->i_uid, inode->i_uid) |
3434 | + || !gid_eq(h_inode->i_gid, inode->i_gid)) | |
3435 | + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n", | |
3436 | + add->pathname, | |
3437 | + i_uid_read(inode), i_gid_read(inode), | |
3438 | + (inode->i_mode & S_IALLUGO), | |
3439 | + i_uid_read(h_inode), i_gid_read(h_inode), | |
3440 | + (h_inode->i_mode & S_IALLUGO)); | |
1facf9fc | 3441 | + } |
3442 | + | |
4f0767ce | 3443 | +out: |
1facf9fc | 3444 | + return err; |
3445 | +} | |
3446 | + | |
3447 | +/* | |
3448 | + * initialize or clean the whiteouts for an adding branch | |
3449 | + */ | |
3450 | +static int au_br_init_wh(struct super_block *sb, struct au_branch *br, | |
86dc4139 | 3451 | + int new_perm) |
1facf9fc | 3452 | +{ |
3453 | + int err, old_perm; | |
3454 | + aufs_bindex_t bindex; | |
febd17d6 | 3455 | + struct inode *h_inode; |
1facf9fc | 3456 | + struct au_wbr *wbr; |
3457 | + struct au_hinode *hdir; | |
5527c038 | 3458 | + struct dentry *h_dentry; |
1facf9fc | 3459 | + |
86dc4139 AM |
3460 | + err = vfsub_mnt_want_write(au_br_mnt(br)); |
3461 | + if (unlikely(err)) | |
3462 | + goto out; | |
3463 | + | |
1facf9fc | 3464 | + wbr = br->br_wbr; |
3465 | + old_perm = br->br_perm; | |
3466 | + br->br_perm = new_perm; | |
3467 | + hdir = NULL; | |
febd17d6 | 3468 | + h_inode = NULL; |
1facf9fc | 3469 | + bindex = au_br_index(sb, br->br_id); |
3470 | + if (0 <= bindex) { | |
5527c038 | 3471 | + hdir = au_hi(d_inode(sb->s_root), bindex); |
5afbbe0d | 3472 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 3473 | + } else { |
5527c038 | 3474 | + h_dentry = au_br_dentry(br); |
febd17d6 JR |
3475 | + h_inode = d_inode(h_dentry); |
3476 | + inode_lock_nested(h_inode, AuLsc_I_PARENT); | |
1facf9fc | 3477 | + } |
3478 | + if (!wbr) | |
86dc4139 | 3479 | + err = au_wh_init(br, sb); |
1facf9fc | 3480 | + else { |
3481 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 3482 | + err = au_wh_init(br, sb); |
1facf9fc | 3483 | + wbr_wh_write_unlock(wbr); |
3484 | + } | |
3485 | + if (hdir) | |
5afbbe0d | 3486 | + au_hn_inode_unlock(hdir); |
1facf9fc | 3487 | + else |
febd17d6 | 3488 | + inode_unlock(h_inode); |
86dc4139 | 3489 | + vfsub_mnt_drop_write(au_br_mnt(br)); |
1facf9fc | 3490 | + br->br_perm = old_perm; |
3491 | + | |
3492 | + if (!err && wbr && !au_br_writable(new_perm)) { | |
1c60b727 | 3493 | + kfree(wbr); |
1facf9fc | 3494 | + br->br_wbr = NULL; |
3495 | + } | |
3496 | + | |
86dc4139 | 3497 | +out: |
1facf9fc | 3498 | + return err; |
3499 | +} | |
3500 | + | |
3501 | +static int au_wbr_init(struct au_branch *br, struct super_block *sb, | |
86dc4139 | 3502 | + int perm) |
1facf9fc | 3503 | +{ |
3504 | + int err; | |
4a4d8108 | 3505 | + struct kstatfs kst; |
1facf9fc | 3506 | + struct au_wbr *wbr; |
3507 | + | |
3508 | + wbr = br->br_wbr; | |
dece6358 | 3509 | + au_rw_init(&wbr->wbr_wh_rwsem); |
1facf9fc | 3510 | + atomic_set(&wbr->wbr_wh_running, 0); |
1facf9fc | 3511 | + |
4a4d8108 AM |
3512 | + /* |
3513 | + * a limit for rmdir/rename a dir | |
523b37e3 | 3514 | + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h |
4a4d8108 | 3515 | + */ |
86dc4139 | 3516 | + err = vfs_statfs(&br->br_path, &kst); |
4a4d8108 AM |
3517 | + if (unlikely(err)) |
3518 | + goto out; | |
3519 | + err = -EINVAL; | |
3520 | + if (kst.f_namelen >= NAME_MAX) | |
86dc4139 | 3521 | + err = au_br_init_wh(sb, br, perm); |
4a4d8108 | 3522 | + else |
523b37e3 AM |
3523 | + pr_err("%pd(%s), unsupported namelen %ld\n", |
3524 | + au_br_dentry(br), | |
86dc4139 | 3525 | + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen); |
1facf9fc | 3526 | + |
4f0767ce | 3527 | +out: |
1facf9fc | 3528 | + return err; |
3529 | +} | |
3530 | + | |
c1595e42 | 3531 | +/* initialize a new branch */ |
1facf9fc | 3532 | +static int au_br_init(struct au_branch *br, struct super_block *sb, |
3533 | + struct au_opt_add *add) | |
3534 | +{ | |
3535 | + int err; | |
5527c038 | 3536 | + struct inode *h_inode; |
1facf9fc | 3537 | + |
3538 | + err = 0; | |
521ced18 JR |
3539 | + spin_lock_init(&br->br_xino.xi_nondir.spin); |
3540 | + init_waitqueue_head(&br->br_xino.xi_nondir.wqh); | |
1facf9fc | 3541 | + br->br_perm = add->perm; |
86dc4139 | 3542 | + br->br_path = add->path; /* set first, path_get() later */ |
4a4d8108 | 3543 | + spin_lock_init(&br->br_dykey_lock); |
5afbbe0d | 3544 | + au_br_count_init(br); |
1facf9fc | 3545 | + atomic_set(&br->br_xino_running, 0); |
3546 | + br->br_id = au_new_br_id(sb); | |
7f207e10 | 3547 | + AuDebugOn(br->br_id < 0); |
1facf9fc | 3548 | + |
8b6a4947 AM |
3549 | + /* always, regardless the given option */ |
3550 | + err = au_dr_br_init(sb, br, &add->path); | |
3551 | + if (unlikely(err)) | |
3552 | + goto out_err; | |
3553 | + | |
1facf9fc | 3554 | + if (au_br_writable(add->perm)) { |
86dc4139 | 3555 | + err = au_wbr_init(br, sb, add->perm); |
1facf9fc | 3556 | + if (unlikely(err)) |
b752ccd1 | 3557 | + goto out_err; |
1facf9fc | 3558 | + } |
3559 | + | |
3560 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
5527c038 JR |
3561 | + h_inode = d_inode(add->path.dentry); |
3562 | + err = au_xino_br(sb, br, h_inode->i_ino, | |
1facf9fc | 3563 | + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1); |
3564 | + if (unlikely(err)) { | |
3565 | + AuDebugOn(br->br_xino.xi_file); | |
b752ccd1 | 3566 | + goto out_err; |
1facf9fc | 3567 | + } |
3568 | + } | |
3569 | + | |
3570 | + sysaufs_br_init(br); | |
86dc4139 | 3571 | + path_get(&br->br_path); |
b752ccd1 | 3572 | + goto out; /* success */ |
1facf9fc | 3573 | + |
4f0767ce | 3574 | +out_err: |
86dc4139 | 3575 | + memset(&br->br_path, 0, sizeof(br->br_path)); |
4f0767ce | 3576 | +out: |
1facf9fc | 3577 | + return err; |
3578 | +} | |
3579 | + | |
3580 | +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3581 | + struct au_branch *br, aufs_bindex_t bbot, |
1facf9fc | 3582 | + aufs_bindex_t amount) |
3583 | +{ | |
3584 | + struct au_branch **brp; | |
3585 | + | |
dece6358 AM |
3586 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3587 | + | |
1facf9fc | 3588 | + brp = sbinfo->si_branch + bindex; |
3589 | + memmove(brp + 1, brp, sizeof(*brp) * amount); | |
3590 | + *brp = br; | |
5afbbe0d AM |
3591 | + sbinfo->si_bbot++; |
3592 | + if (unlikely(bbot < 0)) | |
3593 | + sbinfo->si_bbot = 0; | |
1facf9fc | 3594 | +} |
3595 | + | |
3596 | +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3597 | + aufs_bindex_t bbot, aufs_bindex_t amount) |
1facf9fc | 3598 | +{ |
3599 | + struct au_hdentry *hdp; | |
3600 | + | |
1308ab2a | 3601 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3602 | + | |
5afbbe0d | 3603 | + hdp = au_hdentry(dinfo, bindex); |
1facf9fc | 3604 | + memmove(hdp + 1, hdp, sizeof(*hdp) * amount); |
3605 | + au_h_dentry_init(hdp); | |
5afbbe0d AM |
3606 | + dinfo->di_bbot++; |
3607 | + if (unlikely(bbot < 0)) | |
3608 | + dinfo->di_btop = 0; | |
1facf9fc | 3609 | +} |
3610 | + | |
3611 | +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3612 | + aufs_bindex_t bbot, aufs_bindex_t amount) |
1facf9fc | 3613 | +{ |
3614 | + struct au_hinode *hip; | |
3615 | + | |
1308ab2a | 3616 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3617 | + | |
5afbbe0d | 3618 | + hip = au_hinode(iinfo, bindex); |
1facf9fc | 3619 | + memmove(hip + 1, hip, sizeof(*hip) * amount); |
5afbbe0d AM |
3620 | + au_hinode_init(hip); |
3621 | + iinfo->ii_bbot++; | |
3622 | + if (unlikely(bbot < 0)) | |
3623 | + iinfo->ii_btop = 0; | |
1facf9fc | 3624 | +} |
3625 | + | |
86dc4139 AM |
3626 | +static void au_br_do_add(struct super_block *sb, struct au_branch *br, |
3627 | + aufs_bindex_t bindex) | |
1facf9fc | 3628 | +{ |
86dc4139 | 3629 | + struct dentry *root, *h_dentry; |
5527c038 | 3630 | + struct inode *root_inode, *h_inode; |
5afbbe0d | 3631 | + aufs_bindex_t bbot, amount; |
1facf9fc | 3632 | + |
3633 | + root = sb->s_root; | |
5527c038 | 3634 | + root_inode = d_inode(root); |
5afbbe0d AM |
3635 | + bbot = au_sbbot(sb); |
3636 | + amount = bbot + 1 - bindex; | |
86dc4139 | 3637 | + h_dentry = au_br_dentry(br); |
53392da6 | 3638 | + au_sbilist_lock(); |
5afbbe0d AM |
3639 | + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount); |
3640 | + au_br_do_add_hdp(au_di(root), bindex, bbot, amount); | |
3641 | + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount); | |
1facf9fc | 3642 | + au_set_h_dptr(root, bindex, dget(h_dentry)); |
5527c038 JR |
3643 | + h_inode = d_inode(h_dentry); |
3644 | + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0); | |
53392da6 | 3645 | + au_sbilist_unlock(); |
1facf9fc | 3646 | +} |
3647 | + | |
3648 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3649 | +{ | |
3650 | + int err; | |
5afbbe0d | 3651 | + aufs_bindex_t bbot, add_bindex; |
1facf9fc | 3652 | + struct dentry *root, *h_dentry; |
3653 | + struct inode *root_inode; | |
3654 | + struct au_branch *add_branch; | |
3655 | + | |
3656 | + root = sb->s_root; | |
5527c038 | 3657 | + root_inode = d_inode(root); |
1facf9fc | 3658 | + IMustLock(root_inode); |
5afbbe0d | 3659 | + IiMustWriteLock(root_inode); |
1facf9fc | 3660 | + err = test_add(sb, add, remount); |
3661 | + if (unlikely(err < 0)) | |
3662 | + goto out; | |
3663 | + if (err) { | |
3664 | + err = 0; | |
3665 | + goto out; /* success */ | |
3666 | + } | |
3667 | + | |
5afbbe0d AM |
3668 | + bbot = au_sbbot(sb); |
3669 | + add_branch = au_br_alloc(sb, bbot + 2, add->perm); | |
1facf9fc | 3670 | + err = PTR_ERR(add_branch); |
3671 | + if (IS_ERR(add_branch)) | |
3672 | + goto out; | |
3673 | + | |
3674 | + err = au_br_init(add_branch, sb, add); | |
3675 | + if (unlikely(err)) { | |
3676 | + au_br_do_free(add_branch); | |
3677 | + goto out; | |
3678 | + } | |
3679 | + | |
3680 | + add_bindex = add->bindex; | |
1facf9fc | 3681 | + if (!remount) |
86dc4139 | 3682 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3683 | + else { |
3684 | + sysaufs_brs_del(sb, add_bindex); | |
86dc4139 | 3685 | + au_br_do_add(sb, add_branch, add_bindex); |
1facf9fc | 3686 | + sysaufs_brs_add(sb, add_bindex); |
3687 | + } | |
3688 | + | |
86dc4139 | 3689 | + h_dentry = add->path.dentry; |
1308ab2a | 3690 | + if (!add_bindex) { |
1facf9fc | 3691 | + au_cpup_attr_all(root_inode, /*force*/1); |
1308ab2a | 3692 | + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes; |
3693 | + } else | |
5527c038 | 3694 | + au_add_nlink(root_inode, d_inode(h_dentry)); |
1facf9fc | 3695 | + |
3696 | + /* | |
4a4d8108 | 3697 | + * this test/set prevents aufs from handling unnecesary notify events |
027c5e7a | 3698 | + * of xino files, in case of re-adding a writable branch which was |
1facf9fc | 3699 | + * once detached from aufs. |
3700 | + */ | |
3701 | + if (au_xino_brid(sb) < 0 | |
3702 | + && au_br_writable(add_branch->br_perm) | |
3703 | + && !au_test_fs_bad_xino(h_dentry->d_sb) | |
3704 | + && add_branch->br_xino.xi_file | |
2000de60 | 3705 | + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry) |
1facf9fc | 3706 | + au_xino_brid_set(sb, add_branch->br_id); |
3707 | + | |
4f0767ce | 3708 | +out: |
1facf9fc | 3709 | + return err; |
3710 | +} | |
3711 | + | |
3712 | +/* ---------------------------------------------------------------------- */ | |
3713 | + | |
79b8bda9 | 3714 | +static unsigned long long au_farray_cb(struct super_block *sb, void *a, |
076b876e AM |
3715 | + unsigned long long max __maybe_unused, |
3716 | + void *arg) | |
3717 | +{ | |
3718 | + unsigned long long n; | |
3719 | + struct file **p, *f; | |
8b6a4947 AM |
3720 | + struct hlist_bl_head *files; |
3721 | + struct hlist_bl_node *pos; | |
076b876e | 3722 | + struct au_finfo *finfo; |
076b876e AM |
3723 | + |
3724 | + n = 0; | |
3725 | + p = a; | |
3726 | + files = &au_sbi(sb)->si_files; | |
8b6a4947 AM |
3727 | + hlist_bl_lock(files); |
3728 | + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) { | |
076b876e AM |
3729 | + f = finfo->fi_file; |
3730 | + if (file_count(f) | |
3731 | + && !special_file(file_inode(f)->i_mode)) { | |
3732 | + get_file(f); | |
3733 | + *p++ = f; | |
3734 | + n++; | |
3735 | + AuDebugOn(n > max); | |
3736 | + } | |
3737 | + } | |
8b6a4947 | 3738 | + hlist_bl_unlock(files); |
076b876e AM |
3739 | + |
3740 | + return n; | |
3741 | +} | |
3742 | + | |
3743 | +static struct file **au_farray_alloc(struct super_block *sb, | |
3744 | + unsigned long long *max) | |
3745 | +{ | |
5afbbe0d | 3746 | + *max = au_nfiles(sb); |
79b8bda9 | 3747 | + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL); |
076b876e AM |
3748 | +} |
3749 | + | |
3750 | +static void au_farray_free(struct file **a, unsigned long long max) | |
3751 | +{ | |
3752 | + unsigned long long ull; | |
3753 | + | |
3754 | + for (ull = 0; ull < max; ull++) | |
3755 | + if (a[ull]) | |
3756 | + fput(a[ull]); | |
be52b249 | 3757 | + kvfree(a); |
076b876e AM |
3758 | +} |
3759 | + | |
3760 | +/* ---------------------------------------------------------------------- */ | |
3761 | + | |
1facf9fc | 3762 | +/* |
3763 | + * delete a branch | |
3764 | + */ | |
3765 | + | |
3766 | +/* to show the line number, do not make it inlined function */ | |
4a4d8108 | 3767 | +#define AuVerbose(do_info, fmt, ...) do { \ |
1facf9fc | 3768 | + if (do_info) \ |
4a4d8108 | 3769 | + pr_info(fmt, ##__VA_ARGS__); \ |
1facf9fc | 3770 | +} while (0) |
3771 | + | |
5afbbe0d AM |
3772 | +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop, |
3773 | + aufs_bindex_t bbot) | |
027c5e7a | 3774 | +{ |
5afbbe0d | 3775 | + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot; |
027c5e7a AM |
3776 | +} |
3777 | + | |
5afbbe0d AM |
3778 | +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop, |
3779 | + aufs_bindex_t bbot) | |
027c5e7a | 3780 | +{ |
5afbbe0d | 3781 | + return au_test_ibusy(d_inode(dentry), btop, bbot); |
027c5e7a AM |
3782 | +} |
3783 | + | |
1facf9fc | 3784 | +/* |
3785 | + * test if the branch is deletable or not. | |
3786 | + */ | |
3787 | +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex, | |
b752ccd1 | 3788 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3789 | +{ |
3790 | + int err, i, j, ndentry; | |
5afbbe0d | 3791 | + aufs_bindex_t btop, bbot; |
1facf9fc | 3792 | + struct au_dcsub_pages dpages; |
3793 | + struct au_dpage *dpage; | |
3794 | + struct dentry *d; | |
1facf9fc | 3795 | + |
3796 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
3797 | + if (unlikely(err)) | |
3798 | + goto out; | |
3799 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); | |
3800 | + if (unlikely(err)) | |
3801 | + goto out_dpages; | |
3802 | + | |
1facf9fc | 3803 | + for (i = 0; !err && i < dpages.ndpage; i++) { |
3804 | + dpage = dpages.dpages + i; | |
3805 | + ndentry = dpage->ndentry; | |
3806 | + for (j = 0; !err && j < ndentry; j++) { | |
3807 | + d = dpage->dentries[j]; | |
c1595e42 | 3808 | + AuDebugOn(au_dcount(d) <= 0); |
027c5e7a | 3809 | + if (!au_digen_test(d, sigen)) { |
1facf9fc | 3810 | + di_read_lock_child(d, AuLock_IR); |
027c5e7a AM |
3811 | + if (unlikely(au_dbrange_test(d))) { |
3812 | + di_read_unlock(d, AuLock_IR); | |
3813 | + continue; | |
3814 | + } | |
3815 | + } else { | |
1facf9fc | 3816 | + di_write_lock_child(d); |
027c5e7a AM |
3817 | + if (unlikely(au_dbrange_test(d))) { |
3818 | + di_write_unlock(d); | |
3819 | + continue; | |
3820 | + } | |
1facf9fc | 3821 | + err = au_reval_dpath(d, sigen); |
3822 | + if (!err) | |
3823 | + di_downgrade_lock(d, AuLock_IR); | |
3824 | + else { | |
3825 | + di_write_unlock(d); | |
3826 | + break; | |
3827 | + } | |
3828 | + } | |
3829 | + | |
027c5e7a | 3830 | + /* AuDbgDentry(d); */ |
5afbbe0d AM |
3831 | + btop = au_dbtop(d); |
3832 | + bbot = au_dbbot(d); | |
3833 | + if (btop <= bindex | |
3834 | + && bindex <= bbot | |
1facf9fc | 3835 | + && au_h_dptr(d, bindex) |
5afbbe0d | 3836 | + && au_test_dbusy(d, btop, bbot)) { |
1facf9fc | 3837 | + err = -EBUSY; |
523b37e3 | 3838 | + AuVerbose(verbose, "busy %pd\n", d); |
027c5e7a | 3839 | + AuDbgDentry(d); |
1facf9fc | 3840 | + } |
3841 | + di_read_unlock(d, AuLock_IR); | |
3842 | + } | |
3843 | + } | |
3844 | + | |
4f0767ce | 3845 | +out_dpages: |
1facf9fc | 3846 | + au_dpages_free(&dpages); |
4f0767ce | 3847 | +out: |
1facf9fc | 3848 | + return err; |
3849 | +} | |
3850 | + | |
3851 | +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex, | |
b752ccd1 | 3852 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3853 | +{ |
3854 | + int err; | |
7f207e10 AM |
3855 | + unsigned long long max, ull; |
3856 | + struct inode *i, **array; | |
5afbbe0d | 3857 | + aufs_bindex_t btop, bbot; |
1facf9fc | 3858 | + |
7f207e10 AM |
3859 | + array = au_iarray_alloc(sb, &max); |
3860 | + err = PTR_ERR(array); | |
3861 | + if (IS_ERR(array)) | |
3862 | + goto out; | |
3863 | + | |
1facf9fc | 3864 | + err = 0; |
7f207e10 AM |
3865 | + AuDbg("b%d\n", bindex); |
3866 | + for (ull = 0; !err && ull < max; ull++) { | |
3867 | + i = array[ull]; | |
076b876e AM |
3868 | + if (unlikely(!i)) |
3869 | + break; | |
7f207e10 | 3870 | + if (i->i_ino == AUFS_ROOT_INO) |
1facf9fc | 3871 | + continue; |
3872 | + | |
7f207e10 | 3873 | + /* AuDbgInode(i); */ |
537831f9 | 3874 | + if (au_iigen(i, NULL) == sigen) |
1facf9fc | 3875 | + ii_read_lock_child(i); |
3876 | + else { | |
3877 | + ii_write_lock_child(i); | |
027c5e7a AM |
3878 | + err = au_refresh_hinode_self(i); |
3879 | + au_iigen_dec(i); | |
1facf9fc | 3880 | + if (!err) |
3881 | + ii_downgrade_lock(i); | |
3882 | + else { | |
3883 | + ii_write_unlock(i); | |
3884 | + break; | |
3885 | + } | |
3886 | + } | |
3887 | + | |
5afbbe0d AM |
3888 | + btop = au_ibtop(i); |
3889 | + bbot = au_ibbot(i); | |
3890 | + if (btop <= bindex | |
3891 | + && bindex <= bbot | |
1facf9fc | 3892 | + && au_h_iptr(i, bindex) |
5afbbe0d | 3893 | + && au_test_ibusy(i, btop, bbot)) { |
1facf9fc | 3894 | + err = -EBUSY; |
3895 | + AuVerbose(verbose, "busy i%lu\n", i->i_ino); | |
7f207e10 | 3896 | + AuDbgInode(i); |
1facf9fc | 3897 | + } |
3898 | + ii_read_unlock(i); | |
3899 | + } | |
7f207e10 | 3900 | + au_iarray_free(array, max); |
1facf9fc | 3901 | + |
7f207e10 | 3902 | +out: |
1facf9fc | 3903 | + return err; |
3904 | +} | |
3905 | + | |
b752ccd1 AM |
3906 | +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex, |
3907 | + const unsigned int verbose) | |
1facf9fc | 3908 | +{ |
3909 | + int err; | |
3910 | + unsigned int sigen; | |
3911 | + | |
3912 | + sigen = au_sigen(root->d_sb); | |
3913 | + DiMustNoWaiters(root); | |
5527c038 | 3914 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 3915 | + di_write_unlock(root); |
b752ccd1 | 3916 | + err = test_dentry_busy(root, bindex, sigen, verbose); |
1facf9fc | 3917 | + if (!err) |
b752ccd1 | 3918 | + err = test_inode_busy(root->d_sb, bindex, sigen, verbose); |
1facf9fc | 3919 | + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */ |
3920 | + | |
3921 | + return err; | |
3922 | +} | |
3923 | + | |
076b876e AM |
3924 | +static int test_dir_busy(struct file *file, aufs_bindex_t br_id, |
3925 | + struct file **to_free, int *idx) | |
3926 | +{ | |
3927 | + int err; | |
c1595e42 | 3928 | + unsigned char matched, root; |
5afbbe0d | 3929 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
3930 | + struct au_fidir *fidir; |
3931 | + struct au_hfile *hfile; | |
3932 | + | |
3933 | + err = 0; | |
2000de60 | 3934 | + root = IS_ROOT(file->f_path.dentry); |
c1595e42 JR |
3935 | + if (root) { |
3936 | + get_file(file); | |
3937 | + to_free[*idx] = file; | |
3938 | + (*idx)++; | |
3939 | + goto out; | |
3940 | + } | |
3941 | + | |
076b876e | 3942 | + matched = 0; |
076b876e AM |
3943 | + fidir = au_fi(file)->fi_hdir; |
3944 | + AuDebugOn(!fidir); | |
5afbbe0d AM |
3945 | + bbot = au_fbbot_dir(file); |
3946 | + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) { | |
076b876e AM |
3947 | + hfile = fidir->fd_hfile + bindex; |
3948 | + if (!hfile->hf_file) | |
3949 | + continue; | |
3950 | + | |
c1595e42 | 3951 | + if (hfile->hf_br->br_id == br_id) { |
076b876e | 3952 | + matched = 1; |
076b876e | 3953 | + break; |
c1595e42 | 3954 | + } |
076b876e | 3955 | + } |
c1595e42 | 3956 | + if (matched) |
076b876e AM |
3957 | + err = -EBUSY; |
3958 | + | |
3959 | +out: | |
3960 | + return err; | |
3961 | +} | |
3962 | + | |
3963 | +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id, | |
3964 | + struct file **to_free, int opened) | |
3965 | +{ | |
3966 | + int err, idx; | |
3967 | + unsigned long long ull, max; | |
5afbbe0d | 3968 | + aufs_bindex_t btop; |
076b876e | 3969 | + struct file *file, **array; |
076b876e AM |
3970 | + struct dentry *root; |
3971 | + struct au_hfile *hfile; | |
3972 | + | |
3973 | + array = au_farray_alloc(sb, &max); | |
3974 | + err = PTR_ERR(array); | |
3975 | + if (IS_ERR(array)) | |
3976 | + goto out; | |
3977 | + | |
3978 | + err = 0; | |
3979 | + idx = 0; | |
3980 | + root = sb->s_root; | |
3981 | + di_write_unlock(root); | |
3982 | + for (ull = 0; ull < max; ull++) { | |
3983 | + file = array[ull]; | |
3984 | + if (unlikely(!file)) | |
3985 | + break; | |
3986 | + | |
3987 | + /* AuDbg("%pD\n", file); */ | |
3988 | + fi_read_lock(file); | |
5afbbe0d | 3989 | + btop = au_fbtop(file); |
2000de60 | 3990 | + if (!d_is_dir(file->f_path.dentry)) { |
076b876e AM |
3991 | + hfile = &au_fi(file)->fi_htop; |
3992 | + if (hfile->hf_br->br_id == br_id) | |
3993 | + err = -EBUSY; | |
3994 | + } else | |
3995 | + err = test_dir_busy(file, br_id, to_free, &idx); | |
3996 | + fi_read_unlock(file); | |
3997 | + if (unlikely(err)) | |
3998 | + break; | |
3999 | + } | |
4000 | + di_write_lock_child(root); | |
4001 | + au_farray_free(array, max); | |
4002 | + AuDebugOn(idx > opened); | |
4003 | + | |
4004 | +out: | |
4005 | + return err; | |
4006 | +} | |
4007 | + | |
4008 | +static void br_del_file(struct file **to_free, unsigned long long opened, | |
4009 | + aufs_bindex_t br_id) | |
4010 | +{ | |
4011 | + unsigned long long ull; | |
5afbbe0d | 4012 | + aufs_bindex_t bindex, btop, bbot, bfound; |
076b876e AM |
4013 | + struct file *file; |
4014 | + struct au_fidir *fidir; | |
4015 | + struct au_hfile *hfile; | |
4016 | + | |
4017 | + for (ull = 0; ull < opened; ull++) { | |
4018 | + file = to_free[ull]; | |
4019 | + if (unlikely(!file)) | |
4020 | + break; | |
4021 | + | |
4022 | + /* AuDbg("%pD\n", file); */ | |
2000de60 | 4023 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
076b876e AM |
4024 | + bfound = -1; |
4025 | + fidir = au_fi(file)->fi_hdir; | |
4026 | + AuDebugOn(!fidir); | |
4027 | + fi_write_lock(file); | |
5afbbe0d AM |
4028 | + btop = au_fbtop(file); |
4029 | + bbot = au_fbbot_dir(file); | |
4030 | + for (bindex = btop; bindex <= bbot; bindex++) { | |
076b876e AM |
4031 | + hfile = fidir->fd_hfile + bindex; |
4032 | + if (!hfile->hf_file) | |
4033 | + continue; | |
4034 | + | |
4035 | + if (hfile->hf_br->br_id == br_id) { | |
4036 | + bfound = bindex; | |
4037 | + break; | |
4038 | + } | |
4039 | + } | |
4040 | + AuDebugOn(bfound < 0); | |
4041 | + au_set_h_fptr(file, bfound, NULL); | |
5afbbe0d AM |
4042 | + if (bfound == btop) { |
4043 | + for (btop++; btop <= bbot; btop++) | |
4044 | + if (au_hf_dir(file, btop)) { | |
4045 | + au_set_fbtop(file, btop); | |
076b876e AM |
4046 | + break; |
4047 | + } | |
4048 | + } | |
4049 | + fi_write_unlock(file); | |
4050 | + } | |
4051 | +} | |
4052 | + | |
1facf9fc | 4053 | +static void au_br_do_del_brp(struct au_sbinfo *sbinfo, |
4054 | + const aufs_bindex_t bindex, | |
5afbbe0d | 4055 | + const aufs_bindex_t bbot) |
1facf9fc | 4056 | +{ |
4057 | + struct au_branch **brp, **p; | |
4058 | + | |
dece6358 AM |
4059 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
4060 | + | |
1facf9fc | 4061 | + brp = sbinfo->si_branch + bindex; |
5afbbe0d AM |
4062 | + if (bindex < bbot) |
4063 | + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex)); | |
4064 | + sbinfo->si_branch[0 + bbot] = NULL; | |
4065 | + sbinfo->si_bbot--; | |
1facf9fc | 4066 | + |
e2f27e51 AM |
4067 | + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST, |
4068 | + /*may_shrink*/1); | |
1facf9fc | 4069 | + if (p) |
4070 | + sbinfo->si_branch = p; | |
4a4d8108 | 4071 | + /* harmless error */ |
1facf9fc | 4072 | +} |
4073 | + | |
4074 | +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex, | |
5afbbe0d | 4075 | + const aufs_bindex_t bbot) |
1facf9fc | 4076 | +{ |
4077 | + struct au_hdentry *hdp, *p; | |
4078 | + | |
1308ab2a | 4079 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
4080 | + | |
5afbbe0d AM |
4081 | + hdp = au_hdentry(dinfo, bindex); |
4082 | + if (bindex < bbot) | |
4083 | + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex)); | |
4084 | + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */ | |
4085 | + dinfo->di_bbot--; | |
1facf9fc | 4086 | + |
e2f27e51 AM |
4087 | + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST, |
4088 | + /*may_shrink*/1); | |
1facf9fc | 4089 | + if (p) |
4090 | + dinfo->di_hdentry = p; | |
4a4d8108 | 4091 | + /* harmless error */ |
1facf9fc | 4092 | +} |
4093 | + | |
4094 | +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex, | |
5afbbe0d | 4095 | + const aufs_bindex_t bbot) |
1facf9fc | 4096 | +{ |
4097 | + struct au_hinode *hip, *p; | |
4098 | + | |
1308ab2a | 4099 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
4100 | + | |
5afbbe0d AM |
4101 | + hip = au_hinode(iinfo, bindex); |
4102 | + if (bindex < bbot) | |
4103 | + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex)); | |
4104 | + /* au_hinode_init(au_hinode(iinfo, bbot)); */ | |
4105 | + iinfo->ii_bbot--; | |
1facf9fc | 4106 | + |
e2f27e51 AM |
4107 | + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST, |
4108 | + /*may_shrink*/1); | |
1facf9fc | 4109 | + if (p) |
4110 | + iinfo->ii_hinode = p; | |
4a4d8108 | 4111 | + /* harmless error */ |
1facf9fc | 4112 | +} |
4113 | + | |
4114 | +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex, | |
4115 | + struct au_branch *br) | |
4116 | +{ | |
5afbbe0d | 4117 | + aufs_bindex_t bbot; |
1facf9fc | 4118 | + struct au_sbinfo *sbinfo; |
53392da6 AM |
4119 | + struct dentry *root, *h_root; |
4120 | + struct inode *inode, *h_inode; | |
4121 | + struct au_hinode *hinode; | |
1facf9fc | 4122 | + |
dece6358 AM |
4123 | + SiMustWriteLock(sb); |
4124 | + | |
1facf9fc | 4125 | + root = sb->s_root; |
5527c038 | 4126 | + inode = d_inode(root); |
1facf9fc | 4127 | + sbinfo = au_sbi(sb); |
5afbbe0d | 4128 | + bbot = sbinfo->si_bbot; |
1facf9fc | 4129 | + |
53392da6 AM |
4130 | + h_root = au_h_dptr(root, bindex); |
4131 | + hinode = au_hi(inode, bindex); | |
4132 | + h_inode = au_igrab(hinode->hi_inode); | |
4133 | + au_hiput(hinode); | |
1facf9fc | 4134 | + |
53392da6 | 4135 | + au_sbilist_lock(); |
5afbbe0d AM |
4136 | + au_br_do_del_brp(sbinfo, bindex, bbot); |
4137 | + au_br_do_del_hdp(au_di(root), bindex, bbot); | |
4138 | + au_br_do_del_hip(au_ii(inode), bindex, bbot); | |
53392da6 AM |
4139 | + au_sbilist_unlock(); |
4140 | + | |
8b6a4947 AM |
4141 | + /* ignore an error */ |
4142 | + au_dr_br_fin(sb, br); /* always, regardless the mount option */ | |
4143 | + | |
53392da6 AM |
4144 | + dput(h_root); |
4145 | + iput(h_inode); | |
4146 | + au_br_do_free(br); | |
1facf9fc | 4147 | +} |
4148 | + | |
79b8bda9 AM |
4149 | +static unsigned long long empty_cb(struct super_block *sb, void *array, |
4150 | + unsigned long long max, void *arg) | |
076b876e AM |
4151 | +{ |
4152 | + return max; | |
4153 | +} | |
4154 | + | |
1facf9fc | 4155 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount) |
4156 | +{ | |
4157 | + int err, rerr, i; | |
076b876e | 4158 | + unsigned long long opened; |
1facf9fc | 4159 | + unsigned int mnt_flags; |
5afbbe0d | 4160 | + aufs_bindex_t bindex, bbot, br_id; |
1facf9fc | 4161 | + unsigned char do_wh, verbose; |
4162 | + struct au_branch *br; | |
4163 | + struct au_wbr *wbr; | |
076b876e AM |
4164 | + struct dentry *root; |
4165 | + struct file **to_free; | |
1facf9fc | 4166 | + |
4167 | + err = 0; | |
076b876e AM |
4168 | + opened = 0; |
4169 | + to_free = NULL; | |
4170 | + root = sb->s_root; | |
4171 | + bindex = au_find_dbindex(root, del->h_path.dentry); | |
1facf9fc | 4172 | + if (bindex < 0) { |
4173 | + if (remount) | |
4174 | + goto out; /* success */ | |
4175 | + err = -ENOENT; | |
4a4d8108 | 4176 | + pr_err("%s no such branch\n", del->pathname); |
1facf9fc | 4177 | + goto out; |
4178 | + } | |
4179 | + AuDbg("bindex b%d\n", bindex); | |
4180 | + | |
4181 | + err = -EBUSY; | |
4182 | + mnt_flags = au_mntflags(sb); | |
4183 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
5afbbe0d AM |
4184 | + bbot = au_sbbot(sb); |
4185 | + if (unlikely(!bbot)) { | |
1facf9fc | 4186 | + AuVerbose(verbose, "no more branches left\n"); |
4187 | + goto out; | |
4188 | + } | |
4189 | + br = au_sbr(sb, bindex); | |
86dc4139 | 4190 | + AuDebugOn(!path_equal(&br->br_path, &del->h_path)); |
076b876e AM |
4191 | + |
4192 | + br_id = br->br_id; | |
5afbbe0d | 4193 | + opened = au_br_count(br); |
076b876e | 4194 | + if (unlikely(opened)) { |
79b8bda9 | 4195 | + to_free = au_array_alloc(&opened, empty_cb, sb, NULL); |
076b876e AM |
4196 | + err = PTR_ERR(to_free); |
4197 | + if (IS_ERR(to_free)) | |
4198 | + goto out; | |
4199 | + | |
4200 | + err = test_file_busy(sb, br_id, to_free, opened); | |
4201 | + if (unlikely(err)) { | |
4202 | + AuVerbose(verbose, "%llu file(s) opened\n", opened); | |
4203 | + goto out; | |
4204 | + } | |
1facf9fc | 4205 | + } |
4206 | + | |
4207 | + wbr = br->br_wbr; | |
4208 | + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph); | |
4209 | + if (do_wh) { | |
1308ab2a | 4210 | + /* instead of WbrWhMustWriteLock(wbr) */ |
4211 | + SiMustWriteLock(sb); | |
1facf9fc | 4212 | + for (i = 0; i < AuBrWh_Last; i++) { |
4213 | + dput(wbr->wbr_wh[i]); | |
4214 | + wbr->wbr_wh[i] = NULL; | |
4215 | + } | |
4216 | + } | |
4217 | + | |
076b876e | 4218 | + err = test_children_busy(root, bindex, verbose); |
1facf9fc | 4219 | + if (unlikely(err)) { |
4220 | + if (do_wh) | |
4221 | + goto out_wh; | |
4222 | + goto out; | |
4223 | + } | |
4224 | + | |
4225 | + err = 0; | |
076b876e AM |
4226 | + if (to_free) { |
4227 | + /* | |
4228 | + * now we confirmed the branch is deletable. | |
4229 | + * let's free the remaining opened dirs on the branch. | |
4230 | + */ | |
4231 | + di_write_unlock(root); | |
4232 | + br_del_file(to_free, opened, br_id); | |
4233 | + di_write_lock_child(root); | |
4234 | + } | |
4235 | + | |
1facf9fc | 4236 | + if (!remount) |
4237 | + au_br_do_del(sb, bindex, br); | |
4238 | + else { | |
4239 | + sysaufs_brs_del(sb, bindex); | |
4240 | + au_br_do_del(sb, bindex, br); | |
4241 | + sysaufs_brs_add(sb, bindex); | |
4242 | + } | |
4243 | + | |
1308ab2a | 4244 | + if (!bindex) { |
5527c038 | 4245 | + au_cpup_attr_all(d_inode(root), /*force*/1); |
1308ab2a | 4246 | + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes; |
4247 | + } else | |
5527c038 | 4248 | + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry)); |
1facf9fc | 4249 | + if (au_opt_test(mnt_flags, PLINK)) |
4250 | + au_plink_half_refresh(sb, br_id); | |
4251 | + | |
b752ccd1 | 4252 | + if (au_xino_brid(sb) == br_id) |
1facf9fc | 4253 | + au_xino_brid_set(sb, -1); |
4254 | + goto out; /* success */ | |
4255 | + | |
4f0767ce | 4256 | +out_wh: |
1facf9fc | 4257 | + /* revert */ |
86dc4139 | 4258 | + rerr = au_br_init_wh(sb, br, br->br_perm); |
1facf9fc | 4259 | + if (rerr) |
0c3ec466 AM |
4260 | + pr_warn("failed re-creating base whiteout, %s. (%d)\n", |
4261 | + del->pathname, rerr); | |
4f0767ce | 4262 | +out: |
076b876e AM |
4263 | + if (to_free) |
4264 | + au_farray_free(to_free, opened); | |
1facf9fc | 4265 | + return err; |
4266 | +} | |
4267 | + | |
4268 | +/* ---------------------------------------------------------------------- */ | |
4269 | + | |
027c5e7a AM |
4270 | +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg) |
4271 | +{ | |
4272 | + int err; | |
5afbbe0d | 4273 | + aufs_bindex_t btop, bbot; |
027c5e7a AM |
4274 | + struct aufs_ibusy ibusy; |
4275 | + struct inode *inode, *h_inode; | |
4276 | + | |
4277 | + err = -EPERM; | |
4278 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
4279 | + goto out; | |
4280 | + | |
4281 | + err = copy_from_user(&ibusy, arg, sizeof(ibusy)); | |
4282 | + if (!err) | |
4283 | + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino)); | |
4284 | + if (unlikely(err)) { | |
4285 | + err = -EFAULT; | |
4286 | + AuTraceErr(err); | |
4287 | + goto out; | |
4288 | + } | |
4289 | + | |
4290 | + err = -EINVAL; | |
4291 | + si_read_lock(sb, AuLock_FLUSH); | |
5afbbe0d | 4292 | + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb))) |
027c5e7a AM |
4293 | + goto out_unlock; |
4294 | + | |
4295 | + err = 0; | |
4296 | + ibusy.h_ino = 0; /* invalid */ | |
4297 | + inode = ilookup(sb, ibusy.ino); | |
4298 | + if (!inode | |
4299 | + || inode->i_ino == AUFS_ROOT_INO | |
5afbbe0d | 4300 | + || au_is_bad_inode(inode)) |
027c5e7a AM |
4301 | + goto out_unlock; |
4302 | + | |
4303 | + ii_read_lock_child(inode); | |
5afbbe0d AM |
4304 | + btop = au_ibtop(inode); |
4305 | + bbot = au_ibbot(inode); | |
4306 | + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) { | |
027c5e7a | 4307 | + h_inode = au_h_iptr(inode, ibusy.bindex); |
5afbbe0d | 4308 | + if (h_inode && au_test_ibusy(inode, btop, bbot)) |
027c5e7a AM |
4309 | + ibusy.h_ino = h_inode->i_ino; |
4310 | + } | |
4311 | + ii_read_unlock(inode); | |
4312 | + iput(inode); | |
4313 | + | |
4314 | +out_unlock: | |
4315 | + si_read_unlock(sb); | |
4316 | + if (!err) { | |
4317 | + err = __put_user(ibusy.h_ino, &arg->h_ino); | |
4318 | + if (unlikely(err)) { | |
4319 | + err = -EFAULT; | |
4320 | + AuTraceErr(err); | |
4321 | + } | |
4322 | + } | |
4323 | +out: | |
4324 | + return err; | |
4325 | +} | |
4326 | + | |
4327 | +long au_ibusy_ioctl(struct file *file, unsigned long arg) | |
4328 | +{ | |
2000de60 | 4329 | + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg); |
027c5e7a AM |
4330 | +} |
4331 | + | |
4332 | +#ifdef CONFIG_COMPAT | |
4333 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg) | |
4334 | +{ | |
2000de60 | 4335 | + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg)); |
027c5e7a AM |
4336 | +} |
4337 | +#endif | |
4338 | + | |
4339 | +/* ---------------------------------------------------------------------- */ | |
4340 | + | |
1facf9fc | 4341 | +/* |
4342 | + * change a branch permission | |
4343 | + */ | |
4344 | + | |
dece6358 AM |
4345 | +static void au_warn_ima(void) |
4346 | +{ | |
4347 | +#ifdef CONFIG_IMA | |
1308ab2a | 4348 | + /* since it doesn't support mark_files_ro() */ |
027c5e7a | 4349 | + AuWarn1("RW -> RO makes IMA to produce wrong message\n"); |
dece6358 AM |
4350 | +#endif |
4351 | +} | |
4352 | + | |
1facf9fc | 4353 | +static int do_need_sigen_inc(int a, int b) |
4354 | +{ | |
4355 | + return au_br_whable(a) && !au_br_whable(b); | |
4356 | +} | |
4357 | + | |
4358 | +static int need_sigen_inc(int old, int new) | |
4359 | +{ | |
4360 | + return do_need_sigen_inc(old, new) | |
4361 | + || do_need_sigen_inc(new, old); | |
4362 | +} | |
4363 | + | |
4364 | +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex) | |
4365 | +{ | |
7f207e10 | 4366 | + int err, do_warn; |
027c5e7a | 4367 | + unsigned int mnt_flags; |
7f207e10 | 4368 | + unsigned long long ull, max; |
e49829fe | 4369 | + aufs_bindex_t br_id; |
38d290e6 | 4370 | + unsigned char verbose, writer; |
7f207e10 | 4371 | + struct file *file, *hf, **array; |
e49829fe | 4372 | + struct au_hfile *hfile; |
1facf9fc | 4373 | + |
027c5e7a AM |
4374 | + mnt_flags = au_mntflags(sb); |
4375 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
4376 | + | |
7f207e10 AM |
4377 | + array = au_farray_alloc(sb, &max); |
4378 | + err = PTR_ERR(array); | |
4379 | + if (IS_ERR(array)) | |
1facf9fc | 4380 | + goto out; |
4381 | + | |
7f207e10 | 4382 | + do_warn = 0; |
e49829fe | 4383 | + br_id = au_sbr_id(sb, bindex); |
7f207e10 AM |
4384 | + for (ull = 0; ull < max; ull++) { |
4385 | + file = array[ull]; | |
076b876e AM |
4386 | + if (unlikely(!file)) |
4387 | + break; | |
1facf9fc | 4388 | + |
523b37e3 | 4389 | + /* AuDbg("%pD\n", file); */ |
1facf9fc | 4390 | + fi_read_lock(file); |
4391 | + if (unlikely(au_test_mmapped(file))) { | |
4392 | + err = -EBUSY; | |
523b37e3 | 4393 | + AuVerbose(verbose, "mmapped %pD\n", file); |
7f207e10 | 4394 | + AuDbgFile(file); |
1facf9fc | 4395 | + FiMustNoWaiters(file); |
4396 | + fi_read_unlock(file); | |
7f207e10 | 4397 | + goto out_array; |
1facf9fc | 4398 | + } |
4399 | + | |
e49829fe JR |
4400 | + hfile = &au_fi(file)->fi_htop; |
4401 | + hf = hfile->hf_file; | |
7e9cd9fe | 4402 | + if (!d_is_reg(file->f_path.dentry) |
1facf9fc | 4403 | + || !(file->f_mode & FMODE_WRITE) |
e49829fe | 4404 | + || hfile->hf_br->br_id != br_id |
7f207e10 AM |
4405 | + || !(hf->f_mode & FMODE_WRITE)) |
4406 | + array[ull] = NULL; | |
4407 | + else { | |
4408 | + do_warn = 1; | |
4409 | + get_file(file); | |
1facf9fc | 4410 | + } |
4411 | + | |
1facf9fc | 4412 | + FiMustNoWaiters(file); |
4413 | + fi_read_unlock(file); | |
7f207e10 AM |
4414 | + fput(file); |
4415 | + } | |
1facf9fc | 4416 | + |
4417 | + err = 0; | |
7f207e10 | 4418 | + if (do_warn) |
dece6358 | 4419 | + au_warn_ima(); |
7f207e10 AM |
4420 | + |
4421 | + for (ull = 0; ull < max; ull++) { | |
4422 | + file = array[ull]; | |
4423 | + if (!file) | |
4424 | + continue; | |
4425 | + | |
1facf9fc | 4426 | + /* todo: already flushed? */ |
523b37e3 AM |
4427 | + /* |
4428 | + * fs/super.c:mark_files_ro() is gone, but aufs keeps its | |
4429 | + * approach which resets f_mode and calls mnt_drop_write() and | |
4430 | + * file_release_write() for each file, because the branch | |
4431 | + * attribute in aufs world is totally different from the native | |
4432 | + * fs rw/ro mode. | |
4433 | + */ | |
7f207e10 AM |
4434 | + /* fi_read_lock(file); */ |
4435 | + hfile = &au_fi(file)->fi_htop; | |
4436 | + hf = hfile->hf_file; | |
4437 | + /* fi_read_unlock(file); */ | |
027c5e7a | 4438 | + spin_lock(&hf->f_lock); |
38d290e6 JR |
4439 | + writer = !!(hf->f_mode & FMODE_WRITER); |
4440 | + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER); | |
027c5e7a | 4441 | + spin_unlock(&hf->f_lock); |
38d290e6 JR |
4442 | + if (writer) { |
4443 | + put_write_access(file_inode(hf)); | |
c06a8ce3 | 4444 | + __mnt_drop_write(hf->f_path.mnt); |
1facf9fc | 4445 | + } |
4446 | + } | |
4447 | + | |
7f207e10 AM |
4448 | +out_array: |
4449 | + au_farray_free(array, max); | |
4f0767ce | 4450 | +out: |
7f207e10 | 4451 | + AuTraceErr(err); |
1facf9fc | 4452 | + return err; |
4453 | +} | |
4454 | + | |
4455 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4456 | + int *do_refresh) |
1facf9fc | 4457 | +{ |
4458 | + int err, rerr; | |
4459 | + aufs_bindex_t bindex; | |
4460 | + struct dentry *root; | |
4461 | + struct au_branch *br; | |
076b876e | 4462 | + struct au_br_fhsm *bf; |
1facf9fc | 4463 | + |
4464 | + root = sb->s_root; | |
1facf9fc | 4465 | + bindex = au_find_dbindex(root, mod->h_root); |
4466 | + if (bindex < 0) { | |
4467 | + if (remount) | |
4468 | + return 0; /* success */ | |
4469 | + err = -ENOENT; | |
4a4d8108 | 4470 | + pr_err("%s no such branch\n", mod->path); |
1facf9fc | 4471 | + goto out; |
4472 | + } | |
4473 | + AuDbg("bindex b%d\n", bindex); | |
4474 | + | |
5527c038 | 4475 | + err = test_br(d_inode(mod->h_root), mod->perm, mod->path); |
1facf9fc | 4476 | + if (unlikely(err)) |
4477 | + goto out; | |
4478 | + | |
4479 | + br = au_sbr(sb, bindex); | |
86dc4139 | 4480 | + AuDebugOn(mod->h_root != au_br_dentry(br)); |
1facf9fc | 4481 | + if (br->br_perm == mod->perm) |
4482 | + return 0; /* success */ | |
4483 | + | |
076b876e AM |
4484 | + /* pre-allocate for non-fhsm --> fhsm */ |
4485 | + bf = NULL; | |
4486 | + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) { | |
4487 | + err = au_fhsm_br_alloc(br); | |
4488 | + if (unlikely(err)) | |
4489 | + goto out; | |
4490 | + bf = br->br_fhsm; | |
4491 | + br->br_fhsm = NULL; | |
4492 | + } | |
4493 | + | |
1facf9fc | 4494 | + if (au_br_writable(br->br_perm)) { |
4495 | + /* remove whiteout base */ | |
86dc4139 | 4496 | + err = au_br_init_wh(sb, br, mod->perm); |
1facf9fc | 4497 | + if (unlikely(err)) |
076b876e | 4498 | + goto out_bf; |
1facf9fc | 4499 | + |
4500 | + if (!au_br_writable(mod->perm)) { | |
4501 | + /* rw --> ro, file might be mmapped */ | |
4502 | + DiMustNoWaiters(root); | |
5527c038 | 4503 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 4504 | + di_write_unlock(root); |
4505 | + err = au_br_mod_files_ro(sb, bindex); | |
4506 | + /* aufs_write_lock() calls ..._child() */ | |
4507 | + di_write_lock_child(root); | |
4508 | + | |
4509 | + if (unlikely(err)) { | |
4510 | + rerr = -ENOMEM; | |
be52b249 | 4511 | + br->br_wbr = kzalloc(sizeof(*br->br_wbr), |
1facf9fc | 4512 | + GFP_NOFS); |
86dc4139 AM |
4513 | + if (br->br_wbr) |
4514 | + rerr = au_wbr_init(br, sb, br->br_perm); | |
1facf9fc | 4515 | + if (unlikely(rerr)) { |
4516 | + AuIOErr("nested error %d (%d)\n", | |
4517 | + rerr, err); | |
4518 | + br->br_perm = mod->perm; | |
4519 | + } | |
4520 | + } | |
4521 | + } | |
4522 | + } else if (au_br_writable(mod->perm)) { | |
4523 | + /* ro --> rw */ | |
4524 | + err = -ENOMEM; | |
be52b249 | 4525 | + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS); |
1facf9fc | 4526 | + if (br->br_wbr) { |
86dc4139 | 4527 | + err = au_wbr_init(br, sb, mod->perm); |
1facf9fc | 4528 | + if (unlikely(err)) { |
1c60b727 | 4529 | + kfree(br->br_wbr); |
1facf9fc | 4530 | + br->br_wbr = NULL; |
4531 | + } | |
4532 | + } | |
4533 | + } | |
076b876e AM |
4534 | + if (unlikely(err)) |
4535 | + goto out_bf; | |
4536 | + | |
4537 | + if (au_br_fhsm(br->br_perm)) { | |
4538 | + if (!au_br_fhsm(mod->perm)) { | |
4539 | + /* fhsm --> non-fhsm */ | |
4540 | + au_br_fhsm_fin(br->br_fhsm); | |
1c60b727 | 4541 | + kfree(br->br_fhsm); |
076b876e AM |
4542 | + br->br_fhsm = NULL; |
4543 | + } | |
4544 | + } else if (au_br_fhsm(mod->perm)) | |
4545 | + /* non-fhsm --> fhsm */ | |
4546 | + br->br_fhsm = bf; | |
4547 | + | |
076b876e AM |
4548 | + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm); |
4549 | + br->br_perm = mod->perm; | |
4550 | + goto out; /* success */ | |
1facf9fc | 4551 | + |
076b876e | 4552 | +out_bf: |
8b6a4947 | 4553 | + kfree(bf); |
076b876e AM |
4554 | +out: |
4555 | + AuTraceErr(err); | |
4556 | + return err; | |
4557 | +} | |
4558 | + | |
4559 | +/* ---------------------------------------------------------------------- */ | |
4560 | + | |
4561 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs) | |
4562 | +{ | |
4563 | + int err; | |
4564 | + struct kstatfs kstfs; | |
4565 | + | |
4566 | + err = vfs_statfs(&br->br_path, &kstfs); | |
1facf9fc | 4567 | + if (!err) { |
076b876e AM |
4568 | + stfs->f_blocks = kstfs.f_blocks; |
4569 | + stfs->f_bavail = kstfs.f_bavail; | |
4570 | + stfs->f_files = kstfs.f_files; | |
4571 | + stfs->f_ffree = kstfs.f_ffree; | |
1facf9fc | 4572 | + } |
4573 | + | |
1facf9fc | 4574 | + return err; |
4575 | +} | |
7f207e10 AM |
4576 | diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h |
4577 | --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 4578 | +++ linux/fs/aufs/branch.h 2018-01-29 07:56:20.049991637 +0100 |
8b6a4947 | 4579 | @@ -0,0 +1,333 @@ |
1facf9fc | 4580 | +/* |
a2654f78 | 4581 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 4582 | + * |
4583 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4584 | + * it under the terms of the GNU General Public License as published by | |
4585 | + * the Free Software Foundation; either version 2 of the License, or | |
4586 | + * (at your option) any later version. | |
dece6358 AM |
4587 | + * |
4588 | + * This program is distributed in the hope that it will be useful, | |
4589 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4590 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4591 | + * GNU General Public License for more details. | |
4592 | + * | |
4593 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4594 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4595 | + */ |
4596 | + | |
4597 | +/* | |
4598 | + * branch filesystems and xino for them | |
4599 | + */ | |
4600 | + | |
4601 | +#ifndef __AUFS_BRANCH_H__ | |
4602 | +#define __AUFS_BRANCH_H__ | |
4603 | + | |
4604 | +#ifdef __KERNEL__ | |
4605 | + | |
1facf9fc | 4606 | +#include <linux/mount.h> |
8b6a4947 | 4607 | +#include "dirren.h" |
4a4d8108 | 4608 | +#include "dynop.h" |
1facf9fc | 4609 | +#include "rwsem.h" |
4610 | +#include "super.h" | |
4611 | + | |
4612 | +/* ---------------------------------------------------------------------- */ | |
4613 | + | |
4614 | +/* a xino file */ | |
4615 | +struct au_xino_file { | |
4616 | + struct file *xi_file; | |
521ced18 JR |
4617 | + struct { |
4618 | + spinlock_t spin; | |
4619 | + ino_t *array; | |
4620 | + int total; | |
4621 | + /* reserved for future use */ | |
4622 | + /* unsigned long *bitmap; */ | |
4623 | + wait_queue_head_t wqh; | |
4624 | + } xi_nondir; | |
1facf9fc | 4625 | + |
4626 | + /* todo: make xino files an array to support huge inode number */ | |
4627 | + | |
4628 | +#ifdef CONFIG_DEBUG_FS | |
4629 | + struct dentry *xi_dbgaufs; | |
4630 | +#endif | |
4631 | +}; | |
4632 | + | |
076b876e AM |
4633 | +/* File-based Hierarchical Storage Management */ |
4634 | +struct au_br_fhsm { | |
4635 | +#ifdef CONFIG_AUFS_FHSM | |
4636 | + struct mutex bf_lock; | |
4637 | + unsigned long bf_jiffy; | |
4638 | + struct aufs_stfs bf_stfs; | |
4639 | + int bf_readable; | |
4640 | +#endif | |
4641 | +}; | |
4642 | + | |
1facf9fc | 4643 | +/* members for writable branch only */ |
4644 | +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last}; | |
4645 | +struct au_wbr { | |
dece6358 | 4646 | + struct au_rwsem wbr_wh_rwsem; |
1facf9fc | 4647 | + struct dentry *wbr_wh[AuBrWh_Last]; |
4a4d8108 | 4648 | + atomic_t wbr_wh_running; |
1facf9fc | 4649 | +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */ |
4650 | +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */ | |
4651 | +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */ | |
4652 | + | |
4653 | + /* mfs mode */ | |
4654 | + unsigned long long wbr_bytes; | |
4655 | +}; | |
4656 | + | |
4a4d8108 AM |
4657 | +/* ext2 has 3 types of operations at least, ext3 has 4 */ |
4658 | +#define AuBrDynOp (AuDyLast * 4) | |
4659 | + | |
1716fcea AM |
4660 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
4661 | +/* support for asynchronous destruction */ | |
4662 | +struct au_br_hfsnotify { | |
4663 | + struct fsnotify_group *hfsn_group; | |
4664 | +}; | |
4665 | +#endif | |
4666 | + | |
392086de AM |
4667 | +/* sysfs entries */ |
4668 | +struct au_brsysfs { | |
4669 | + char name[16]; | |
4670 | + struct attribute attr; | |
4671 | +}; | |
4672 | + | |
4673 | +enum { | |
4674 | + AuBrSysfs_BR, | |
4675 | + AuBrSysfs_BRID, | |
4676 | + AuBrSysfs_Last | |
4677 | +}; | |
4678 | + | |
1facf9fc | 4679 | +/* protected by superblock rwsem */ |
4680 | +struct au_branch { | |
4681 | + struct au_xino_file br_xino; | |
4682 | + | |
4683 | + aufs_bindex_t br_id; | |
4684 | + | |
4685 | + int br_perm; | |
86dc4139 | 4686 | + struct path br_path; |
4a4d8108 AM |
4687 | + spinlock_t br_dykey_lock; |
4688 | + struct au_dykey *br_dykey[AuBrDynOp]; | |
5afbbe0d | 4689 | + struct percpu_counter br_count; |
1facf9fc | 4690 | + |
4691 | + struct au_wbr *br_wbr; | |
076b876e | 4692 | + struct au_br_fhsm *br_fhsm; |
1facf9fc | 4693 | + |
4694 | + /* xino truncation */ | |
1facf9fc | 4695 | + atomic_t br_xino_running; |
4696 | + | |
027c5e7a | 4697 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
1716fcea | 4698 | + struct au_br_hfsnotify *br_hfsn; |
027c5e7a AM |
4699 | +#endif |
4700 | + | |
1facf9fc | 4701 | +#ifdef CONFIG_SYSFS |
392086de AM |
4702 | + /* entries under sysfs per mount-point */ |
4703 | + struct au_brsysfs br_sysfs[AuBrSysfs_Last]; | |
1facf9fc | 4704 | +#endif |
8b6a4947 AM |
4705 | + |
4706 | + struct au_dr_br br_dirren; | |
1facf9fc | 4707 | +}; |
4708 | + | |
4709 | +/* ---------------------------------------------------------------------- */ | |
4710 | + | |
86dc4139 AM |
4711 | +static inline struct vfsmount *au_br_mnt(struct au_branch *br) |
4712 | +{ | |
4713 | + return br->br_path.mnt; | |
4714 | +} | |
4715 | + | |
4716 | +static inline struct dentry *au_br_dentry(struct au_branch *br) | |
4717 | +{ | |
4718 | + return br->br_path.dentry; | |
4719 | +} | |
4720 | + | |
4721 | +static inline struct super_block *au_br_sb(struct au_branch *br) | |
4722 | +{ | |
4723 | + return au_br_mnt(br)->mnt_sb; | |
4724 | +} | |
4725 | + | |
5afbbe0d AM |
4726 | +static inline void au_br_get(struct au_branch *br) |
4727 | +{ | |
4728 | + percpu_counter_inc(&br->br_count); | |
4729 | +} | |
4730 | + | |
4731 | +static inline void au_br_put(struct au_branch *br) | |
4732 | +{ | |
4733 | + percpu_counter_dec(&br->br_count); | |
4734 | +} | |
4735 | + | |
4736 | +static inline s64 au_br_count(struct au_branch *br) | |
4737 | +{ | |
4738 | + return percpu_counter_sum(&br->br_count); | |
4739 | +} | |
4740 | + | |
4741 | +static inline void au_br_count_init(struct au_branch *br) | |
4742 | +{ | |
4743 | + percpu_counter_init(&br->br_count, 0, GFP_NOFS); | |
4744 | +} | |
4745 | + | |
4746 | +static inline void au_br_count_fin(struct au_branch *br) | |
4747 | +{ | |
4748 | + percpu_counter_destroy(&br->br_count); | |
4749 | +} | |
4750 | + | |
1facf9fc | 4751 | +static inline int au_br_rdonly(struct au_branch *br) |
4752 | +{ | |
8b6a4947 | 4753 | + return (sb_rdonly(au_br_sb(br)) |
1facf9fc | 4754 | + || !au_br_writable(br->br_perm)) |
4755 | + ? -EROFS : 0; | |
4756 | +} | |
4757 | + | |
4a4d8108 | 4758 | +static inline int au_br_hnotifyable(int brperm __maybe_unused) |
1facf9fc | 4759 | +{ |
4a4d8108 | 4760 | +#ifdef CONFIG_AUFS_HNOTIFY |
1e00d052 | 4761 | + return !(brperm & AuBrPerm_RR); |
1facf9fc | 4762 | +#else |
4763 | + return 0; | |
4764 | +#endif | |
4765 | +} | |
4766 | + | |
b912730e AM |
4767 | +static inline int au_br_test_oflag(int oflag, struct au_branch *br) |
4768 | +{ | |
4769 | + int err, exec_flag; | |
4770 | + | |
4771 | + err = 0; | |
4772 | + exec_flag = oflag & __FMODE_EXEC; | |
79b8bda9 | 4773 | + if (unlikely(exec_flag && path_noexec(&br->br_path))) |
b912730e AM |
4774 | + err = -EACCES; |
4775 | + | |
4776 | + return err; | |
4777 | +} | |
4778 | + | |
1facf9fc | 4779 | +/* ---------------------------------------------------------------------- */ |
4780 | + | |
4781 | +/* branch.c */ | |
4782 | +struct au_sbinfo; | |
4783 | +void au_br_free(struct au_sbinfo *sinfo); | |
4784 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id); | |
4785 | +struct au_opt_add; | |
4786 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount); | |
4787 | +struct au_opt_del; | |
4788 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount); | |
027c5e7a AM |
4789 | +long au_ibusy_ioctl(struct file *file, unsigned long arg); |
4790 | +#ifdef CONFIG_COMPAT | |
4791 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg); | |
4792 | +#endif | |
1facf9fc | 4793 | +struct au_opt_mod; |
4794 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4795 | + int *do_refresh); |
076b876e AM |
4796 | +struct aufs_stfs; |
4797 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs); | |
1facf9fc | 4798 | + |
4799 | +/* xino.c */ | |
4800 | +static const loff_t au_loff_max = LLONG_MAX; | |
4801 | + | |
4802 | +int au_xib_trunc(struct super_block *sb); | |
5527c038 | 4803 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size, |
1facf9fc | 4804 | + loff_t *pos); |
5527c038 JR |
4805 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
4806 | + size_t size, loff_t *pos); | |
1facf9fc | 4807 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src); |
4808 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent); | |
4809 | +ino_t au_xino_new_ino(struct super_block *sb); | |
b752ccd1 | 4810 | +void au_xino_delete_inode(struct inode *inode, const int unlinked); |
1facf9fc | 4811 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
4812 | + ino_t ino); | |
4813 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4814 | + ino_t *ino); | |
4815 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino, | |
4816 | + struct file *base_file, int do_test); | |
4817 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex); | |
4818 | + | |
4819 | +struct au_opt_xino; | |
4820 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount); | |
4821 | +void au_xino_clr(struct super_block *sb); | |
4822 | +struct file *au_xino_def(struct super_block *sb); | |
4823 | +int au_xino_path(struct seq_file *seq, struct file *file); | |
4824 | + | |
521ced18 JR |
4825 | +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex, |
4826 | + ino_t h_ino, int idx); | |
4827 | +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4828 | + int *idx); | |
4829 | + | |
1facf9fc | 4830 | +/* ---------------------------------------------------------------------- */ |
4831 | + | |
4832 | +/* Superblock to branch */ | |
4833 | +static inline | |
4834 | +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex) | |
4835 | +{ | |
4836 | + return au_sbr(sb, bindex)->br_id; | |
4837 | +} | |
4838 | + | |
4839 | +static inline | |
4840 | +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex) | |
4841 | +{ | |
86dc4139 | 4842 | + return au_br_mnt(au_sbr(sb, bindex)); |
1facf9fc | 4843 | +} |
4844 | + | |
4845 | +static inline | |
4846 | +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex) | |
4847 | +{ | |
86dc4139 | 4848 | + return au_br_sb(au_sbr(sb, bindex)); |
1facf9fc | 4849 | +} |
4850 | + | |
5afbbe0d AM |
4851 | +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex) |
4852 | +{ | |
4853 | + au_br_get(au_sbr(sb, bindex)); | |
4854 | +} | |
4855 | + | |
1facf9fc | 4856 | +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex) |
4857 | +{ | |
5afbbe0d | 4858 | + au_br_put(au_sbr(sb, bindex)); |
1facf9fc | 4859 | +} |
4860 | + | |
4861 | +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex) | |
4862 | +{ | |
4863 | + return au_sbr(sb, bindex)->br_perm; | |
4864 | +} | |
4865 | + | |
4866 | +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex) | |
4867 | +{ | |
4868 | + return au_br_whable(au_sbr_perm(sb, bindex)); | |
4869 | +} | |
4870 | + | |
4871 | +/* ---------------------------------------------------------------------- */ | |
4872 | + | |
8b6a4947 AM |
4873 | +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem) |
4874 | +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem) | |
4875 | +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem) | |
4876 | +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem) | |
1facf9fc | 4877 | +/* |
8b6a4947 AM |
4878 | +#define wbr_wh_read_trylock_nested(wbr) \ |
4879 | + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem) | |
4880 | +#define wbr_wh_write_trylock_nested(wbr) \ | |
4881 | + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem) | |
4882 | +*/ | |
1facf9fc | 4883 | + |
8b6a4947 AM |
4884 | +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem) |
4885 | +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem) | |
4886 | +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem) | |
4887 | + | |
4888 | +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem) | |
4889 | +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem) | |
4890 | +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem) | |
dece6358 | 4891 | + |
076b876e AM |
4892 | +/* ---------------------------------------------------------------------- */ |
4893 | + | |
4894 | +#ifdef CONFIG_AUFS_FHSM | |
4895 | +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm) | |
4896 | +{ | |
4897 | + mutex_init(&brfhsm->bf_lock); | |
4898 | + brfhsm->bf_jiffy = 0; | |
4899 | + brfhsm->bf_readable = 0; | |
4900 | +} | |
4901 | + | |
4902 | +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm) | |
4903 | +{ | |
4904 | + mutex_destroy(&brfhsm->bf_lock); | |
4905 | +} | |
4906 | +#else | |
4907 | +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm) | |
4908 | +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm) | |
4909 | +#endif | |
4910 | + | |
1facf9fc | 4911 | +#endif /* __KERNEL__ */ |
4912 | +#endif /* __AUFS_BRANCH_H__ */ | |
7f207e10 AM |
4913 | diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk |
4914 | --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 AM |
4915 | +++ linux/fs/aufs/conf.mk 2018-01-29 07:56:20.049991637 +0100 |
4916 | @@ -0,0 +1,40 @@ | |
4917 | +# SPDX-License-Identifier: GPL-2.0 | |
4a4d8108 AM |
4918 | + |
4919 | +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS} | |
4920 | + | |
4921 | +define AuConf | |
4922 | +ifdef ${1} | |
4923 | +AuConfStr += ${1}=${${1}} | |
4924 | +endif | |
4925 | +endef | |
4926 | + | |
b752ccd1 | 4927 | +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \ |
e49829fe | 4928 | + SBILIST \ |
7f207e10 | 4929 | + HNOTIFY HFSNOTIFY \ |
4a4d8108 | 4930 | + EXPORT INO_T_64 \ |
c1595e42 | 4931 | + XATTR \ |
076b876e | 4932 | + FHSM \ |
4a4d8108 | 4933 | + RDU \ |
8b6a4947 | 4934 | + DIRREN \ |
4a4d8108 AM |
4935 | + SHWH \ |
4936 | + BR_RAMFS \ | |
4937 | + BR_FUSE POLL \ | |
4938 | + BR_HFSPLUS \ | |
4939 | + BDEV_LOOP \ | |
b752ccd1 AM |
4940 | + DEBUG MAGIC_SYSRQ |
4941 | +$(foreach i, ${AuConfAll}, \ | |
4a4d8108 AM |
4942 | + $(eval $(call AuConf,CONFIG_AUFS_${i}))) |
4943 | + | |
4944 | +AuConfName = ${obj}/conf.str | |
4945 | +${AuConfName}.tmp: FORCE | |
4946 | + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@ | |
4947 | +${AuConfName}: ${AuConfName}.tmp | |
4948 | + @diff -q $< $@ > /dev/null 2>&1 || { \ | |
4949 | + echo ' GEN ' $@; \ | |
4950 | + cp -p $< $@; \ | |
4951 | + } | |
4952 | +FORCE: | |
4953 | +clean-files += ${AuConfName} ${AuConfName}.tmp | |
4954 | +${obj}/sysfs.o: ${AuConfName} | |
b752ccd1 AM |
4955 | + |
4956 | +-include ${srctree}/${src}/conf_priv.mk | |
7f207e10 AM |
4957 | diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c |
4958 | --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 AM |
4959 | +++ linux/fs/aufs/cpup.c 2018-01-29 07:56:20.053325069 +0100 |
4960 | @@ -0,0 +1,1442 @@ | |
1facf9fc | 4961 | +/* |
a2654f78 | 4962 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 4963 | + * |
4964 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4965 | + * it under the terms of the GNU General Public License as published by | |
4966 | + * the Free Software Foundation; either version 2 of the License, or | |
4967 | + * (at your option) any later version. | |
dece6358 AM |
4968 | + * |
4969 | + * This program is distributed in the hope that it will be useful, | |
4970 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4971 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4972 | + * GNU General Public License for more details. | |
4973 | + * | |
4974 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4975 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4976 | + */ |
4977 | + | |
4978 | +/* | |
4979 | + * copy-up functions, see wbr_policy.c for copy-down | |
4980 | + */ | |
4981 | + | |
4982 | +#include <linux/fs_stack.h> | |
dece6358 | 4983 | +#include <linux/mm.h> |
8cdd5066 | 4984 | +#include <linux/task_work.h> |
1facf9fc | 4985 | +#include "aufs.h" |
4986 | + | |
86dc4139 | 4987 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags) |
1facf9fc | 4988 | +{ |
4989 | + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE | |
367653fa | 4990 | + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT; |
1facf9fc | 4991 | + |
86dc4139 AM |
4992 | + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags)); |
4993 | + | |
4994 | + dst->i_flags |= iflags & ~mask; | |
1facf9fc | 4995 | + if (au_test_fs_notime(dst->i_sb)) |
4996 | + dst->i_flags |= S_NOATIME | S_NOCMTIME; | |
4997 | +} | |
4998 | + | |
4999 | +void au_cpup_attr_timesizes(struct inode *inode) | |
5000 | +{ | |
5001 | + struct inode *h_inode; | |
5002 | + | |
5afbbe0d | 5003 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 5004 | + fsstack_copy_attr_times(inode, h_inode); |
4a4d8108 | 5005 | + fsstack_copy_inode_size(inode, h_inode); |
1facf9fc | 5006 | +} |
5007 | + | |
5008 | +void au_cpup_attr_nlink(struct inode *inode, int force) | |
5009 | +{ | |
5010 | + struct inode *h_inode; | |
5011 | + struct super_block *sb; | |
5afbbe0d | 5012 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 5013 | + |
5014 | + sb = inode->i_sb; | |
5afbbe0d | 5015 | + bindex = au_ibtop(inode); |
1facf9fc | 5016 | + h_inode = au_h_iptr(inode, bindex); |
5017 | + if (!force | |
5018 | + && !S_ISDIR(h_inode->i_mode) | |
5019 | + && au_opt_test(au_mntflags(sb), PLINK) | |
5020 | + && au_plink_test(inode)) | |
5021 | + return; | |
5022 | + | |
7eafdf33 AM |
5023 | + /* |
5024 | + * 0 can happen in revalidating. | |
38d290e6 JR |
5025 | + * h_inode->i_mutex may not be held here, but it is harmless since once |
5026 | + * i_nlink reaches 0, it will never become positive except O_TMPFILE | |
5027 | + * case. | |
5028 | + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause | |
5029 | + * the incorrect link count. | |
7eafdf33 | 5030 | + */ |
92d182d2 | 5031 | + set_nlink(inode, h_inode->i_nlink); |
1facf9fc | 5032 | + |
5033 | + /* | |
5034 | + * fewer nlink makes find(1) noisy, but larger nlink doesn't. | |
5035 | + * it may includes whplink directory. | |
5036 | + */ | |
5037 | + if (S_ISDIR(h_inode->i_mode)) { | |
5afbbe0d AM |
5038 | + bbot = au_ibbot(inode); |
5039 | + for (bindex++; bindex <= bbot; bindex++) { | |
1facf9fc | 5040 | + h_inode = au_h_iptr(inode, bindex); |
5041 | + if (h_inode) | |
5042 | + au_add_nlink(inode, h_inode); | |
5043 | + } | |
5044 | + } | |
5045 | +} | |
5046 | + | |
5047 | +void au_cpup_attr_changeable(struct inode *inode) | |
5048 | +{ | |
5049 | + struct inode *h_inode; | |
5050 | + | |
5afbbe0d | 5051 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 5052 | + inode->i_mode = h_inode->i_mode; |
5053 | + inode->i_uid = h_inode->i_uid; | |
5054 | + inode->i_gid = h_inode->i_gid; | |
5055 | + au_cpup_attr_timesizes(inode); | |
86dc4139 | 5056 | + au_cpup_attr_flags(inode, h_inode->i_flags); |
1facf9fc | 5057 | +} |
5058 | + | |
5059 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode) | |
5060 | +{ | |
5061 | + struct au_iinfo *iinfo = au_ii(inode); | |
5062 | + | |
1308ab2a | 5063 | + IiMustWriteLock(inode); |
5064 | + | |
1facf9fc | 5065 | + iinfo->ii_higen = h_inode->i_generation; |
5066 | + iinfo->ii_hsb1 = h_inode->i_sb; | |
5067 | +} | |
5068 | + | |
5069 | +void au_cpup_attr_all(struct inode *inode, int force) | |
5070 | +{ | |
5071 | + struct inode *h_inode; | |
5072 | + | |
5afbbe0d | 5073 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 5074 | + au_cpup_attr_changeable(inode); |
5075 | + if (inode->i_nlink > 0) | |
5076 | + au_cpup_attr_nlink(inode, force); | |
5077 | + inode->i_rdev = h_inode->i_rdev; | |
5078 | + inode->i_blkbits = h_inode->i_blkbits; | |
5079 | + au_cpup_igen(inode, h_inode); | |
5080 | +} | |
5081 | + | |
5082 | +/* ---------------------------------------------------------------------- */ | |
5083 | + | |
5084 | +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */ | |
5085 | + | |
5086 | +/* keep the timestamps of the parent dir when cpup */ | |
5087 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
5088 | + struct path *h_path) | |
5089 | +{ | |
5090 | + struct inode *h_inode; | |
5091 | + | |
5092 | + dt->dt_dentry = dentry; | |
5093 | + dt->dt_h_path = *h_path; | |
5527c038 | 5094 | + h_inode = d_inode(h_path->dentry); |
1facf9fc | 5095 | + dt->dt_atime = h_inode->i_atime; |
5096 | + dt->dt_mtime = h_inode->i_mtime; | |
5097 | + /* smp_mb(); */ | |
5098 | +} | |
5099 | + | |
5100 | +void au_dtime_revert(struct au_dtime *dt) | |
5101 | +{ | |
5102 | + struct iattr attr; | |
5103 | + int err; | |
5104 | + | |
5105 | + attr.ia_atime = dt->dt_atime; | |
5106 | + attr.ia_mtime = dt->dt_mtime; | |
5107 | + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET | |
5108 | + | ATTR_ATIME | ATTR_ATIME_SET; | |
5109 | + | |
523b37e3 AM |
5110 | + /* no delegation since this is a directory */ |
5111 | + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL); | |
1facf9fc | 5112 | + if (unlikely(err)) |
0c3ec466 | 5113 | + pr_warn("restoring timestamps failed(%d). ignored\n", err); |
1facf9fc | 5114 | +} |
5115 | + | |
5116 | +/* ---------------------------------------------------------------------- */ | |
5117 | + | |
86dc4139 AM |
5118 | +/* internal use only */ |
5119 | +struct au_cpup_reg_attr { | |
5120 | + int valid; | |
5121 | + struct kstat st; | |
5122 | + unsigned int iflags; /* inode->i_flags */ | |
5123 | +}; | |
5124 | + | |
1facf9fc | 5125 | +static noinline_for_stack |
86dc4139 AM |
5126 | +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src, |
5127 | + struct au_cpup_reg_attr *h_src_attr) | |
1facf9fc | 5128 | +{ |
c1595e42 | 5129 | + int err, sbits, icex; |
7e9cd9fe AM |
5130 | + unsigned int mnt_flags; |
5131 | + unsigned char verbose; | |
1facf9fc | 5132 | + struct iattr ia; |
5133 | + struct path h_path; | |
1308ab2a | 5134 | + struct inode *h_isrc, *h_idst; |
86dc4139 | 5135 | + struct kstat *h_st; |
c1595e42 | 5136 | + struct au_branch *br; |
1facf9fc | 5137 | + |
5138 | + h_path.dentry = au_h_dptr(dst, bindex); | |
5527c038 | 5139 | + h_idst = d_inode(h_path.dentry); |
c1595e42 JR |
5140 | + br = au_sbr(dst->d_sb, bindex); |
5141 | + h_path.mnt = au_br_mnt(br); | |
5527c038 | 5142 | + h_isrc = d_inode(h_src); |
1308ab2a | 5143 | + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID |
1facf9fc | 5144 | + | ATTR_ATIME | ATTR_MTIME |
5145 | + | ATTR_ATIME_SET | ATTR_MTIME_SET; | |
86dc4139 AM |
5146 | + if (h_src_attr && h_src_attr->valid) { |
5147 | + h_st = &h_src_attr->st; | |
5148 | + ia.ia_uid = h_st->uid; | |
5149 | + ia.ia_gid = h_st->gid; | |
5150 | + ia.ia_atime = h_st->atime; | |
5151 | + ia.ia_mtime = h_st->mtime; | |
5152 | + if (h_idst->i_mode != h_st->mode | |
5153 | + && !S_ISLNK(h_idst->i_mode)) { | |
5154 | + ia.ia_valid |= ATTR_MODE; | |
5155 | + ia.ia_mode = h_st->mode; | |
5156 | + } | |
5157 | + sbits = !!(h_st->mode & (S_ISUID | S_ISGID)); | |
5158 | + au_cpup_attr_flags(h_idst, h_src_attr->iflags); | |
5159 | + } else { | |
5160 | + ia.ia_uid = h_isrc->i_uid; | |
5161 | + ia.ia_gid = h_isrc->i_gid; | |
5162 | + ia.ia_atime = h_isrc->i_atime; | |
5163 | + ia.ia_mtime = h_isrc->i_mtime; | |
5164 | + if (h_idst->i_mode != h_isrc->i_mode | |
5165 | + && !S_ISLNK(h_idst->i_mode)) { | |
5166 | + ia.ia_valid |= ATTR_MODE; | |
5167 | + ia.ia_mode = h_isrc->i_mode; | |
5168 | + } | |
5169 | + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID)); | |
5170 | + au_cpup_attr_flags(h_idst, h_isrc->i_flags); | |
1308ab2a | 5171 | + } |
523b37e3 AM |
5172 | + /* no delegation since it is just created */ |
5173 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 5174 | + |
5175 | + /* is this nfs only? */ | |
5176 | + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) { | |
5177 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
5178 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 5179 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); |
1facf9fc | 5180 | + } |
5181 | + | |
c1595e42 | 5182 | + icex = br->br_perm & AuBrAttr_ICEX; |
7e9cd9fe AM |
5183 | + if (!err) { |
5184 | + mnt_flags = au_mntflags(dst->d_sb); | |
5185 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
5186 | + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose); | |
5187 | + } | |
c1595e42 | 5188 | + |
1facf9fc | 5189 | + return err; |
5190 | +} | |
5191 | + | |
5192 | +/* ---------------------------------------------------------------------- */ | |
5193 | + | |
5194 | +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len, | |
5195 | + char *buf, unsigned long blksize) | |
5196 | +{ | |
5197 | + int err; | |
5198 | + size_t sz, rbytes, wbytes; | |
5199 | + unsigned char all_zero; | |
5200 | + char *p, *zp; | |
febd17d6 | 5201 | + struct inode *h_inode; |
1facf9fc | 5202 | + /* reduce stack usage */ |
5203 | + struct iattr *ia; | |
5204 | + | |
5205 | + zp = page_address(ZERO_PAGE(0)); | |
5206 | + if (unlikely(!zp)) | |
5207 | + return -ENOMEM; /* possible? */ | |
5208 | + | |
5209 | + err = 0; | |
5210 | + all_zero = 0; | |
5211 | + while (len) { | |
5212 | + AuDbg("len %lld\n", len); | |
5213 | + sz = blksize; | |
5214 | + if (len < blksize) | |
5215 | + sz = len; | |
5216 | + | |
5217 | + rbytes = 0; | |
5218 | + /* todo: signal_pending? */ | |
5219 | + while (!rbytes || err == -EAGAIN || err == -EINTR) { | |
5220 | + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos); | |
5221 | + err = rbytes; | |
5222 | + } | |
5223 | + if (unlikely(err < 0)) | |
5224 | + break; | |
5225 | + | |
5226 | + all_zero = 0; | |
5227 | + if (len >= rbytes && rbytes == blksize) | |
5228 | + all_zero = !memcmp(buf, zp, rbytes); | |
5229 | + if (!all_zero) { | |
5230 | + wbytes = rbytes; | |
5231 | + p = buf; | |
5232 | + while (wbytes) { | |
5233 | + size_t b; | |
5234 | + | |
5235 | + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos); | |
5236 | + err = b; | |
5237 | + /* todo: signal_pending? */ | |
5238 | + if (unlikely(err == -EAGAIN || err == -EINTR)) | |
5239 | + continue; | |
5240 | + if (unlikely(err < 0)) | |
5241 | + break; | |
5242 | + wbytes -= b; | |
5243 | + p += b; | |
5244 | + } | |
392086de AM |
5245 | + if (unlikely(err < 0)) |
5246 | + break; | |
1facf9fc | 5247 | + } else { |
5248 | + loff_t res; | |
5249 | + | |
5250 | + AuLabel(hole); | |
5251 | + res = vfsub_llseek(dst, rbytes, SEEK_CUR); | |
5252 | + err = res; | |
5253 | + if (unlikely(res < 0)) | |
5254 | + break; | |
5255 | + } | |
5256 | + len -= rbytes; | |
5257 | + err = 0; | |
5258 | + } | |
5259 | + | |
5260 | + /* the last block may be a hole */ | |
5261 | + if (!err && all_zero) { | |
5262 | + AuLabel(last hole); | |
5263 | + | |
5264 | + err = 1; | |
2000de60 | 5265 | + if (au_test_nfs(dst->f_path.dentry->d_sb)) { |
1facf9fc | 5266 | + /* nfs requires this step to make last hole */ |
5267 | + /* is this only nfs? */ | |
5268 | + do { | |
5269 | + /* todo: signal_pending? */ | |
5270 | + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos); | |
5271 | + } while (err == -EAGAIN || err == -EINTR); | |
5272 | + if (err == 1) | |
5273 | + dst->f_pos--; | |
5274 | + } | |
5275 | + | |
5276 | + if (err == 1) { | |
5277 | + ia = (void *)buf; | |
5278 | + ia->ia_size = dst->f_pos; | |
5279 | + ia->ia_valid = ATTR_SIZE | ATTR_FILE; | |
5280 | + ia->ia_file = dst; | |
febd17d6 JR |
5281 | + h_inode = file_inode(dst); |
5282 | + inode_lock_nested(h_inode, AuLsc_I_CHILD2); | |
523b37e3 AM |
5283 | + /* no delegation since it is just created */ |
5284 | + err = vfsub_notify_change(&dst->f_path, ia, | |
5285 | + /*delegated*/NULL); | |
febd17d6 | 5286 | + inode_unlock(h_inode); |
1facf9fc | 5287 | + } |
5288 | + } | |
5289 | + | |
5290 | + return err; | |
5291 | +} | |
5292 | + | |
5293 | +int au_copy_file(struct file *dst, struct file *src, loff_t len) | |
5294 | +{ | |
5295 | + int err; | |
5296 | + unsigned long blksize; | |
5297 | + unsigned char do_kfree; | |
5298 | + char *buf; | |
5299 | + | |
5300 | + err = -ENOMEM; | |
2000de60 | 5301 | + blksize = dst->f_path.dentry->d_sb->s_blocksize; |
1facf9fc | 5302 | + if (!blksize || PAGE_SIZE < blksize) |
5303 | + blksize = PAGE_SIZE; | |
5304 | + AuDbg("blksize %lu\n", blksize); | |
5305 | + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *)); | |
5306 | + if (do_kfree) | |
5307 | + buf = kmalloc(blksize, GFP_NOFS); | |
5308 | + else | |
5309 | + buf = (void *)__get_free_page(GFP_NOFS); | |
5310 | + if (unlikely(!buf)) | |
5311 | + goto out; | |
5312 | + | |
5313 | + if (len > (1 << 22)) | |
5314 | + AuDbg("copying a large file %lld\n", (long long)len); | |
5315 | + | |
5316 | + src->f_pos = 0; | |
5317 | + dst->f_pos = 0; | |
5318 | + err = au_do_copy_file(dst, src, len, buf, blksize); | |
5319 | + if (do_kfree) | |
1c60b727 | 5320 | + kfree(buf); |
1facf9fc | 5321 | + else |
1c60b727 | 5322 | + free_page((unsigned long)buf); |
1facf9fc | 5323 | + |
4f0767ce | 5324 | +out: |
1facf9fc | 5325 | + return err; |
5326 | +} | |
5327 | + | |
1c60b727 AM |
5328 | +static int au_do_copy(struct file *dst, struct file *src, loff_t len) |
5329 | +{ | |
5330 | + int err; | |
5331 | + struct super_block *h_src_sb; | |
5332 | + struct inode *h_src_inode; | |
5333 | + | |
5334 | + h_src_inode = file_inode(src); | |
5335 | + h_src_sb = h_src_inode->i_sb; | |
5336 | + | |
5337 | + /* XFS acquires inode_lock */ | |
5338 | + if (!au_test_xfs(h_src_sb)) | |
5339 | + err = au_copy_file(dst, src, len); | |
5340 | + else { | |
3c1bdaff | 5341 | + inode_unlock_shared(h_src_inode); |
1c60b727 | 5342 | + err = au_copy_file(dst, src, len); |
3c1bdaff | 5343 | + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
1c60b727 AM |
5344 | + } |
5345 | + | |
5346 | + return err; | |
5347 | +} | |
5348 | + | |
5349 | +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len) | |
5350 | +{ | |
5351 | + int err; | |
5352 | + struct super_block *h_src_sb; | |
5353 | + struct inode *h_src_inode; | |
5354 | + | |
5355 | + h_src_inode = file_inode(src); | |
5356 | + h_src_sb = h_src_inode->i_sb; | |
5357 | + if (h_src_sb != file_inode(dst)->i_sb | |
5358 | + || !dst->f_op->clone_file_range) { | |
5359 | + err = au_do_copy(dst, src, len); | |
5360 | + goto out; | |
5361 | + } | |
5362 | + | |
5363 | + if (!au_test_nfs(h_src_sb)) { | |
3c1bdaff | 5364 | + inode_unlock_shared(h_src_inode); |
1c60b727 | 5365 | + err = vfsub_clone_file_range(src, dst, len); |
3c1bdaff | 5366 | + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
1c60b727 AM |
5367 | + } else |
5368 | + err = vfsub_clone_file_range(src, dst, len); | |
5369 | + /* older XFS has a condition in cloning */ | |
5370 | + if (unlikely(err != -EOPNOTSUPP)) | |
5371 | + goto out; | |
5372 | + | |
5373 | + /* the backend fs on NFS may not support cloning */ | |
5374 | + err = au_do_copy(dst, src, len); | |
5375 | + | |
5376 | +out: | |
5377 | + AuTraceErr(err); | |
5378 | + return err; | |
5379 | +} | |
5380 | + | |
1facf9fc | 5381 | +/* |
5382 | + * to support a sparse file which is opened with O_APPEND, | |
5383 | + * we need to close the file. | |
5384 | + */ | |
c2b27bf2 | 5385 | +static int au_cp_regular(struct au_cp_generic *cpg) |
1facf9fc | 5386 | +{ |
5387 | + int err, i; | |
5388 | + enum { SRC, DST }; | |
5389 | + struct { | |
5390 | + aufs_bindex_t bindex; | |
5391 | + unsigned int flags; | |
5392 | + struct dentry *dentry; | |
392086de | 5393 | + int force_wr; |
1facf9fc | 5394 | + struct file *file; |
523b37e3 | 5395 | + void *label; |
1facf9fc | 5396 | + } *f, file[] = { |
5397 | + { | |
c2b27bf2 | 5398 | + .bindex = cpg->bsrc, |
1facf9fc | 5399 | + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE, |
523b37e3 | 5400 | + .label = &&out |
1facf9fc | 5401 | + }, |
5402 | + { | |
c2b27bf2 | 5403 | + .bindex = cpg->bdst, |
1facf9fc | 5404 | + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE, |
392086de | 5405 | + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST), |
523b37e3 | 5406 | + .label = &&out_src |
1facf9fc | 5407 | + } |
5408 | + }; | |
521ced18 | 5409 | + struct super_block *sb, *h_src_sb; |
e2f27e51 | 5410 | + struct inode *h_src_inode; |
8cdd5066 | 5411 | + struct task_struct *tsk = current; |
1facf9fc | 5412 | + |
5413 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5414 | + sb = cpg->dentry->d_sb; |
1facf9fc | 5415 | + f = file; |
5416 | + for (i = 0; i < 2; i++, f++) { | |
c2b27bf2 AM |
5417 | + f->dentry = au_h_dptr(cpg->dentry, f->bindex); |
5418 | + f->file = au_h_open(cpg->dentry, f->bindex, f->flags, | |
392086de | 5419 | + /*file*/NULL, f->force_wr); |
1facf9fc | 5420 | + err = PTR_ERR(f->file); |
5421 | + if (IS_ERR(f->file)) | |
5422 | + goto *f->label; | |
1facf9fc | 5423 | + } |
5424 | + | |
5425 | + /* try stopping to update while we copyup */ | |
e2f27e51 | 5426 | + h_src_inode = d_inode(file[SRC].dentry); |
521ced18 JR |
5427 | + h_src_sb = h_src_inode->i_sb; |
5428 | + if (!au_test_nfs(h_src_sb)) | |
e2f27e51 | 5429 | + IMustLock(h_src_inode); |
1c60b727 | 5430 | + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len); |
1facf9fc | 5431 | + |
8cdd5066 JR |
5432 | + /* i wonder if we had O_NO_DELAY_FPUT flag */ |
5433 | + if (tsk->flags & PF_KTHREAD) | |
5434 | + __fput_sync(file[DST].file); | |
5435 | + else { | |
2121bcd9 | 5436 | + /* it happend actually */ |
8cdd5066 JR |
5437 | + fput(file[DST].file); |
5438 | + /* | |
5439 | + * too bad. | |
5440 | + * we have to call both since we don't know which place the file | |
5441 | + * was added to. | |
5442 | + */ | |
5443 | + task_work_run(); | |
5444 | + flush_delayed_fput(); | |
5445 | + } | |
1facf9fc | 5446 | + au_sbr_put(sb, file[DST].bindex); |
523b37e3 | 5447 | + |
4f0767ce | 5448 | +out_src: |
1facf9fc | 5449 | + fput(file[SRC].file); |
5450 | + au_sbr_put(sb, file[SRC].bindex); | |
4f0767ce | 5451 | +out: |
1facf9fc | 5452 | + return err; |
5453 | +} | |
5454 | + | |
c2b27bf2 | 5455 | +static int au_do_cpup_regular(struct au_cp_generic *cpg, |
86dc4139 | 5456 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5457 | +{ |
5458 | + int err, rerr; | |
5459 | + loff_t l; | |
86dc4139 | 5460 | + struct path h_path; |
38d290e6 | 5461 | + struct inode *h_src_inode, *h_dst_inode; |
1facf9fc | 5462 | + |
5463 | + err = 0; | |
5527c038 | 5464 | + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc); |
86dc4139 | 5465 | + l = i_size_read(h_src_inode); |
c2b27bf2 AM |
5466 | + if (cpg->len == -1 || l < cpg->len) |
5467 | + cpg->len = l; | |
5468 | + if (cpg->len) { | |
86dc4139 | 5469 | + /* try stopping to update while we are referencing */ |
3c1bdaff | 5470 | + vfsub_inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
c2b27bf2 | 5471 | + au_pin_hdir_unlock(cpg->pin); |
1facf9fc | 5472 | + |
c2b27bf2 AM |
5473 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5474 | + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc); | |
86dc4139 | 5475 | + h_src_attr->iflags = h_src_inode->i_flags; |
5527c038 | 5476 | + if (!au_test_nfs(h_src_inode->i_sb)) |
521ced18 | 5477 | + err = vfsub_getattr(&h_path, &h_src_attr->st); |
5527c038 | 5478 | + else { |
3c1bdaff | 5479 | + inode_unlock_shared(h_src_inode); |
521ced18 | 5480 | + err = vfsub_getattr(&h_path, &h_src_attr->st); |
8b6a4947 AM |
5481 | + vfsub_inode_lock_shared_nested(h_src_inode, |
5482 | + AuLsc_I_CHILD); | |
5527c038 | 5483 | + } |
86dc4139 | 5484 | + if (unlikely(err)) { |
3c1bdaff | 5485 | + inode_unlock_shared(h_src_inode); |
86dc4139 AM |
5486 | + goto out; |
5487 | + } | |
5488 | + h_src_attr->valid = 1; | |
e2f27e51 AM |
5489 | + if (!au_test_nfs(h_src_inode->i_sb)) { |
5490 | + err = au_cp_regular(cpg); | |
3c1bdaff | 5491 | + inode_unlock_shared(h_src_inode); |
e2f27e51 | 5492 | + } else { |
3c1bdaff | 5493 | + inode_unlock_shared(h_src_inode); |
e2f27e51 AM |
5494 | + err = au_cp_regular(cpg); |
5495 | + } | |
c2b27bf2 | 5496 | + rerr = au_pin_hdir_relock(cpg->pin); |
86dc4139 AM |
5497 | + if (!err && rerr) |
5498 | + err = rerr; | |
1facf9fc | 5499 | + } |
38d290e6 JR |
5500 | + if (!err && (h_src_inode->i_state & I_LINKABLE)) { |
5501 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst); | |
5527c038 | 5502 | + h_dst_inode = d_inode(h_path.dentry); |
38d290e6 JR |
5503 | + spin_lock(&h_dst_inode->i_lock); |
5504 | + h_dst_inode->i_state |= I_LINKABLE; | |
5505 | + spin_unlock(&h_dst_inode->i_lock); | |
5506 | + } | |
1facf9fc | 5507 | + |
4f0767ce | 5508 | +out: |
1facf9fc | 5509 | + return err; |
5510 | +} | |
5511 | + | |
5512 | +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src, | |
5513 | + struct inode *h_dir) | |
5514 | +{ | |
5515 | + int err, symlen; | |
5516 | + mm_segment_t old_fs; | |
b752ccd1 AM |
5517 | + union { |
5518 | + char *k; | |
5519 | + char __user *u; | |
5520 | + } sym; | |
1facf9fc | 5521 | + |
5522 | + err = -ENOMEM; | |
537831f9 | 5523 | + sym.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 5524 | + if (unlikely(!sym.k)) |
1facf9fc | 5525 | + goto out; |
5526 | + | |
9dbd164d | 5527 | + /* unnecessary to support mmap_sem since symlink is not mmap-able */ |
1facf9fc | 5528 | + old_fs = get_fs(); |
5529 | + set_fs(KERNEL_DS); | |
a2654f78 | 5530 | + symlen = vfs_readlink(h_src, sym.u, PATH_MAX); |
1facf9fc | 5531 | + err = symlen; |
5532 | + set_fs(old_fs); | |
5533 | + | |
5534 | + if (symlen > 0) { | |
b752ccd1 AM |
5535 | + sym.k[symlen] = 0; |
5536 | + err = vfsub_symlink(h_dir, h_path, sym.k); | |
1facf9fc | 5537 | + } |
1c60b727 | 5538 | + free_page((unsigned long)sym.k); |
1facf9fc | 5539 | + |
4f0767ce | 5540 | +out: |
1facf9fc | 5541 | + return err; |
5542 | +} | |
5543 | + | |
8cdd5066 JR |
5544 | +/* |
5545 | + * regardless 'acl' option, reset all ACL. | |
5546 | + * All ACL will be copied up later from the original entry on the lower branch. | |
5547 | + */ | |
5548 | +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode) | |
5549 | +{ | |
5550 | + int err; | |
5551 | + struct dentry *h_dentry; | |
5552 | + struct inode *h_inode; | |
5553 | + | |
5554 | + h_dentry = h_path->dentry; | |
5555 | + h_inode = d_inode(h_dentry); | |
5556 | + /* forget_all_cached_acls(h_inode)); */ | |
5557 | + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS); | |
5558 | + AuTraceErr(err); | |
5559 | + if (err == -EOPNOTSUPP) | |
5560 | + err = 0; | |
5561 | + if (!err) | |
5562 | + err = vfsub_acl_chmod(h_inode, mode); | |
5563 | + | |
5564 | + AuTraceErr(err); | |
5565 | + return err; | |
5566 | +} | |
5567 | + | |
5568 | +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent, | |
5569 | + struct inode *h_dir, struct path *h_path) | |
5570 | +{ | |
5571 | + int err; | |
5572 | + struct inode *dir, *inode; | |
5573 | + | |
5574 | + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT); | |
5575 | + AuTraceErr(err); | |
5576 | + if (err == -EOPNOTSUPP) | |
5577 | + err = 0; | |
5578 | + if (unlikely(err)) | |
5579 | + goto out; | |
5580 | + | |
5581 | + /* | |
5582 | + * strange behaviour from the users view, | |
5583 | + * particularry setattr case | |
5584 | + */ | |
5585 | + dir = d_inode(dst_parent); | |
5afbbe0d | 5586 | + if (au_ibtop(dir) == cpg->bdst) |
8cdd5066 JR |
5587 | + au_cpup_attr_nlink(dir, /*force*/1); |
5588 | + inode = d_inode(cpg->dentry); | |
5589 | + au_cpup_attr_nlink(inode, /*force*/1); | |
5590 | + | |
5591 | +out: | |
5592 | + return err; | |
5593 | +} | |
5594 | + | |
1facf9fc | 5595 | +static noinline_for_stack |
c2b27bf2 | 5596 | +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent, |
86dc4139 | 5597 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5598 | +{ |
5599 | + int err; | |
5600 | + umode_t mode; | |
5601 | + unsigned int mnt_flags; | |
076b876e | 5602 | + unsigned char isdir, isreg, force; |
c2b27bf2 | 5603 | + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5604 | + struct au_dtime dt; |
5605 | + struct path h_path; | |
5606 | + struct dentry *h_src, *h_dst, *h_parent; | |
8cdd5066 | 5607 | + struct inode *h_inode, *h_dir; |
1facf9fc | 5608 | + struct super_block *sb; |
5609 | + | |
5610 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5611 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 JR |
5612 | + h_inode = d_inode(h_src); |
5613 | + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc)); | |
1facf9fc | 5614 | + |
5615 | + /* try stopping to be referenced while we are creating */ | |
c2b27bf2 AM |
5616 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); |
5617 | + if (au_ftest_cpup(cpg->flags, RENAME)) | |
86dc4139 AM |
5618 | + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX, |
5619 | + AUFS_WH_PFX_LEN)); | |
1facf9fc | 5620 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5621 | + h_dir = d_inode(h_parent); |
1facf9fc | 5622 | + IMustLock(h_dir); |
5623 | + AuDebugOn(h_parent != h_dst->d_parent); | |
5624 | + | |
c2b27bf2 AM |
5625 | + sb = cpg->dentry->d_sb; |
5626 | + h_path.mnt = au_sbr_mnt(sb, cpg->bdst); | |
1facf9fc | 5627 | + if (do_dt) { |
5628 | + h_path.dentry = h_parent; | |
5629 | + au_dtime_store(&dt, dst_parent, &h_path); | |
5630 | + } | |
5631 | + h_path.dentry = h_dst; | |
5632 | + | |
076b876e | 5633 | + isreg = 0; |
1facf9fc | 5634 | + isdir = 0; |
5635 | + mode = h_inode->i_mode; | |
5636 | + switch (mode & S_IFMT) { | |
5637 | + case S_IFREG: | |
076b876e | 5638 | + isreg = 1; |
8cdd5066 | 5639 | + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR, |
b4510431 | 5640 | + /*want_excl*/true); |
1facf9fc | 5641 | + if (!err) |
c2b27bf2 | 5642 | + err = au_do_cpup_regular(cpg, h_src_attr); |
1facf9fc | 5643 | + break; |
5644 | + case S_IFDIR: | |
5645 | + isdir = 1; | |
5646 | + err = vfsub_mkdir(h_dir, &h_path, mode); | |
8cdd5066 JR |
5647 | + if (!err) |
5648 | + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path); | |
1facf9fc | 5649 | + break; |
5650 | + case S_IFLNK: | |
5651 | + err = au_do_cpup_symlink(&h_path, h_src, h_dir); | |
5652 | + break; | |
5653 | + case S_IFCHR: | |
5654 | + case S_IFBLK: | |
5655 | + AuDebugOn(!capable(CAP_MKNOD)); | |
5656 | + /*FALLTHROUGH*/ | |
5657 | + case S_IFIFO: | |
5658 | + case S_IFSOCK: | |
5659 | + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev); | |
5660 | + break; | |
5661 | + default: | |
5662 | + AuIOErr("Unknown inode type 0%o\n", mode); | |
5663 | + err = -EIO; | |
5664 | + } | |
8cdd5066 JR |
5665 | + if (!err) |
5666 | + err = au_reset_acl(h_dir, &h_path, mode); | |
1facf9fc | 5667 | + |
5668 | + mnt_flags = au_mntflags(sb); | |
5669 | + if (!au_opt_test(mnt_flags, UDBA_NONE) | |
5670 | + && !isdir | |
5671 | + && au_opt_test(mnt_flags, XINO) | |
38d290e6 JR |
5672 | + && (h_inode->i_nlink == 1 |
5673 | + || (h_inode->i_state & I_LINKABLE)) | |
1facf9fc | 5674 | + /* todo: unnecessary? */ |
5527c038 | 5675 | + /* && d_inode(cpg->dentry)->i_nlink == 1 */ |
c2b27bf2 AM |
5676 | + && cpg->bdst < cpg->bsrc |
5677 | + && !au_ftest_cpup(cpg->flags, KEEPLINO)) | |
5678 | + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0); | |
1facf9fc | 5679 | + /* ignore this error */ |
5680 | + | |
076b876e AM |
5681 | + if (!err) { |
5682 | + force = 0; | |
5683 | + if (isreg) { | |
5684 | + force = !!cpg->len; | |
5685 | + if (cpg->len == -1) | |
5686 | + force = !!i_size_read(h_inode); | |
5687 | + } | |
5688 | + au_fhsm_wrote(sb, cpg->bdst, force); | |
5689 | + } | |
5690 | + | |
1facf9fc | 5691 | + if (do_dt) |
5692 | + au_dtime_revert(&dt); | |
5693 | + return err; | |
5694 | +} | |
5695 | + | |
392086de | 5696 | +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path) |
86dc4139 AM |
5697 | +{ |
5698 | + int err; | |
392086de | 5699 | + struct dentry *dentry, *h_dentry, *h_parent, *parent; |
86dc4139 | 5700 | + struct inode *h_dir; |
392086de | 5701 | + aufs_bindex_t bdst; |
86dc4139 | 5702 | + |
392086de AM |
5703 | + dentry = cpg->dentry; |
5704 | + bdst = cpg->bdst; | |
5705 | + h_dentry = au_h_dptr(dentry, bdst); | |
5706 | + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) { | |
5707 | + dget(h_dentry); | |
5708 | + au_set_h_dptr(dentry, bdst, NULL); | |
5709 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); | |
5710 | + if (!err) | |
5711 | + h_path->dentry = dget(au_h_dptr(dentry, bdst)); | |
86dc4139 | 5712 | + au_set_h_dptr(dentry, bdst, h_dentry); |
392086de AM |
5713 | + } else { |
5714 | + err = 0; | |
5715 | + parent = dget_parent(dentry); | |
5716 | + h_parent = au_h_dptr(parent, bdst); | |
5717 | + dput(parent); | |
5718 | + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
5719 | + if (IS_ERR(h_path->dentry)) | |
5720 | + err = PTR_ERR(h_path->dentry); | |
86dc4139 | 5721 | + } |
392086de AM |
5722 | + if (unlikely(err)) |
5723 | + goto out; | |
86dc4139 | 5724 | + |
86dc4139 | 5725 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ |
5527c038 | 5726 | + h_dir = d_inode(h_parent); |
86dc4139 | 5727 | + IMustLock(h_dir); |
523b37e3 AM |
5728 | + AuDbg("%pd %pd\n", h_dentry, h_path->dentry); |
5729 | + /* no delegation since it is just created */ | |
f2c43d5f AM |
5730 | + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL, |
5731 | + /*flags*/0); | |
86dc4139 AM |
5732 | + dput(h_path->dentry); |
5733 | + | |
5734 | +out: | |
5735 | + return err; | |
5736 | +} | |
5737 | + | |
1facf9fc | 5738 | +/* |
5739 | + * copyup the @dentry from @bsrc to @bdst. | |
5740 | + * the caller must set the both of lower dentries. | |
5741 | + * @len is for truncating when it is -1 copyup the entire file. | |
5742 | + * in link/rename cases, @dst_parent may be different from the real one. | |
c2b27bf2 | 5743 | + * basic->bsrc can be larger than basic->bdst. |
f2c43d5f AM |
5744 | + * aufs doesn't touch the credential so |
5745 | + * security_inode_copy_up{,_xattr}() are unnecrssary. | |
1facf9fc | 5746 | + */ |
c2b27bf2 | 5747 | +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5748 | +{ |
5749 | + int err, rerr; | |
5afbbe0d | 5750 | + aufs_bindex_t old_ibtop; |
1facf9fc | 5751 | + unsigned char isdir, plink; |
1facf9fc | 5752 | + struct dentry *h_src, *h_dst, *h_parent; |
5527c038 | 5753 | + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode; |
1facf9fc | 5754 | + struct super_block *sb; |
86dc4139 | 5755 | + struct au_branch *br; |
c2b27bf2 AM |
5756 | + /* to reuduce stack size */ |
5757 | + struct { | |
5758 | + struct au_dtime dt; | |
5759 | + struct path h_path; | |
5760 | + struct au_cpup_reg_attr h_src_attr; | |
5761 | + } *a; | |
1facf9fc | 5762 | + |
c2b27bf2 AM |
5763 | + err = -ENOMEM; |
5764 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
5765 | + if (unlikely(!a)) | |
5766 | + goto out; | |
5767 | + a->h_src_attr.valid = 0; | |
1facf9fc | 5768 | + |
c2b27bf2 AM |
5769 | + sb = cpg->dentry->d_sb; |
5770 | + br = au_sbr(sb, cpg->bdst); | |
5771 | + a->h_path.mnt = au_br_mnt(br); | |
5772 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); | |
1facf9fc | 5773 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5774 | + h_dir = d_inode(h_parent); |
1facf9fc | 5775 | + IMustLock(h_dir); |
5776 | + | |
c2b27bf2 | 5777 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5778 | + inode = d_inode(cpg->dentry); |
1facf9fc | 5779 | + |
5780 | + if (!dst_parent) | |
c2b27bf2 | 5781 | + dst_parent = dget_parent(cpg->dentry); |
1facf9fc | 5782 | + else |
5783 | + dget(dst_parent); | |
5784 | + | |
5785 | + plink = !!au_opt_test(au_mntflags(sb), PLINK); | |
c2b27bf2 | 5786 | + dst_inode = au_h_iptr(inode, cpg->bdst); |
1facf9fc | 5787 | + if (dst_inode) { |
5788 | + if (unlikely(!plink)) { | |
5789 | + err = -EIO; | |
027c5e7a AM |
5790 | + AuIOErr("hi%lu(i%lu) exists on b%d " |
5791 | + "but plink is disabled\n", | |
c2b27bf2 AM |
5792 | + dst_inode->i_ino, inode->i_ino, cpg->bdst); |
5793 | + goto out_parent; | |
1facf9fc | 5794 | + } |
5795 | + | |
5796 | + if (dst_inode->i_nlink) { | |
c2b27bf2 | 5797 | + const int do_dt = au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5798 | + |
c2b27bf2 | 5799 | + h_src = au_plink_lkup(inode, cpg->bdst); |
1facf9fc | 5800 | + err = PTR_ERR(h_src); |
5801 | + if (IS_ERR(h_src)) | |
c2b27bf2 | 5802 | + goto out_parent; |
5527c038 | 5803 | + if (unlikely(d_is_negative(h_src))) { |
1facf9fc | 5804 | + err = -EIO; |
79b8bda9 | 5805 | + AuIOErr("i%lu exists on b%d " |
027c5e7a | 5806 | + "but not pseudo-linked\n", |
79b8bda9 | 5807 | + inode->i_ino, cpg->bdst); |
1facf9fc | 5808 | + dput(h_src); |
c2b27bf2 | 5809 | + goto out_parent; |
1facf9fc | 5810 | + } |
5811 | + | |
5812 | + if (do_dt) { | |
c2b27bf2 AM |
5813 | + a->h_path.dentry = h_parent; |
5814 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
1facf9fc | 5815 | + } |
86dc4139 | 5816 | + |
c2b27bf2 | 5817 | + a->h_path.dentry = h_dst; |
523b37e3 AM |
5818 | + delegated = NULL; |
5819 | + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated); | |
c2b27bf2 | 5820 | + if (!err && au_ftest_cpup(cpg->flags, RENAME)) |
392086de | 5821 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
1facf9fc | 5822 | + if (do_dt) |
c2b27bf2 | 5823 | + au_dtime_revert(&a->dt); |
523b37e3 AM |
5824 | + if (unlikely(err == -EWOULDBLOCK)) { |
5825 | + pr_warn("cannot retry for NFSv4 delegation" | |
5826 | + " for an internal link\n"); | |
5827 | + iput(delegated); | |
5828 | + } | |
1facf9fc | 5829 | + dput(h_src); |
c2b27bf2 | 5830 | + goto out_parent; |
1facf9fc | 5831 | + } else |
5832 | + /* todo: cpup_wh_file? */ | |
5833 | + /* udba work */ | |
4a4d8108 | 5834 | + au_update_ibrange(inode, /*do_put_zero*/1); |
1facf9fc | 5835 | + } |
5836 | + | |
86dc4139 | 5837 | + isdir = S_ISDIR(inode->i_mode); |
5afbbe0d | 5838 | + old_ibtop = au_ibtop(inode); |
c2b27bf2 | 5839 | + err = cpup_entry(cpg, dst_parent, &a->h_src_attr); |
1facf9fc | 5840 | + if (unlikely(err)) |
86dc4139 | 5841 | + goto out_rev; |
5527c038 | 5842 | + dst_inode = d_inode(h_dst); |
febd17d6 | 5843 | + inode_lock_nested(dst_inode, AuLsc_I_CHILD2); |
86dc4139 | 5844 | + /* todo: necessary? */ |
c2b27bf2 | 5845 | + /* au_pin_hdir_unlock(cpg->pin); */ |
1facf9fc | 5846 | + |
c2b27bf2 | 5847 | + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr); |
86dc4139 AM |
5848 | + if (unlikely(err)) { |
5849 | + /* todo: necessary? */ | |
c2b27bf2 | 5850 | + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */ |
febd17d6 | 5851 | + inode_unlock(dst_inode); |
86dc4139 AM |
5852 | + goto out_rev; |
5853 | + } | |
5854 | + | |
5afbbe0d | 5855 | + if (cpg->bdst < old_ibtop) { |
86dc4139 | 5856 | + if (S_ISREG(inode->i_mode)) { |
c2b27bf2 | 5857 | + err = au_dy_iaop(inode, cpg->bdst, dst_inode); |
86dc4139 | 5858 | + if (unlikely(err)) { |
c2b27bf2 AM |
5859 | + /* ignore an error */ |
5860 | + /* au_pin_hdir_relock(cpg->pin); */ | |
febd17d6 | 5861 | + inode_unlock(dst_inode); |
86dc4139 | 5862 | + goto out_rev; |
4a4d8108 | 5863 | + } |
4a4d8108 | 5864 | + } |
5afbbe0d | 5865 | + au_set_ibtop(inode, cpg->bdst); |
c2b27bf2 | 5866 | + } else |
5afbbe0d | 5867 | + au_set_ibbot(inode, cpg->bdst); |
c2b27bf2 | 5868 | + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode), |
86dc4139 AM |
5869 | + au_hi_flags(inode, isdir)); |
5870 | + | |
5871 | + /* todo: necessary? */ | |
c2b27bf2 | 5872 | + /* err = au_pin_hdir_relock(cpg->pin); */ |
febd17d6 | 5873 | + inode_unlock(dst_inode); |
86dc4139 AM |
5874 | + if (unlikely(err)) |
5875 | + goto out_rev; | |
5876 | + | |
5527c038 | 5877 | + src_inode = d_inode(h_src); |
86dc4139 | 5878 | + if (!isdir |
5527c038 JR |
5879 | + && (src_inode->i_nlink > 1 |
5880 | + || src_inode->i_state & I_LINKABLE) | |
86dc4139 | 5881 | + && plink) |
c2b27bf2 | 5882 | + au_plink_append(inode, cpg->bdst, h_dst); |
86dc4139 | 5883 | + |
c2b27bf2 AM |
5884 | + if (au_ftest_cpup(cpg->flags, RENAME)) { |
5885 | + a->h_path.dentry = h_dst; | |
392086de | 5886 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
86dc4139 AM |
5887 | + } |
5888 | + if (!err) | |
c2b27bf2 | 5889 | + goto out_parent; /* success */ |
1facf9fc | 5890 | + |
5891 | + /* revert */ | |
4a4d8108 | 5892 | +out_rev: |
c2b27bf2 AM |
5893 | + a->h_path.dentry = h_parent; |
5894 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
5895 | + a->h_path.dentry = h_dst; | |
86dc4139 | 5896 | + rerr = 0; |
5527c038 | 5897 | + if (d_is_positive(h_dst)) { |
523b37e3 AM |
5898 | + if (!isdir) { |
5899 | + /* no delegation since it is just created */ | |
5900 | + rerr = vfsub_unlink(h_dir, &a->h_path, | |
5901 | + /*delegated*/NULL, /*force*/0); | |
5902 | + } else | |
c2b27bf2 | 5903 | + rerr = vfsub_rmdir(h_dir, &a->h_path); |
86dc4139 | 5904 | + } |
c2b27bf2 | 5905 | + au_dtime_revert(&a->dt); |
1facf9fc | 5906 | + if (rerr) { |
5907 | + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr); | |
5908 | + err = -EIO; | |
5909 | + } | |
c2b27bf2 | 5910 | +out_parent: |
1facf9fc | 5911 | + dput(dst_parent); |
1c60b727 | 5912 | + kfree(a); |
c2b27bf2 | 5913 | +out: |
1facf9fc | 5914 | + return err; |
5915 | +} | |
5916 | + | |
7e9cd9fe | 5917 | +#if 0 /* reserved */ |
1facf9fc | 5918 | +struct au_cpup_single_args { |
5919 | + int *errp; | |
c2b27bf2 | 5920 | + struct au_cp_generic *cpg; |
1facf9fc | 5921 | + struct dentry *dst_parent; |
5922 | +}; | |
5923 | + | |
5924 | +static void au_call_cpup_single(void *args) | |
5925 | +{ | |
5926 | + struct au_cpup_single_args *a = args; | |
86dc4139 | 5927 | + |
c2b27bf2 AM |
5928 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5929 | + *a->errp = au_cpup_single(a->cpg, a->dst_parent); | |
5930 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5931 | +} |
c2b27bf2 | 5932 | +#endif |
1facf9fc | 5933 | + |
53392da6 AM |
5934 | +/* |
5935 | + * prevent SIGXFSZ in copy-up. | |
5936 | + * testing CAP_MKNOD is for generic fs, | |
5937 | + * but CAP_FSETID is for xfs only, currently. | |
5938 | + */ | |
86dc4139 | 5939 | +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode) |
53392da6 AM |
5940 | +{ |
5941 | + int do_sio; | |
86dc4139 AM |
5942 | + struct super_block *sb; |
5943 | + struct inode *h_dir; | |
53392da6 AM |
5944 | + |
5945 | + do_sio = 0; | |
86dc4139 | 5946 | + sb = au_pinned_parent(pin)->d_sb; |
53392da6 AM |
5947 | + if (!au_wkq_test() |
5948 | + && (!au_sbi(sb)->si_plink_maint_pid | |
5949 | + || au_plink_maint(sb, AuLock_NOPLM))) { | |
5950 | + switch (mode & S_IFMT) { | |
5951 | + case S_IFREG: | |
5952 | + /* no condition about RLIMIT_FSIZE and the file size */ | |
5953 | + do_sio = 1; | |
5954 | + break; | |
5955 | + case S_IFCHR: | |
5956 | + case S_IFBLK: | |
5957 | + do_sio = !capable(CAP_MKNOD); | |
5958 | + break; | |
5959 | + } | |
5960 | + if (!do_sio) | |
5961 | + do_sio = ((mode & (S_ISUID | S_ISGID)) | |
5962 | + && !capable(CAP_FSETID)); | |
86dc4139 AM |
5963 | + /* this workaround may be removed in the future */ |
5964 | + if (!do_sio) { | |
5965 | + h_dir = au_pinned_h_dir(pin); | |
5966 | + do_sio = h_dir->i_mode & S_ISVTX; | |
5967 | + } | |
53392da6 AM |
5968 | + } |
5969 | + | |
5970 | + return do_sio; | |
5971 | +} | |
5972 | + | |
7e9cd9fe | 5973 | +#if 0 /* reserved */ |
c2b27bf2 | 5974 | +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5975 | +{ |
5976 | + int err, wkq_err; | |
1facf9fc | 5977 | + struct dentry *h_dentry; |
5978 | + | |
c2b27bf2 | 5979 | + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5980 | + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode)) |
c2b27bf2 | 5981 | + err = au_cpup_single(cpg, dst_parent); |
1facf9fc | 5982 | + else { |
5983 | + struct au_cpup_single_args args = { | |
5984 | + .errp = &err, | |
c2b27bf2 AM |
5985 | + .cpg = cpg, |
5986 | + .dst_parent = dst_parent | |
1facf9fc | 5987 | + }; |
5988 | + wkq_err = au_wkq_wait(au_call_cpup_single, &args); | |
5989 | + if (unlikely(wkq_err)) | |
5990 | + err = wkq_err; | |
5991 | + } | |
5992 | + | |
5993 | + return err; | |
5994 | +} | |
c2b27bf2 | 5995 | +#endif |
1facf9fc | 5996 | + |
5997 | +/* | |
5998 | + * copyup the @dentry from the first active lower branch to @bdst, | |
5999 | + * using au_cpup_single(). | |
6000 | + */ | |
c2b27bf2 | 6001 | +static int au_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 6002 | +{ |
6003 | + int err; | |
c2b27bf2 AM |
6004 | + unsigned int flags_orig; |
6005 | + struct dentry *dentry; | |
6006 | + | |
6007 | + AuDebugOn(cpg->bsrc < 0); | |
1facf9fc | 6008 | + |
c2b27bf2 | 6009 | + dentry = cpg->dentry; |
86dc4139 | 6010 | + DiMustWriteLock(dentry); |
1facf9fc | 6011 | + |
c2b27bf2 | 6012 | + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1); |
1facf9fc | 6013 | + if (!err) { |
c2b27bf2 AM |
6014 | + flags_orig = cpg->flags; |
6015 | + au_fset_cpup(cpg->flags, RENAME); | |
6016 | + err = au_cpup_single(cpg, NULL); | |
6017 | + cpg->flags = flags_orig; | |
1facf9fc | 6018 | + if (!err) |
6019 | + return 0; /* success */ | |
6020 | + | |
6021 | + /* revert */ | |
c2b27bf2 | 6022 | + au_set_h_dptr(dentry, cpg->bdst, NULL); |
5afbbe0d | 6023 | + au_set_dbtop(dentry, cpg->bsrc); |
1facf9fc | 6024 | + } |
6025 | + | |
6026 | + return err; | |
6027 | +} | |
6028 | + | |
6029 | +struct au_cpup_simple_args { | |
6030 | + int *errp; | |
c2b27bf2 | 6031 | + struct au_cp_generic *cpg; |
1facf9fc | 6032 | +}; |
6033 | + | |
6034 | +static void au_call_cpup_simple(void *args) | |
6035 | +{ | |
6036 | + struct au_cpup_simple_args *a = args; | |
86dc4139 | 6037 | + |
c2b27bf2 AM |
6038 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
6039 | + *a->errp = au_cpup_simple(a->cpg); | |
6040 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 6041 | +} |
6042 | + | |
c2b27bf2 | 6043 | +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 6044 | +{ |
6045 | + int err, wkq_err; | |
c2b27bf2 AM |
6046 | + struct dentry *dentry, *parent; |
6047 | + struct file *h_file; | |
1facf9fc | 6048 | + struct inode *h_dir; |
6049 | + | |
c2b27bf2 AM |
6050 | + dentry = cpg->dentry; |
6051 | + h_file = NULL; | |
6052 | + if (au_ftest_cpup(cpg->flags, HOPEN)) { | |
6053 | + AuDebugOn(cpg->bsrc < 0); | |
392086de | 6054 | + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0); |
c2b27bf2 AM |
6055 | + err = PTR_ERR(h_file); |
6056 | + if (IS_ERR(h_file)) | |
6057 | + goto out; | |
6058 | + } | |
6059 | + | |
1facf9fc | 6060 | + parent = dget_parent(dentry); |
5527c038 | 6061 | + h_dir = au_h_iptr(d_inode(parent), cpg->bdst); |
53392da6 | 6062 | + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE) |
5527c038 | 6063 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 6064 | + err = au_cpup_simple(cpg); |
1facf9fc | 6065 | + else { |
6066 | + struct au_cpup_simple_args args = { | |
6067 | + .errp = &err, | |
c2b27bf2 | 6068 | + .cpg = cpg |
1facf9fc | 6069 | + }; |
6070 | + wkq_err = au_wkq_wait(au_call_cpup_simple, &args); | |
6071 | + if (unlikely(wkq_err)) | |
6072 | + err = wkq_err; | |
6073 | + } | |
6074 | + | |
6075 | + dput(parent); | |
c2b27bf2 AM |
6076 | + if (h_file) |
6077 | + au_h_open_post(dentry, cpg->bsrc, h_file); | |
6078 | + | |
6079 | +out: | |
1facf9fc | 6080 | + return err; |
6081 | +} | |
6082 | + | |
c2b27bf2 | 6083 | +int au_sio_cpup_simple(struct au_cp_generic *cpg) |
367653fa | 6084 | +{ |
5afbbe0d | 6085 | + aufs_bindex_t bsrc, bbot; |
c2b27bf2 | 6086 | + struct dentry *dentry, *h_dentry; |
367653fa | 6087 | + |
c2b27bf2 AM |
6088 | + if (cpg->bsrc < 0) { |
6089 | + dentry = cpg->dentry; | |
5afbbe0d AM |
6090 | + bbot = au_dbbot(dentry); |
6091 | + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) { | |
c2b27bf2 AM |
6092 | + h_dentry = au_h_dptr(dentry, bsrc); |
6093 | + if (h_dentry) { | |
5527c038 | 6094 | + AuDebugOn(d_is_negative(h_dentry)); |
c2b27bf2 AM |
6095 | + break; |
6096 | + } | |
6097 | + } | |
5afbbe0d | 6098 | + AuDebugOn(bsrc > bbot); |
c2b27bf2 | 6099 | + cpg->bsrc = bsrc; |
367653fa | 6100 | + } |
c2b27bf2 AM |
6101 | + AuDebugOn(cpg->bsrc <= cpg->bdst); |
6102 | + return au_do_sio_cpup_simple(cpg); | |
6103 | +} | |
367653fa | 6104 | + |
c2b27bf2 AM |
6105 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg) |
6106 | +{ | |
6107 | + AuDebugOn(cpg->bdst <= cpg->bsrc); | |
6108 | + return au_do_sio_cpup_simple(cpg); | |
367653fa AM |
6109 | +} |
6110 | + | |
1facf9fc | 6111 | +/* ---------------------------------------------------------------------- */ |
6112 | + | |
6113 | +/* | |
6114 | + * copyup the deleted file for writing. | |
6115 | + */ | |
c2b27bf2 AM |
6116 | +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry, |
6117 | + struct file *file) | |
1facf9fc | 6118 | +{ |
6119 | + int err; | |
c2b27bf2 AM |
6120 | + unsigned int flags_orig; |
6121 | + aufs_bindex_t bsrc_orig; | |
c2b27bf2 | 6122 | + struct au_dinfo *dinfo; |
5afbbe0d AM |
6123 | + struct { |
6124 | + struct au_hdentry *hd; | |
6125 | + struct dentry *h_dentry; | |
6126 | + } hdst, hsrc; | |
1facf9fc | 6127 | + |
c2b27bf2 | 6128 | + dinfo = au_di(cpg->dentry); |
1308ab2a | 6129 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
6130 | + | |
c2b27bf2 | 6131 | + bsrc_orig = cpg->bsrc; |
5afbbe0d AM |
6132 | + cpg->bsrc = dinfo->di_btop; |
6133 | + hdst.hd = au_hdentry(dinfo, cpg->bdst); | |
6134 | + hdst.h_dentry = hdst.hd->hd_dentry; | |
6135 | + hdst.hd->hd_dentry = wh_dentry; | |
6136 | + dinfo->di_btop = cpg->bdst; | |
6137 | + | |
6138 | + hsrc.h_dentry = NULL; | |
027c5e7a | 6139 | + if (file) { |
5afbbe0d AM |
6140 | + hsrc.hd = au_hdentry(dinfo, cpg->bsrc); |
6141 | + hsrc.h_dentry = hsrc.hd->hd_dentry; | |
6142 | + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry; | |
027c5e7a | 6143 | + } |
c2b27bf2 AM |
6144 | + flags_orig = cpg->flags; |
6145 | + cpg->flags = !AuCpup_DTIME; | |
6146 | + err = au_cpup_single(cpg, /*h_parent*/NULL); | |
6147 | + cpg->flags = flags_orig; | |
027c5e7a AM |
6148 | + if (file) { |
6149 | + if (!err) | |
6150 | + err = au_reopen_nondir(file); | |
5afbbe0d | 6151 | + hsrc.hd->hd_dentry = hsrc.h_dentry; |
1facf9fc | 6152 | + } |
5afbbe0d AM |
6153 | + hdst.hd->hd_dentry = hdst.h_dentry; |
6154 | + dinfo->di_btop = cpg->bsrc; | |
c2b27bf2 | 6155 | + cpg->bsrc = bsrc_orig; |
1facf9fc | 6156 | + |
6157 | + return err; | |
6158 | +} | |
6159 | + | |
c2b27bf2 | 6160 | +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 6161 | +{ |
6162 | + int err; | |
c2b27bf2 | 6163 | + aufs_bindex_t bdst; |
1facf9fc | 6164 | + struct au_dtime dt; |
c2b27bf2 | 6165 | + struct dentry *dentry, *parent, *h_parent, *wh_dentry; |
1facf9fc | 6166 | + struct au_branch *br; |
6167 | + struct path h_path; | |
6168 | + | |
c2b27bf2 AM |
6169 | + dentry = cpg->dentry; |
6170 | + bdst = cpg->bdst; | |
1facf9fc | 6171 | + br = au_sbr(dentry->d_sb, bdst); |
6172 | + parent = dget_parent(dentry); | |
6173 | + h_parent = au_h_dptr(parent, bdst); | |
6174 | + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
6175 | + err = PTR_ERR(wh_dentry); | |
6176 | + if (IS_ERR(wh_dentry)) | |
6177 | + goto out; | |
6178 | + | |
6179 | + h_path.dentry = h_parent; | |
86dc4139 | 6180 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 6181 | + au_dtime_store(&dt, parent, &h_path); |
c2b27bf2 | 6182 | + err = au_do_cpup_wh(cpg, wh_dentry, file); |
1facf9fc | 6183 | + if (unlikely(err)) |
6184 | + goto out_wh; | |
6185 | + | |
6186 | + dget(wh_dentry); | |
6187 | + h_path.dentry = wh_dentry; | |
2000de60 | 6188 | + if (!d_is_dir(wh_dentry)) { |
523b37e3 | 6189 | + /* no delegation since it is just created */ |
5527c038 | 6190 | + err = vfsub_unlink(d_inode(h_parent), &h_path, |
523b37e3 AM |
6191 | + /*delegated*/NULL, /*force*/0); |
6192 | + } else | |
5527c038 | 6193 | + err = vfsub_rmdir(d_inode(h_parent), &h_path); |
1facf9fc | 6194 | + if (unlikely(err)) { |
523b37e3 AM |
6195 | + AuIOErr("failed remove copied-up tmp file %pd(%d)\n", |
6196 | + wh_dentry, err); | |
1facf9fc | 6197 | + err = -EIO; |
6198 | + } | |
6199 | + au_dtime_revert(&dt); | |
5527c038 | 6200 | + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry); |
1facf9fc | 6201 | + |
4f0767ce | 6202 | +out_wh: |
1facf9fc | 6203 | + dput(wh_dentry); |
4f0767ce | 6204 | +out: |
1facf9fc | 6205 | + dput(parent); |
6206 | + return err; | |
6207 | +} | |
6208 | + | |
6209 | +struct au_cpup_wh_args { | |
6210 | + int *errp; | |
c2b27bf2 | 6211 | + struct au_cp_generic *cpg; |
1facf9fc | 6212 | + struct file *file; |
6213 | +}; | |
6214 | + | |
6215 | +static void au_call_cpup_wh(void *args) | |
6216 | +{ | |
6217 | + struct au_cpup_wh_args *a = args; | |
86dc4139 | 6218 | + |
c2b27bf2 AM |
6219 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
6220 | + *a->errp = au_cpup_wh(a->cpg, a->file); | |
6221 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 6222 | +} |
6223 | + | |
c2b27bf2 | 6224 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 6225 | +{ |
6226 | + int err, wkq_err; | |
c2b27bf2 | 6227 | + aufs_bindex_t bdst; |
c1595e42 | 6228 | + struct dentry *dentry, *parent, *h_orph, *h_parent; |
86dc4139 | 6229 | + struct inode *dir, *h_dir, *h_tmpdir; |
1facf9fc | 6230 | + struct au_wbr *wbr; |
c2b27bf2 | 6231 | + struct au_pin wh_pin, *pin_orig; |
1facf9fc | 6232 | + |
c2b27bf2 AM |
6233 | + dentry = cpg->dentry; |
6234 | + bdst = cpg->bdst; | |
1facf9fc | 6235 | + parent = dget_parent(dentry); |
5527c038 | 6236 | + dir = d_inode(parent); |
1facf9fc | 6237 | + h_orph = NULL; |
6238 | + h_parent = NULL; | |
6239 | + h_dir = au_igrab(au_h_iptr(dir, bdst)); | |
6240 | + h_tmpdir = h_dir; | |
c2b27bf2 | 6241 | + pin_orig = NULL; |
1facf9fc | 6242 | + if (!h_dir->i_nlink) { |
6243 | + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr; | |
6244 | + h_orph = wbr->wbr_orph; | |
6245 | + | |
6246 | + h_parent = dget(au_h_dptr(parent, bdst)); | |
1facf9fc | 6247 | + au_set_h_dptr(parent, bdst, dget(h_orph)); |
5527c038 | 6248 | + h_tmpdir = d_inode(h_orph); |
1facf9fc | 6249 | + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0); |
6250 | + | |
febd17d6 | 6251 | + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3); |
4a4d8108 | 6252 | + /* todo: au_h_open_pre()? */ |
86dc4139 | 6253 | + |
c2b27bf2 | 6254 | + pin_orig = cpg->pin; |
86dc4139 | 6255 | + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT, |
c2b27bf2 AM |
6256 | + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED); |
6257 | + cpg->pin = &wh_pin; | |
1facf9fc | 6258 | + } |
6259 | + | |
53392da6 | 6260 | + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE) |
5527c038 | 6261 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 6262 | + err = au_cpup_wh(cpg, file); |
1facf9fc | 6263 | + else { |
6264 | + struct au_cpup_wh_args args = { | |
6265 | + .errp = &err, | |
c2b27bf2 AM |
6266 | + .cpg = cpg, |
6267 | + .file = file | |
1facf9fc | 6268 | + }; |
6269 | + wkq_err = au_wkq_wait(au_call_cpup_wh, &args); | |
6270 | + if (unlikely(wkq_err)) | |
6271 | + err = wkq_err; | |
6272 | + } | |
6273 | + | |
6274 | + if (h_orph) { | |
febd17d6 | 6275 | + inode_unlock(h_tmpdir); |
4a4d8108 | 6276 | + /* todo: au_h_open_post()? */ |
1facf9fc | 6277 | + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0); |
1facf9fc | 6278 | + au_set_h_dptr(parent, bdst, h_parent); |
c2b27bf2 AM |
6279 | + AuDebugOn(!pin_orig); |
6280 | + cpg->pin = pin_orig; | |
1facf9fc | 6281 | + } |
6282 | + iput(h_dir); | |
6283 | + dput(parent); | |
6284 | + | |
6285 | + return err; | |
6286 | +} | |
6287 | + | |
6288 | +/* ---------------------------------------------------------------------- */ | |
6289 | + | |
6290 | +/* | |
6291 | + * generic routine for both of copy-up and copy-down. | |
6292 | + */ | |
6293 | +/* cf. revalidate function in file.c */ | |
6294 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
6295 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6296 | + struct au_pin *pin, |
1facf9fc | 6297 | + struct dentry *h_parent, void *arg), |
6298 | + void *arg) | |
6299 | +{ | |
6300 | + int err; | |
6301 | + struct au_pin pin; | |
5527c038 | 6302 | + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry; |
1facf9fc | 6303 | + |
6304 | + err = 0; | |
6305 | + parent = dget_parent(dentry); | |
6306 | + if (IS_ROOT(parent)) | |
6307 | + goto out; | |
6308 | + | |
6309 | + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2, | |
6310 | + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE); | |
6311 | + | |
6312 | + /* do not use au_dpage */ | |
6313 | + real_parent = parent; | |
6314 | + while (1) { | |
6315 | + dput(parent); | |
6316 | + parent = dget_parent(dentry); | |
6317 | + h_parent = au_h_dptr(parent, bdst); | |
6318 | + if (h_parent) | |
6319 | + goto out; /* success */ | |
6320 | + | |
6321 | + /* find top dir which is necessary to cpup */ | |
6322 | + do { | |
6323 | + d = parent; | |
6324 | + dput(parent); | |
6325 | + parent = dget_parent(d); | |
6326 | + di_read_lock_parent3(parent, !AuLock_IR); | |
6327 | + h_parent = au_h_dptr(parent, bdst); | |
6328 | + di_read_unlock(parent, !AuLock_IR); | |
6329 | + } while (!h_parent); | |
6330 | + | |
6331 | + if (d != real_parent) | |
6332 | + di_write_lock_child3(d); | |
6333 | + | |
6334 | + /* somebody else might create while we were sleeping */ | |
5527c038 JR |
6335 | + h_dentry = au_h_dptr(d, bdst); |
6336 | + if (!h_dentry || d_is_negative(h_dentry)) { | |
6337 | + if (h_dentry) | |
5afbbe0d | 6338 | + au_update_dbtop(d); |
1facf9fc | 6339 | + |
6340 | + au_pin_set_dentry(&pin, d); | |
6341 | + err = au_do_pin(&pin); | |
6342 | + if (!err) { | |
86dc4139 | 6343 | + err = cp(d, bdst, &pin, h_parent, arg); |
1facf9fc | 6344 | + au_unpin(&pin); |
6345 | + } | |
6346 | + } | |
6347 | + | |
6348 | + if (d != real_parent) | |
6349 | + di_write_unlock(d); | |
6350 | + if (unlikely(err)) | |
6351 | + break; | |
6352 | + } | |
6353 | + | |
4f0767ce | 6354 | +out: |
1facf9fc | 6355 | + dput(parent); |
6356 | + return err; | |
6357 | +} | |
6358 | + | |
6359 | +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6360 | + struct au_pin *pin, |
2000de60 | 6361 | + struct dentry *h_parent __maybe_unused, |
1facf9fc | 6362 | + void *arg __maybe_unused) |
6363 | +{ | |
c2b27bf2 AM |
6364 | + struct au_cp_generic cpg = { |
6365 | + .dentry = dentry, | |
6366 | + .bdst = bdst, | |
6367 | + .bsrc = -1, | |
6368 | + .len = 0, | |
6369 | + .pin = pin, | |
6370 | + .flags = AuCpup_DTIME | |
6371 | + }; | |
6372 | + return au_sio_cpup_simple(&cpg); | |
1facf9fc | 6373 | +} |
6374 | + | |
6375 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
6376 | +{ | |
6377 | + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL); | |
6378 | +} | |
6379 | + | |
6380 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
6381 | +{ | |
6382 | + int err; | |
6383 | + struct dentry *parent; | |
6384 | + struct inode *dir; | |
6385 | + | |
6386 | + parent = dget_parent(dentry); | |
5527c038 | 6387 | + dir = d_inode(parent); |
1facf9fc | 6388 | + err = 0; |
6389 | + if (au_h_iptr(dir, bdst)) | |
6390 | + goto out; | |
6391 | + | |
6392 | + di_read_unlock(parent, AuLock_IR); | |
6393 | + di_write_lock_parent(parent); | |
6394 | + /* someone else might change our inode while we were sleeping */ | |
6395 | + if (!au_h_iptr(dir, bdst)) | |
6396 | + err = au_cpup_dirs(dentry, bdst); | |
6397 | + di_downgrade_lock(parent, AuLock_IR); | |
6398 | + | |
4f0767ce | 6399 | +out: |
1facf9fc | 6400 | + dput(parent); |
6401 | + return err; | |
6402 | +} | |
7f207e10 AM |
6403 | diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h |
6404 | --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 6405 | +++ linux/fs/aufs/cpup.h 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 | 6406 | @@ -0,0 +1,99 @@ |
1facf9fc | 6407 | +/* |
a2654f78 | 6408 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6409 | + * |
6410 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6411 | + * it under the terms of the GNU General Public License as published by | |
6412 | + * the Free Software Foundation; either version 2 of the License, or | |
6413 | + * (at your option) any later version. | |
dece6358 AM |
6414 | + * |
6415 | + * This program is distributed in the hope that it will be useful, | |
6416 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6417 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6418 | + * GNU General Public License for more details. | |
6419 | + * | |
6420 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6421 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6422 | + */ |
6423 | + | |
6424 | +/* | |
6425 | + * copy-up/down functions | |
6426 | + */ | |
6427 | + | |
6428 | +#ifndef __AUFS_CPUP_H__ | |
6429 | +#define __AUFS_CPUP_H__ | |
6430 | + | |
6431 | +#ifdef __KERNEL__ | |
6432 | + | |
dece6358 | 6433 | +#include <linux/path.h> |
1facf9fc | 6434 | + |
dece6358 AM |
6435 | +struct inode; |
6436 | +struct file; | |
86dc4139 | 6437 | +struct au_pin; |
dece6358 | 6438 | + |
86dc4139 | 6439 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags); |
1facf9fc | 6440 | +void au_cpup_attr_timesizes(struct inode *inode); |
6441 | +void au_cpup_attr_nlink(struct inode *inode, int force); | |
6442 | +void au_cpup_attr_changeable(struct inode *inode); | |
6443 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode); | |
6444 | +void au_cpup_attr_all(struct inode *inode, int force); | |
6445 | + | |
6446 | +/* ---------------------------------------------------------------------- */ | |
6447 | + | |
c2b27bf2 AM |
6448 | +struct au_cp_generic { |
6449 | + struct dentry *dentry; | |
6450 | + aufs_bindex_t bdst, bsrc; | |
6451 | + loff_t len; | |
6452 | + struct au_pin *pin; | |
6453 | + unsigned int flags; | |
6454 | +}; | |
6455 | + | |
1facf9fc | 6456 | +/* cpup flags */ |
392086de AM |
6457 | +#define AuCpup_DTIME 1 /* do dtime_store/revert */ |
6458 | +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino, | |
6459 | + for link(2) */ | |
6460 | +#define AuCpup_RENAME (1 << 2) /* rename after cpup */ | |
6461 | +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in | |
6462 | + cpup */ | |
6463 | +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the | |
6464 | + existing entry */ | |
6465 | +#define AuCpup_RWDST (1 << 5) /* force write target even if | |
6466 | + the branch is marked as RO */ | |
c2b27bf2 | 6467 | + |
8b6a4947 AM |
6468 | +#ifndef CONFIG_AUFS_BR_HFSPLUS |
6469 | +#undef AuCpup_HOPEN | |
6470 | +#define AuCpup_HOPEN 0 | |
6471 | +#endif | |
6472 | + | |
1facf9fc | 6473 | +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name) |
7f207e10 AM |
6474 | +#define au_fset_cpup(flags, name) \ |
6475 | + do { (flags) |= AuCpup_##name; } while (0) | |
6476 | +#define au_fclr_cpup(flags, name) \ | |
6477 | + do { (flags) &= ~AuCpup_##name; } while (0) | |
1facf9fc | 6478 | + |
6479 | +int au_copy_file(struct file *dst, struct file *src, loff_t len); | |
c2b27bf2 AM |
6480 | +int au_sio_cpup_simple(struct au_cp_generic *cpg); |
6481 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg); | |
6482 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file); | |
1facf9fc | 6483 | + |
6484 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
6485 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6486 | + struct au_pin *pin, |
1facf9fc | 6487 | + struct dentry *h_parent, void *arg), |
6488 | + void *arg); | |
6489 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
6490 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
6491 | + | |
6492 | +/* ---------------------------------------------------------------------- */ | |
6493 | + | |
6494 | +/* keep timestamps when copyup */ | |
6495 | +struct au_dtime { | |
6496 | + struct dentry *dt_dentry; | |
6497 | + struct path dt_h_path; | |
6498 | + struct timespec dt_atime, dt_mtime; | |
6499 | +}; | |
6500 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
6501 | + struct path *h_path); | |
6502 | +void au_dtime_revert(struct au_dtime *dt); | |
6503 | + | |
6504 | +#endif /* __KERNEL__ */ | |
6505 | +#endif /* __AUFS_CPUP_H__ */ | |
7f207e10 AM |
6506 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c |
6507 | --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 6508 | +++ linux/fs/aufs/dbgaufs.c 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 | 6509 | @@ -0,0 +1,437 @@ |
1facf9fc | 6510 | +/* |
a2654f78 | 6511 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6512 | + * |
6513 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6514 | + * it under the terms of the GNU General Public License as published by | |
6515 | + * the Free Software Foundation; either version 2 of the License, or | |
6516 | + * (at your option) any later version. | |
dece6358 AM |
6517 | + * |
6518 | + * This program is distributed in the hope that it will be useful, | |
6519 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6520 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6521 | + * GNU General Public License for more details. | |
6522 | + * | |
6523 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6524 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6525 | + */ |
6526 | + | |
6527 | +/* | |
6528 | + * debugfs interface | |
6529 | + */ | |
6530 | + | |
6531 | +#include <linux/debugfs.h> | |
6532 | +#include "aufs.h" | |
6533 | + | |
6534 | +#ifndef CONFIG_SYSFS | |
6535 | +#error DEBUG_FS depends upon SYSFS | |
6536 | +#endif | |
6537 | + | |
6538 | +static struct dentry *dbgaufs; | |
6539 | +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH; | |
6540 | + | |
6541 | +/* 20 is max digits length of ulong 64 */ | |
6542 | +struct dbgaufs_arg { | |
6543 | + int n; | |
6544 | + char a[20 * 4]; | |
6545 | +}; | |
6546 | + | |
6547 | +/* | |
6548 | + * common function for all XINO files | |
6549 | + */ | |
6550 | +static int dbgaufs_xi_release(struct inode *inode __maybe_unused, | |
6551 | + struct file *file) | |
6552 | +{ | |
1c60b727 | 6553 | + kfree(file->private_data); |
1facf9fc | 6554 | + return 0; |
6555 | +} | |
6556 | + | |
6557 | +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt) | |
6558 | +{ | |
6559 | + int err; | |
6560 | + struct kstat st; | |
6561 | + struct dbgaufs_arg *p; | |
6562 | + | |
6563 | + err = -ENOMEM; | |
6564 | + p = kmalloc(sizeof(*p), GFP_NOFS); | |
6565 | + if (unlikely(!p)) | |
6566 | + goto out; | |
6567 | + | |
6568 | + err = 0; | |
6569 | + p->n = 0; | |
6570 | + file->private_data = p; | |
6571 | + if (!xf) | |
6572 | + goto out; | |
6573 | + | |
521ced18 | 6574 | + err = vfsub_getattr(&xf->f_path, &st); |
1facf9fc | 6575 | + if (!err) { |
6576 | + if (do_fcnt) | |
6577 | + p->n = snprintf | |
521ced18 | 6578 | + (p->a, sizeof(p->a), "%ld, %llux%u %lld\n", |
1facf9fc | 6579 | + (long)file_count(xf), st.blocks, st.blksize, |
6580 | + (long long)st.size); | |
6581 | + else | |
521ced18 | 6582 | + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n", |
1facf9fc | 6583 | + st.blocks, st.blksize, |
6584 | + (long long)st.size); | |
6585 | + AuDebugOn(p->n >= sizeof(p->a)); | |
6586 | + } else { | |
6587 | + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err); | |
6588 | + err = 0; | |
6589 | + } | |
6590 | + | |
4f0767ce | 6591 | +out: |
1facf9fc | 6592 | + return err; |
6593 | + | |
6594 | +} | |
6595 | + | |
6596 | +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf, | |
6597 | + size_t count, loff_t *ppos) | |
6598 | +{ | |
6599 | + struct dbgaufs_arg *p; | |
6600 | + | |
6601 | + p = file->private_data; | |
6602 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6603 | +} | |
6604 | + | |
6605 | +/* ---------------------------------------------------------------------- */ | |
6606 | + | |
86dc4139 AM |
6607 | +struct dbgaufs_plink_arg { |
6608 | + int n; | |
6609 | + char a[]; | |
6610 | +}; | |
6611 | + | |
6612 | +static int dbgaufs_plink_release(struct inode *inode __maybe_unused, | |
6613 | + struct file *file) | |
6614 | +{ | |
1c60b727 | 6615 | + free_page((unsigned long)file->private_data); |
86dc4139 AM |
6616 | + return 0; |
6617 | +} | |
6618 | + | |
6619 | +static int dbgaufs_plink_open(struct inode *inode, struct file *file) | |
6620 | +{ | |
6621 | + int err, i, limit; | |
6622 | + unsigned long n, sum; | |
6623 | + struct dbgaufs_plink_arg *p; | |
6624 | + struct au_sbinfo *sbinfo; | |
6625 | + struct super_block *sb; | |
8b6a4947 | 6626 | + struct hlist_bl_head *hbl; |
86dc4139 AM |
6627 | + |
6628 | + err = -ENOMEM; | |
6629 | + p = (void *)get_zeroed_page(GFP_NOFS); | |
6630 | + if (unlikely(!p)) | |
6631 | + goto out; | |
6632 | + | |
6633 | + err = -EFBIG; | |
6634 | + sbinfo = inode->i_private; | |
6635 | + sb = sbinfo->si_sb; | |
6636 | + si_noflush_read_lock(sb); | |
6637 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
6638 | + limit = PAGE_SIZE - sizeof(p->n); | |
6639 | + | |
6640 | + /* the number of buckets */ | |
6641 | + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH); | |
6642 | + p->n += n; | |
6643 | + limit -= n; | |
6644 | + | |
6645 | + sum = 0; | |
8b6a4947 AM |
6646 | + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH; |
6647 | + i++, hbl++) { | |
6648 | + n = au_hbl_count(hbl); | |
86dc4139 AM |
6649 | + sum += n; |
6650 | + | |
6651 | + n = snprintf(p->a + p->n, limit, "%lu ", n); | |
6652 | + p->n += n; | |
6653 | + limit -= n; | |
6654 | + if (unlikely(limit <= 0)) | |
6655 | + goto out_free; | |
6656 | + } | |
6657 | + p->a[p->n - 1] = '\n'; | |
6658 | + | |
6659 | + /* the sum of plinks */ | |
6660 | + n = snprintf(p->a + p->n, limit, "%lu\n", sum); | |
6661 | + p->n += n; | |
6662 | + limit -= n; | |
6663 | + if (unlikely(limit <= 0)) | |
6664 | + goto out_free; | |
6665 | + } else { | |
6666 | +#define str "1\n0\n0\n" | |
6667 | + p->n = sizeof(str) - 1; | |
6668 | + strcpy(p->a, str); | |
6669 | +#undef str | |
6670 | + } | |
6671 | + si_read_unlock(sb); | |
6672 | + | |
6673 | + err = 0; | |
6674 | + file->private_data = p; | |
6675 | + goto out; /* success */ | |
6676 | + | |
6677 | +out_free: | |
1c60b727 | 6678 | + free_page((unsigned long)p); |
86dc4139 AM |
6679 | +out: |
6680 | + return err; | |
6681 | +} | |
6682 | + | |
6683 | +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf, | |
6684 | + size_t count, loff_t *ppos) | |
6685 | +{ | |
6686 | + struct dbgaufs_plink_arg *p; | |
6687 | + | |
6688 | + p = file->private_data; | |
6689 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6690 | +} | |
6691 | + | |
6692 | +static const struct file_operations dbgaufs_plink_fop = { | |
6693 | + .owner = THIS_MODULE, | |
6694 | + .open = dbgaufs_plink_open, | |
6695 | + .release = dbgaufs_plink_release, | |
6696 | + .read = dbgaufs_plink_read | |
6697 | +}; | |
6698 | + | |
6699 | +/* ---------------------------------------------------------------------- */ | |
6700 | + | |
1facf9fc | 6701 | +static int dbgaufs_xib_open(struct inode *inode, struct file *file) |
6702 | +{ | |
6703 | + int err; | |
6704 | + struct au_sbinfo *sbinfo; | |
6705 | + struct super_block *sb; | |
6706 | + | |
6707 | + sbinfo = inode->i_private; | |
6708 | + sb = sbinfo->si_sb; | |
6709 | + si_noflush_read_lock(sb); | |
6710 | + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0); | |
6711 | + si_read_unlock(sb); | |
6712 | + return err; | |
6713 | +} | |
6714 | + | |
6715 | +static const struct file_operations dbgaufs_xib_fop = { | |
4a4d8108 | 6716 | + .owner = THIS_MODULE, |
1facf9fc | 6717 | + .open = dbgaufs_xib_open, |
6718 | + .release = dbgaufs_xi_release, | |
6719 | + .read = dbgaufs_xi_read | |
6720 | +}; | |
6721 | + | |
6722 | +/* ---------------------------------------------------------------------- */ | |
6723 | + | |
6724 | +#define DbgaufsXi_PREFIX "xi" | |
6725 | + | |
6726 | +static int dbgaufs_xino_open(struct inode *inode, struct file *file) | |
6727 | +{ | |
6728 | + int err; | |
6729 | + long l; | |
6730 | + struct au_sbinfo *sbinfo; | |
6731 | + struct super_block *sb; | |
6732 | + struct file *xf; | |
6733 | + struct qstr *name; | |
6734 | + | |
6735 | + err = -ENOENT; | |
6736 | + xf = NULL; | |
2000de60 | 6737 | + name = &file->f_path.dentry->d_name; |
1facf9fc | 6738 | + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX) |
6739 | + || memcmp(name->name, DbgaufsXi_PREFIX, | |
6740 | + sizeof(DbgaufsXi_PREFIX) - 1))) | |
6741 | + goto out; | |
9dbd164d | 6742 | + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l); |
1facf9fc | 6743 | + if (unlikely(err)) |
6744 | + goto out; | |
6745 | + | |
6746 | + sbinfo = inode->i_private; | |
6747 | + sb = sbinfo->si_sb; | |
6748 | + si_noflush_read_lock(sb); | |
5afbbe0d | 6749 | + if (l <= au_sbbot(sb)) { |
1facf9fc | 6750 | + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file; |
6751 | + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1); | |
6752 | + } else | |
6753 | + err = -ENOENT; | |
6754 | + si_read_unlock(sb); | |
6755 | + | |
4f0767ce | 6756 | +out: |
1facf9fc | 6757 | + return err; |
6758 | +} | |
6759 | + | |
6760 | +static const struct file_operations dbgaufs_xino_fop = { | |
4a4d8108 | 6761 | + .owner = THIS_MODULE, |
1facf9fc | 6762 | + .open = dbgaufs_xino_open, |
6763 | + .release = dbgaufs_xi_release, | |
6764 | + .read = dbgaufs_xi_read | |
6765 | +}; | |
6766 | + | |
6767 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
6768 | +{ | |
5afbbe0d | 6769 | + aufs_bindex_t bbot; |
1facf9fc | 6770 | + struct au_branch *br; |
6771 | + struct au_xino_file *xi; | |
6772 | + | |
6773 | + if (!au_sbi(sb)->si_dbgaufs) | |
6774 | + return; | |
6775 | + | |
5afbbe0d AM |
6776 | + bbot = au_sbbot(sb); |
6777 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 6778 | + br = au_sbr(sb, bindex); |
6779 | + xi = &br->br_xino; | |
e2f27e51 AM |
6780 | + /* debugfs acquires the parent i_mutex */ |
6781 | + lockdep_off(); | |
c06a8ce3 | 6782 | + debugfs_remove(xi->xi_dbgaufs); |
e2f27e51 | 6783 | + lockdep_on(); |
c06a8ce3 | 6784 | + xi->xi_dbgaufs = NULL; |
1facf9fc | 6785 | + } |
6786 | +} | |
6787 | + | |
6788 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
6789 | +{ | |
6790 | + struct au_sbinfo *sbinfo; | |
6791 | + struct dentry *parent; | |
6792 | + struct au_branch *br; | |
6793 | + struct au_xino_file *xi; | |
5afbbe0d | 6794 | + aufs_bindex_t bbot; |
1facf9fc | 6795 | + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */ |
6796 | + | |
6797 | + sbinfo = au_sbi(sb); | |
6798 | + parent = sbinfo->si_dbgaufs; | |
6799 | + if (!parent) | |
6800 | + return; | |
6801 | + | |
5afbbe0d AM |
6802 | + bbot = au_sbbot(sb); |
6803 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 6804 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex); |
6805 | + br = au_sbr(sb, bindex); | |
6806 | + xi = &br->br_xino; | |
6807 | + AuDebugOn(xi->xi_dbgaufs); | |
f0c0a007 AM |
6808 | + /* debugfs acquires the parent i_mutex */ |
6809 | + lockdep_off(); | |
1facf9fc | 6810 | + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent, |
6811 | + sbinfo, &dbgaufs_xino_fop); | |
f0c0a007 | 6812 | + lockdep_on(); |
1facf9fc | 6813 | + /* ignore an error */ |
6814 | + if (unlikely(!xi->xi_dbgaufs)) | |
6815 | + AuWarn1("failed %s under debugfs\n", name); | |
6816 | + } | |
6817 | +} | |
6818 | + | |
6819 | +/* ---------------------------------------------------------------------- */ | |
6820 | + | |
6821 | +#ifdef CONFIG_AUFS_EXPORT | |
6822 | +static int dbgaufs_xigen_open(struct inode *inode, struct file *file) | |
6823 | +{ | |
6824 | + int err; | |
6825 | + struct au_sbinfo *sbinfo; | |
6826 | + struct super_block *sb; | |
6827 | + | |
6828 | + sbinfo = inode->i_private; | |
6829 | + sb = sbinfo->si_sb; | |
6830 | + si_noflush_read_lock(sb); | |
6831 | + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0); | |
6832 | + si_read_unlock(sb); | |
6833 | + return err; | |
6834 | +} | |
6835 | + | |
6836 | +static const struct file_operations dbgaufs_xigen_fop = { | |
4a4d8108 | 6837 | + .owner = THIS_MODULE, |
1facf9fc | 6838 | + .open = dbgaufs_xigen_open, |
6839 | + .release = dbgaufs_xi_release, | |
6840 | + .read = dbgaufs_xi_read | |
6841 | +}; | |
6842 | + | |
6843 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6844 | +{ | |
6845 | + int err; | |
6846 | + | |
dece6358 | 6847 | + /* |
c1595e42 | 6848 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6849 | + * so the tiny check for si_rwsem is unnecessary. |
6850 | + */ | |
6851 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6852 | + | |
1facf9fc | 6853 | + err = -EIO; |
6854 | + sbinfo->si_dbgaufs_xigen = debugfs_create_file | |
6855 | + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6856 | + &dbgaufs_xigen_fop); | |
6857 | + if (sbinfo->si_dbgaufs_xigen) | |
6858 | + err = 0; | |
6859 | + | |
6860 | + return err; | |
6861 | +} | |
6862 | +#else | |
6863 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6864 | +{ | |
6865 | + return 0; | |
6866 | +} | |
6867 | +#endif /* CONFIG_AUFS_EXPORT */ | |
6868 | + | |
6869 | +/* ---------------------------------------------------------------------- */ | |
6870 | + | |
6871 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo) | |
6872 | +{ | |
dece6358 | 6873 | + /* |
7e9cd9fe | 6874 | + * This function is a dynamic '__fin' function actually, |
dece6358 AM |
6875 | + * so the tiny check for si_rwsem is unnecessary. |
6876 | + */ | |
6877 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6878 | + | |
1facf9fc | 6879 | + debugfs_remove_recursive(sbinfo->si_dbgaufs); |
6880 | + sbinfo->si_dbgaufs = NULL; | |
6881 | + kobject_put(&sbinfo->si_kobj); | |
6882 | +} | |
6883 | + | |
6884 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo) | |
6885 | +{ | |
6886 | + int err; | |
6887 | + char name[SysaufsSiNameLen]; | |
6888 | + | |
dece6358 | 6889 | + /* |
c1595e42 | 6890 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6891 | + * so the tiny check for si_rwsem is unnecessary. |
6892 | + */ | |
6893 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6894 | + | |
1facf9fc | 6895 | + err = -ENOENT; |
6896 | + if (!dbgaufs) { | |
6897 | + AuErr1("/debug/aufs is uninitialized\n"); | |
6898 | + goto out; | |
6899 | + } | |
6900 | + | |
6901 | + err = -EIO; | |
6902 | + sysaufs_name(sbinfo, name); | |
6903 | + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs); | |
6904 | + if (unlikely(!sbinfo->si_dbgaufs)) | |
6905 | + goto out; | |
6906 | + kobject_get(&sbinfo->si_kobj); | |
6907 | + | |
6908 | + sbinfo->si_dbgaufs_xib = debugfs_create_file | |
6909 | + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6910 | + &dbgaufs_xib_fop); | |
6911 | + if (unlikely(!sbinfo->si_dbgaufs_xib)) | |
6912 | + goto out_dir; | |
6913 | + | |
86dc4139 AM |
6914 | + sbinfo->si_dbgaufs_plink = debugfs_create_file |
6915 | + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6916 | + &dbgaufs_plink_fop); | |
6917 | + if (unlikely(!sbinfo->si_dbgaufs_plink)) | |
6918 | + goto out_dir; | |
6919 | + | |
1facf9fc | 6920 | + err = dbgaufs_xigen_init(sbinfo); |
6921 | + if (!err) | |
6922 | + goto out; /* success */ | |
6923 | + | |
4f0767ce | 6924 | +out_dir: |
1facf9fc | 6925 | + dbgaufs_si_fin(sbinfo); |
4f0767ce | 6926 | +out: |
1facf9fc | 6927 | + return err; |
6928 | +} | |
6929 | + | |
6930 | +/* ---------------------------------------------------------------------- */ | |
6931 | + | |
6932 | +void dbgaufs_fin(void) | |
6933 | +{ | |
6934 | + debugfs_remove(dbgaufs); | |
6935 | +} | |
6936 | + | |
6937 | +int __init dbgaufs_init(void) | |
6938 | +{ | |
6939 | + int err; | |
6940 | + | |
6941 | + err = -EIO; | |
6942 | + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL); | |
6943 | + if (dbgaufs) | |
6944 | + err = 0; | |
6945 | + return err; | |
6946 | +} | |
7f207e10 AM |
6947 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h |
6948 | --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 6949 | +++ linux/fs/aufs/dbgaufs.h 2018-01-29 07:56:20.053325069 +0100 |
523b37e3 | 6950 | @@ -0,0 +1,48 @@ |
1facf9fc | 6951 | +/* |
a2654f78 | 6952 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 6953 | + * |
6954 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6955 | + * it under the terms of the GNU General Public License as published by | |
6956 | + * the Free Software Foundation; either version 2 of the License, or | |
6957 | + * (at your option) any later version. | |
dece6358 AM |
6958 | + * |
6959 | + * This program is distributed in the hope that it will be useful, | |
6960 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6961 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6962 | + * GNU General Public License for more details. | |
6963 | + * | |
6964 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6965 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6966 | + */ |
6967 | + | |
6968 | +/* | |
6969 | + * debugfs interface | |
6970 | + */ | |
6971 | + | |
6972 | +#ifndef __DBGAUFS_H__ | |
6973 | +#define __DBGAUFS_H__ | |
6974 | + | |
6975 | +#ifdef __KERNEL__ | |
6976 | + | |
dece6358 | 6977 | +struct super_block; |
1facf9fc | 6978 | +struct au_sbinfo; |
dece6358 | 6979 | + |
1facf9fc | 6980 | +#ifdef CONFIG_DEBUG_FS |
6981 | +/* dbgaufs.c */ | |
6982 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
6983 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
6984 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo); | |
6985 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo); | |
6986 | +void dbgaufs_fin(void); | |
6987 | +int __init dbgaufs_init(void); | |
1facf9fc | 6988 | +#else |
4a4d8108 AM |
6989 | +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) |
6990 | +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
6991 | +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo) | |
6992 | +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo) | |
6993 | +AuStubVoid(dbgaufs_fin, void) | |
6994 | +AuStubInt0(__init dbgaufs_init, void) | |
1facf9fc | 6995 | +#endif /* CONFIG_DEBUG_FS */ |
6996 | + | |
6997 | +#endif /* __KERNEL__ */ | |
6998 | +#endif /* __DBGAUFS_H__ */ | |
7f207e10 AM |
6999 | diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c |
7000 | --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 7001 | +++ linux/fs/aufs/dcsub.c 2018-01-29 07:56:20.053325069 +0100 |
e2f27e51 | 7002 | @@ -0,0 +1,225 @@ |
1facf9fc | 7003 | +/* |
a2654f78 | 7004 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7005 | + * |
7006 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7007 | + * it under the terms of the GNU General Public License as published by | |
7008 | + * the Free Software Foundation; either version 2 of the License, or | |
7009 | + * (at your option) any later version. | |
dece6358 AM |
7010 | + * |
7011 | + * This program is distributed in the hope that it will be useful, | |
7012 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7013 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7014 | + * GNU General Public License for more details. | |
7015 | + * | |
7016 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7017 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7018 | + */ |
7019 | + | |
7020 | +/* | |
7021 | + * sub-routines for dentry cache | |
7022 | + */ | |
7023 | + | |
7024 | +#include "aufs.h" | |
7025 | + | |
7026 | +static void au_dpage_free(struct au_dpage *dpage) | |
7027 | +{ | |
7028 | + int i; | |
7029 | + struct dentry **p; | |
7030 | + | |
7031 | + p = dpage->dentries; | |
7032 | + for (i = 0; i < dpage->ndentry; i++) | |
7033 | + dput(*p++); | |
1c60b727 | 7034 | + free_page((unsigned long)dpage->dentries); |
1facf9fc | 7035 | +} |
7036 | + | |
7037 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp) | |
7038 | +{ | |
7039 | + int err; | |
7040 | + void *p; | |
7041 | + | |
7042 | + err = -ENOMEM; | |
7043 | + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp); | |
7044 | + if (unlikely(!dpages->dpages)) | |
7045 | + goto out; | |
7046 | + | |
7047 | + p = (void *)__get_free_page(gfp); | |
7048 | + if (unlikely(!p)) | |
7049 | + goto out_dpages; | |
7050 | + | |
7051 | + dpages->dpages[0].ndentry = 0; | |
7052 | + dpages->dpages[0].dentries = p; | |
7053 | + dpages->ndpage = 1; | |
7054 | + return 0; /* success */ | |
7055 | + | |
4f0767ce | 7056 | +out_dpages: |
1c60b727 | 7057 | + kfree(dpages->dpages); |
4f0767ce | 7058 | +out: |
1facf9fc | 7059 | + return err; |
7060 | +} | |
7061 | + | |
7062 | +void au_dpages_free(struct au_dcsub_pages *dpages) | |
7063 | +{ | |
7064 | + int i; | |
7065 | + struct au_dpage *p; | |
7066 | + | |
7067 | + p = dpages->dpages; | |
7068 | + for (i = 0; i < dpages->ndpage; i++) | |
7069 | + au_dpage_free(p++); | |
1c60b727 | 7070 | + kfree(dpages->dpages); |
1facf9fc | 7071 | +} |
7072 | + | |
7073 | +static int au_dpages_append(struct au_dcsub_pages *dpages, | |
7074 | + struct dentry *dentry, gfp_t gfp) | |
7075 | +{ | |
7076 | + int err, sz; | |
7077 | + struct au_dpage *dpage; | |
7078 | + void *p; | |
7079 | + | |
7080 | + dpage = dpages->dpages + dpages->ndpage - 1; | |
7081 | + sz = PAGE_SIZE / sizeof(dentry); | |
7082 | + if (unlikely(dpage->ndentry >= sz)) { | |
7083 | + AuLabel(new dpage); | |
7084 | + err = -ENOMEM; | |
7085 | + sz = dpages->ndpage * sizeof(*dpages->dpages); | |
7086 | + p = au_kzrealloc(dpages->dpages, sz, | |
e2f27e51 AM |
7087 | + sz + sizeof(*dpages->dpages), gfp, |
7088 | + /*may_shrink*/0); | |
1facf9fc | 7089 | + if (unlikely(!p)) |
7090 | + goto out; | |
7091 | + | |
7092 | + dpages->dpages = p; | |
7093 | + dpage = dpages->dpages + dpages->ndpage; | |
7094 | + p = (void *)__get_free_page(gfp); | |
7095 | + if (unlikely(!p)) | |
7096 | + goto out; | |
7097 | + | |
7098 | + dpage->ndentry = 0; | |
7099 | + dpage->dentries = p; | |
7100 | + dpages->ndpage++; | |
7101 | + } | |
7102 | + | |
c1595e42 | 7103 | + AuDebugOn(au_dcount(dentry) <= 0); |
027c5e7a | 7104 | + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry); |
1facf9fc | 7105 | + return 0; /* success */ |
7106 | + | |
4f0767ce | 7107 | +out: |
1facf9fc | 7108 | + return err; |
7109 | +} | |
7110 | + | |
c1595e42 JR |
7111 | +/* todo: BAD approach */ |
7112 | +/* copied from linux/fs/dcache.c */ | |
7113 | +enum d_walk_ret { | |
7114 | + D_WALK_CONTINUE, | |
7115 | + D_WALK_QUIT, | |
7116 | + D_WALK_NORETRY, | |
7117 | + D_WALK_SKIP, | |
7118 | +}; | |
7119 | + | |
7120 | +extern void d_walk(struct dentry *parent, void *data, | |
7121 | + enum d_walk_ret (*enter)(void *, struct dentry *), | |
7122 | + void (*finish)(void *)); | |
7123 | + | |
7124 | +struct ac_dpages_arg { | |
1facf9fc | 7125 | + int err; |
c1595e42 JR |
7126 | + struct au_dcsub_pages *dpages; |
7127 | + struct super_block *sb; | |
7128 | + au_dpages_test test; | |
7129 | + void *arg; | |
7130 | +}; | |
1facf9fc | 7131 | + |
c1595e42 JR |
7132 | +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry) |
7133 | +{ | |
7134 | + enum d_walk_ret ret; | |
7135 | + struct ac_dpages_arg *arg = _arg; | |
1facf9fc | 7136 | + |
c1595e42 JR |
7137 | + ret = D_WALK_CONTINUE; |
7138 | + if (dentry->d_sb == arg->sb | |
7139 | + && !IS_ROOT(dentry) | |
7140 | + && au_dcount(dentry) > 0 | |
7141 | + && au_di(dentry) | |
7142 | + && (!arg->test || arg->test(dentry, arg->arg))) { | |
7143 | + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC); | |
7144 | + if (unlikely(arg->err)) | |
7145 | + ret = D_WALK_QUIT; | |
1facf9fc | 7146 | + } |
7147 | + | |
c1595e42 JR |
7148 | + return ret; |
7149 | +} | |
027c5e7a | 7150 | + |
c1595e42 JR |
7151 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, |
7152 | + au_dpages_test test, void *arg) | |
7153 | +{ | |
7154 | + struct ac_dpages_arg args = { | |
7155 | + .err = 0, | |
7156 | + .dpages = dpages, | |
7157 | + .sb = root->d_sb, | |
7158 | + .test = test, | |
7159 | + .arg = arg | |
7160 | + }; | |
027c5e7a | 7161 | + |
c1595e42 JR |
7162 | + d_walk(root, &args, au_call_dpages_append, NULL); |
7163 | + | |
7164 | + return args.err; | |
1facf9fc | 7165 | +} |
7166 | + | |
7167 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
7168 | + int do_include, au_dpages_test test, void *arg) | |
7169 | +{ | |
7170 | + int err; | |
7171 | + | |
7172 | + err = 0; | |
027c5e7a AM |
7173 | + write_seqlock(&rename_lock); |
7174 | + spin_lock(&dentry->d_lock); | |
7175 | + if (do_include | |
c1595e42 | 7176 | + && au_dcount(dentry) > 0 |
027c5e7a | 7177 | + && (!test || test(dentry, arg))) |
1facf9fc | 7178 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
7179 | + spin_unlock(&dentry->d_lock); |
7180 | + if (unlikely(err)) | |
7181 | + goto out; | |
7182 | + | |
7183 | + /* | |
523b37e3 | 7184 | + * RCU for vfsmount is unnecessary since this is a traverse in a single |
027c5e7a AM |
7185 | + * mount |
7186 | + */ | |
1facf9fc | 7187 | + while (!IS_ROOT(dentry)) { |
027c5e7a AM |
7188 | + dentry = dentry->d_parent; /* rename_lock is locked */ |
7189 | + spin_lock(&dentry->d_lock); | |
c1595e42 | 7190 | + if (au_dcount(dentry) > 0 |
027c5e7a | 7191 | + && (!test || test(dentry, arg))) |
1facf9fc | 7192 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
7193 | + spin_unlock(&dentry->d_lock); |
7194 | + if (unlikely(err)) | |
7195 | + break; | |
1facf9fc | 7196 | + } |
7197 | + | |
4f0767ce | 7198 | +out: |
027c5e7a | 7199 | + write_sequnlock(&rename_lock); |
1facf9fc | 7200 | + return err; |
7201 | +} | |
7202 | + | |
027c5e7a AM |
7203 | +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg) |
7204 | +{ | |
7205 | + return au_di(dentry) && dentry->d_sb == arg; | |
7206 | +} | |
7207 | + | |
7208 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, | |
7209 | + struct dentry *dentry, int do_include) | |
7210 | +{ | |
7211 | + return au_dcsub_pages_rev(dpages, dentry, do_include, | |
7212 | + au_dcsub_dpages_aufs, dentry->d_sb); | |
7213 | +} | |
7214 | + | |
4a4d8108 | 7215 | +int au_test_subdir(struct dentry *d1, struct dentry *d2) |
1facf9fc | 7216 | +{ |
4a4d8108 AM |
7217 | + struct path path[2] = { |
7218 | + { | |
7219 | + .dentry = d1 | |
7220 | + }, | |
7221 | + { | |
7222 | + .dentry = d2 | |
7223 | + } | |
7224 | + }; | |
1facf9fc | 7225 | + |
4a4d8108 | 7226 | + return path_is_under(path + 0, path + 1); |
1facf9fc | 7227 | +} |
7f207e10 AM |
7228 | diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h |
7229 | --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 7230 | +++ linux/fs/aufs/dcsub.h 2018-01-29 07:56:20.053325069 +0100 |
5527c038 | 7231 | @@ -0,0 +1,136 @@ |
1facf9fc | 7232 | +/* |
a2654f78 | 7233 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7234 | + * |
7235 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7236 | + * it under the terms of the GNU General Public License as published by | |
7237 | + * the Free Software Foundation; either version 2 of the License, or | |
7238 | + * (at your option) any later version. | |
dece6358 AM |
7239 | + * |
7240 | + * This program is distributed in the hope that it will be useful, | |
7241 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7242 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7243 | + * GNU General Public License for more details. | |
7244 | + * | |
7245 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7246 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7247 | + */ |
7248 | + | |
7249 | +/* | |
7250 | + * sub-routines for dentry cache | |
7251 | + */ | |
7252 | + | |
7253 | +#ifndef __AUFS_DCSUB_H__ | |
7254 | +#define __AUFS_DCSUB_H__ | |
7255 | + | |
7256 | +#ifdef __KERNEL__ | |
7257 | + | |
7f207e10 | 7258 | +#include <linux/dcache.h> |
027c5e7a | 7259 | +#include <linux/fs.h> |
dece6358 | 7260 | + |
1facf9fc | 7261 | +struct au_dpage { |
7262 | + int ndentry; | |
7263 | + struct dentry **dentries; | |
7264 | +}; | |
7265 | + | |
7266 | +struct au_dcsub_pages { | |
7267 | + int ndpage; | |
7268 | + struct au_dpage *dpages; | |
7269 | +}; | |
7270 | + | |
7271 | +/* ---------------------------------------------------------------------- */ | |
7272 | + | |
7f207e10 | 7273 | +/* dcsub.c */ |
1facf9fc | 7274 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp); |
7275 | +void au_dpages_free(struct au_dcsub_pages *dpages); | |
7276 | +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg); | |
7277 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, | |
7278 | + au_dpages_test test, void *arg); | |
7279 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
7280 | + int do_include, au_dpages_test test, void *arg); | |
027c5e7a AM |
7281 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, |
7282 | + struct dentry *dentry, int do_include); | |
4a4d8108 | 7283 | +int au_test_subdir(struct dentry *d1, struct dentry *d2); |
1facf9fc | 7284 | + |
7f207e10 AM |
7285 | +/* ---------------------------------------------------------------------- */ |
7286 | + | |
523b37e3 AM |
7287 | +/* |
7288 | + * todo: in linux-3.13, several similar (but faster) helpers are added to | |
7289 | + * include/linux/dcache.h. Try them (in the future). | |
7290 | + */ | |
7291 | + | |
027c5e7a AM |
7292 | +static inline int au_d_hashed_positive(struct dentry *d) |
7293 | +{ | |
7294 | + int err; | |
5527c038 | 7295 | + struct inode *inode = d_inode(d); |
076b876e | 7296 | + |
027c5e7a | 7297 | + err = 0; |
5527c038 JR |
7298 | + if (unlikely(d_unhashed(d) |
7299 | + || d_is_negative(d) | |
7300 | + || !inode->i_nlink)) | |
027c5e7a AM |
7301 | + err = -ENOENT; |
7302 | + return err; | |
7303 | +} | |
7304 | + | |
38d290e6 JR |
7305 | +static inline int au_d_linkable(struct dentry *d) |
7306 | +{ | |
7307 | + int err; | |
5527c038 | 7308 | + struct inode *inode = d_inode(d); |
076b876e | 7309 | + |
38d290e6 JR |
7310 | + err = au_d_hashed_positive(d); |
7311 | + if (err | |
5527c038 | 7312 | + && d_is_positive(d) |
38d290e6 JR |
7313 | + && (inode->i_state & I_LINKABLE)) |
7314 | + err = 0; | |
7315 | + return err; | |
7316 | +} | |
7317 | + | |
027c5e7a AM |
7318 | +static inline int au_d_alive(struct dentry *d) |
7319 | +{ | |
7320 | + int err; | |
7321 | + struct inode *inode; | |
076b876e | 7322 | + |
027c5e7a AM |
7323 | + err = 0; |
7324 | + if (!IS_ROOT(d)) | |
7325 | + err = au_d_hashed_positive(d); | |
7326 | + else { | |
5527c038 JR |
7327 | + inode = d_inode(d); |
7328 | + if (unlikely(d_unlinked(d) | |
7329 | + || d_is_negative(d) | |
7330 | + || !inode->i_nlink)) | |
027c5e7a AM |
7331 | + err = -ENOENT; |
7332 | + } | |
7333 | + return err; | |
7334 | +} | |
7335 | + | |
7336 | +static inline int au_alive_dir(struct dentry *d) | |
7f207e10 | 7337 | +{ |
027c5e7a | 7338 | + int err; |
076b876e | 7339 | + |
027c5e7a | 7340 | + err = au_d_alive(d); |
5527c038 | 7341 | + if (unlikely(err || IS_DEADDIR(d_inode(d)))) |
027c5e7a AM |
7342 | + err = -ENOENT; |
7343 | + return err; | |
7f207e10 AM |
7344 | +} |
7345 | + | |
38d290e6 JR |
7346 | +static inline int au_qstreq(struct qstr *a, struct qstr *b) |
7347 | +{ | |
7348 | + return a->len == b->len | |
7349 | + && !memcmp(a->name, b->name, a->len); | |
7350 | +} | |
7351 | + | |
7e9cd9fe AM |
7352 | +/* |
7353 | + * by the commit | |
7354 | + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without | |
7355 | + * taking d_lock | |
7356 | + * the type of d_lockref.count became int, but the inlined function d_count() | |
7357 | + * still returns unsigned int. | |
7358 | + * I don't know why. Maybe it is for every d_count() users? | |
7359 | + * Anyway au_dcount() lives on. | |
7360 | + */ | |
c1595e42 JR |
7361 | +static inline int au_dcount(struct dentry *d) |
7362 | +{ | |
7363 | + return (int)d_count(d); | |
7364 | +} | |
7365 | + | |
1facf9fc | 7366 | +#endif /* __KERNEL__ */ |
7367 | +#endif /* __AUFS_DCSUB_H__ */ | |
7f207e10 AM |
7368 | diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c |
7369 | --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 7370 | +++ linux/fs/aufs/debug.c 2018-01-29 07:56:20.053325069 +0100 |
f0c0a007 | 7371 | @@ -0,0 +1,440 @@ |
1facf9fc | 7372 | +/* |
a2654f78 | 7373 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7374 | + * |
7375 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7376 | + * it under the terms of the GNU General Public License as published by | |
7377 | + * the Free Software Foundation; either version 2 of the License, or | |
7378 | + * (at your option) any later version. | |
dece6358 AM |
7379 | + * |
7380 | + * This program is distributed in the hope that it will be useful, | |
7381 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7382 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7383 | + * GNU General Public License for more details. | |
7384 | + * | |
7385 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7386 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7387 | + */ |
7388 | + | |
7389 | +/* | |
7390 | + * debug print functions | |
7391 | + */ | |
7392 | + | |
7393 | +#include "aufs.h" | |
7394 | + | |
392086de AM |
7395 | +/* Returns 0, or -errno. arg is in kp->arg. */ |
7396 | +static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
7397 | +{ | |
7398 | + int err, n; | |
7399 | + | |
7400 | + err = kstrtoint(val, 0, &n); | |
7401 | + if (!err) { | |
7402 | + if (n > 0) | |
7403 | + au_debug_on(); | |
7404 | + else | |
7405 | + au_debug_off(); | |
7406 | + } | |
7407 | + return err; | |
7408 | +} | |
7409 | + | |
7410 | +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
7411 | +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
7412 | +{ | |
7413 | + atomic_t *a; | |
7414 | + | |
7415 | + a = kp->arg; | |
7416 | + return sprintf(buffer, "%d", atomic_read(a)); | |
7417 | +} | |
7418 | + | |
7419 | +static struct kernel_param_ops param_ops_atomic_t = { | |
7420 | + .set = param_atomic_t_set, | |
7421 | + .get = param_atomic_t_get | |
7422 | + /* void (*free)(void *arg) */ | |
7423 | +}; | |
7424 | + | |
7425 | +atomic_t aufs_debug = ATOMIC_INIT(0); | |
1facf9fc | 7426 | +MODULE_PARM_DESC(debug, "debug print"); |
392086de | 7427 | +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP); |
1facf9fc | 7428 | + |
c1595e42 | 7429 | +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ |
1facf9fc | 7430 | +char *au_plevel = KERN_DEBUG; |
e49829fe JR |
7431 | +#define dpri(fmt, ...) do { \ |
7432 | + if ((au_plevel \ | |
7433 | + && strcmp(au_plevel, KERN_DEBUG)) \ | |
7434 | + || au_debug_test()) \ | |
7435 | + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
1facf9fc | 7436 | +} while (0) |
7437 | + | |
7438 | +/* ---------------------------------------------------------------------- */ | |
7439 | + | |
7440 | +void au_dpri_whlist(struct au_nhash *whlist) | |
7441 | +{ | |
7442 | + unsigned long ul, n; | |
7443 | + struct hlist_head *head; | |
c06a8ce3 | 7444 | + struct au_vdir_wh *pos; |
1facf9fc | 7445 | + |
7446 | + n = whlist->nh_num; | |
7447 | + head = whlist->nh_head; | |
7448 | + for (ul = 0; ul < n; ul++) { | |
c06a8ce3 | 7449 | + hlist_for_each_entry(pos, head, wh_hash) |
1facf9fc | 7450 | + dpri("b%d, %.*s, %d\n", |
c06a8ce3 AM |
7451 | + pos->wh_bindex, |
7452 | + pos->wh_str.len, pos->wh_str.name, | |
7453 | + pos->wh_str.len); | |
1facf9fc | 7454 | + head++; |
7455 | + } | |
7456 | +} | |
7457 | + | |
7458 | +void au_dpri_vdir(struct au_vdir *vdir) | |
7459 | +{ | |
7460 | + unsigned long ul; | |
7461 | + union au_vdir_deblk_p p; | |
7462 | + unsigned char *o; | |
7463 | + | |
7464 | + if (!vdir || IS_ERR(vdir)) { | |
7465 | + dpri("err %ld\n", PTR_ERR(vdir)); | |
7466 | + return; | |
7467 | + } | |
7468 | + | |
7469 | + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n", | |
7470 | + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, | |
7471 | + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
7472 | + for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
7473 | + p.deblk = vdir->vd_deblk[ul]; | |
7474 | + o = p.deblk; | |
7475 | + dpri("[%lu]: %p\n", ul, o); | |
7476 | + } | |
7477 | +} | |
7478 | + | |
53392da6 | 7479 | +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, |
1facf9fc | 7480 | + struct dentry *wh) |
7481 | +{ | |
7482 | + char *n = NULL; | |
7483 | + int l = 0; | |
7484 | + | |
7485 | + if (!inode || IS_ERR(inode)) { | |
7486 | + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
7487 | + return -1; | |
7488 | + } | |
7489 | + | |
c2b27bf2 | 7490 | + /* the type of i_blocks depends upon CONFIG_LBDAF */ |
1facf9fc | 7491 | + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) |
7492 | + && sizeof(inode->i_blocks) != sizeof(u64)); | |
7493 | + if (wh) { | |
7494 | + n = (void *)wh->d_name.name; | |
7495 | + l = wh->d_name.len; | |
7496 | + } | |
7497 | + | |
53392da6 AM |
7498 | + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," |
7499 | + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
7500 | + bindex, inode, | |
1facf9fc | 7501 | + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", |
7502 | + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
7503 | + i_size_read(inode), (unsigned long long)inode->i_blocks, | |
53392da6 | 7504 | + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff, |
1facf9fc | 7505 | + inode->i_mapping ? inode->i_mapping->nrpages : 0, |
b752ccd1 AM |
7506 | + inode->i_state, inode->i_flags, inode->i_version, |
7507 | + inode->i_generation, | |
1facf9fc | 7508 | + l ? ", wh " : "", l, n); |
7509 | + return 0; | |
7510 | +} | |
7511 | + | |
7512 | +void au_dpri_inode(struct inode *inode) | |
7513 | +{ | |
7514 | + struct au_iinfo *iinfo; | |
5afbbe0d | 7515 | + struct au_hinode *hi; |
1facf9fc | 7516 | + aufs_bindex_t bindex; |
53392da6 | 7517 | + int err, hn; |
1facf9fc | 7518 | + |
53392da6 | 7519 | + err = do_pri_inode(-1, inode, -1, NULL); |
5afbbe0d | 7520 | + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode)) |
1facf9fc | 7521 | + return; |
7522 | + | |
7523 | + iinfo = au_ii(inode); | |
5afbbe0d AM |
7524 | + dpri("i-1: btop %d, bbot %d, gen %d\n", |
7525 | + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL)); | |
7526 | + if (iinfo->ii_btop < 0) | |
1facf9fc | 7527 | + return; |
53392da6 | 7528 | + hn = 0; |
5afbbe0d AM |
7529 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) { |
7530 | + hi = au_hinode(iinfo, bindex); | |
7531 | + hn = !!au_hn(hi); | |
7532 | + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry); | |
53392da6 | 7533 | + } |
1facf9fc | 7534 | +} |
7535 | + | |
2cbb1c4b JR |
7536 | +void au_dpri_dalias(struct inode *inode) |
7537 | +{ | |
7538 | + struct dentry *d; | |
7539 | + | |
7540 | + spin_lock(&inode->i_lock); | |
c1595e42 | 7541 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) |
2cbb1c4b JR |
7542 | + au_dpri_dentry(d); |
7543 | + spin_unlock(&inode->i_lock); | |
7544 | +} | |
7545 | + | |
1facf9fc | 7546 | +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) |
7547 | +{ | |
7548 | + struct dentry *wh = NULL; | |
53392da6 | 7549 | + int hn; |
5afbbe0d | 7550 | + struct inode *inode; |
076b876e | 7551 | + struct au_iinfo *iinfo; |
5afbbe0d | 7552 | + struct au_hinode *hi; |
1facf9fc | 7553 | + |
7554 | + if (!dentry || IS_ERR(dentry)) { | |
7555 | + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
7556 | + return -1; | |
7557 | + } | |
7558 | + /* do not call dget_parent() here */ | |
027c5e7a | 7559 | + /* note: access d_xxx without d_lock */ |
523b37e3 AM |
7560 | + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", |
7561 | + bindex, dentry, dentry, | |
1facf9fc | 7562 | + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", |
c1595e42 | 7563 | + au_dcount(dentry), dentry->d_flags, |
523b37e3 | 7564 | + d_unhashed(dentry) ? "un" : ""); |
53392da6 | 7565 | + hn = -1; |
5afbbe0d AM |
7566 | + inode = NULL; |
7567 | + if (d_is_positive(dentry)) | |
7568 | + inode = d_inode(dentry); | |
7569 | + if (inode | |
7570 | + && au_test_aufs(dentry->d_sb) | |
7571 | + && bindex >= 0 | |
7572 | + && !au_is_bad_inode(inode)) { | |
7573 | + iinfo = au_ii(inode); | |
7574 | + hi = au_hinode(iinfo, bindex); | |
7575 | + hn = !!au_hn(hi); | |
7576 | + wh = hi->hi_whdentry; | |
7577 | + } | |
7578 | + do_pri_inode(bindex, inode, hn, wh); | |
1facf9fc | 7579 | + return 0; |
7580 | +} | |
7581 | + | |
7582 | +void au_dpri_dentry(struct dentry *dentry) | |
7583 | +{ | |
7584 | + struct au_dinfo *dinfo; | |
7585 | + aufs_bindex_t bindex; | |
7586 | + int err; | |
7587 | + | |
7588 | + err = do_pri_dentry(-1, dentry); | |
7589 | + if (err || !au_test_aufs(dentry->d_sb)) | |
7590 | + return; | |
7591 | + | |
7592 | + dinfo = au_di(dentry); | |
7593 | + if (!dinfo) | |
7594 | + return; | |
5afbbe0d AM |
7595 | + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", |
7596 | + dinfo->di_btop, dinfo->di_bbot, | |
38d290e6 JR |
7597 | + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), |
7598 | + dinfo->di_tmpfile); | |
5afbbe0d | 7599 | + if (dinfo->di_btop < 0) |
1facf9fc | 7600 | + return; |
5afbbe0d AM |
7601 | + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++) |
7602 | + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry); | |
1facf9fc | 7603 | +} |
7604 | + | |
7605 | +static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
7606 | +{ | |
7607 | + char a[32]; | |
7608 | + | |
7609 | + if (!file || IS_ERR(file)) { | |
7610 | + dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
7611 | + return -1; | |
7612 | + } | |
7613 | + a[0] = 0; | |
7614 | + if (bindex < 0 | |
b912730e | 7615 | + && !IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7616 | + && au_test_aufs(file->f_path.dentry->d_sb) |
1facf9fc | 7617 | + && au_fi(file)) |
e49829fe | 7618 | + snprintf(a, sizeof(a), ", gen %d, mmapped %d", |
2cbb1c4b | 7619 | + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); |
b752ccd1 | 7620 | + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", |
1facf9fc | 7621 | + bindex, file->f_mode, file->f_flags, (long)file_count(file), |
b752ccd1 | 7622 | + file->f_version, file->f_pos, a); |
b912730e | 7623 | + if (!IS_ERR_OR_NULL(file->f_path.dentry)) |
2000de60 | 7624 | + do_pri_dentry(bindex, file->f_path.dentry); |
1facf9fc | 7625 | + return 0; |
7626 | +} | |
7627 | + | |
7628 | +void au_dpri_file(struct file *file) | |
7629 | +{ | |
7630 | + struct au_finfo *finfo; | |
4a4d8108 AM |
7631 | + struct au_fidir *fidir; |
7632 | + struct au_hfile *hfile; | |
1facf9fc | 7633 | + aufs_bindex_t bindex; |
7634 | + int err; | |
7635 | + | |
7636 | + err = do_pri_file(-1, file); | |
2000de60 | 7637 | + if (err |
b912730e | 7638 | + || IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7639 | + || !au_test_aufs(file->f_path.dentry->d_sb)) |
1facf9fc | 7640 | + return; |
7641 | + | |
7642 | + finfo = au_fi(file); | |
7643 | + if (!finfo) | |
7644 | + return; | |
4a4d8108 | 7645 | + if (finfo->fi_btop < 0) |
1facf9fc | 7646 | + return; |
4a4d8108 AM |
7647 | + fidir = finfo->fi_hdir; |
7648 | + if (!fidir) | |
7649 | + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
7650 | + else | |
e49829fe JR |
7651 | + for (bindex = finfo->fi_btop; |
7652 | + bindex >= 0 && bindex <= fidir->fd_bbot; | |
4a4d8108 AM |
7653 | + bindex++) { |
7654 | + hfile = fidir->fd_hfile + bindex; | |
7655 | + do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
7656 | + } | |
1facf9fc | 7657 | +} |
7658 | + | |
7659 | +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
7660 | +{ | |
7661 | + struct vfsmount *mnt; | |
7662 | + struct super_block *sb; | |
7663 | + | |
7664 | + if (!br || IS_ERR(br)) | |
7665 | + goto out; | |
86dc4139 | 7666 | + mnt = au_br_mnt(br); |
1facf9fc | 7667 | + if (!mnt || IS_ERR(mnt)) |
7668 | + goto out; | |
7669 | + sb = mnt->mnt_sb; | |
7670 | + if (!sb || IS_ERR(sb)) | |
7671 | + goto out; | |
7672 | + | |
5afbbe0d | 7673 | + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, " |
b752ccd1 | 7674 | + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " |
1facf9fc | 7675 | + "xino %d\n", |
5afbbe0d | 7676 | + bindex, br->br_perm, br->br_id, au_br_count(br), |
1e00d052 | 7677 | + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), |
b752ccd1 | 7678 | + sb->s_flags, sb->s_count, |
1facf9fc | 7679 | + atomic_read(&sb->s_active), !!br->br_xino.xi_file); |
7680 | + return 0; | |
7681 | + | |
4f0767ce | 7682 | +out: |
1facf9fc | 7683 | + dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); |
7684 | + return -1; | |
7685 | +} | |
7686 | + | |
7687 | +void au_dpri_sb(struct super_block *sb) | |
7688 | +{ | |
7689 | + struct au_sbinfo *sbinfo; | |
7690 | + aufs_bindex_t bindex; | |
7691 | + int err; | |
7692 | + /* to reuduce stack size */ | |
7693 | + struct { | |
7694 | + struct vfsmount mnt; | |
7695 | + struct au_branch fake; | |
7696 | + } *a; | |
7697 | + | |
7698 | + /* this function can be called from magic sysrq */ | |
7699 | + a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
7700 | + if (unlikely(!a)) { | |
7701 | + dpri("no memory\n"); | |
7702 | + return; | |
7703 | + } | |
7704 | + | |
7705 | + a->mnt.mnt_sb = sb; | |
86dc4139 | 7706 | + a->fake.br_path.mnt = &a->mnt; |
5afbbe0d | 7707 | + au_br_count_init(&a->fake); |
1facf9fc | 7708 | + err = do_pri_br(-1, &a->fake); |
5afbbe0d | 7709 | + au_br_count_fin(&a->fake); |
1c60b727 | 7710 | + kfree(a); |
1facf9fc | 7711 | + dpri("dev 0x%x\n", sb->s_dev); |
7712 | + if (err || !au_test_aufs(sb)) | |
7713 | + return; | |
7714 | + | |
7715 | + sbinfo = au_sbi(sb); | |
7716 | + if (!sbinfo) | |
7717 | + return; | |
f0c0a007 AM |
7718 | + dpri("nw %d, gen %u, kobj %d\n", |
7719 | + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
521ced18 | 7720 | + kref_read(&sbinfo->si_kobj.kref)); |
5afbbe0d | 7721 | + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++) |
1facf9fc | 7722 | + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); |
7723 | +} | |
7724 | + | |
7725 | +/* ---------------------------------------------------------------------- */ | |
7726 | + | |
027c5e7a AM |
7727 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) |
7728 | +{ | |
5527c038 | 7729 | + struct inode *h_inode, *inode = d_inode(dentry); |
027c5e7a | 7730 | + struct dentry *h_dentry; |
5afbbe0d | 7731 | + aufs_bindex_t bindex, bbot, bi; |
027c5e7a AM |
7732 | + |
7733 | + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
7734 | + return; | |
7735 | + | |
5afbbe0d AM |
7736 | + bbot = au_dbbot(dentry); |
7737 | + bi = au_ibbot(inode); | |
7738 | + if (bi < bbot) | |
7739 | + bbot = bi; | |
7740 | + bindex = au_dbtop(dentry); | |
7741 | + bi = au_ibtop(inode); | |
027c5e7a AM |
7742 | + if (bi > bindex) |
7743 | + bindex = bi; | |
7744 | + | |
5afbbe0d | 7745 | + for (; bindex <= bbot; bindex++) { |
027c5e7a AM |
7746 | + h_dentry = au_h_dptr(dentry, bindex); |
7747 | + if (!h_dentry) | |
7748 | + continue; | |
7749 | + h_inode = au_h_iptr(inode, bindex); | |
5527c038 | 7750 | + if (unlikely(h_inode != d_inode(h_dentry))) { |
392086de | 7751 | + au_debug_on(); |
027c5e7a AM |
7752 | + AuDbg("b%d, %s:%d\n", bindex, func, line); |
7753 | + AuDbgDentry(dentry); | |
7754 | + AuDbgInode(inode); | |
392086de | 7755 | + au_debug_off(); |
027c5e7a AM |
7756 | + BUG(); |
7757 | + } | |
7758 | + } | |
7759 | +} | |
7760 | + | |
1facf9fc | 7761 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) |
7762 | +{ | |
7763 | + int err, i, j; | |
7764 | + struct au_dcsub_pages dpages; | |
7765 | + struct au_dpage *dpage; | |
7766 | + struct dentry **dentries; | |
7767 | + | |
7768 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
7769 | + AuDebugOn(err); | |
027c5e7a | 7770 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); |
1facf9fc | 7771 | + AuDebugOn(err); |
7772 | + for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
7773 | + dpage = dpages.dpages + i; | |
7774 | + dentries = dpage->dentries; | |
7775 | + for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
027c5e7a | 7776 | + AuDebugOn(au_digen_test(dentries[j], sigen)); |
1facf9fc | 7777 | + } |
7778 | + au_dpages_free(&dpages); | |
7779 | +} | |
7780 | + | |
1facf9fc | 7781 | +void au_dbg_verify_kthread(void) |
7782 | +{ | |
53392da6 | 7783 | + if (au_wkq_test()) { |
1facf9fc | 7784 | + au_dbg_blocked(); |
1e00d052 AM |
7785 | + /* |
7786 | + * It may be recursive, but udba=notify between two aufs mounts, | |
7787 | + * where a single ro branch is shared, is not a problem. | |
7788 | + */ | |
7789 | + /* WARN_ON(1); */ | |
1facf9fc | 7790 | + } |
7791 | +} | |
7792 | + | |
7793 | +/* ---------------------------------------------------------------------- */ | |
7794 | + | |
1facf9fc | 7795 | +int __init au_debug_init(void) |
7796 | +{ | |
7797 | + aufs_bindex_t bindex; | |
7798 | + struct au_vdir_destr destr; | |
7799 | + | |
7800 | + bindex = -1; | |
7801 | + AuDebugOn(bindex >= 0); | |
7802 | + | |
7803 | + destr.len = -1; | |
7804 | + AuDebugOn(destr.len < NAME_MAX); | |
7805 | + | |
7806 | +#ifdef CONFIG_4KSTACKS | |
0c3ec466 | 7807 | + pr_warn("CONFIG_4KSTACKS is defined.\n"); |
1facf9fc | 7808 | +#endif |
7809 | + | |
1facf9fc | 7810 | + return 0; |
7811 | +} | |
7f207e10 AM |
7812 | diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h |
7813 | --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 7814 | +++ linux/fs/aufs/debug.h 2018-01-29 07:56:20.053325069 +0100 |
5527c038 | 7815 | @@ -0,0 +1,225 @@ |
1facf9fc | 7816 | +/* |
a2654f78 | 7817 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 7818 | + * |
7819 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7820 | + * it under the terms of the GNU General Public License as published by | |
7821 | + * the Free Software Foundation; either version 2 of the License, or | |
7822 | + * (at your option) any later version. | |
dece6358 AM |
7823 | + * |
7824 | + * This program is distributed in the hope that it will be useful, | |
7825 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7826 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7827 | + * GNU General Public License for more details. | |
7828 | + * | |
7829 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7830 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7831 | + */ |
7832 | + | |
7833 | +/* | |
7834 | + * debug print functions | |
7835 | + */ | |
7836 | + | |
7837 | +#ifndef __AUFS_DEBUG_H__ | |
7838 | +#define __AUFS_DEBUG_H__ | |
7839 | + | |
7840 | +#ifdef __KERNEL__ | |
7841 | + | |
392086de | 7842 | +#include <linux/atomic.h> |
4a4d8108 AM |
7843 | +#include <linux/module.h> |
7844 | +#include <linux/kallsyms.h> | |
1facf9fc | 7845 | +#include <linux/sysrq.h> |
4a4d8108 | 7846 | + |
1facf9fc | 7847 | +#ifdef CONFIG_AUFS_DEBUG |
7848 | +#define AuDebugOn(a) BUG_ON(a) | |
7849 | + | |
7850 | +/* module parameter */ | |
392086de AM |
7851 | +extern atomic_t aufs_debug; |
7852 | +static inline void au_debug_on(void) | |
1facf9fc | 7853 | +{ |
392086de AM |
7854 | + atomic_inc(&aufs_debug); |
7855 | +} | |
7856 | +static inline void au_debug_off(void) | |
7857 | +{ | |
7858 | + atomic_dec_if_positive(&aufs_debug); | |
1facf9fc | 7859 | +} |
7860 | + | |
7861 | +static inline int au_debug_test(void) | |
7862 | +{ | |
392086de | 7863 | + return atomic_read(&aufs_debug) > 0; |
1facf9fc | 7864 | +} |
7865 | +#else | |
7866 | +#define AuDebugOn(a) do {} while (0) | |
392086de AM |
7867 | +AuStubVoid(au_debug_on, void) |
7868 | +AuStubVoid(au_debug_off, void) | |
4a4d8108 | 7869 | +AuStubInt0(au_debug_test, void) |
1facf9fc | 7870 | +#endif /* CONFIG_AUFS_DEBUG */ |
7871 | + | |
392086de AM |
7872 | +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) |
7873 | + | |
1facf9fc | 7874 | +/* ---------------------------------------------------------------------- */ |
7875 | + | |
7876 | +/* debug print */ | |
7877 | + | |
4a4d8108 | 7878 | +#define AuDbg(fmt, ...) do { \ |
1facf9fc | 7879 | + if (au_debug_test()) \ |
4a4d8108 | 7880 | + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ |
1facf9fc | 7881 | +} while (0) |
4a4d8108 AM |
7882 | +#define AuLabel(l) AuDbg(#l "\n") |
7883 | +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
7884 | +#define AuWarn1(fmt, ...) do { \ | |
1facf9fc | 7885 | + static unsigned char _c; \ |
7886 | + if (!_c++) \ | |
0c3ec466 | 7887 | + pr_warn(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7888 | +} while (0) |
7889 | + | |
4a4d8108 | 7890 | +#define AuErr1(fmt, ...) do { \ |
1facf9fc | 7891 | + static unsigned char _c; \ |
7892 | + if (!_c++) \ | |
4a4d8108 | 7893 | + pr_err(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7894 | +} while (0) |
7895 | + | |
4a4d8108 | 7896 | +#define AuIOErr1(fmt, ...) do { \ |
1facf9fc | 7897 | + static unsigned char _c; \ |
7898 | + if (!_c++) \ | |
4a4d8108 | 7899 | + AuIOErr(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7900 | +} while (0) |
7901 | + | |
7902 | +#define AuUnsupportMsg "This operation is not supported." \ | |
7903 | + " Please report this application to aufs-users ML." | |
4a4d8108 AM |
7904 | +#define AuUnsupport(fmt, ...) do { \ |
7905 | + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
1facf9fc | 7906 | + dump_stack(); \ |
7907 | +} while (0) | |
7908 | + | |
7909 | +#define AuTraceErr(e) do { \ | |
7910 | + if (unlikely((e) < 0)) \ | |
7911 | + AuDbg("err %d\n", (int)(e)); \ | |
7912 | +} while (0) | |
7913 | + | |
7914 | +#define AuTraceErrPtr(p) do { \ | |
7915 | + if (IS_ERR(p)) \ | |
7916 | + AuDbg("err %ld\n", PTR_ERR(p)); \ | |
7917 | +} while (0) | |
7918 | + | |
7919 | +/* dirty macros for debug print, use with "%.*s" and caution */ | |
7920 | +#define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
1facf9fc | 7921 | + |
7922 | +/* ---------------------------------------------------------------------- */ | |
7923 | + | |
dece6358 | 7924 | +struct dentry; |
1facf9fc | 7925 | +#ifdef CONFIG_AUFS_DEBUG |
c1595e42 | 7926 | +extern struct mutex au_dbg_mtx; |
1facf9fc | 7927 | +extern char *au_plevel; |
7928 | +struct au_nhash; | |
7929 | +void au_dpri_whlist(struct au_nhash *whlist); | |
7930 | +struct au_vdir; | |
7931 | +void au_dpri_vdir(struct au_vdir *vdir); | |
dece6358 | 7932 | +struct inode; |
1facf9fc | 7933 | +void au_dpri_inode(struct inode *inode); |
2cbb1c4b | 7934 | +void au_dpri_dalias(struct inode *inode); |
1facf9fc | 7935 | +void au_dpri_dentry(struct dentry *dentry); |
dece6358 | 7936 | +struct file; |
1facf9fc | 7937 | +void au_dpri_file(struct file *filp); |
dece6358 | 7938 | +struct super_block; |
1facf9fc | 7939 | +void au_dpri_sb(struct super_block *sb); |
7940 | + | |
027c5e7a AM |
7941 | +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) |
7942 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
1facf9fc | 7943 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); |
1facf9fc | 7944 | +void au_dbg_verify_kthread(void); |
7945 | + | |
7946 | +int __init au_debug_init(void); | |
7e9cd9fe | 7947 | + |
1facf9fc | 7948 | +#define AuDbgWhlist(w) do { \ |
c1595e42 | 7949 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7950 | + AuDbg(#w "\n"); \ |
7951 | + au_dpri_whlist(w); \ | |
c1595e42 | 7952 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7953 | +} while (0) |
7954 | + | |
7955 | +#define AuDbgVdir(v) do { \ | |
c1595e42 | 7956 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7957 | + AuDbg(#v "\n"); \ |
7958 | + au_dpri_vdir(v); \ | |
c1595e42 | 7959 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7960 | +} while (0) |
7961 | + | |
7962 | +#define AuDbgInode(i) do { \ | |
c1595e42 | 7963 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7964 | + AuDbg(#i "\n"); \ |
7965 | + au_dpri_inode(i); \ | |
c1595e42 | 7966 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7967 | +} while (0) |
7968 | + | |
2cbb1c4b | 7969 | +#define AuDbgDAlias(i) do { \ |
c1595e42 | 7970 | + mutex_lock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7971 | + AuDbg(#i "\n"); \ |
7972 | + au_dpri_dalias(i); \ | |
c1595e42 | 7973 | + mutex_unlock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7974 | +} while (0) |
7975 | + | |
1facf9fc | 7976 | +#define AuDbgDentry(d) do { \ |
c1595e42 | 7977 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7978 | + AuDbg(#d "\n"); \ |
7979 | + au_dpri_dentry(d); \ | |
c1595e42 | 7980 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7981 | +} while (0) |
7982 | + | |
7983 | +#define AuDbgFile(f) do { \ | |
c1595e42 | 7984 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7985 | + AuDbg(#f "\n"); \ |
7986 | + au_dpri_file(f); \ | |
c1595e42 | 7987 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7988 | +} while (0) |
7989 | + | |
7990 | +#define AuDbgSb(sb) do { \ | |
c1595e42 | 7991 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7992 | + AuDbg(#sb "\n"); \ |
7993 | + au_dpri_sb(sb); \ | |
c1595e42 | 7994 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7995 | +} while (0) |
7996 | + | |
4a4d8108 AM |
7997 | +#define AuDbgSym(addr) do { \ |
7998 | + char sym[KSYM_SYMBOL_LEN]; \ | |
7999 | + sprint_symbol(sym, (unsigned long)addr); \ | |
8000 | + AuDbg("%s\n", sym); \ | |
8001 | +} while (0) | |
1facf9fc | 8002 | +#else |
027c5e7a | 8003 | +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) |
4a4d8108 AM |
8004 | +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) |
8005 | +AuStubVoid(au_dbg_verify_kthread, void) | |
8006 | +AuStubInt0(__init au_debug_init, void) | |
1facf9fc | 8007 | + |
1facf9fc | 8008 | +#define AuDbgWhlist(w) do {} while (0) |
8009 | +#define AuDbgVdir(v) do {} while (0) | |
8010 | +#define AuDbgInode(i) do {} while (0) | |
2cbb1c4b | 8011 | +#define AuDbgDAlias(i) do {} while (0) |
1facf9fc | 8012 | +#define AuDbgDentry(d) do {} while (0) |
8013 | +#define AuDbgFile(f) do {} while (0) | |
8014 | +#define AuDbgSb(sb) do {} while (0) | |
4a4d8108 | 8015 | +#define AuDbgSym(addr) do {} while (0) |
1facf9fc | 8016 | +#endif /* CONFIG_AUFS_DEBUG */ |
8017 | + | |
8018 | +/* ---------------------------------------------------------------------- */ | |
8019 | + | |
8020 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
8021 | +int __init au_sysrq_init(void); | |
8022 | +void au_sysrq_fin(void); | |
8023 | + | |
8024 | +#ifdef CONFIG_HW_CONSOLE | |
8025 | +#define au_dbg_blocked() do { \ | |
8026 | + WARN_ON(1); \ | |
0c5527e5 | 8027 | + handle_sysrq('w'); \ |
1facf9fc | 8028 | +} while (0) |
8029 | +#else | |
4a4d8108 | 8030 | +AuStubVoid(au_dbg_blocked, void) |
1facf9fc | 8031 | +#endif |
8032 | + | |
8033 | +#else | |
4a4d8108 AM |
8034 | +AuStubInt0(__init au_sysrq_init, void) |
8035 | +AuStubVoid(au_sysrq_fin, void) | |
8036 | +AuStubVoid(au_dbg_blocked, void) | |
1facf9fc | 8037 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ |
8038 | + | |
8039 | +#endif /* __KERNEL__ */ | |
8040 | +#endif /* __AUFS_DEBUG_H__ */ | |
7f207e10 AM |
8041 | diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c |
8042 | --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 8043 | +++ linux/fs/aufs/dentry.c 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 | 8044 | @@ -0,0 +1,1152 @@ |
1facf9fc | 8045 | +/* |
a2654f78 | 8046 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 8047 | + * |
8048 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8049 | + * it under the terms of the GNU General Public License as published by | |
8050 | + * the Free Software Foundation; either version 2 of the License, or | |
8051 | + * (at your option) any later version. | |
dece6358 AM |
8052 | + * |
8053 | + * This program is distributed in the hope that it will be useful, | |
8054 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8055 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8056 | + * GNU General Public License for more details. | |
8057 | + * | |
8058 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8059 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8060 | + */ |
8061 | + | |
8062 | +/* | |
8063 | + * lookup and dentry operations | |
8064 | + */ | |
8065 | + | |
dece6358 | 8066 | +#include <linux/namei.h> |
1facf9fc | 8067 | +#include "aufs.h" |
8068 | + | |
1facf9fc | 8069 | +/* |
8070 | + * returns positive/negative dentry, NULL or an error. | |
8071 | + * NULL means whiteout-ed or not-found. | |
8072 | + */ | |
8073 | +static struct dentry* | |
8074 | +au_do_lookup(struct dentry *h_parent, struct dentry *dentry, | |
8b6a4947 | 8075 | + aufs_bindex_t bindex, struct au_do_lookup_args *args) |
1facf9fc | 8076 | +{ |
8077 | + struct dentry *h_dentry; | |
2000de60 | 8078 | + struct inode *h_inode; |
1facf9fc | 8079 | + struct au_branch *br; |
8080 | + int wh_found, opq; | |
8081 | + unsigned char wh_able; | |
8082 | + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG); | |
076b876e AM |
8083 | + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags, |
8084 | + IGNORE_PERM); | |
1facf9fc | 8085 | + |
1facf9fc | 8086 | + wh_found = 0; |
8087 | + br = au_sbr(dentry->d_sb, bindex); | |
8088 | + wh_able = !!au_br_whable(br->br_perm); | |
8089 | + if (wh_able) | |
8b6a4947 | 8090 | + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm); |
1facf9fc | 8091 | + h_dentry = ERR_PTR(wh_found); |
8092 | + if (!wh_found) | |
8093 | + goto real_lookup; | |
8094 | + if (unlikely(wh_found < 0)) | |
8095 | + goto out; | |
8096 | + | |
8097 | + /* We found a whiteout */ | |
5afbbe0d | 8098 | + /* au_set_dbbot(dentry, bindex); */ |
1facf9fc | 8099 | + au_set_dbwh(dentry, bindex); |
8100 | + if (!allow_neg) | |
8101 | + return NULL; /* success */ | |
8102 | + | |
4f0767ce | 8103 | +real_lookup: |
076b876e | 8104 | + if (!ignore_perm) |
8b6a4947 | 8105 | + h_dentry = vfsub_lkup_one(args->name, h_parent); |
076b876e | 8106 | + else |
8b6a4947 | 8107 | + h_dentry = au_sio_lkup_one(args->name, h_parent); |
2000de60 JR |
8108 | + if (IS_ERR(h_dentry)) { |
8109 | + if (PTR_ERR(h_dentry) == -ENAMETOOLONG | |
8110 | + && !allow_neg) | |
8111 | + h_dentry = NULL; | |
1facf9fc | 8112 | + goto out; |
2000de60 | 8113 | + } |
1facf9fc | 8114 | + |
5527c038 JR |
8115 | + h_inode = d_inode(h_dentry); |
8116 | + if (d_is_negative(h_dentry)) { | |
1facf9fc | 8117 | + if (!allow_neg) |
8118 | + goto out_neg; | |
8119 | + } else if (wh_found | |
8120 | + || (args->type && args->type != (h_inode->i_mode & S_IFMT))) | |
8121 | + goto out_neg; | |
8b6a4947 AM |
8122 | + else if (au_ftest_lkup(args->flags, DIRREN) |
8123 | + /* && h_inode */ | |
8124 | + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) { | |
8125 | + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry, | |
8126 | + (unsigned long long)h_inode->i_ino); | |
8127 | + goto out_neg; | |
8128 | + } | |
1facf9fc | 8129 | + |
5afbbe0d AM |
8130 | + if (au_dbbot(dentry) <= bindex) |
8131 | + au_set_dbbot(dentry, bindex); | |
8132 | + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry)) | |
8133 | + au_set_dbtop(dentry, bindex); | |
1facf9fc | 8134 | + au_set_h_dptr(dentry, bindex, h_dentry); |
8135 | + | |
2000de60 JR |
8136 | + if (!d_is_dir(h_dentry) |
8137 | + || !wh_able | |
5527c038 | 8138 | + || (d_really_is_positive(dentry) && !d_is_dir(dentry))) |
1facf9fc | 8139 | + goto out; /* success */ |
8140 | + | |
3c1bdaff | 8141 | + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD); |
076b876e | 8142 | + opq = au_diropq_test(h_dentry); |
3c1bdaff | 8143 | + inode_unlock_shared(h_inode); |
1facf9fc | 8144 | + if (opq > 0) |
8145 | + au_set_dbdiropq(dentry, bindex); | |
8146 | + else if (unlikely(opq < 0)) { | |
8147 | + au_set_h_dptr(dentry, bindex, NULL); | |
8148 | + h_dentry = ERR_PTR(opq); | |
8149 | + } | |
8150 | + goto out; | |
8151 | + | |
4f0767ce | 8152 | +out_neg: |
1facf9fc | 8153 | + dput(h_dentry); |
8154 | + h_dentry = NULL; | |
4f0767ce | 8155 | +out: |
1facf9fc | 8156 | + return h_dentry; |
8157 | +} | |
8158 | + | |
dece6358 AM |
8159 | +static int au_test_shwh(struct super_block *sb, const struct qstr *name) |
8160 | +{ | |
8161 | + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH) | |
8162 | + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))) | |
8163 | + return -EPERM; | |
8164 | + return 0; | |
8165 | +} | |
8166 | + | |
1facf9fc | 8167 | +/* |
8168 | + * returns the number of lower positive dentries, | |
8169 | + * otherwise an error. | |
8170 | + * can be called at unlinking with @type is zero. | |
8171 | + */ | |
5afbbe0d AM |
8172 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop, |
8173 | + unsigned int flags) | |
1facf9fc | 8174 | +{ |
8175 | + int npositive, err; | |
8176 | + aufs_bindex_t bindex, btail, bdiropq; | |
8b6a4947 | 8177 | + unsigned char isdir, dirperm1, dirren; |
1facf9fc | 8178 | + struct au_do_lookup_args args = { |
8b6a4947 AM |
8179 | + .flags = flags, |
8180 | + .name = &dentry->d_name | |
1facf9fc | 8181 | + }; |
1facf9fc | 8182 | + struct dentry *parent; |
076b876e | 8183 | + struct super_block *sb; |
1facf9fc | 8184 | + |
076b876e | 8185 | + sb = dentry->d_sb; |
8b6a4947 | 8186 | + err = au_test_shwh(sb, args.name); |
dece6358 | 8187 | + if (unlikely(err)) |
1facf9fc | 8188 | + goto out; |
8189 | + | |
8b6a4947 | 8190 | + err = au_wh_name_alloc(&args.whname, args.name); |
1facf9fc | 8191 | + if (unlikely(err)) |
8192 | + goto out; | |
8193 | + | |
2000de60 | 8194 | + isdir = !!d_is_dir(dentry); |
076b876e | 8195 | + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1); |
8b6a4947 AM |
8196 | + dirren = !!au_opt_test(au_mntflags(sb), DIRREN); |
8197 | + if (dirren) | |
8198 | + au_fset_lkup(args.flags, DIRREN); | |
1facf9fc | 8199 | + |
8200 | + npositive = 0; | |
4a4d8108 | 8201 | + parent = dget_parent(dentry); |
1facf9fc | 8202 | + btail = au_dbtaildir(parent); |
5afbbe0d | 8203 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 8204 | + struct dentry *h_parent, *h_dentry; |
8205 | + struct inode *h_inode, *h_dir; | |
8b6a4947 | 8206 | + struct au_branch *br; |
1facf9fc | 8207 | + |
8208 | + h_dentry = au_h_dptr(dentry, bindex); | |
8209 | + if (h_dentry) { | |
5527c038 | 8210 | + if (d_is_positive(h_dentry)) |
1facf9fc | 8211 | + npositive++; |
5afbbe0d | 8212 | + break; |
1facf9fc | 8213 | + } |
8214 | + h_parent = au_h_dptr(parent, bindex); | |
2000de60 | 8215 | + if (!h_parent || !d_is_dir(h_parent)) |
1facf9fc | 8216 | + continue; |
8217 | + | |
8b6a4947 AM |
8218 | + if (dirren) { |
8219 | + /* if the inum matches, then use the prepared name */ | |
8220 | + err = au_dr_lkup_name(&args, bindex); | |
8221 | + if (unlikely(err)) | |
8222 | + goto out_parent; | |
8223 | + } | |
8224 | + | |
5527c038 | 8225 | + h_dir = d_inode(h_parent); |
3c1bdaff | 8226 | + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT); |
8b6a4947 | 8227 | + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args); |
3c1bdaff | 8228 | + inode_unlock_shared(h_dir); |
1facf9fc | 8229 | + err = PTR_ERR(h_dentry); |
8230 | + if (IS_ERR(h_dentry)) | |
4a4d8108 | 8231 | + goto out_parent; |
2000de60 JR |
8232 | + if (h_dentry) |
8233 | + au_fclr_lkup(args.flags, ALLOW_NEG); | |
076b876e AM |
8234 | + if (dirperm1) |
8235 | + au_fset_lkup(args.flags, IGNORE_PERM); | |
1facf9fc | 8236 | + |
79b8bda9 | 8237 | + if (au_dbwh(dentry) == bindex) |
1facf9fc | 8238 | + break; |
8239 | + if (!h_dentry) | |
8240 | + continue; | |
5527c038 | 8241 | + if (d_is_negative(h_dentry)) |
1facf9fc | 8242 | + continue; |
5527c038 | 8243 | + h_inode = d_inode(h_dentry); |
1facf9fc | 8244 | + npositive++; |
8245 | + if (!args.type) | |
8246 | + args.type = h_inode->i_mode & S_IFMT; | |
8247 | + if (args.type != S_IFDIR) | |
8248 | + break; | |
8249 | + else if (isdir) { | |
8250 | + /* the type of lower may be different */ | |
8251 | + bdiropq = au_dbdiropq(dentry); | |
8252 | + if (bdiropq >= 0 && bdiropq <= bindex) | |
8253 | + break; | |
8254 | + } | |
8b6a4947 AM |
8255 | + br = au_sbr(sb, bindex); |
8256 | + if (dirren | |
8257 | + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino, | |
8258 | + /*add_ent*/NULL)) { | |
8259 | + /* prepare next name to lookup */ | |
8260 | + err = au_dr_lkup(&args, dentry, bindex); | |
8261 | + if (unlikely(err)) | |
8262 | + goto out_parent; | |
8263 | + } | |
1facf9fc | 8264 | + } |
8265 | + | |
8266 | + if (npositive) { | |
8267 | + AuLabel(positive); | |
5afbbe0d | 8268 | + au_update_dbtop(dentry); |
1facf9fc | 8269 | + } |
8270 | + err = npositive; | |
076b876e | 8271 | + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE) |
5afbbe0d | 8272 | + && au_dbtop(dentry) < 0)) { |
1facf9fc | 8273 | + err = -EIO; |
523b37e3 AM |
8274 | + AuIOErr("both of real entry and whiteout found, %pd, err %d\n", |
8275 | + dentry, err); | |
027c5e7a | 8276 | + } |
1facf9fc | 8277 | + |
4f0767ce | 8278 | +out_parent: |
4a4d8108 | 8279 | + dput(parent); |
8b6a4947 AM |
8280 | + kfree(args.whname.name); |
8281 | + if (dirren) | |
8282 | + au_dr_lkup_fin(&args); | |
4f0767ce | 8283 | +out: |
1facf9fc | 8284 | + return err; |
8285 | +} | |
8286 | + | |
076b876e | 8287 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent) |
1facf9fc | 8288 | +{ |
8289 | + struct dentry *dentry; | |
8290 | + int wkq_err; | |
8291 | + | |
5527c038 | 8292 | + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC)) |
b4510431 | 8293 | + dentry = vfsub_lkup_one(name, parent); |
1facf9fc | 8294 | + else { |
b4510431 AM |
8295 | + struct vfsub_lkup_one_args args = { |
8296 | + .errp = &dentry, | |
8297 | + .name = name, | |
8298 | + .parent = parent | |
1facf9fc | 8299 | + }; |
8300 | + | |
b4510431 | 8301 | + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args); |
1facf9fc | 8302 | + if (unlikely(wkq_err)) |
8303 | + dentry = ERR_PTR(wkq_err); | |
8304 | + } | |
8305 | + | |
8306 | + return dentry; | |
8307 | +} | |
8308 | + | |
8309 | +/* | |
8310 | + * lookup @dentry on @bindex which should be negative. | |
8311 | + */ | |
86dc4139 | 8312 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh) |
1facf9fc | 8313 | +{ |
8314 | + int err; | |
8315 | + struct dentry *parent, *h_parent, *h_dentry; | |
86dc4139 | 8316 | + struct au_branch *br; |
1facf9fc | 8317 | + |
1facf9fc | 8318 | + parent = dget_parent(dentry); |
8319 | + h_parent = au_h_dptr(parent, bindex); | |
86dc4139 AM |
8320 | + br = au_sbr(dentry->d_sb, bindex); |
8321 | + if (wh) | |
8322 | + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
8323 | + else | |
076b876e | 8324 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); |
1facf9fc | 8325 | + err = PTR_ERR(h_dentry); |
8326 | + if (IS_ERR(h_dentry)) | |
8327 | + goto out; | |
5527c038 | 8328 | + if (unlikely(d_is_positive(h_dentry))) { |
1facf9fc | 8329 | + err = -EIO; |
523b37e3 | 8330 | + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex); |
1facf9fc | 8331 | + dput(h_dentry); |
8332 | + goto out; | |
8333 | + } | |
8334 | + | |
4a4d8108 | 8335 | + err = 0; |
5afbbe0d AM |
8336 | + if (bindex < au_dbtop(dentry)) |
8337 | + au_set_dbtop(dentry, bindex); | |
8338 | + if (au_dbbot(dentry) < bindex) | |
8339 | + au_set_dbbot(dentry, bindex); | |
1facf9fc | 8340 | + au_set_h_dptr(dentry, bindex, h_dentry); |
1facf9fc | 8341 | + |
4f0767ce | 8342 | +out: |
1facf9fc | 8343 | + dput(parent); |
8344 | + return err; | |
8345 | +} | |
8346 | + | |
8347 | +/* ---------------------------------------------------------------------- */ | |
8348 | + | |
8349 | +/* subset of struct inode */ | |
8350 | +struct au_iattr { | |
8351 | + unsigned long i_ino; | |
8352 | + /* unsigned int i_nlink; */ | |
0c3ec466 AM |
8353 | + kuid_t i_uid; |
8354 | + kgid_t i_gid; | |
1facf9fc | 8355 | + u64 i_version; |
8356 | +/* | |
8357 | + loff_t i_size; | |
8358 | + blkcnt_t i_blocks; | |
8359 | +*/ | |
8360 | + umode_t i_mode; | |
8361 | +}; | |
8362 | + | |
8363 | +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode) | |
8364 | +{ | |
8365 | + ia->i_ino = h_inode->i_ino; | |
8366 | + /* ia->i_nlink = h_inode->i_nlink; */ | |
8367 | + ia->i_uid = h_inode->i_uid; | |
8368 | + ia->i_gid = h_inode->i_gid; | |
8369 | + ia->i_version = h_inode->i_version; | |
8370 | +/* | |
8371 | + ia->i_size = h_inode->i_size; | |
8372 | + ia->i_blocks = h_inode->i_blocks; | |
8373 | +*/ | |
8374 | + ia->i_mode = (h_inode->i_mode & S_IFMT); | |
8375 | +} | |
8376 | + | |
8377 | +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode) | |
8378 | +{ | |
8379 | + return ia->i_ino != h_inode->i_ino | |
8380 | + /* || ia->i_nlink != h_inode->i_nlink */ | |
0c3ec466 | 8381 | + || !uid_eq(ia->i_uid, h_inode->i_uid) |
2dfbb274 | 8382 | + || !gid_eq(ia->i_gid, h_inode->i_gid) |
1facf9fc | 8383 | + || ia->i_version != h_inode->i_version |
8384 | +/* | |
8385 | + || ia->i_size != h_inode->i_size | |
8386 | + || ia->i_blocks != h_inode->i_blocks | |
8387 | +*/ | |
8388 | + || ia->i_mode != (h_inode->i_mode & S_IFMT); | |
8389 | +} | |
8390 | + | |
8391 | +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent, | |
8392 | + struct au_branch *br) | |
8393 | +{ | |
8394 | + int err; | |
8395 | + struct au_iattr ia; | |
8396 | + struct inode *h_inode; | |
8397 | + struct dentry *h_d; | |
8398 | + struct super_block *h_sb; | |
8399 | + | |
8400 | + err = 0; | |
8401 | + memset(&ia, -1, sizeof(ia)); | |
8402 | + h_sb = h_dentry->d_sb; | |
5527c038 JR |
8403 | + h_inode = NULL; |
8404 | + if (d_is_positive(h_dentry)) { | |
8405 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8406 | + au_iattr_save(&ia, h_inode); |
5527c038 | 8407 | + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb)) |
1facf9fc | 8408 | + /* nfs d_revalidate may return 0 for negative dentry */ |
8409 | + /* fuse d_revalidate always return 0 for negative dentry */ | |
8410 | + goto out; | |
8411 | + | |
8412 | + /* main purpose is namei.c:cached_lookup() and d_revalidate */ | |
b4510431 | 8413 | + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent); |
1facf9fc | 8414 | + err = PTR_ERR(h_d); |
8415 | + if (IS_ERR(h_d)) | |
8416 | + goto out; | |
8417 | + | |
8418 | + err = 0; | |
8419 | + if (unlikely(h_d != h_dentry | |
5527c038 | 8420 | + || d_inode(h_d) != h_inode |
1facf9fc | 8421 | + || (h_inode && au_iattr_test(&ia, h_inode)))) |
8422 | + err = au_busy_or_stale(); | |
8423 | + dput(h_d); | |
8424 | + | |
4f0767ce | 8425 | +out: |
1facf9fc | 8426 | + AuTraceErr(err); |
8427 | + return err; | |
8428 | +} | |
8429 | + | |
8430 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, | |
8431 | + struct dentry *h_parent, struct au_branch *br) | |
8432 | +{ | |
8433 | + int err; | |
8434 | + | |
8435 | + err = 0; | |
027c5e7a AM |
8436 | + if (udba == AuOpt_UDBA_REVAL |
8437 | + && !au_test_fs_remote(h_dentry->d_sb)) { | |
1facf9fc | 8438 | + IMustLock(h_dir); |
5527c038 | 8439 | + err = (d_inode(h_dentry->d_parent) != h_dir); |
027c5e7a | 8440 | + } else if (udba != AuOpt_UDBA_NONE) |
1facf9fc | 8441 | + err = au_h_verify_dentry(h_dentry, h_parent, br); |
8442 | + | |
8443 | + return err; | |
8444 | +} | |
8445 | + | |
8446 | +/* ---------------------------------------------------------------------- */ | |
8447 | + | |
027c5e7a | 8448 | +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 8449 | +{ |
027c5e7a | 8450 | + int err; |
5afbbe0d | 8451 | + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq; |
027c5e7a AM |
8452 | + struct au_hdentry tmp, *p, *q; |
8453 | + struct au_dinfo *dinfo; | |
8454 | + struct super_block *sb; | |
1facf9fc | 8455 | + |
027c5e7a | 8456 | + DiMustWriteLock(dentry); |
1308ab2a | 8457 | + |
027c5e7a AM |
8458 | + sb = dentry->d_sb; |
8459 | + dinfo = au_di(dentry); | |
5afbbe0d | 8460 | + bbot = dinfo->di_bbot; |
1facf9fc | 8461 | + bwh = dinfo->di_bwh; |
8462 | + bdiropq = dinfo->di_bdiropq; | |
5afbbe0d AM |
8463 | + bindex = dinfo->di_btop; |
8464 | + p = au_hdentry(dinfo, bindex); | |
8465 | + for (; bindex <= bbot; bindex++, p++) { | |
027c5e7a | 8466 | + if (!p->hd_dentry) |
1facf9fc | 8467 | + continue; |
8468 | + | |
027c5e7a AM |
8469 | + new_bindex = au_br_index(sb, p->hd_id); |
8470 | + if (new_bindex == bindex) | |
1facf9fc | 8471 | + continue; |
1facf9fc | 8472 | + |
1facf9fc | 8473 | + if (dinfo->di_bwh == bindex) |
8474 | + bwh = new_bindex; | |
8475 | + if (dinfo->di_bdiropq == bindex) | |
8476 | + bdiropq = new_bindex; | |
8477 | + if (new_bindex < 0) { | |
8478 | + au_hdput(p); | |
8479 | + p->hd_dentry = NULL; | |
8480 | + continue; | |
8481 | + } | |
8482 | + | |
8483 | + /* swap two lower dentries, and loop again */ | |
5afbbe0d | 8484 | + q = au_hdentry(dinfo, new_bindex); |
1facf9fc | 8485 | + tmp = *q; |
8486 | + *q = *p; | |
8487 | + *p = tmp; | |
8488 | + if (tmp.hd_dentry) { | |
8489 | + bindex--; | |
8490 | + p--; | |
8491 | + } | |
8492 | + } | |
8493 | + | |
1facf9fc | 8494 | + dinfo->di_bwh = -1; |
5afbbe0d | 8495 | + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh)) |
1facf9fc | 8496 | + dinfo->di_bwh = bwh; |
8497 | + | |
8498 | + dinfo->di_bdiropq = -1; | |
8499 | + if (bdiropq >= 0 | |
5afbbe0d | 8500 | + && bdiropq <= au_sbbot(sb) |
1facf9fc | 8501 | + && au_sbr_whable(sb, bdiropq)) |
8502 | + dinfo->di_bdiropq = bdiropq; | |
8503 | + | |
027c5e7a | 8504 | + err = -EIO; |
5afbbe0d AM |
8505 | + dinfo->di_btop = -1; |
8506 | + dinfo->di_bbot = -1; | |
8507 | + bbot = au_dbbot(parent); | |
8508 | + bindex = 0; | |
8509 | + p = au_hdentry(dinfo, bindex); | |
8510 | + for (; bindex <= bbot; bindex++, p++) | |
1facf9fc | 8511 | + if (p->hd_dentry) { |
5afbbe0d | 8512 | + dinfo->di_btop = bindex; |
1facf9fc | 8513 | + break; |
8514 | + } | |
8515 | + | |
5afbbe0d AM |
8516 | + if (dinfo->di_btop >= 0) { |
8517 | + bindex = bbot; | |
8518 | + p = au_hdentry(dinfo, bindex); | |
8519 | + for (; bindex >= 0; bindex--, p--) | |
027c5e7a | 8520 | + if (p->hd_dentry) { |
5afbbe0d | 8521 | + dinfo->di_bbot = bindex; |
027c5e7a AM |
8522 | + err = 0; |
8523 | + break; | |
8524 | + } | |
8525 | + } | |
8526 | + | |
8527 | + return err; | |
1facf9fc | 8528 | +} |
8529 | + | |
027c5e7a | 8530 | +static void au_do_hide(struct dentry *dentry) |
1facf9fc | 8531 | +{ |
027c5e7a | 8532 | + struct inode *inode; |
1facf9fc | 8533 | + |
5527c038 JR |
8534 | + if (d_really_is_positive(dentry)) { |
8535 | + inode = d_inode(dentry); | |
8536 | + if (!d_is_dir(dentry)) { | |
027c5e7a AM |
8537 | + if (inode->i_nlink && !d_unhashed(dentry)) |
8538 | + drop_nlink(inode); | |
8539 | + } else { | |
8540 | + clear_nlink(inode); | |
8541 | + /* stop next lookup */ | |
8542 | + inode->i_flags |= S_DEAD; | |
8543 | + } | |
8544 | + smp_mb(); /* necessary? */ | |
8545 | + } | |
8546 | + d_drop(dentry); | |
8547 | +} | |
1308ab2a | 8548 | + |
027c5e7a AM |
8549 | +static int au_hide_children(struct dentry *parent) |
8550 | +{ | |
8551 | + int err, i, j, ndentry; | |
8552 | + struct au_dcsub_pages dpages; | |
8553 | + struct au_dpage *dpage; | |
8554 | + struct dentry *dentry; | |
1facf9fc | 8555 | + |
027c5e7a | 8556 | + err = au_dpages_init(&dpages, GFP_NOFS); |
1facf9fc | 8557 | + if (unlikely(err)) |
8558 | + goto out; | |
027c5e7a AM |
8559 | + err = au_dcsub_pages(&dpages, parent, NULL, NULL); |
8560 | + if (unlikely(err)) | |
8561 | + goto out_dpages; | |
1facf9fc | 8562 | + |
027c5e7a AM |
8563 | + /* in reverse order */ |
8564 | + for (i = dpages.ndpage - 1; i >= 0; i--) { | |
8565 | + dpage = dpages.dpages + i; | |
8566 | + ndentry = dpage->ndentry; | |
8567 | + for (j = ndentry - 1; j >= 0; j--) { | |
8568 | + dentry = dpage->dentries[j]; | |
8569 | + if (dentry != parent) | |
8570 | + au_do_hide(dentry); | |
8571 | + } | |
8572 | + } | |
1facf9fc | 8573 | + |
027c5e7a AM |
8574 | +out_dpages: |
8575 | + au_dpages_free(&dpages); | |
4f0767ce | 8576 | +out: |
027c5e7a | 8577 | + return err; |
1facf9fc | 8578 | +} |
8579 | + | |
027c5e7a | 8580 | +static void au_hide(struct dentry *dentry) |
1facf9fc | 8581 | +{ |
027c5e7a | 8582 | + int err; |
1facf9fc | 8583 | + |
027c5e7a | 8584 | + AuDbgDentry(dentry); |
2000de60 | 8585 | + if (d_is_dir(dentry)) { |
027c5e7a AM |
8586 | + /* shrink_dcache_parent(dentry); */ |
8587 | + err = au_hide_children(dentry); | |
8588 | + if (unlikely(err)) | |
523b37e3 AM |
8589 | + AuIOErr("%pd, failed hiding children, ignored %d\n", |
8590 | + dentry, err); | |
027c5e7a AM |
8591 | + } |
8592 | + au_do_hide(dentry); | |
8593 | +} | |
1facf9fc | 8594 | + |
027c5e7a AM |
8595 | +/* |
8596 | + * By adding a dirty branch, a cached dentry may be affected in various ways. | |
8597 | + * | |
8598 | + * a dirty branch is added | |
8599 | + * - on the top of layers | |
8600 | + * - in the middle of layers | |
8601 | + * - to the bottom of layers | |
8602 | + * | |
8603 | + * on the added branch there exists | |
8604 | + * - a whiteout | |
8605 | + * - a diropq | |
8606 | + * - a same named entry | |
8607 | + * + exist | |
8608 | + * * negative --> positive | |
8609 | + * * positive --> positive | |
8610 | + * - type is unchanged | |
8611 | + * - type is changed | |
8612 | + * + doesn't exist | |
8613 | + * * negative --> negative | |
8614 | + * * positive --> negative (rejected by au_br_del() for non-dir case) | |
8615 | + * - none | |
8616 | + */ | |
8617 | +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo, | |
8618 | + struct au_dinfo *tmp) | |
8619 | +{ | |
8620 | + int err; | |
5afbbe0d | 8621 | + aufs_bindex_t bindex, bbot; |
027c5e7a AM |
8622 | + struct { |
8623 | + struct dentry *dentry; | |
8624 | + struct inode *inode; | |
8625 | + mode_t mode; | |
be52b249 AM |
8626 | + } orig_h, tmp_h = { |
8627 | + .dentry = NULL | |
8628 | + }; | |
027c5e7a AM |
8629 | + struct au_hdentry *hd; |
8630 | + struct inode *inode, *h_inode; | |
8631 | + struct dentry *h_dentry; | |
8632 | + | |
8633 | + err = 0; | |
5afbbe0d | 8634 | + AuDebugOn(dinfo->di_btop < 0); |
027c5e7a | 8635 | + orig_h.mode = 0; |
5afbbe0d | 8636 | + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry; |
5527c038 JR |
8637 | + orig_h.inode = NULL; |
8638 | + if (d_is_positive(orig_h.dentry)) { | |
8639 | + orig_h.inode = d_inode(orig_h.dentry); | |
027c5e7a | 8640 | + orig_h.mode = orig_h.inode->i_mode & S_IFMT; |
5527c038 | 8641 | + } |
5afbbe0d AM |
8642 | + if (tmp->di_btop >= 0) { |
8643 | + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry; | |
5527c038 JR |
8644 | + if (d_is_positive(tmp_h.dentry)) { |
8645 | + tmp_h.inode = d_inode(tmp_h.dentry); | |
027c5e7a | 8646 | + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT; |
5527c038 | 8647 | + } |
027c5e7a AM |
8648 | + } |
8649 | + | |
5527c038 JR |
8650 | + inode = NULL; |
8651 | + if (d_really_is_positive(dentry)) | |
8652 | + inode = d_inode(dentry); | |
027c5e7a AM |
8653 | + if (!orig_h.inode) { |
8654 | + AuDbg("nagative originally\n"); | |
8655 | + if (inode) { | |
8656 | + au_hide(dentry); | |
8657 | + goto out; | |
8658 | + } | |
8659 | + AuDebugOn(inode); | |
5afbbe0d | 8660 | + AuDebugOn(dinfo->di_btop != dinfo->di_bbot); |
027c5e7a AM |
8661 | + AuDebugOn(dinfo->di_bdiropq != -1); |
8662 | + | |
8663 | + if (!tmp_h.inode) { | |
8664 | + AuDbg("negative --> negative\n"); | |
8665 | + /* should have only one negative lower */ | |
5afbbe0d AM |
8666 | + if (tmp->di_btop >= 0 |
8667 | + && tmp->di_btop < dinfo->di_btop) { | |
8668 | + AuDebugOn(tmp->di_btop != tmp->di_bbot); | |
8669 | + AuDebugOn(dinfo->di_btop != dinfo->di_bbot); | |
8670 | + au_set_h_dptr(dentry, dinfo->di_btop, NULL); | |
027c5e7a | 8671 | + au_di_cp(dinfo, tmp); |
5afbbe0d AM |
8672 | + hd = au_hdentry(tmp, tmp->di_btop); |
8673 | + au_set_h_dptr(dentry, tmp->di_btop, | |
027c5e7a AM |
8674 | + dget(hd->hd_dentry)); |
8675 | + } | |
8676 | + au_dbg_verify_dinode(dentry); | |
8677 | + } else { | |
8678 | + AuDbg("negative --> positive\n"); | |
8679 | + /* | |
8680 | + * similar to the behaviour of creating with bypassing | |
8681 | + * aufs. | |
8682 | + * unhash it in order to force an error in the | |
8683 | + * succeeding create operation. | |
8684 | + * we should not set S_DEAD here. | |
8685 | + */ | |
8686 | + d_drop(dentry); | |
8687 | + /* au_di_swap(tmp, dinfo); */ | |
8688 | + au_dbg_verify_dinode(dentry); | |
8689 | + } | |
8690 | + } else { | |
8691 | + AuDbg("positive originally\n"); | |
8692 | + /* inode may be NULL */ | |
8693 | + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode); | |
8694 | + if (!tmp_h.inode) { | |
8695 | + AuDbg("positive --> negative\n"); | |
8696 | + /* or bypassing aufs */ | |
8697 | + au_hide(dentry); | |
5afbbe0d | 8698 | + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop) |
027c5e7a AM |
8699 | + dinfo->di_bwh = tmp->di_bwh; |
8700 | + if (inode) | |
8701 | + err = au_refresh_hinode_self(inode); | |
8702 | + au_dbg_verify_dinode(dentry); | |
8703 | + } else if (orig_h.mode == tmp_h.mode) { | |
8704 | + AuDbg("positive --> positive, same type\n"); | |
8705 | + if (!S_ISDIR(orig_h.mode) | |
5afbbe0d | 8706 | + && dinfo->di_btop > tmp->di_btop) { |
027c5e7a AM |
8707 | + /* |
8708 | + * similar to the behaviour of removing and | |
8709 | + * creating. | |
8710 | + */ | |
8711 | + au_hide(dentry); | |
8712 | + if (inode) | |
8713 | + err = au_refresh_hinode_self(inode); | |
8714 | + au_dbg_verify_dinode(dentry); | |
8715 | + } else { | |
8716 | + /* fill empty slots */ | |
5afbbe0d AM |
8717 | + if (dinfo->di_btop > tmp->di_btop) |
8718 | + dinfo->di_btop = tmp->di_btop; | |
8719 | + if (dinfo->di_bbot < tmp->di_bbot) | |
8720 | + dinfo->di_bbot = tmp->di_bbot; | |
027c5e7a AM |
8721 | + dinfo->di_bwh = tmp->di_bwh; |
8722 | + dinfo->di_bdiropq = tmp->di_bdiropq; | |
5afbbe0d AM |
8723 | + bbot = dinfo->di_bbot; |
8724 | + bindex = tmp->di_btop; | |
8725 | + hd = au_hdentry(tmp, bindex); | |
8726 | + for (; bindex <= bbot; bindex++, hd++) { | |
027c5e7a AM |
8727 | + if (au_h_dptr(dentry, bindex)) |
8728 | + continue; | |
5afbbe0d | 8729 | + h_dentry = hd->hd_dentry; |
027c5e7a AM |
8730 | + if (!h_dentry) |
8731 | + continue; | |
5527c038 JR |
8732 | + AuDebugOn(d_is_negative(h_dentry)); |
8733 | + h_inode = d_inode(h_dentry); | |
027c5e7a AM |
8734 | + AuDebugOn(orig_h.mode |
8735 | + != (h_inode->i_mode | |
8736 | + & S_IFMT)); | |
8737 | + au_set_h_dptr(dentry, bindex, | |
8738 | + dget(h_dentry)); | |
8739 | + } | |
5afbbe0d AM |
8740 | + if (inode) |
8741 | + err = au_refresh_hinode(inode, dentry); | |
027c5e7a AM |
8742 | + au_dbg_verify_dinode(dentry); |
8743 | + } | |
8744 | + } else { | |
8745 | + AuDbg("positive --> positive, different type\n"); | |
8746 | + /* similar to the behaviour of removing and creating */ | |
8747 | + au_hide(dentry); | |
8748 | + if (inode) | |
8749 | + err = au_refresh_hinode_self(inode); | |
8750 | + au_dbg_verify_dinode(dentry); | |
8751 | + } | |
8752 | + } | |
8753 | + | |
8754 | +out: | |
8755 | + return err; | |
8756 | +} | |
8757 | + | |
79b8bda9 AM |
8758 | +void au_refresh_dop(struct dentry *dentry, int force_reval) |
8759 | +{ | |
8760 | + const struct dentry_operations *dop | |
8761 | + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op; | |
8762 | + static const unsigned int mask | |
8763 | + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE; | |
8764 | + | |
8765 | + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags)); | |
8766 | + | |
8767 | + if (dentry->d_op == dop) | |
8768 | + return; | |
8769 | + | |
8770 | + AuDbg("%pd\n", dentry); | |
8771 | + spin_lock(&dentry->d_lock); | |
8772 | + if (dop == &aufs_dop) | |
8773 | + dentry->d_flags |= mask; | |
8774 | + else | |
8775 | + dentry->d_flags &= ~mask; | |
8776 | + dentry->d_op = dop; | |
8777 | + spin_unlock(&dentry->d_lock); | |
8778 | +} | |
8779 | + | |
027c5e7a AM |
8780 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent) |
8781 | +{ | |
e2f27e51 | 8782 | + int err, ebrange, nbr; |
027c5e7a AM |
8783 | + unsigned int sigen; |
8784 | + struct au_dinfo *dinfo, *tmp; | |
8785 | + struct super_block *sb; | |
8786 | + struct inode *inode; | |
8787 | + | |
8788 | + DiMustWriteLock(dentry); | |
8789 | + AuDebugOn(IS_ROOT(dentry)); | |
5527c038 | 8790 | + AuDebugOn(d_really_is_negative(parent)); |
027c5e7a AM |
8791 | + |
8792 | + sb = dentry->d_sb; | |
027c5e7a AM |
8793 | + sigen = au_sigen(sb); |
8794 | + err = au_digen_test(parent, sigen); | |
8795 | + if (unlikely(err)) | |
8796 | + goto out; | |
8797 | + | |
e2f27e51 | 8798 | + nbr = au_sbbot(sb) + 1; |
027c5e7a | 8799 | + dinfo = au_di(dentry); |
e2f27e51 | 8800 | + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0); |
027c5e7a AM |
8801 | + if (unlikely(err)) |
8802 | + goto out; | |
8803 | + ebrange = au_dbrange_test(dentry); | |
8804 | + if (!ebrange) | |
8805 | + ebrange = au_do_refresh_hdentry(dentry, parent); | |
8806 | + | |
38d290e6 | 8807 | + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) { |
5afbbe0d | 8808 | + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0); |
5527c038 JR |
8809 | + if (d_really_is_positive(dentry)) { |
8810 | + inode = d_inode(dentry); | |
027c5e7a | 8811 | + err = au_refresh_hinode_self(inode); |
5527c038 | 8812 | + } |
027c5e7a AM |
8813 | + au_dbg_verify_dinode(dentry); |
8814 | + if (!err) | |
8815 | + goto out_dgen; /* success */ | |
8816 | + goto out; | |
8817 | + } | |
8818 | + | |
8819 | + /* temporary dinfo */ | |
8820 | + AuDbgDentry(dentry); | |
8821 | + err = -ENOMEM; | |
8822 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
8823 | + if (unlikely(!tmp)) | |
8824 | + goto out; | |
8825 | + au_di_swap(tmp, dinfo); | |
8826 | + /* returns the number of positive dentries */ | |
8827 | + /* | |
8828 | + * if current working dir is removed, it returns an error. | |
8829 | + * but the dentry is legal. | |
8830 | + */ | |
5afbbe0d | 8831 | + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG); |
027c5e7a AM |
8832 | + AuDbgDentry(dentry); |
8833 | + au_di_swap(tmp, dinfo); | |
8834 | + if (err == -ENOENT) | |
8835 | + err = 0; | |
8836 | + if (err >= 0) { | |
8837 | + /* compare/refresh by dinfo */ | |
8838 | + AuDbgDentry(dentry); | |
8839 | + err = au_refresh_by_dinfo(dentry, dinfo, tmp); | |
8840 | + au_dbg_verify_dinode(dentry); | |
8841 | + AuTraceErr(err); | |
8842 | + } | |
e2f27e51 | 8843 | + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */ |
027c5e7a AM |
8844 | + au_rw_write_unlock(&tmp->di_rwsem); |
8845 | + au_di_free(tmp); | |
8846 | + if (unlikely(err)) | |
8847 | + goto out; | |
8848 | + | |
8849 | +out_dgen: | |
8850 | + au_update_digen(dentry); | |
8851 | +out: | |
8852 | + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) { | |
523b37e3 | 8853 | + AuIOErr("failed refreshing %pd, %d\n", dentry, err); |
027c5e7a AM |
8854 | + AuDbgDentry(dentry); |
8855 | + } | |
8856 | + AuTraceErr(err); | |
8857 | + return err; | |
8858 | +} | |
8859 | + | |
b4510431 AM |
8860 | +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags, |
8861 | + struct dentry *dentry, aufs_bindex_t bindex) | |
027c5e7a AM |
8862 | +{ |
8863 | + int err, valid; | |
027c5e7a AM |
8864 | + |
8865 | + err = 0; | |
8866 | + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE)) | |
8867 | + goto out; | |
027c5e7a AM |
8868 | + |
8869 | + AuDbg("b%d\n", bindex); | |
b4510431 AM |
8870 | + /* |
8871 | + * gave up supporting LOOKUP_CREATE/OPEN for lower fs, | |
8872 | + * due to whiteout and branch permission. | |
8873 | + */ | |
8874 | + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE | |
8875 | + | LOOKUP_FOLLOW | LOOKUP_EXCL); | |
8876 | + /* it may return tri-state */ | |
8877 | + valid = h_dentry->d_op->d_revalidate(h_dentry, flags); | |
1facf9fc | 8878 | + |
8879 | + if (unlikely(valid < 0)) | |
8880 | + err = valid; | |
8881 | + else if (!valid) | |
8882 | + err = -EINVAL; | |
8883 | + | |
4f0767ce | 8884 | +out: |
1facf9fc | 8885 | + AuTraceErr(err); |
8886 | + return err; | |
8887 | +} | |
8888 | + | |
8889 | +/* todo: remove this */ | |
8890 | +static int h_d_revalidate(struct dentry *dentry, struct inode *inode, | |
8b6a4947 | 8891 | + unsigned int flags, int do_udba, int dirren) |
1facf9fc | 8892 | +{ |
8893 | + int err; | |
8894 | + umode_t mode, h_mode; | |
5afbbe0d | 8895 | + aufs_bindex_t bindex, btail, btop, ibs, ibe; |
38d290e6 | 8896 | + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile; |
4a4d8108 | 8897 | + struct inode *h_inode, *h_cached_inode; |
1facf9fc | 8898 | + struct dentry *h_dentry; |
8899 | + struct qstr *name, *h_name; | |
8900 | + | |
8901 | + err = 0; | |
8902 | + plus = 0; | |
8903 | + mode = 0; | |
1facf9fc | 8904 | + ibs = -1; |
8905 | + ibe = -1; | |
8906 | + unhashed = !!d_unhashed(dentry); | |
8907 | + is_root = !!IS_ROOT(dentry); | |
8908 | + name = &dentry->d_name; | |
38d290e6 | 8909 | + tmpfile = au_di(dentry)->di_tmpfile; |
1facf9fc | 8910 | + |
8911 | + /* | |
7f207e10 AM |
8912 | + * Theoretically, REVAL test should be unnecessary in case of |
8913 | + * {FS,I}NOTIFY. | |
8914 | + * But {fs,i}notify doesn't fire some necessary events, | |
1facf9fc | 8915 | + * IN_ATTRIB for atime/nlink/pageio |
1facf9fc | 8916 | + * Let's do REVAL test too. |
8917 | + */ | |
8918 | + if (do_udba && inode) { | |
8919 | + mode = (inode->i_mode & S_IFMT); | |
8920 | + plus = (inode->i_nlink > 0); | |
5afbbe0d AM |
8921 | + ibs = au_ibtop(inode); |
8922 | + ibe = au_ibbot(inode); | |
1facf9fc | 8923 | + } |
8924 | + | |
5afbbe0d AM |
8925 | + btop = au_dbtop(dentry); |
8926 | + btail = btop; | |
1facf9fc | 8927 | + if (inode && S_ISDIR(inode->i_mode)) |
8928 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 8929 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 8930 | + h_dentry = au_h_dptr(dentry, bindex); |
8931 | + if (!h_dentry) | |
8932 | + continue; | |
8933 | + | |
523b37e3 AM |
8934 | + AuDbg("b%d, %pd\n", bindex, h_dentry); |
8935 | + h_nfs = !!au_test_nfs(h_dentry->d_sb); | |
027c5e7a | 8936 | + spin_lock(&h_dentry->d_lock); |
1facf9fc | 8937 | + h_name = &h_dentry->d_name; |
8938 | + if (unlikely(do_udba | |
8939 | + && !is_root | |
523b37e3 AM |
8940 | + && ((!h_nfs |
8941 | + && (unhashed != !!d_unhashed(h_dentry) | |
8b6a4947 | 8942 | + || (!tmpfile && !dirren |
38d290e6 JR |
8943 | + && !au_qstreq(name, h_name)) |
8944 | + )) | |
523b37e3 AM |
8945 | + || (h_nfs |
8946 | + && !(flags & LOOKUP_OPEN) | |
8947 | + && (h_dentry->d_flags | |
8948 | + & DCACHE_NFSFS_RENAMED))) | |
1facf9fc | 8949 | + )) { |
38d290e6 JR |
8950 | + int h_unhashed; |
8951 | + | |
8952 | + h_unhashed = d_unhashed(h_dentry); | |
027c5e7a | 8953 | + spin_unlock(&h_dentry->d_lock); |
38d290e6 JR |
8954 | + AuDbg("unhash 0x%x 0x%x, %pd %pd\n", |
8955 | + unhashed, h_unhashed, dentry, h_dentry); | |
1facf9fc | 8956 | + goto err; |
8957 | + } | |
027c5e7a | 8958 | + spin_unlock(&h_dentry->d_lock); |
1facf9fc | 8959 | + |
b4510431 | 8960 | + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex); |
1facf9fc | 8961 | + if (unlikely(err)) |
8962 | + /* do not goto err, to keep the errno */ | |
8963 | + break; | |
8964 | + | |
8965 | + /* todo: plink too? */ | |
8966 | + if (!do_udba) | |
8967 | + continue; | |
8968 | + | |
8969 | + /* UDBA tests */ | |
5527c038 | 8970 | + if (unlikely(!!inode != d_is_positive(h_dentry))) |
1facf9fc | 8971 | + goto err; |
8972 | + | |
5527c038 JR |
8973 | + h_inode = NULL; |
8974 | + if (d_is_positive(h_dentry)) | |
8975 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8976 | + h_plus = plus; |
8977 | + h_mode = mode; | |
8978 | + h_cached_inode = h_inode; | |
8979 | + if (h_inode) { | |
8980 | + h_mode = (h_inode->i_mode & S_IFMT); | |
8981 | + h_plus = (h_inode->i_nlink > 0); | |
8982 | + } | |
8983 | + if (inode && ibs <= bindex && bindex <= ibe) | |
8984 | + h_cached_inode = au_h_iptr(inode, bindex); | |
8985 | + | |
523b37e3 | 8986 | + if (!h_nfs) { |
38d290e6 | 8987 | + if (unlikely(plus != h_plus && !tmpfile)) |
523b37e3 AM |
8988 | + goto err; |
8989 | + } else { | |
8990 | + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED) | |
8991 | + && !is_root | |
8992 | + && !IS_ROOT(h_dentry) | |
8993 | + && unhashed != d_unhashed(h_dentry))) | |
8994 | + goto err; | |
8995 | + } | |
8996 | + if (unlikely(mode != h_mode | |
1facf9fc | 8997 | + || h_cached_inode != h_inode)) |
8998 | + goto err; | |
8999 | + continue; | |
9000 | + | |
f6b6e03d | 9001 | +err: |
1facf9fc | 9002 | + err = -EINVAL; |
9003 | + break; | |
9004 | + } | |
9005 | + | |
523b37e3 | 9006 | + AuTraceErr(err); |
1facf9fc | 9007 | + return err; |
9008 | +} | |
9009 | + | |
027c5e7a | 9010 | +/* todo: consolidate with do_refresh() and au_reval_for_attr() */ |
1facf9fc | 9011 | +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen) |
9012 | +{ | |
9013 | + int err; | |
9014 | + struct dentry *parent; | |
1facf9fc | 9015 | + |
027c5e7a | 9016 | + if (!au_digen_test(dentry, sigen)) |
1facf9fc | 9017 | + return 0; |
9018 | + | |
9019 | + parent = dget_parent(dentry); | |
9020 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 9021 | + AuDebugOn(au_digen_test(parent, sigen)); |
1facf9fc | 9022 | + au_dbg_verify_gen(parent, sigen); |
027c5e7a | 9023 | + err = au_refresh_dentry(dentry, parent); |
1facf9fc | 9024 | + di_read_unlock(parent, AuLock_IR); |
9025 | + dput(parent); | |
027c5e7a | 9026 | + AuTraceErr(err); |
1facf9fc | 9027 | + return err; |
9028 | +} | |
9029 | + | |
9030 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen) | |
9031 | +{ | |
9032 | + int err; | |
9033 | + struct dentry *d, *parent; | |
1facf9fc | 9034 | + |
027c5e7a | 9035 | + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR)) |
1facf9fc | 9036 | + return simple_reval_dpath(dentry, sigen); |
9037 | + | |
9038 | + /* slow loop, keep it simple and stupid */ | |
9039 | + /* cf: au_cpup_dirs() */ | |
9040 | + err = 0; | |
9041 | + parent = NULL; | |
027c5e7a | 9042 | + while (au_digen_test(dentry, sigen)) { |
1facf9fc | 9043 | + d = dentry; |
9044 | + while (1) { | |
9045 | + dput(parent); | |
9046 | + parent = dget_parent(d); | |
027c5e7a | 9047 | + if (!au_digen_test(parent, sigen)) |
1facf9fc | 9048 | + break; |
9049 | + d = parent; | |
9050 | + } | |
9051 | + | |
1facf9fc | 9052 | + if (d != dentry) |
027c5e7a | 9053 | + di_write_lock_child2(d); |
1facf9fc | 9054 | + |
9055 | + /* someone might update our dentry while we were sleeping */ | |
027c5e7a AM |
9056 | + if (au_digen_test(d, sigen)) { |
9057 | + /* | |
9058 | + * todo: consolidate with simple_reval_dpath(), | |
9059 | + * do_refresh() and au_reval_for_attr(). | |
9060 | + */ | |
1facf9fc | 9061 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a | 9062 | + err = au_refresh_dentry(d, parent); |
1facf9fc | 9063 | + di_read_unlock(parent, AuLock_IR); |
9064 | + } | |
9065 | + | |
9066 | + if (d != dentry) | |
9067 | + di_write_unlock(d); | |
9068 | + dput(parent); | |
9069 | + if (unlikely(err)) | |
9070 | + break; | |
9071 | + } | |
9072 | + | |
9073 | + return err; | |
9074 | +} | |
9075 | + | |
9076 | +/* | |
9077 | + * if valid returns 1, otherwise 0. | |
9078 | + */ | |
b4510431 | 9079 | +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags) |
1facf9fc | 9080 | +{ |
9081 | + int valid, err; | |
9082 | + unsigned int sigen; | |
8b6a4947 | 9083 | + unsigned char do_udba, dirren; |
1facf9fc | 9084 | + struct super_block *sb; |
9085 | + struct inode *inode; | |
9086 | + | |
027c5e7a | 9087 | + /* todo: support rcu-walk? */ |
b4510431 | 9088 | + if (flags & LOOKUP_RCU) |
027c5e7a AM |
9089 | + return -ECHILD; |
9090 | + | |
9091 | + valid = 0; | |
9092 | + if (unlikely(!au_di(dentry))) | |
9093 | + goto out; | |
9094 | + | |
e49829fe | 9095 | + valid = 1; |
1facf9fc | 9096 | + sb = dentry->d_sb; |
e49829fe JR |
9097 | + /* |
9098 | + * todo: very ugly | |
9099 | + * i_mutex of parent dir may be held, | |
9100 | + * but we should not return 'invalid' due to busy. | |
9101 | + */ | |
9102 | + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM); | |
9103 | + if (unlikely(err)) { | |
9104 | + valid = err; | |
027c5e7a | 9105 | + AuTraceErr(err); |
e49829fe JR |
9106 | + goto out; |
9107 | + } | |
5527c038 JR |
9108 | + inode = NULL; |
9109 | + if (d_really_is_positive(dentry)) | |
9110 | + inode = d_inode(dentry); | |
5afbbe0d | 9111 | + if (unlikely(inode && au_is_bad_inode(inode))) { |
c1595e42 JR |
9112 | + err = -EINVAL; |
9113 | + AuTraceErr(err); | |
9114 | + goto out_dgrade; | |
9115 | + } | |
027c5e7a AM |
9116 | + if (unlikely(au_dbrange_test(dentry))) { |
9117 | + err = -EINVAL; | |
9118 | + AuTraceErr(err); | |
9119 | + goto out_dgrade; | |
1facf9fc | 9120 | + } |
027c5e7a AM |
9121 | + |
9122 | + sigen = au_sigen(sb); | |
9123 | + if (au_digen_test(dentry, sigen)) { | |
1facf9fc | 9124 | + AuDebugOn(IS_ROOT(dentry)); |
027c5e7a AM |
9125 | + err = au_reval_dpath(dentry, sigen); |
9126 | + if (unlikely(err)) { | |
9127 | + AuTraceErr(err); | |
1facf9fc | 9128 | + goto out_dgrade; |
027c5e7a | 9129 | + } |
1facf9fc | 9130 | + } |
9131 | + di_downgrade_lock(dentry, AuLock_IR); | |
9132 | + | |
1facf9fc | 9133 | + err = -EINVAL; |
c1595e42 | 9134 | + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY)) |
523b37e3 | 9135 | + && inode |
38d290e6 | 9136 | + && !(inode->i_state && I_LINKABLE) |
79b8bda9 AM |
9137 | + && (IS_DEADDIR(inode) || !inode->i_nlink)) { |
9138 | + AuTraceErr(err); | |
027c5e7a | 9139 | + goto out_inval; |
79b8bda9 | 9140 | + } |
027c5e7a | 9141 | + |
1facf9fc | 9142 | + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE); |
9143 | + if (do_udba && inode) { | |
5afbbe0d | 9144 | + aufs_bindex_t btop = au_ibtop(inode); |
027c5e7a | 9145 | + struct inode *h_inode; |
1facf9fc | 9146 | + |
5afbbe0d AM |
9147 | + if (btop >= 0) { |
9148 | + h_inode = au_h_iptr(inode, btop); | |
79b8bda9 AM |
9149 | + if (h_inode && au_test_higen(inode, h_inode)) { |
9150 | + AuTraceErr(err); | |
027c5e7a | 9151 | + goto out_inval; |
79b8bda9 | 9152 | + } |
027c5e7a | 9153 | + } |
1facf9fc | 9154 | + } |
9155 | + | |
8b6a4947 AM |
9156 | + dirren = !!au_opt_test(au_mntflags(sb), DIRREN); |
9157 | + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren); | |
5afbbe0d | 9158 | + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) { |
1facf9fc | 9159 | + err = -EIO; |
523b37e3 AM |
9160 | + AuDbg("both of real entry and whiteout found, %p, err %d\n", |
9161 | + dentry, err); | |
027c5e7a | 9162 | + } |
e49829fe | 9163 | + goto out_inval; |
1facf9fc | 9164 | + |
4f0767ce | 9165 | +out_dgrade: |
1facf9fc | 9166 | + di_downgrade_lock(dentry, AuLock_IR); |
e49829fe | 9167 | +out_inval: |
1facf9fc | 9168 | + aufs_read_unlock(dentry, AuLock_IR); |
9169 | + AuTraceErr(err); | |
9170 | + valid = !err; | |
e49829fe | 9171 | +out: |
027c5e7a | 9172 | + if (!valid) { |
523b37e3 | 9173 | + AuDbg("%pd invalid, %d\n", dentry, valid); |
027c5e7a AM |
9174 | + d_drop(dentry); |
9175 | + } | |
1facf9fc | 9176 | + return valid; |
9177 | +} | |
9178 | + | |
9179 | +static void aufs_d_release(struct dentry *dentry) | |
9180 | +{ | |
027c5e7a | 9181 | + if (au_di(dentry)) { |
4a4d8108 AM |
9182 | + au_di_fin(dentry); |
9183 | + au_hn_di_reinit(dentry); | |
1facf9fc | 9184 | + } |
1facf9fc | 9185 | +} |
9186 | + | |
4a4d8108 | 9187 | +const struct dentry_operations aufs_dop = { |
c06a8ce3 AM |
9188 | + .d_revalidate = aufs_d_revalidate, |
9189 | + .d_weak_revalidate = aufs_d_revalidate, | |
9190 | + .d_release = aufs_d_release | |
1facf9fc | 9191 | +}; |
79b8bda9 AM |
9192 | + |
9193 | +/* aufs_dop without d_revalidate */ | |
9194 | +const struct dentry_operations aufs_dop_noreval = { | |
9195 | + .d_release = aufs_d_release | |
9196 | +}; | |
7f207e10 AM |
9197 | diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h |
9198 | --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 9199 | +++ linux/fs/aufs/dentry.h 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 | 9200 | @@ -0,0 +1,266 @@ |
1facf9fc | 9201 | +/* |
a2654f78 | 9202 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 9203 | + * |
9204 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9205 | + * it under the terms of the GNU General Public License as published by | |
9206 | + * the Free Software Foundation; either version 2 of the License, or | |
9207 | + * (at your option) any later version. | |
dece6358 AM |
9208 | + * |
9209 | + * This program is distributed in the hope that it will be useful, | |
9210 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9211 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9212 | + * GNU General Public License for more details. | |
9213 | + * | |
9214 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9215 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9216 | + */ |
9217 | + | |
9218 | +/* | |
9219 | + * lookup and dentry operations | |
9220 | + */ | |
9221 | + | |
9222 | +#ifndef __AUFS_DENTRY_H__ | |
9223 | +#define __AUFS_DENTRY_H__ | |
9224 | + | |
9225 | +#ifdef __KERNEL__ | |
9226 | + | |
dece6358 | 9227 | +#include <linux/dcache.h> |
8b6a4947 | 9228 | +#include "dirren.h" |
1facf9fc | 9229 | +#include "rwsem.h" |
9230 | + | |
1facf9fc | 9231 | +struct au_hdentry { |
9232 | + struct dentry *hd_dentry; | |
027c5e7a | 9233 | + aufs_bindex_t hd_id; |
1facf9fc | 9234 | +}; |
9235 | + | |
9236 | +struct au_dinfo { | |
9237 | + atomic_t di_generation; | |
9238 | + | |
dece6358 | 9239 | + struct au_rwsem di_rwsem; |
5afbbe0d | 9240 | + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq; |
38d290e6 | 9241 | + unsigned char di_tmpfile; /* to allow the different name */ |
1c60b727 | 9242 | + struct au_hdentry *di_hdentry; |
4a4d8108 | 9243 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 9244 | + |
9245 | +/* ---------------------------------------------------------------------- */ | |
9246 | + | |
5afbbe0d AM |
9247 | +/* flags for au_lkup_dentry() */ |
9248 | +#define AuLkup_ALLOW_NEG 1 | |
9249 | +#define AuLkup_IGNORE_PERM (1 << 1) | |
8b6a4947 | 9250 | +#define AuLkup_DIRREN (1 << 2) |
5afbbe0d AM |
9251 | +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name) |
9252 | +#define au_fset_lkup(flags, name) \ | |
9253 | + do { (flags) |= AuLkup_##name; } while (0) | |
9254 | +#define au_fclr_lkup(flags, name) \ | |
9255 | + do { (flags) &= ~AuLkup_##name; } while (0) | |
9256 | + | |
8b6a4947 AM |
9257 | +#ifndef CONFIG_AUFS_DIRREN |
9258 | +#undef AuLkup_DIRREN | |
9259 | +#define AuLkup_DIRREN 0 | |
9260 | +#endif | |
9261 | + | |
9262 | +struct au_do_lookup_args { | |
9263 | + unsigned int flags; | |
9264 | + mode_t type; | |
9265 | + struct qstr whname, *name; | |
9266 | + struct au_dr_lookup dirren; | |
9267 | +}; | |
9268 | + | |
5afbbe0d AM |
9269 | +/* ---------------------------------------------------------------------- */ |
9270 | + | |
1facf9fc | 9271 | +/* dentry.c */ |
79b8bda9 | 9272 | +extern const struct dentry_operations aufs_dop, aufs_dop_noreval; |
1facf9fc | 9273 | +struct au_branch; |
076b876e | 9274 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent); |
1facf9fc | 9275 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, |
9276 | + struct dentry *h_parent, struct au_branch *br); | |
9277 | + | |
5afbbe0d AM |
9278 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop, |
9279 | + unsigned int flags); | |
86dc4139 | 9280 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh); |
027c5e7a | 9281 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent); |
1facf9fc | 9282 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen); |
79b8bda9 | 9283 | +void au_refresh_dop(struct dentry *dentry, int force_reval); |
1facf9fc | 9284 | + |
9285 | +/* dinfo.c */ | |
4a4d8108 | 9286 | +void au_di_init_once(void *_di); |
027c5e7a AM |
9287 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc); |
9288 | +void au_di_free(struct au_dinfo *dinfo); | |
9289 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b); | |
9290 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src); | |
4a4d8108 AM |
9291 | +int au_di_init(struct dentry *dentry); |
9292 | +void au_di_fin(struct dentry *dentry); | |
e2f27e51 | 9293 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink); |
1facf9fc | 9294 | + |
9295 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc); | |
9296 | +void di_read_unlock(struct dentry *d, int flags); | |
9297 | +void di_downgrade_lock(struct dentry *d, int flags); | |
9298 | +void di_write_lock(struct dentry *d, unsigned int lsc); | |
9299 | +void di_write_unlock(struct dentry *d); | |
9300 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir); | |
9301 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir); | |
9302 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2); | |
9303 | + | |
9304 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex); | |
2cbb1c4b | 9305 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex); |
1facf9fc | 9306 | +aufs_bindex_t au_dbtail(struct dentry *dentry); |
9307 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry); | |
9308 | + | |
9309 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9310 | + struct dentry *h_dentry); | |
027c5e7a AM |
9311 | +int au_digen_test(struct dentry *dentry, unsigned int sigen); |
9312 | +int au_dbrange_test(struct dentry *dentry); | |
1facf9fc | 9313 | +void au_update_digen(struct dentry *dentry); |
9314 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero); | |
5afbbe0d AM |
9315 | +void au_update_dbtop(struct dentry *dentry); |
9316 | +void au_update_dbbot(struct dentry *dentry); | |
1facf9fc | 9317 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry); |
9318 | + | |
9319 | +/* ---------------------------------------------------------------------- */ | |
9320 | + | |
9321 | +static inline struct au_dinfo *au_di(struct dentry *dentry) | |
9322 | +{ | |
9323 | + return dentry->d_fsdata; | |
9324 | +} | |
9325 | + | |
9326 | +/* ---------------------------------------------------------------------- */ | |
9327 | + | |
9328 | +/* lock subclass for dinfo */ | |
9329 | +enum { | |
9330 | + AuLsc_DI_CHILD, /* child first */ | |
4a4d8108 | 9331 | + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */ |
1facf9fc | 9332 | + AuLsc_DI_CHILD3, /* copyup dirs */ |
9333 | + AuLsc_DI_PARENT, | |
9334 | + AuLsc_DI_PARENT2, | |
027c5e7a AM |
9335 | + AuLsc_DI_PARENT3, |
9336 | + AuLsc_DI_TMP /* temp for replacing dinfo */ | |
1facf9fc | 9337 | +}; |
9338 | + | |
9339 | +/* | |
9340 | + * di_read_lock_child, di_write_lock_child, | |
9341 | + * di_read_lock_child2, di_write_lock_child2, | |
9342 | + * di_read_lock_child3, di_write_lock_child3, | |
9343 | + * di_read_lock_parent, di_write_lock_parent, | |
9344 | + * di_read_lock_parent2, di_write_lock_parent2, | |
9345 | + * di_read_lock_parent3, di_write_lock_parent3, | |
9346 | + */ | |
9347 | +#define AuReadLockFunc(name, lsc) \ | |
9348 | +static inline void di_read_lock_##name(struct dentry *d, int flags) \ | |
9349 | +{ di_read_lock(d, flags, AuLsc_DI_##lsc); } | |
9350 | + | |
9351 | +#define AuWriteLockFunc(name, lsc) \ | |
9352 | +static inline void di_write_lock_##name(struct dentry *d) \ | |
9353 | +{ di_write_lock(d, AuLsc_DI_##lsc); } | |
9354 | + | |
9355 | +#define AuRWLockFuncs(name, lsc) \ | |
9356 | + AuReadLockFunc(name, lsc) \ | |
9357 | + AuWriteLockFunc(name, lsc) | |
9358 | + | |
9359 | +AuRWLockFuncs(child, CHILD); | |
9360 | +AuRWLockFuncs(child2, CHILD2); | |
9361 | +AuRWLockFuncs(child3, CHILD3); | |
9362 | +AuRWLockFuncs(parent, PARENT); | |
9363 | +AuRWLockFuncs(parent2, PARENT2); | |
9364 | +AuRWLockFuncs(parent3, PARENT3); | |
9365 | + | |
9366 | +#undef AuReadLockFunc | |
9367 | +#undef AuWriteLockFunc | |
9368 | +#undef AuRWLockFuncs | |
9369 | + | |
9370 | +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem) | |
dece6358 AM |
9371 | +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem) |
9372 | +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem) | |
1facf9fc | 9373 | + |
9374 | +/* ---------------------------------------------------------------------- */ | |
9375 | + | |
9376 | +/* todo: memory barrier? */ | |
9377 | +static inline unsigned int au_digen(struct dentry *d) | |
9378 | +{ | |
9379 | + return atomic_read(&au_di(d)->di_generation); | |
9380 | +} | |
9381 | + | |
9382 | +static inline void au_h_dentry_init(struct au_hdentry *hdentry) | |
9383 | +{ | |
9384 | + hdentry->hd_dentry = NULL; | |
9385 | +} | |
9386 | + | |
5afbbe0d AM |
9387 | +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di, |
9388 | + aufs_bindex_t bindex) | |
9389 | +{ | |
9390 | + return di->di_hdentry + bindex; | |
9391 | +} | |
9392 | + | |
1facf9fc | 9393 | +static inline void au_hdput(struct au_hdentry *hd) |
9394 | +{ | |
4a4d8108 AM |
9395 | + if (hd) |
9396 | + dput(hd->hd_dentry); | |
1facf9fc | 9397 | +} |
9398 | + | |
5afbbe0d | 9399 | +static inline aufs_bindex_t au_dbtop(struct dentry *dentry) |
1facf9fc | 9400 | +{ |
1308ab2a | 9401 | + DiMustAnyLock(dentry); |
5afbbe0d | 9402 | + return au_di(dentry)->di_btop; |
1facf9fc | 9403 | +} |
9404 | + | |
5afbbe0d | 9405 | +static inline aufs_bindex_t au_dbbot(struct dentry *dentry) |
1facf9fc | 9406 | +{ |
1308ab2a | 9407 | + DiMustAnyLock(dentry); |
5afbbe0d | 9408 | + return au_di(dentry)->di_bbot; |
1facf9fc | 9409 | +} |
9410 | + | |
9411 | +static inline aufs_bindex_t au_dbwh(struct dentry *dentry) | |
9412 | +{ | |
1308ab2a | 9413 | + DiMustAnyLock(dentry); |
1facf9fc | 9414 | + return au_di(dentry)->di_bwh; |
9415 | +} | |
9416 | + | |
9417 | +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry) | |
9418 | +{ | |
1308ab2a | 9419 | + DiMustAnyLock(dentry); |
1facf9fc | 9420 | + return au_di(dentry)->di_bdiropq; |
9421 | +} | |
9422 | + | |
9423 | +/* todo: hard/soft set? */ | |
5afbbe0d | 9424 | +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex) |
1facf9fc | 9425 | +{ |
1308ab2a | 9426 | + DiMustWriteLock(dentry); |
5afbbe0d | 9427 | + au_di(dentry)->di_btop = bindex; |
1facf9fc | 9428 | +} |
9429 | + | |
5afbbe0d | 9430 | +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex) |
1facf9fc | 9431 | +{ |
1308ab2a | 9432 | + DiMustWriteLock(dentry); |
5afbbe0d | 9433 | + au_di(dentry)->di_bbot = bindex; |
1facf9fc | 9434 | +} |
9435 | + | |
9436 | +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex) | |
9437 | +{ | |
1308ab2a | 9438 | + DiMustWriteLock(dentry); |
5afbbe0d | 9439 | + /* dbwh can be outside of btop - bbot range */ |
1facf9fc | 9440 | + au_di(dentry)->di_bwh = bindex; |
9441 | +} | |
9442 | + | |
9443 | +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex) | |
9444 | +{ | |
1308ab2a | 9445 | + DiMustWriteLock(dentry); |
1facf9fc | 9446 | + au_di(dentry)->di_bdiropq = bindex; |
9447 | +} | |
9448 | + | |
9449 | +/* ---------------------------------------------------------------------- */ | |
9450 | + | |
4a4d8108 | 9451 | +#ifdef CONFIG_AUFS_HNOTIFY |
1facf9fc | 9452 | +static inline void au_digen_dec(struct dentry *d) |
9453 | +{ | |
e49829fe | 9454 | + atomic_dec(&au_di(d)->di_generation); |
1facf9fc | 9455 | +} |
9456 | + | |
4a4d8108 | 9457 | +static inline void au_hn_di_reinit(struct dentry *dentry) |
1facf9fc | 9458 | +{ |
9459 | + dentry->d_fsdata = NULL; | |
9460 | +} | |
9461 | +#else | |
4a4d8108 AM |
9462 | +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused) |
9463 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
1facf9fc | 9464 | + |
9465 | +#endif /* __KERNEL__ */ | |
9466 | +#endif /* __AUFS_DENTRY_H__ */ | |
7f207e10 AM |
9467 | diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c |
9468 | --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 9469 | +++ linux/fs/aufs/dinfo.c 2018-01-29 07:56:20.053325069 +0100 |
e2f27e51 | 9470 | @@ -0,0 +1,553 @@ |
1facf9fc | 9471 | +/* |
a2654f78 | 9472 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 9473 | + * |
9474 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9475 | + * it under the terms of the GNU General Public License as published by | |
9476 | + * the Free Software Foundation; either version 2 of the License, or | |
9477 | + * (at your option) any later version. | |
dece6358 AM |
9478 | + * |
9479 | + * This program is distributed in the hope that it will be useful, | |
9480 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9481 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9482 | + * GNU General Public License for more details. | |
9483 | + * | |
9484 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9485 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9486 | + */ |
9487 | + | |
9488 | +/* | |
9489 | + * dentry private data | |
9490 | + */ | |
9491 | + | |
9492 | +#include "aufs.h" | |
9493 | + | |
e49829fe | 9494 | +void au_di_init_once(void *_dinfo) |
4a4d8108 | 9495 | +{ |
e49829fe | 9496 | + struct au_dinfo *dinfo = _dinfo; |
4a4d8108 | 9497 | + |
e49829fe | 9498 | + au_rw_init(&dinfo->di_rwsem); |
4a4d8108 AM |
9499 | +} |
9500 | + | |
027c5e7a | 9501 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc) |
1facf9fc | 9502 | +{ |
9503 | + struct au_dinfo *dinfo; | |
027c5e7a | 9504 | + int nbr, i; |
1facf9fc | 9505 | + |
9506 | + dinfo = au_cache_alloc_dinfo(); | |
9507 | + if (unlikely(!dinfo)) | |
9508 | + goto out; | |
9509 | + | |
5afbbe0d | 9510 | + nbr = au_sbbot(sb) + 1; |
1facf9fc | 9511 | + if (nbr <= 0) |
9512 | + nbr = 1; | |
9513 | + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS); | |
027c5e7a AM |
9514 | + if (dinfo->di_hdentry) { |
9515 | + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc); | |
5afbbe0d AM |
9516 | + dinfo->di_btop = -1; |
9517 | + dinfo->di_bbot = -1; | |
027c5e7a AM |
9518 | + dinfo->di_bwh = -1; |
9519 | + dinfo->di_bdiropq = -1; | |
38d290e6 | 9520 | + dinfo->di_tmpfile = 0; |
027c5e7a AM |
9521 | + for (i = 0; i < nbr; i++) |
9522 | + dinfo->di_hdentry[i].hd_id = -1; | |
9523 | + goto out; | |
9524 | + } | |
1facf9fc | 9525 | + |
1c60b727 | 9526 | + au_cache_free_dinfo(dinfo); |
027c5e7a AM |
9527 | + dinfo = NULL; |
9528 | + | |
4f0767ce | 9529 | +out: |
027c5e7a | 9530 | + return dinfo; |
1facf9fc | 9531 | +} |
9532 | + | |
027c5e7a | 9533 | +void au_di_free(struct au_dinfo *dinfo) |
4a4d8108 | 9534 | +{ |
4a4d8108 | 9535 | + struct au_hdentry *p; |
5afbbe0d | 9536 | + aufs_bindex_t bbot, bindex; |
4a4d8108 AM |
9537 | + |
9538 | + /* dentry may not be revalidated */ | |
5afbbe0d | 9539 | + bindex = dinfo->di_btop; |
4a4d8108 | 9540 | + if (bindex >= 0) { |
5afbbe0d AM |
9541 | + bbot = dinfo->di_bbot; |
9542 | + p = au_hdentry(dinfo, bindex); | |
9543 | + while (bindex++ <= bbot) | |
4a4d8108 AM |
9544 | + au_hdput(p++); |
9545 | + } | |
1c60b727 AM |
9546 | + kfree(dinfo->di_hdentry); |
9547 | + au_cache_free_dinfo(dinfo); | |
027c5e7a AM |
9548 | +} |
9549 | + | |
9550 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b) | |
9551 | +{ | |
9552 | + struct au_hdentry *p; | |
9553 | + aufs_bindex_t bi; | |
9554 | + | |
9555 | + AuRwMustWriteLock(&a->di_rwsem); | |
9556 | + AuRwMustWriteLock(&b->di_rwsem); | |
9557 | + | |
9558 | +#define DiSwap(v, name) \ | |
9559 | + do { \ | |
9560 | + v = a->di_##name; \ | |
9561 | + a->di_##name = b->di_##name; \ | |
9562 | + b->di_##name = v; \ | |
9563 | + } while (0) | |
9564 | + | |
9565 | + DiSwap(p, hdentry); | |
5afbbe0d AM |
9566 | + DiSwap(bi, btop); |
9567 | + DiSwap(bi, bbot); | |
027c5e7a AM |
9568 | + DiSwap(bi, bwh); |
9569 | + DiSwap(bi, bdiropq); | |
9570 | + /* smp_mb(); */ | |
9571 | + | |
9572 | +#undef DiSwap | |
9573 | +} | |
9574 | + | |
9575 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src) | |
9576 | +{ | |
9577 | + AuRwMustWriteLock(&dst->di_rwsem); | |
9578 | + AuRwMustWriteLock(&src->di_rwsem); | |
9579 | + | |
5afbbe0d AM |
9580 | + dst->di_btop = src->di_btop; |
9581 | + dst->di_bbot = src->di_bbot; | |
027c5e7a AM |
9582 | + dst->di_bwh = src->di_bwh; |
9583 | + dst->di_bdiropq = src->di_bdiropq; | |
9584 | + /* smp_mb(); */ | |
9585 | +} | |
9586 | + | |
9587 | +int au_di_init(struct dentry *dentry) | |
9588 | +{ | |
9589 | + int err; | |
9590 | + struct super_block *sb; | |
9591 | + struct au_dinfo *dinfo; | |
9592 | + | |
9593 | + err = 0; | |
9594 | + sb = dentry->d_sb; | |
9595 | + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD); | |
9596 | + if (dinfo) { | |
9597 | + atomic_set(&dinfo->di_generation, au_sigen(sb)); | |
9598 | + /* smp_mb(); */ /* atomic_set */ | |
9599 | + dentry->d_fsdata = dinfo; | |
9600 | + } else | |
9601 | + err = -ENOMEM; | |
9602 | + | |
9603 | + return err; | |
9604 | +} | |
9605 | + | |
9606 | +void au_di_fin(struct dentry *dentry) | |
9607 | +{ | |
9608 | + struct au_dinfo *dinfo; | |
9609 | + | |
9610 | + dinfo = au_di(dentry); | |
9611 | + AuRwDestroy(&dinfo->di_rwsem); | |
9612 | + au_di_free(dinfo); | |
4a4d8108 AM |
9613 | +} |
9614 | + | |
e2f27e51 | 9615 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink) |
1facf9fc | 9616 | +{ |
9617 | + int err, sz; | |
9618 | + struct au_hdentry *hdp; | |
9619 | + | |
1308ab2a | 9620 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
9621 | + | |
1facf9fc | 9622 | + err = -ENOMEM; |
5afbbe0d | 9623 | + sz = sizeof(*hdp) * (dinfo->di_bbot + 1); |
1facf9fc | 9624 | + if (!sz) |
9625 | + sz = sizeof(*hdp); | |
e2f27e51 AM |
9626 | + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS, |
9627 | + may_shrink); | |
1facf9fc | 9628 | + if (hdp) { |
9629 | + dinfo->di_hdentry = hdp; | |
9630 | + err = 0; | |
9631 | + } | |
9632 | + | |
9633 | + return err; | |
9634 | +} | |
9635 | + | |
9636 | +/* ---------------------------------------------------------------------- */ | |
9637 | + | |
9638 | +static void do_ii_write_lock(struct inode *inode, unsigned int lsc) | |
9639 | +{ | |
9640 | + switch (lsc) { | |
9641 | + case AuLsc_DI_CHILD: | |
9642 | + ii_write_lock_child(inode); | |
9643 | + break; | |
9644 | + case AuLsc_DI_CHILD2: | |
9645 | + ii_write_lock_child2(inode); | |
9646 | + break; | |
9647 | + case AuLsc_DI_CHILD3: | |
9648 | + ii_write_lock_child3(inode); | |
9649 | + break; | |
9650 | + case AuLsc_DI_PARENT: | |
9651 | + ii_write_lock_parent(inode); | |
9652 | + break; | |
9653 | + case AuLsc_DI_PARENT2: | |
9654 | + ii_write_lock_parent2(inode); | |
9655 | + break; | |
9656 | + case AuLsc_DI_PARENT3: | |
9657 | + ii_write_lock_parent3(inode); | |
9658 | + break; | |
9659 | + default: | |
9660 | + BUG(); | |
9661 | + } | |
9662 | +} | |
9663 | + | |
9664 | +static void do_ii_read_lock(struct inode *inode, unsigned int lsc) | |
9665 | +{ | |
9666 | + switch (lsc) { | |
9667 | + case AuLsc_DI_CHILD: | |
9668 | + ii_read_lock_child(inode); | |
9669 | + break; | |
9670 | + case AuLsc_DI_CHILD2: | |
9671 | + ii_read_lock_child2(inode); | |
9672 | + break; | |
9673 | + case AuLsc_DI_CHILD3: | |
9674 | + ii_read_lock_child3(inode); | |
9675 | + break; | |
9676 | + case AuLsc_DI_PARENT: | |
9677 | + ii_read_lock_parent(inode); | |
9678 | + break; | |
9679 | + case AuLsc_DI_PARENT2: | |
9680 | + ii_read_lock_parent2(inode); | |
9681 | + break; | |
9682 | + case AuLsc_DI_PARENT3: | |
9683 | + ii_read_lock_parent3(inode); | |
9684 | + break; | |
9685 | + default: | |
9686 | + BUG(); | |
9687 | + } | |
9688 | +} | |
9689 | + | |
9690 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc) | |
9691 | +{ | |
5527c038 JR |
9692 | + struct inode *inode; |
9693 | + | |
dece6358 | 9694 | + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9695 | + if (d_really_is_positive(d)) { |
9696 | + inode = d_inode(d); | |
1facf9fc | 9697 | + if (au_ftest_lock(flags, IW)) |
5527c038 | 9698 | + do_ii_write_lock(inode, lsc); |
1facf9fc | 9699 | + else if (au_ftest_lock(flags, IR)) |
5527c038 | 9700 | + do_ii_read_lock(inode, lsc); |
1facf9fc | 9701 | + } |
9702 | +} | |
9703 | + | |
9704 | +void di_read_unlock(struct dentry *d, int flags) | |
9705 | +{ | |
5527c038 JR |
9706 | + struct inode *inode; |
9707 | + | |
9708 | + if (d_really_is_positive(d)) { | |
9709 | + inode = d_inode(d); | |
027c5e7a AM |
9710 | + if (au_ftest_lock(flags, IW)) { |
9711 | + au_dbg_verify_dinode(d); | |
5527c038 | 9712 | + ii_write_unlock(inode); |
027c5e7a AM |
9713 | + } else if (au_ftest_lock(flags, IR)) { |
9714 | + au_dbg_verify_dinode(d); | |
5527c038 | 9715 | + ii_read_unlock(inode); |
027c5e7a | 9716 | + } |
1facf9fc | 9717 | + } |
dece6358 | 9718 | + au_rw_read_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9719 | +} |
9720 | + | |
9721 | +void di_downgrade_lock(struct dentry *d, int flags) | |
9722 | +{ | |
5527c038 JR |
9723 | + if (d_really_is_positive(d) && au_ftest_lock(flags, IR)) |
9724 | + ii_downgrade_lock(d_inode(d)); | |
dece6358 | 9725 | + au_rw_dgrade_lock(&au_di(d)->di_rwsem); |
1facf9fc | 9726 | +} |
9727 | + | |
9728 | +void di_write_lock(struct dentry *d, unsigned int lsc) | |
9729 | +{ | |
dece6358 | 9730 | + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9731 | + if (d_really_is_positive(d)) |
9732 | + do_ii_write_lock(d_inode(d), lsc); | |
1facf9fc | 9733 | +} |
9734 | + | |
9735 | +void di_write_unlock(struct dentry *d) | |
9736 | +{ | |
027c5e7a | 9737 | + au_dbg_verify_dinode(d); |
5527c038 JR |
9738 | + if (d_really_is_positive(d)) |
9739 | + ii_write_unlock(d_inode(d)); | |
dece6358 | 9740 | + au_rw_write_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9741 | +} |
9742 | + | |
9743 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir) | |
9744 | +{ | |
9745 | + AuDebugOn(d1 == d2 | |
5527c038 | 9746 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9747 | + || d1->d_sb != d2->d_sb); |
9748 | + | |
521ced18 JR |
9749 | + if ((isdir && au_test_subdir(d1, d2)) |
9750 | + || d1 < d2) { | |
1facf9fc | 9751 | + di_write_lock_child(d1); |
9752 | + di_write_lock_child2(d2); | |
9753 | + } else { | |
1facf9fc | 9754 | + di_write_lock_child(d2); |
9755 | + di_write_lock_child2(d1); | |
9756 | + } | |
9757 | +} | |
9758 | + | |
9759 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir) | |
9760 | +{ | |
9761 | + AuDebugOn(d1 == d2 | |
5527c038 | 9762 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9763 | + || d1->d_sb != d2->d_sb); |
9764 | + | |
521ced18 JR |
9765 | + if ((isdir && au_test_subdir(d1, d2)) |
9766 | + || d1 < d2) { | |
1facf9fc | 9767 | + di_write_lock_parent(d1); |
9768 | + di_write_lock_parent2(d2); | |
9769 | + } else { | |
1facf9fc | 9770 | + di_write_lock_parent(d2); |
9771 | + di_write_lock_parent2(d1); | |
9772 | + } | |
9773 | +} | |
9774 | + | |
9775 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2) | |
9776 | +{ | |
9777 | + di_write_unlock(d1); | |
5527c038 | 9778 | + if (d_inode(d1) == d_inode(d2)) |
dece6358 | 9779 | + au_rw_write_unlock(&au_di(d2)->di_rwsem); |
1facf9fc | 9780 | + else |
9781 | + di_write_unlock(d2); | |
9782 | +} | |
9783 | + | |
9784 | +/* ---------------------------------------------------------------------- */ | |
9785 | + | |
9786 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex) | |
9787 | +{ | |
9788 | + struct dentry *d; | |
9789 | + | |
1308ab2a | 9790 | + DiMustAnyLock(dentry); |
9791 | + | |
5afbbe0d | 9792 | + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry)) |
1facf9fc | 9793 | + return NULL; |
9794 | + AuDebugOn(bindex < 0); | |
5afbbe0d | 9795 | + d = au_hdentry(au_di(dentry), bindex)->hd_dentry; |
c1595e42 | 9796 | + AuDebugOn(d && au_dcount(d) <= 0); |
1facf9fc | 9797 | + return d; |
9798 | +} | |
9799 | + | |
2cbb1c4b JR |
9800 | +/* |
9801 | + * extended version of au_h_dptr(). | |
38d290e6 JR |
9802 | + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or |
9803 | + * error. | |
2cbb1c4b JR |
9804 | + */ |
9805 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex) | |
9806 | +{ | |
9807 | + struct dentry *h_dentry; | |
9808 | + struct inode *inode, *h_inode; | |
9809 | + | |
5527c038 | 9810 | + AuDebugOn(d_really_is_negative(dentry)); |
2cbb1c4b JR |
9811 | + |
9812 | + h_dentry = NULL; | |
5afbbe0d AM |
9813 | + if (au_dbtop(dentry) <= bindex |
9814 | + && bindex <= au_dbbot(dentry)) | |
2cbb1c4b | 9815 | + h_dentry = au_h_dptr(dentry, bindex); |
38d290e6 | 9816 | + if (h_dentry && !au_d_linkable(h_dentry)) { |
2cbb1c4b JR |
9817 | + dget(h_dentry); |
9818 | + goto out; /* success */ | |
9819 | + } | |
9820 | + | |
5527c038 | 9821 | + inode = d_inode(dentry); |
5afbbe0d AM |
9822 | + AuDebugOn(bindex < au_ibtop(inode)); |
9823 | + AuDebugOn(au_ibbot(inode) < bindex); | |
2cbb1c4b JR |
9824 | + h_inode = au_h_iptr(inode, bindex); |
9825 | + h_dentry = d_find_alias(h_inode); | |
9826 | + if (h_dentry) { | |
9827 | + if (!IS_ERR(h_dentry)) { | |
38d290e6 | 9828 | + if (!au_d_linkable(h_dentry)) |
2cbb1c4b JR |
9829 | + goto out; /* success */ |
9830 | + dput(h_dentry); | |
9831 | + } else | |
9832 | + goto out; | |
9833 | + } | |
9834 | + | |
9835 | + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) { | |
9836 | + h_dentry = au_plink_lkup(inode, bindex); | |
9837 | + AuDebugOn(!h_dentry); | |
9838 | + if (!IS_ERR(h_dentry)) { | |
9839 | + if (!au_d_hashed_positive(h_dentry)) | |
9840 | + goto out; /* success */ | |
9841 | + dput(h_dentry); | |
9842 | + h_dentry = NULL; | |
9843 | + } | |
9844 | + } | |
9845 | + | |
9846 | +out: | |
9847 | + AuDbgDentry(h_dentry); | |
9848 | + return h_dentry; | |
9849 | +} | |
9850 | + | |
1facf9fc | 9851 | +aufs_bindex_t au_dbtail(struct dentry *dentry) |
9852 | +{ | |
5afbbe0d | 9853 | + aufs_bindex_t bbot, bwh; |
1facf9fc | 9854 | + |
5afbbe0d AM |
9855 | + bbot = au_dbbot(dentry); |
9856 | + if (0 <= bbot) { | |
1facf9fc | 9857 | + bwh = au_dbwh(dentry); |
9858 | + if (!bwh) | |
9859 | + return bwh; | |
5afbbe0d | 9860 | + if (0 < bwh && bwh < bbot) |
1facf9fc | 9861 | + return bwh - 1; |
9862 | + } | |
5afbbe0d | 9863 | + return bbot; |
1facf9fc | 9864 | +} |
9865 | + | |
9866 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry) | |
9867 | +{ | |
5afbbe0d | 9868 | + aufs_bindex_t bbot, bopq; |
1facf9fc | 9869 | + |
5afbbe0d AM |
9870 | + bbot = au_dbtail(dentry); |
9871 | + if (0 <= bbot) { | |
1facf9fc | 9872 | + bopq = au_dbdiropq(dentry); |
5afbbe0d AM |
9873 | + if (0 <= bopq && bopq < bbot) |
9874 | + bbot = bopq; | |
1facf9fc | 9875 | + } |
5afbbe0d | 9876 | + return bbot; |
1facf9fc | 9877 | +} |
9878 | + | |
9879 | +/* ---------------------------------------------------------------------- */ | |
9880 | + | |
9881 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9882 | + struct dentry *h_dentry) | |
9883 | +{ | |
5afbbe0d AM |
9884 | + struct au_dinfo *dinfo; |
9885 | + struct au_hdentry *hd; | |
027c5e7a | 9886 | + struct au_branch *br; |
1facf9fc | 9887 | + |
1308ab2a | 9888 | + DiMustWriteLock(dentry); |
9889 | + | |
5afbbe0d AM |
9890 | + dinfo = au_di(dentry); |
9891 | + hd = au_hdentry(dinfo, bindex); | |
4a4d8108 | 9892 | + au_hdput(hd); |
1facf9fc | 9893 | + hd->hd_dentry = h_dentry; |
027c5e7a AM |
9894 | + if (h_dentry) { |
9895 | + br = au_sbr(dentry->d_sb, bindex); | |
9896 | + hd->hd_id = br->br_id; | |
9897 | + } | |
9898 | +} | |
9899 | + | |
9900 | +int au_dbrange_test(struct dentry *dentry) | |
9901 | +{ | |
9902 | + int err; | |
5afbbe0d | 9903 | + aufs_bindex_t btop, bbot; |
027c5e7a AM |
9904 | + |
9905 | + err = 0; | |
5afbbe0d AM |
9906 | + btop = au_dbtop(dentry); |
9907 | + bbot = au_dbbot(dentry); | |
9908 | + if (btop >= 0) | |
9909 | + AuDebugOn(bbot < 0 && btop > bbot); | |
027c5e7a AM |
9910 | + else { |
9911 | + err = -EIO; | |
5afbbe0d | 9912 | + AuDebugOn(bbot >= 0); |
027c5e7a AM |
9913 | + } |
9914 | + | |
9915 | + return err; | |
9916 | +} | |
9917 | + | |
9918 | +int au_digen_test(struct dentry *dentry, unsigned int sigen) | |
9919 | +{ | |
9920 | + int err; | |
9921 | + | |
9922 | + err = 0; | |
9923 | + if (unlikely(au_digen(dentry) != sigen | |
5527c038 | 9924 | + || au_iigen_test(d_inode(dentry), sigen))) |
027c5e7a AM |
9925 | + err = -EIO; |
9926 | + | |
9927 | + return err; | |
1facf9fc | 9928 | +} |
9929 | + | |
9930 | +void au_update_digen(struct dentry *dentry) | |
9931 | +{ | |
9932 | + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb)); | |
9933 | + /* smp_mb(); */ /* atomic_set */ | |
9934 | +} | |
9935 | + | |
9936 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero) | |
9937 | +{ | |
9938 | + struct au_dinfo *dinfo; | |
9939 | + struct dentry *h_d; | |
4a4d8108 | 9940 | + struct au_hdentry *hdp; |
5afbbe0d | 9941 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9942 | + |
1308ab2a | 9943 | + DiMustWriteLock(dentry); |
9944 | + | |
1facf9fc | 9945 | + dinfo = au_di(dentry); |
5afbbe0d | 9946 | + if (!dinfo || dinfo->di_btop < 0) |
1facf9fc | 9947 | + return; |
9948 | + | |
9949 | + if (do_put_zero) { | |
5afbbe0d AM |
9950 | + bbot = dinfo->di_bbot; |
9951 | + bindex = dinfo->di_btop; | |
9952 | + hdp = au_hdentry(dinfo, bindex); | |
9953 | + for (; bindex <= bbot; bindex++, hdp++) { | |
9954 | + h_d = hdp->hd_dentry; | |
5527c038 | 9955 | + if (h_d && d_is_negative(h_d)) |
1facf9fc | 9956 | + au_set_h_dptr(dentry, bindex, NULL); |
9957 | + } | |
9958 | + } | |
9959 | + | |
5afbbe0d AM |
9960 | + dinfo->di_btop = 0; |
9961 | + hdp = au_hdentry(dinfo, dinfo->di_btop); | |
9962 | + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++) | |
9963 | + if (hdp->hd_dentry) | |
1facf9fc | 9964 | + break; |
5afbbe0d AM |
9965 | + if (dinfo->di_btop > dinfo->di_bbot) { |
9966 | + dinfo->di_btop = -1; | |
9967 | + dinfo->di_bbot = -1; | |
1facf9fc | 9968 | + return; |
9969 | + } | |
9970 | + | |
5afbbe0d AM |
9971 | + hdp = au_hdentry(dinfo, dinfo->di_bbot); |
9972 | + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--) | |
9973 | + if (hdp->hd_dentry) | |
1facf9fc | 9974 | + break; |
5afbbe0d | 9975 | + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0); |
1facf9fc | 9976 | +} |
9977 | + | |
5afbbe0d | 9978 | +void au_update_dbtop(struct dentry *dentry) |
1facf9fc | 9979 | +{ |
5afbbe0d | 9980 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9981 | + struct dentry *h_dentry; |
9982 | + | |
5afbbe0d AM |
9983 | + bbot = au_dbbot(dentry); |
9984 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) { | |
1facf9fc | 9985 | + h_dentry = au_h_dptr(dentry, bindex); |
9986 | + if (!h_dentry) | |
9987 | + continue; | |
5527c038 | 9988 | + if (d_is_positive(h_dentry)) { |
5afbbe0d | 9989 | + au_set_dbtop(dentry, bindex); |
1facf9fc | 9990 | + return; |
9991 | + } | |
9992 | + au_set_h_dptr(dentry, bindex, NULL); | |
9993 | + } | |
9994 | +} | |
9995 | + | |
5afbbe0d | 9996 | +void au_update_dbbot(struct dentry *dentry) |
1facf9fc | 9997 | +{ |
5afbbe0d | 9998 | + aufs_bindex_t bindex, btop; |
1facf9fc | 9999 | + struct dentry *h_dentry; |
10000 | + | |
5afbbe0d AM |
10001 | + btop = au_dbtop(dentry); |
10002 | + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) { | |
1facf9fc | 10003 | + h_dentry = au_h_dptr(dentry, bindex); |
10004 | + if (!h_dentry) | |
10005 | + continue; | |
5527c038 | 10006 | + if (d_is_positive(h_dentry)) { |
5afbbe0d | 10007 | + au_set_dbbot(dentry, bindex); |
1facf9fc | 10008 | + return; |
10009 | + } | |
10010 | + au_set_h_dptr(dentry, bindex, NULL); | |
10011 | + } | |
10012 | +} | |
10013 | + | |
10014 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry) | |
10015 | +{ | |
5afbbe0d | 10016 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 10017 | + |
5afbbe0d AM |
10018 | + bbot = au_dbbot(dentry); |
10019 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) | |
1facf9fc | 10020 | + if (au_h_dptr(dentry, bindex) == h_dentry) |
10021 | + return bindex; | |
10022 | + return -1; | |
10023 | +} | |
7f207e10 AM |
10024 | diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c |
10025 | --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 10026 | +++ linux/fs/aufs/dir.c 2018-01-29 07:56:20.053325069 +0100 |
1c60b727 | 10027 | @@ -0,0 +1,759 @@ |
1facf9fc | 10028 | +/* |
a2654f78 | 10029 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 10030 | + * |
10031 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10032 | + * it under the terms of the GNU General Public License as published by | |
10033 | + * the Free Software Foundation; either version 2 of the License, or | |
10034 | + * (at your option) any later version. | |
dece6358 AM |
10035 | + * |
10036 | + * This program is distributed in the hope that it will be useful, | |
10037 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10038 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10039 | + * GNU General Public License for more details. | |
10040 | + * | |
10041 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10042 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10043 | + */ |
10044 | + | |
10045 | +/* | |
10046 | + * directory operations | |
10047 | + */ | |
10048 | + | |
10049 | +#include <linux/fs_stack.h> | |
10050 | +#include "aufs.h" | |
10051 | + | |
10052 | +void au_add_nlink(struct inode *dir, struct inode *h_dir) | |
10053 | +{ | |
9dbd164d AM |
10054 | + unsigned int nlink; |
10055 | + | |
1facf9fc | 10056 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
10057 | + | |
9dbd164d AM |
10058 | + nlink = dir->i_nlink; |
10059 | + nlink += h_dir->i_nlink - 2; | |
1facf9fc | 10060 | + if (h_dir->i_nlink < 2) |
9dbd164d | 10061 | + nlink += 2; |
f6b6e03d | 10062 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 10063 | + /* 0 can happen in revaliding */ |
92d182d2 | 10064 | + set_nlink(dir, nlink); |
1facf9fc | 10065 | +} |
10066 | + | |
10067 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir) | |
10068 | +{ | |
9dbd164d AM |
10069 | + unsigned int nlink; |
10070 | + | |
1facf9fc | 10071 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
10072 | + | |
9dbd164d AM |
10073 | + nlink = dir->i_nlink; |
10074 | + nlink -= h_dir->i_nlink - 2; | |
1facf9fc | 10075 | + if (h_dir->i_nlink < 2) |
9dbd164d | 10076 | + nlink -= 2; |
f6b6e03d | 10077 | + smp_mb(); /* for i_nlink */ |
92d182d2 | 10078 | + /* nlink == 0 means the branch-fs is broken */ |
9dbd164d | 10079 | + set_nlink(dir, nlink); |
1facf9fc | 10080 | +} |
10081 | + | |
1308ab2a | 10082 | +loff_t au_dir_size(struct file *file, struct dentry *dentry) |
10083 | +{ | |
10084 | + loff_t sz; | |
5afbbe0d | 10085 | + aufs_bindex_t bindex, bbot; |
1308ab2a | 10086 | + struct file *h_file; |
10087 | + struct dentry *h_dentry; | |
10088 | + | |
10089 | + sz = 0; | |
10090 | + if (file) { | |
2000de60 | 10091 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
1308ab2a | 10092 | + |
5afbbe0d AM |
10093 | + bbot = au_fbbot_dir(file); |
10094 | + for (bindex = au_fbtop(file); | |
10095 | + bindex <= bbot && sz < KMALLOC_MAX_SIZE; | |
1308ab2a | 10096 | + bindex++) { |
4a4d8108 | 10097 | + h_file = au_hf_dir(file, bindex); |
c06a8ce3 AM |
10098 | + if (h_file && file_inode(h_file)) |
10099 | + sz += vfsub_f_size_read(h_file); | |
1308ab2a | 10100 | + } |
10101 | + } else { | |
10102 | + AuDebugOn(!dentry); | |
2000de60 | 10103 | + AuDebugOn(!d_is_dir(dentry)); |
1308ab2a | 10104 | + |
5afbbe0d AM |
10105 | + bbot = au_dbtaildir(dentry); |
10106 | + for (bindex = au_dbtop(dentry); | |
10107 | + bindex <= bbot && sz < KMALLOC_MAX_SIZE; | |
1308ab2a | 10108 | + bindex++) { |
10109 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 JR |
10110 | + if (h_dentry && d_is_positive(h_dentry)) |
10111 | + sz += i_size_read(d_inode(h_dentry)); | |
1308ab2a | 10112 | + } |
10113 | + } | |
10114 | + if (sz < KMALLOC_MAX_SIZE) | |
10115 | + sz = roundup_pow_of_two(sz); | |
10116 | + if (sz > KMALLOC_MAX_SIZE) | |
10117 | + sz = KMALLOC_MAX_SIZE; | |
10118 | + else if (sz < NAME_MAX) { | |
10119 | + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX); | |
10120 | + sz = AUFS_RDBLK_DEF; | |
10121 | + } | |
10122 | + return sz; | |
10123 | +} | |
10124 | + | |
b912730e AM |
10125 | +struct au_dir_ts_arg { |
10126 | + struct dentry *dentry; | |
10127 | + aufs_bindex_t brid; | |
10128 | +}; | |
10129 | + | |
10130 | +static void au_do_dir_ts(void *arg) | |
10131 | +{ | |
10132 | + struct au_dir_ts_arg *a = arg; | |
10133 | + struct au_dtime dt; | |
10134 | + struct path h_path; | |
10135 | + struct inode *dir, *h_dir; | |
10136 | + struct super_block *sb; | |
10137 | + struct au_branch *br; | |
10138 | + struct au_hinode *hdir; | |
10139 | + int err; | |
5afbbe0d | 10140 | + aufs_bindex_t btop, bindex; |
b912730e AM |
10141 | + |
10142 | + sb = a->dentry->d_sb; | |
5527c038 | 10143 | + if (d_really_is_negative(a->dentry)) |
b912730e | 10144 | + goto out; |
5527c038 | 10145 | + /* no dir->i_mutex lock */ |
b95c5147 AM |
10146 | + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */ |
10147 | + | |
5527c038 | 10148 | + dir = d_inode(a->dentry); |
5afbbe0d | 10149 | + btop = au_ibtop(dir); |
b912730e | 10150 | + bindex = au_br_index(sb, a->brid); |
5afbbe0d | 10151 | + if (bindex < btop) |
b912730e AM |
10152 | + goto out_unlock; |
10153 | + | |
10154 | + br = au_sbr(sb, bindex); | |
10155 | + h_path.dentry = au_h_dptr(a->dentry, bindex); | |
10156 | + if (!h_path.dentry) | |
10157 | + goto out_unlock; | |
10158 | + h_path.mnt = au_br_mnt(br); | |
10159 | + au_dtime_store(&dt, a->dentry, &h_path); | |
10160 | + | |
5afbbe0d | 10161 | + br = au_sbr(sb, btop); |
b912730e AM |
10162 | + if (!au_br_writable(br->br_perm)) |
10163 | + goto out_unlock; | |
5afbbe0d | 10164 | + h_path.dentry = au_h_dptr(a->dentry, btop); |
b912730e AM |
10165 | + h_path.mnt = au_br_mnt(br); |
10166 | + err = vfsub_mnt_want_write(h_path.mnt); | |
10167 | + if (err) | |
10168 | + goto out_unlock; | |
5afbbe0d AM |
10169 | + hdir = au_hi(dir, btop); |
10170 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); | |
10171 | + h_dir = au_h_iptr(dir, btop); | |
b912730e AM |
10172 | + if (h_dir->i_nlink |
10173 | + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) { | |
10174 | + dt.dt_h_path = h_path; | |
10175 | + au_dtime_revert(&dt); | |
10176 | + } | |
5afbbe0d | 10177 | + au_hn_inode_unlock(hdir); |
b912730e AM |
10178 | + vfsub_mnt_drop_write(h_path.mnt); |
10179 | + au_cpup_attr_timesizes(dir); | |
10180 | + | |
10181 | +out_unlock: | |
10182 | + aufs_read_unlock(a->dentry, AuLock_DW); | |
10183 | +out: | |
10184 | + dput(a->dentry); | |
10185 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1c60b727 | 10186 | + kfree(arg); |
b912730e AM |
10187 | +} |
10188 | + | |
10189 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex) | |
10190 | +{ | |
10191 | + int perm, wkq_err; | |
5afbbe0d | 10192 | + aufs_bindex_t btop; |
b912730e AM |
10193 | + struct au_dir_ts_arg *arg; |
10194 | + struct dentry *dentry; | |
10195 | + struct super_block *sb; | |
10196 | + | |
10197 | + IMustLock(dir); | |
10198 | + | |
10199 | + dentry = d_find_any_alias(dir); | |
10200 | + AuDebugOn(!dentry); | |
10201 | + sb = dentry->d_sb; | |
5afbbe0d AM |
10202 | + btop = au_ibtop(dir); |
10203 | + if (btop == bindex) { | |
b912730e AM |
10204 | + au_cpup_attr_timesizes(dir); |
10205 | + goto out; | |
10206 | + } | |
10207 | + | |
5afbbe0d | 10208 | + perm = au_sbr_perm(sb, btop); |
b912730e AM |
10209 | + if (!au_br_writable(perm)) |
10210 | + goto out; | |
10211 | + | |
10212 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
10213 | + if (!arg) | |
10214 | + goto out; | |
10215 | + | |
10216 | + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */ | |
10217 | + arg->brid = au_sbr_id(sb, bindex); | |
10218 | + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0); | |
10219 | + if (unlikely(wkq_err)) { | |
10220 | + pr_err("wkq %d\n", wkq_err); | |
10221 | + dput(dentry); | |
1c60b727 | 10222 | + kfree(arg); |
b912730e AM |
10223 | + } |
10224 | + | |
10225 | +out: | |
10226 | + dput(dentry); | |
10227 | +} | |
10228 | + | |
1facf9fc | 10229 | +/* ---------------------------------------------------------------------- */ |
10230 | + | |
10231 | +static int reopen_dir(struct file *file) | |
10232 | +{ | |
10233 | + int err; | |
10234 | + unsigned int flags; | |
5afbbe0d | 10235 | + aufs_bindex_t bindex, btail, btop; |
1facf9fc | 10236 | + struct dentry *dentry, *h_dentry; |
10237 | + struct file *h_file; | |
10238 | + | |
10239 | + /* open all lower dirs */ | |
2000de60 | 10240 | + dentry = file->f_path.dentry; |
5afbbe0d AM |
10241 | + btop = au_dbtop(dentry); |
10242 | + for (bindex = au_fbtop(file); bindex < btop; bindex++) | |
1facf9fc | 10243 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d | 10244 | + au_set_fbtop(file, btop); |
1facf9fc | 10245 | + |
10246 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 10247 | + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--) |
1facf9fc | 10248 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d | 10249 | + au_set_fbbot_dir(file, btail); |
1facf9fc | 10250 | + |
4a4d8108 | 10251 | + flags = vfsub_file_flags(file); |
5afbbe0d | 10252 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 10253 | + h_dentry = au_h_dptr(dentry, bindex); |
10254 | + if (!h_dentry) | |
10255 | + continue; | |
4a4d8108 | 10256 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 10257 | + if (h_file) |
10258 | + continue; | |
10259 | + | |
392086de | 10260 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 10261 | + err = PTR_ERR(h_file); |
10262 | + if (IS_ERR(h_file)) | |
10263 | + goto out; /* close all? */ | |
10264 | + au_set_h_fptr(file, bindex, h_file); | |
10265 | + } | |
10266 | + au_update_figen(file); | |
10267 | + /* todo: necessary? */ | |
10268 | + /* file->f_ra = h_file->f_ra; */ | |
10269 | + err = 0; | |
10270 | + | |
4f0767ce | 10271 | +out: |
1facf9fc | 10272 | + return err; |
10273 | +} | |
10274 | + | |
b912730e | 10275 | +static int do_open_dir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 10276 | +{ |
10277 | + int err; | |
10278 | + aufs_bindex_t bindex, btail; | |
10279 | + struct dentry *dentry, *h_dentry; | |
8cdd5066 | 10280 | + struct vfsmount *mnt; |
1facf9fc | 10281 | + |
1308ab2a | 10282 | + FiMustWriteLock(file); |
b912730e | 10283 | + AuDebugOn(h_file); |
1308ab2a | 10284 | + |
523b37e3 | 10285 | + err = 0; |
8cdd5066 | 10286 | + mnt = file->f_path.mnt; |
2000de60 | 10287 | + dentry = file->f_path.dentry; |
5527c038 | 10288 | + file->f_version = d_inode(dentry)->i_version; |
5afbbe0d AM |
10289 | + bindex = au_dbtop(dentry); |
10290 | + au_set_fbtop(file, bindex); | |
1facf9fc | 10291 | + btail = au_dbtaildir(dentry); |
5afbbe0d | 10292 | + au_set_fbbot_dir(file, btail); |
1facf9fc | 10293 | + for (; !err && bindex <= btail; bindex++) { |
10294 | + h_dentry = au_h_dptr(dentry, bindex); | |
10295 | + if (!h_dentry) | |
10296 | + continue; | |
10297 | + | |
8cdd5066 JR |
10298 | + err = vfsub_test_mntns(mnt, h_dentry->d_sb); |
10299 | + if (unlikely(err)) | |
10300 | + break; | |
392086de | 10301 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 10302 | + if (IS_ERR(h_file)) { |
10303 | + err = PTR_ERR(h_file); | |
10304 | + break; | |
10305 | + } | |
10306 | + au_set_h_fptr(file, bindex, h_file); | |
10307 | + } | |
10308 | + au_update_figen(file); | |
10309 | + /* todo: necessary? */ | |
10310 | + /* file->f_ra = h_file->f_ra; */ | |
10311 | + if (!err) | |
10312 | + return 0; /* success */ | |
10313 | + | |
10314 | + /* close all */ | |
5afbbe0d | 10315 | + for (bindex = au_fbtop(file); bindex <= btail; bindex++) |
1facf9fc | 10316 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d AM |
10317 | + au_set_fbtop(file, -1); |
10318 | + au_set_fbbot_dir(file, -1); | |
4a4d8108 | 10319 | + |
1facf9fc | 10320 | + return err; |
10321 | +} | |
10322 | + | |
10323 | +static int aufs_open_dir(struct inode *inode __maybe_unused, | |
10324 | + struct file *file) | |
10325 | +{ | |
4a4d8108 AM |
10326 | + int err; |
10327 | + struct super_block *sb; | |
10328 | + struct au_fidir *fidir; | |
10329 | + | |
10330 | + err = -ENOMEM; | |
2000de60 | 10331 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 10332 | + si_read_lock(sb, AuLock_FLUSH); |
e49829fe | 10333 | + fidir = au_fidir_alloc(sb); |
4a4d8108 | 10334 | + if (fidir) { |
b912730e AM |
10335 | + struct au_do_open_args args = { |
10336 | + .open = do_open_dir, | |
10337 | + .fidir = fidir | |
10338 | + }; | |
10339 | + err = au_do_open(file, &args); | |
4a4d8108 | 10340 | + if (unlikely(err)) |
1c60b727 | 10341 | + kfree(fidir); |
4a4d8108 AM |
10342 | + } |
10343 | + si_read_unlock(sb); | |
10344 | + return err; | |
1facf9fc | 10345 | +} |
10346 | + | |
10347 | +static int aufs_release_dir(struct inode *inode __maybe_unused, | |
10348 | + struct file *file) | |
10349 | +{ | |
10350 | + struct au_vdir *vdir_cache; | |
4a4d8108 AM |
10351 | + struct au_finfo *finfo; |
10352 | + struct au_fidir *fidir; | |
f0c0a007 | 10353 | + struct au_hfile *hf; |
5afbbe0d | 10354 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 10355 | + |
4a4d8108 AM |
10356 | + finfo = au_fi(file); |
10357 | + fidir = finfo->fi_hdir; | |
10358 | + if (fidir) { | |
8b6a4947 AM |
10359 | + au_hbl_del(&finfo->fi_hlist, |
10360 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 AM |
10361 | + vdir_cache = fidir->fd_vdir_cache; /* lock-free */ |
10362 | + if (vdir_cache) | |
1c60b727 | 10363 | + au_vdir_free(vdir_cache); |
4a4d8108 AM |
10364 | + |
10365 | + bindex = finfo->fi_btop; | |
10366 | + if (bindex >= 0) { | |
f0c0a007 | 10367 | + hf = fidir->fd_hfile + bindex; |
4a4d8108 AM |
10368 | + /* |
10369 | + * calls fput() instead of filp_close(), | |
10370 | + * since no dnotify or lock for the lower file. | |
10371 | + */ | |
5afbbe0d | 10372 | + bbot = fidir->fd_bbot; |
f0c0a007 AM |
10373 | + for (; bindex <= bbot; bindex++, hf++) |
10374 | + if (hf->hf_file) | |
1c60b727 | 10375 | + au_hfput(hf, /*execed*/0); |
4a4d8108 | 10376 | + } |
1c60b727 | 10377 | + kfree(fidir); |
4a4d8108 | 10378 | + finfo->fi_hdir = NULL; |
1facf9fc | 10379 | + } |
1c60b727 | 10380 | + au_finfo_fin(file); |
1facf9fc | 10381 | + return 0; |
10382 | +} | |
10383 | + | |
10384 | +/* ---------------------------------------------------------------------- */ | |
10385 | + | |
4a4d8108 AM |
10386 | +static int au_do_flush_dir(struct file *file, fl_owner_t id) |
10387 | +{ | |
10388 | + int err; | |
5afbbe0d | 10389 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
10390 | + struct file *h_file; |
10391 | + | |
10392 | + err = 0; | |
5afbbe0d AM |
10393 | + bbot = au_fbbot_dir(file); |
10394 | + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) { | |
4a4d8108 AM |
10395 | + h_file = au_hf_dir(file, bindex); |
10396 | + if (h_file) | |
10397 | + err = vfsub_flush(h_file, id); | |
10398 | + } | |
10399 | + return err; | |
10400 | +} | |
10401 | + | |
10402 | +static int aufs_flush_dir(struct file *file, fl_owner_t id) | |
10403 | +{ | |
10404 | + return au_do_flush(file, id, au_do_flush_dir); | |
10405 | +} | |
10406 | + | |
10407 | +/* ---------------------------------------------------------------------- */ | |
10408 | + | |
1facf9fc | 10409 | +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync) |
10410 | +{ | |
10411 | + int err; | |
5afbbe0d | 10412 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 10413 | + struct inode *inode; |
10414 | + struct super_block *sb; | |
10415 | + | |
10416 | + err = 0; | |
10417 | + sb = dentry->d_sb; | |
5527c038 | 10418 | + inode = d_inode(dentry); |
1facf9fc | 10419 | + IMustLock(inode); |
5afbbe0d AM |
10420 | + bbot = au_dbbot(dentry); |
10421 | + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) { | |
1facf9fc | 10422 | + struct path h_path; |
1facf9fc | 10423 | + |
10424 | + if (au_test_ro(sb, bindex, inode)) | |
10425 | + continue; | |
10426 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
10427 | + if (!h_path.dentry) | |
10428 | + continue; | |
1facf9fc | 10429 | + |
1facf9fc | 10430 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
53392da6 | 10431 | + err = vfsub_fsync(NULL, &h_path, datasync); |
1facf9fc | 10432 | + } |
10433 | + | |
10434 | + return err; | |
10435 | +} | |
10436 | + | |
10437 | +static int au_do_fsync_dir(struct file *file, int datasync) | |
10438 | +{ | |
10439 | + int err; | |
5afbbe0d | 10440 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 10441 | + struct file *h_file; |
10442 | + struct super_block *sb; | |
10443 | + struct inode *inode; | |
1facf9fc | 10444 | + |
521ced18 | 10445 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0); |
1facf9fc | 10446 | + if (unlikely(err)) |
10447 | + goto out; | |
10448 | + | |
c06a8ce3 | 10449 | + inode = file_inode(file); |
b912730e | 10450 | + sb = inode->i_sb; |
5afbbe0d AM |
10451 | + bbot = au_fbbot_dir(file); |
10452 | + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) { | |
4a4d8108 | 10453 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 10454 | + if (!h_file || au_test_ro(sb, bindex, inode)) |
10455 | + continue; | |
10456 | + | |
53392da6 | 10457 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
1facf9fc | 10458 | + } |
10459 | + | |
4f0767ce | 10460 | +out: |
1facf9fc | 10461 | + return err; |
10462 | +} | |
10463 | + | |
10464 | +/* | |
10465 | + * @file may be NULL | |
10466 | + */ | |
1e00d052 AM |
10467 | +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end, |
10468 | + int datasync) | |
1facf9fc | 10469 | +{ |
10470 | + int err; | |
b752ccd1 | 10471 | + struct dentry *dentry; |
5527c038 | 10472 | + struct inode *inode; |
1facf9fc | 10473 | + struct super_block *sb; |
1facf9fc | 10474 | + |
10475 | + err = 0; | |
2000de60 | 10476 | + dentry = file->f_path.dentry; |
5527c038 | 10477 | + inode = d_inode(dentry); |
febd17d6 | 10478 | + inode_lock(inode); |
1facf9fc | 10479 | + sb = dentry->d_sb; |
10480 | + si_noflush_read_lock(sb); | |
10481 | + if (file) | |
10482 | + err = au_do_fsync_dir(file, datasync); | |
10483 | + else { | |
10484 | + di_write_lock_child(dentry); | |
10485 | + err = au_do_fsync_dir_no_file(dentry, datasync); | |
10486 | + } | |
5527c038 | 10487 | + au_cpup_attr_timesizes(inode); |
1facf9fc | 10488 | + di_write_unlock(dentry); |
10489 | + if (file) | |
10490 | + fi_write_unlock(file); | |
10491 | + | |
10492 | + si_read_unlock(sb); | |
febd17d6 | 10493 | + inode_unlock(inode); |
1facf9fc | 10494 | + return err; |
10495 | +} | |
10496 | + | |
10497 | +/* ---------------------------------------------------------------------- */ | |
10498 | + | |
5afbbe0d | 10499 | +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx) |
1facf9fc | 10500 | +{ |
10501 | + int err; | |
10502 | + struct dentry *dentry; | |
9dbd164d | 10503 | + struct inode *inode, *h_inode; |
1facf9fc | 10504 | + struct super_block *sb; |
10505 | + | |
523b37e3 | 10506 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 10507 | + |
2000de60 | 10508 | + dentry = file->f_path.dentry; |
5527c038 | 10509 | + inode = d_inode(dentry); |
1facf9fc | 10510 | + IMustLock(inode); |
10511 | + | |
10512 | + sb = dentry->d_sb; | |
10513 | + si_read_lock(sb, AuLock_FLUSH); | |
521ced18 | 10514 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0); |
1facf9fc | 10515 | + if (unlikely(err)) |
10516 | + goto out; | |
027c5e7a AM |
10517 | + err = au_alive_dir(dentry); |
10518 | + if (!err) | |
10519 | + err = au_vdir_init(file); | |
1facf9fc | 10520 | + di_downgrade_lock(dentry, AuLock_IR); |
10521 | + if (unlikely(err)) | |
10522 | + goto out_unlock; | |
10523 | + | |
5afbbe0d | 10524 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
b752ccd1 | 10525 | + if (!au_test_nfsd()) { |
392086de | 10526 | + err = au_vdir_fill_de(file, ctx); |
9dbd164d | 10527 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 10528 | + } else { |
10529 | + /* | |
10530 | + * nfsd filldir may call lookup_one_len(), vfs_getattr(), | |
10531 | + * encode_fh() and others. | |
10532 | + */ | |
9dbd164d | 10533 | + atomic_inc(&h_inode->i_count); |
1facf9fc | 10534 | + di_read_unlock(dentry, AuLock_IR); |
10535 | + si_read_unlock(sb); | |
392086de | 10536 | + err = au_vdir_fill_de(file, ctx); |
1facf9fc | 10537 | + fsstack_copy_attr_atime(inode, h_inode); |
10538 | + fi_write_unlock(file); | |
9dbd164d | 10539 | + iput(h_inode); |
1facf9fc | 10540 | + |
10541 | + AuTraceErr(err); | |
10542 | + return err; | |
10543 | + } | |
10544 | + | |
4f0767ce | 10545 | +out_unlock: |
1facf9fc | 10546 | + di_read_unlock(dentry, AuLock_IR); |
10547 | + fi_write_unlock(file); | |
4f0767ce | 10548 | +out: |
1facf9fc | 10549 | + si_read_unlock(sb); |
10550 | + return err; | |
10551 | +} | |
10552 | + | |
10553 | +/* ---------------------------------------------------------------------- */ | |
10554 | + | |
10555 | +#define AuTestEmpty_WHONLY 1 | |
dece6358 AM |
10556 | +#define AuTestEmpty_CALLED (1 << 1) |
10557 | +#define AuTestEmpty_SHWH (1 << 2) | |
1facf9fc | 10558 | +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name) |
7f207e10 AM |
10559 | +#define au_fset_testempty(flags, name) \ |
10560 | + do { (flags) |= AuTestEmpty_##name; } while (0) | |
10561 | +#define au_fclr_testempty(flags, name) \ | |
10562 | + do { (flags) &= ~AuTestEmpty_##name; } while (0) | |
1facf9fc | 10563 | + |
dece6358 AM |
10564 | +#ifndef CONFIG_AUFS_SHWH |
10565 | +#undef AuTestEmpty_SHWH | |
10566 | +#define AuTestEmpty_SHWH 0 | |
10567 | +#endif | |
10568 | + | |
1facf9fc | 10569 | +struct test_empty_arg { |
392086de | 10570 | + struct dir_context ctx; |
1308ab2a | 10571 | + struct au_nhash *whlist; |
1facf9fc | 10572 | + unsigned int flags; |
10573 | + int err; | |
10574 | + aufs_bindex_t bindex; | |
10575 | +}; | |
10576 | + | |
392086de AM |
10577 | +static int test_empty_cb(struct dir_context *ctx, const char *__name, |
10578 | + int namelen, loff_t offset __maybe_unused, u64 ino, | |
dece6358 | 10579 | + unsigned int d_type) |
1facf9fc | 10580 | +{ |
392086de AM |
10581 | + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg, |
10582 | + ctx); | |
1facf9fc | 10583 | + char *name = (void *)__name; |
10584 | + | |
10585 | + arg->err = 0; | |
10586 | + au_fset_testempty(arg->flags, CALLED); | |
10587 | + /* smp_mb(); */ | |
10588 | + if (name[0] == '.' | |
10589 | + && (namelen == 1 || (name[1] == '.' && namelen == 2))) | |
10590 | + goto out; /* success */ | |
10591 | + | |
10592 | + if (namelen <= AUFS_WH_PFX_LEN | |
10593 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
10594 | + if (au_ftest_testempty(arg->flags, WHONLY) | |
1308ab2a | 10595 | + && !au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 10596 | + arg->err = -ENOTEMPTY; |
10597 | + goto out; | |
10598 | + } | |
10599 | + | |
10600 | + name += AUFS_WH_PFX_LEN; | |
10601 | + namelen -= AUFS_WH_PFX_LEN; | |
1308ab2a | 10602 | + if (!au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 10603 | + arg->err = au_nhash_append_wh |
1308ab2a | 10604 | + (arg->whlist, name, namelen, ino, d_type, arg->bindex, |
dece6358 | 10605 | + au_ftest_testempty(arg->flags, SHWH)); |
1facf9fc | 10606 | + |
4f0767ce | 10607 | +out: |
1facf9fc | 10608 | + /* smp_mb(); */ |
10609 | + AuTraceErr(arg->err); | |
10610 | + return arg->err; | |
10611 | +} | |
10612 | + | |
10613 | +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
10614 | +{ | |
10615 | + int err; | |
10616 | + struct file *h_file; | |
10617 | + | |
10618 | + h_file = au_h_open(dentry, arg->bindex, | |
10619 | + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE, | |
392086de | 10620 | + /*file*/NULL, /*force_wr*/0); |
1facf9fc | 10621 | + err = PTR_ERR(h_file); |
10622 | + if (IS_ERR(h_file)) | |
10623 | + goto out; | |
10624 | + | |
10625 | + err = 0; | |
10626 | + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE) | |
c06a8ce3 | 10627 | + && !file_inode(h_file)->i_nlink) |
1facf9fc | 10628 | + goto out_put; |
10629 | + | |
10630 | + do { | |
10631 | + arg->err = 0; | |
10632 | + au_fclr_testempty(arg->flags, CALLED); | |
10633 | + /* smp_mb(); */ | |
392086de | 10634 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1facf9fc | 10635 | + if (err >= 0) |
10636 | + err = arg->err; | |
10637 | + } while (!err && au_ftest_testempty(arg->flags, CALLED)); | |
10638 | + | |
4f0767ce | 10639 | +out_put: |
1facf9fc | 10640 | + fput(h_file); |
10641 | + au_sbr_put(dentry->d_sb, arg->bindex); | |
4f0767ce | 10642 | +out: |
1facf9fc | 10643 | + return err; |
10644 | +} | |
10645 | + | |
10646 | +struct do_test_empty_args { | |
10647 | + int *errp; | |
10648 | + struct dentry *dentry; | |
10649 | + struct test_empty_arg *arg; | |
10650 | +}; | |
10651 | + | |
10652 | +static void call_do_test_empty(void *args) | |
10653 | +{ | |
10654 | + struct do_test_empty_args *a = args; | |
10655 | + *a->errp = do_test_empty(a->dentry, a->arg); | |
10656 | +} | |
10657 | + | |
10658 | +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
10659 | +{ | |
10660 | + int err, wkq_err; | |
10661 | + struct dentry *h_dentry; | |
10662 | + struct inode *h_inode; | |
10663 | + | |
10664 | + h_dentry = au_h_dptr(dentry, arg->bindex); | |
5527c038 | 10665 | + h_inode = d_inode(h_dentry); |
53392da6 | 10666 | + /* todo: i_mode changes anytime? */ |
3c1bdaff | 10667 | + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD); |
1facf9fc | 10668 | + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ); |
3c1bdaff | 10669 | + inode_unlock_shared(h_inode); |
1facf9fc | 10670 | + if (!err) |
10671 | + err = do_test_empty(dentry, arg); | |
10672 | + else { | |
10673 | + struct do_test_empty_args args = { | |
10674 | + .errp = &err, | |
10675 | + .dentry = dentry, | |
10676 | + .arg = arg | |
10677 | + }; | |
10678 | + unsigned int flags = arg->flags; | |
10679 | + | |
10680 | + wkq_err = au_wkq_wait(call_do_test_empty, &args); | |
10681 | + if (unlikely(wkq_err)) | |
10682 | + err = wkq_err; | |
10683 | + arg->flags = flags; | |
10684 | + } | |
10685 | + | |
10686 | + return err; | |
10687 | +} | |
10688 | + | |
10689 | +int au_test_empty_lower(struct dentry *dentry) | |
10690 | +{ | |
10691 | + int err; | |
1308ab2a | 10692 | + unsigned int rdhash; |
5afbbe0d | 10693 | + aufs_bindex_t bindex, btop, btail; |
1308ab2a | 10694 | + struct au_nhash whlist; |
392086de AM |
10695 | + struct test_empty_arg arg = { |
10696 | + .ctx = { | |
2000de60 | 10697 | + .actor = test_empty_cb |
392086de AM |
10698 | + } |
10699 | + }; | |
076b876e | 10700 | + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg); |
1facf9fc | 10701 | + |
dece6358 AM |
10702 | + SiMustAnyLock(dentry->d_sb); |
10703 | + | |
1308ab2a | 10704 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; |
10705 | + if (!rdhash) | |
10706 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry)); | |
10707 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
dece6358 | 10708 | + if (unlikely(err)) |
1facf9fc | 10709 | + goto out; |
10710 | + | |
1facf9fc | 10711 | + arg.flags = 0; |
1308ab2a | 10712 | + arg.whlist = &whlist; |
5afbbe0d | 10713 | + btop = au_dbtop(dentry); |
dece6358 AM |
10714 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10715 | + au_fset_testempty(arg.flags, SHWH); | |
076b876e AM |
10716 | + test_empty = do_test_empty; |
10717 | + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)) | |
10718 | + test_empty = sio_test_empty; | |
5afbbe0d | 10719 | + arg.bindex = btop; |
076b876e | 10720 | + err = test_empty(dentry, &arg); |
1facf9fc | 10721 | + if (unlikely(err)) |
10722 | + goto out_whlist; | |
10723 | + | |
10724 | + au_fset_testempty(arg.flags, WHONLY); | |
10725 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 10726 | + for (bindex = btop + 1; !err && bindex <= btail; bindex++) { |
1facf9fc | 10727 | + struct dentry *h_dentry; |
10728 | + | |
10729 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10730 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10731 | + arg.bindex = bindex; |
076b876e | 10732 | + err = test_empty(dentry, &arg); |
1facf9fc | 10733 | + } |
10734 | + } | |
10735 | + | |
4f0767ce | 10736 | +out_whlist: |
1308ab2a | 10737 | + au_nhash_wh_free(&whlist); |
4f0767ce | 10738 | +out: |
1facf9fc | 10739 | + return err; |
10740 | +} | |
10741 | + | |
10742 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist) | |
10743 | +{ | |
10744 | + int err; | |
392086de AM |
10745 | + struct test_empty_arg arg = { |
10746 | + .ctx = { | |
2000de60 | 10747 | + .actor = test_empty_cb |
392086de AM |
10748 | + } |
10749 | + }; | |
1facf9fc | 10750 | + aufs_bindex_t bindex, btail; |
10751 | + | |
10752 | + err = 0; | |
1308ab2a | 10753 | + arg.whlist = whlist; |
1facf9fc | 10754 | + arg.flags = AuTestEmpty_WHONLY; |
dece6358 AM |
10755 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10756 | + au_fset_testempty(arg.flags, SHWH); | |
1facf9fc | 10757 | + btail = au_dbtaildir(dentry); |
5afbbe0d | 10758 | + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) { |
1facf9fc | 10759 | + struct dentry *h_dentry; |
10760 | + | |
10761 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10762 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10763 | + arg.bindex = bindex; |
10764 | + err = sio_test_empty(dentry, &arg); | |
10765 | + } | |
10766 | + } | |
10767 | + | |
10768 | + return err; | |
10769 | +} | |
10770 | + | |
10771 | +/* ---------------------------------------------------------------------- */ | |
10772 | + | |
10773 | +const struct file_operations aufs_dir_fop = { | |
4a4d8108 | 10774 | + .owner = THIS_MODULE, |
027c5e7a | 10775 | + .llseek = default_llseek, |
1facf9fc | 10776 | + .read = generic_read_dir, |
5afbbe0d | 10777 | + .iterate_shared = aufs_iterate_shared, |
1facf9fc | 10778 | + .unlocked_ioctl = aufs_ioctl_dir, |
b752ccd1 AM |
10779 | +#ifdef CONFIG_COMPAT |
10780 | + .compat_ioctl = aufs_compat_ioctl_dir, | |
10781 | +#endif | |
1facf9fc | 10782 | + .open = aufs_open_dir, |
10783 | + .release = aufs_release_dir, | |
4a4d8108 | 10784 | + .flush = aufs_flush_dir, |
1facf9fc | 10785 | + .fsync = aufs_fsync_dir |
10786 | +}; | |
7f207e10 AM |
10787 | diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h |
10788 | --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 10789 | +++ linux/fs/aufs/dir.h 2018-01-29 07:56:20.053325069 +0100 |
1c60b727 | 10790 | @@ -0,0 +1,131 @@ |
1facf9fc | 10791 | +/* |
a2654f78 | 10792 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 10793 | + * |
10794 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10795 | + * it under the terms of the GNU General Public License as published by | |
10796 | + * the Free Software Foundation; either version 2 of the License, or | |
10797 | + * (at your option) any later version. | |
dece6358 AM |
10798 | + * |
10799 | + * This program is distributed in the hope that it will be useful, | |
10800 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10801 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10802 | + * GNU General Public License for more details. | |
10803 | + * | |
10804 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10805 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10806 | + */ |
10807 | + | |
10808 | +/* | |
10809 | + * directory operations | |
10810 | + */ | |
10811 | + | |
10812 | +#ifndef __AUFS_DIR_H__ | |
10813 | +#define __AUFS_DIR_H__ | |
10814 | + | |
10815 | +#ifdef __KERNEL__ | |
10816 | + | |
10817 | +#include <linux/fs.h> | |
1facf9fc | 10818 | + |
10819 | +/* ---------------------------------------------------------------------- */ | |
10820 | + | |
10821 | +/* need to be faster and smaller */ | |
10822 | + | |
10823 | +struct au_nhash { | |
dece6358 AM |
10824 | + unsigned int nh_num; |
10825 | + struct hlist_head *nh_head; | |
1facf9fc | 10826 | +}; |
10827 | + | |
10828 | +struct au_vdir_destr { | |
10829 | + unsigned char len; | |
10830 | + unsigned char name[0]; | |
10831 | +} __packed; | |
10832 | + | |
10833 | +struct au_vdir_dehstr { | |
10834 | + struct hlist_node hash; | |
1c60b727 | 10835 | + struct au_vdir_destr *str; |
4a4d8108 | 10836 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10837 | + |
10838 | +struct au_vdir_de { | |
10839 | + ino_t de_ino; | |
10840 | + unsigned char de_type; | |
10841 | + /* caution: packed */ | |
10842 | + struct au_vdir_destr de_str; | |
10843 | +} __packed; | |
10844 | + | |
10845 | +struct au_vdir_wh { | |
10846 | + struct hlist_node wh_hash; | |
dece6358 AM |
10847 | +#ifdef CONFIG_AUFS_SHWH |
10848 | + ino_t wh_ino; | |
1facf9fc | 10849 | + aufs_bindex_t wh_bindex; |
dece6358 AM |
10850 | + unsigned char wh_type; |
10851 | +#else | |
10852 | + aufs_bindex_t wh_bindex; | |
10853 | +#endif | |
10854 | + /* caution: packed */ | |
1facf9fc | 10855 | + struct au_vdir_destr wh_str; |
10856 | +} __packed; | |
10857 | + | |
10858 | +union au_vdir_deblk_p { | |
10859 | + unsigned char *deblk; | |
10860 | + struct au_vdir_de *de; | |
10861 | +}; | |
10862 | + | |
10863 | +struct au_vdir { | |
10864 | + unsigned char **vd_deblk; | |
10865 | + unsigned long vd_nblk; | |
1facf9fc | 10866 | + struct { |
10867 | + unsigned long ul; | |
10868 | + union au_vdir_deblk_p p; | |
10869 | + } vd_last; | |
10870 | + | |
10871 | + unsigned long vd_version; | |
dece6358 | 10872 | + unsigned int vd_deblk_sz; |
1c60b727 | 10873 | + unsigned long vd_jiffy; |
4a4d8108 | 10874 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10875 | + |
10876 | +/* ---------------------------------------------------------------------- */ | |
10877 | + | |
10878 | +/* dir.c */ | |
10879 | +extern const struct file_operations aufs_dir_fop; | |
10880 | +void au_add_nlink(struct inode *dir, struct inode *h_dir); | |
10881 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir); | |
1308ab2a | 10882 | +loff_t au_dir_size(struct file *file, struct dentry *dentry); |
b912730e | 10883 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc); |
1facf9fc | 10884 | +int au_test_empty_lower(struct dentry *dentry); |
10885 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist); | |
10886 | + | |
10887 | +/* vdir.c */ | |
1308ab2a | 10888 | +unsigned int au_rdhash_est(loff_t sz); |
dece6358 AM |
10889 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp); |
10890 | +void au_nhash_wh_free(struct au_nhash *whlist); | |
1facf9fc | 10891 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, |
10892 | + int limit); | |
dece6358 AM |
10893 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen); |
10894 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
10895 | + unsigned int d_type, aufs_bindex_t bindex, | |
10896 | + unsigned char shwh); | |
1c60b727 | 10897 | +void au_vdir_free(struct au_vdir *vdir); |
1facf9fc | 10898 | +int au_vdir_init(struct file *file); |
392086de | 10899 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx); |
1facf9fc | 10900 | + |
10901 | +/* ioctl.c */ | |
10902 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg); | |
10903 | + | |
1308ab2a | 10904 | +#ifdef CONFIG_AUFS_RDU |
10905 | +/* rdu.c */ | |
10906 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
10907 | +#ifdef CONFIG_COMPAT |
10908 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, | |
10909 | + unsigned long arg); | |
10910 | +#endif | |
1308ab2a | 10911 | +#else |
c1595e42 JR |
10912 | +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file, |
10913 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10914 | +#ifdef CONFIG_COMPAT |
c1595e42 JR |
10915 | +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file, |
10916 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10917 | +#endif |
1308ab2a | 10918 | +#endif |
10919 | + | |
1facf9fc | 10920 | +#endif /* __KERNEL__ */ |
10921 | +#endif /* __AUFS_DIR_H__ */ | |
8b6a4947 AM |
10922 | diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c |
10923 | --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 10924 | +++ linux/fs/aufs/dirren.c 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 AM |
10925 | @@ -0,0 +1,1315 @@ |
10926 | +/* | |
10927 | + * Copyright (C) 2017 Junjiro R. Okajima | |
10928 | + * | |
10929 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10930 | + * it under the terms of the GNU General Public License as published by | |
10931 | + * the Free Software Foundation; either version 2 of the License, or | |
10932 | + * (at your option) any later version. | |
10933 | + * | |
10934 | + * This program is distributed in the hope that it will be useful, | |
10935 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10936 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10937 | + * GNU General Public License for more details. | |
10938 | + * | |
10939 | + * You should have received a copy of the GNU General Public License | |
10940 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
10941 | + */ | |
10942 | + | |
10943 | +/* | |
10944 | + * special handling in renaming a directoy | |
10945 | + * in order to support looking-up the before-renamed name on the lower readonly | |
10946 | + * branches | |
10947 | + */ | |
10948 | + | |
10949 | +#include <linux/byteorder/generic.h> | |
10950 | +#include "aufs.h" | |
10951 | + | |
10952 | +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent) | |
10953 | +{ | |
10954 | + int idx; | |
10955 | + | |
10956 | + idx = au_dr_ihash(ent->dr_h_ino); | |
10957 | + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx); | |
10958 | +} | |
10959 | + | |
10960 | +static int au_dr_hino_test_empty(struct au_dr_br *dr) | |
10961 | +{ | |
10962 | + int ret, i; | |
10963 | + struct hlist_bl_head *hbl; | |
10964 | + | |
10965 | + ret = 1; | |
10966 | + for (i = 0; ret && i < AuDirren_NHASH; i++) { | |
10967 | + hbl = dr->dr_h_ino + i; | |
10968 | + hlist_bl_lock(hbl); | |
10969 | + ret &= hlist_bl_empty(hbl); | |
10970 | + hlist_bl_unlock(hbl); | |
10971 | + } | |
10972 | + | |
10973 | + return ret; | |
10974 | +} | |
10975 | + | |
10976 | +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino) | |
10977 | +{ | |
10978 | + struct au_dr_hino *found, *ent; | |
10979 | + struct hlist_bl_head *hbl; | |
10980 | + struct hlist_bl_node *pos; | |
10981 | + int idx; | |
10982 | + | |
10983 | + found = NULL; | |
10984 | + idx = au_dr_ihash(ino); | |
10985 | + hbl = dr->dr_h_ino + idx; | |
10986 | + hlist_bl_lock(hbl); | |
10987 | + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode) | |
10988 | + if (ent->dr_h_ino == ino) { | |
10989 | + found = ent; | |
10990 | + break; | |
10991 | + } | |
10992 | + hlist_bl_unlock(hbl); | |
10993 | + | |
10994 | + return found; | |
10995 | +} | |
10996 | + | |
10997 | +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino, | |
10998 | + struct au_dr_hino *add_ent) | |
10999 | +{ | |
11000 | + int found, idx; | |
11001 | + struct hlist_bl_head *hbl; | |
11002 | + struct hlist_bl_node *pos; | |
11003 | + struct au_dr_hino *ent; | |
11004 | + | |
11005 | + found = 0; | |
11006 | + idx = au_dr_ihash(ino); | |
11007 | + hbl = dr->dr_h_ino + idx; | |
11008 | +#if 0 | |
11009 | + { | |
11010 | + struct hlist_bl_node *tmp; | |
11011 | + | |
11012 | + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode) | |
11013 | + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino); | |
11014 | + } | |
11015 | +#endif | |
11016 | + hlist_bl_lock(hbl); | |
11017 | + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode) | |
11018 | + if (ent->dr_h_ino == ino) { | |
11019 | + found = 1; | |
11020 | + break; | |
11021 | + } | |
11022 | + if (!found && add_ent) | |
11023 | + hlist_bl_add_head(&add_ent->dr_hnode, hbl); | |
11024 | + hlist_bl_unlock(hbl); | |
11025 | + | |
11026 | + if (!found && add_ent) | |
11027 | + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino); | |
11028 | + | |
11029 | + return found; | |
11030 | +} | |
11031 | + | |
11032 | +void au_dr_hino_free(struct au_dr_br *dr) | |
11033 | +{ | |
11034 | + int i; | |
11035 | + struct hlist_bl_head *hbl; | |
11036 | + struct hlist_bl_node *pos, *tmp; | |
11037 | + struct au_dr_hino *ent; | |
11038 | + | |
11039 | + /* SiMustWriteLock(sb); */ | |
11040 | + | |
11041 | + for (i = 0; i < AuDirren_NHASH; i++) { | |
11042 | + hbl = dr->dr_h_ino + i; | |
11043 | + /* no spinlock since sbinfo must be write-locked */ | |
11044 | + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode) | |
11045 | + kfree(ent); | |
11046 | + INIT_HLIST_BL_HEAD(hbl); | |
11047 | + } | |
11048 | +} | |
11049 | + | |
11050 | +/* returns the number of inodes or an error */ | |
11051 | +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br, | |
11052 | + struct file *hinofile) | |
11053 | +{ | |
11054 | + int err, i; | |
11055 | + ssize_t ssz; | |
11056 | + loff_t pos, oldsize; | |
11057 | + __be64 u64; | |
11058 | + struct inode *hinoinode; | |
11059 | + struct hlist_bl_head *hbl; | |
11060 | + struct hlist_bl_node *n1, *n2; | |
11061 | + struct au_dr_hino *ent; | |
11062 | + | |
11063 | + SiMustWriteLock(sb); | |
11064 | + AuDebugOn(!au_br_writable(br->br_perm)); | |
11065 | + | |
11066 | + hinoinode = file_inode(hinofile); | |
11067 | + oldsize = i_size_read(hinoinode); | |
11068 | + | |
11069 | + err = 0; | |
11070 | + pos = 0; | |
11071 | + hbl = br->br_dirren.dr_h_ino; | |
11072 | + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) { | |
11073 | + /* no bit-lock since sbinfo must be write-locked */ | |
11074 | + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) { | |
11075 | + AuDbg("hi%llu, %pD2\n", | |
11076 | + (unsigned long long)ent->dr_h_ino, hinofile); | |
11077 | + u64 = cpu_to_be64(ent->dr_h_ino); | |
11078 | + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos); | |
11079 | + if (ssz == sizeof(u64)) | |
11080 | + continue; | |
11081 | + | |
11082 | + /* write error */ | |
11083 | + pr_err("ssz %zd, %pD2\n", ssz, hinofile); | |
11084 | + err = -ENOSPC; | |
11085 | + if (ssz < 0) | |
11086 | + err = ssz; | |
11087 | + break; | |
11088 | + } | |
11089 | + } | |
11090 | + /* regardless the error */ | |
11091 | + if (pos < oldsize) { | |
11092 | + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile); | |
11093 | + AuTraceErr(err); | |
11094 | + } | |
11095 | + | |
11096 | + AuTraceErr(err); | |
11097 | + return err; | |
11098 | +} | |
11099 | + | |
11100 | +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile) | |
11101 | +{ | |
11102 | + int err, hidx; | |
11103 | + ssize_t ssz; | |
11104 | + size_t sz, n; | |
11105 | + loff_t pos; | |
11106 | + uint64_t u64; | |
11107 | + struct au_dr_hino *ent; | |
11108 | + struct inode *hinoinode; | |
11109 | + struct hlist_bl_head *hbl; | |
11110 | + | |
11111 | + err = 0; | |
11112 | + pos = 0; | |
11113 | + hbl = dr->dr_h_ino; | |
11114 | + hinoinode = file_inode(hinofile); | |
11115 | + sz = i_size_read(hinoinode); | |
11116 | + AuDebugOn(sz % sizeof(u64)); | |
11117 | + n = sz / sizeof(u64); | |
11118 | + while (n--) { | |
11119 | + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos); | |
11120 | + if (unlikely(ssz != sizeof(u64))) { | |
11121 | + pr_err("ssz %zd, %pD2\n", ssz, hinofile); | |
11122 | + err = -EINVAL; | |
11123 | + if (ssz < 0) | |
11124 | + err = ssz; | |
11125 | + goto out_free; | |
11126 | + } | |
11127 | + | |
11128 | + ent = kmalloc(sizeof(*ent), GFP_NOFS); | |
11129 | + if (!ent) { | |
11130 | + err = -ENOMEM; | |
11131 | + AuTraceErr(err); | |
11132 | + goto out_free; | |
11133 | + } | |
11134 | + ent->dr_h_ino = be64_to_cpu((__force __be64)u64); | |
11135 | + AuDbg("hi%llu, %pD2\n", | |
11136 | + (unsigned long long)ent->dr_h_ino, hinofile); | |
11137 | + hidx = au_dr_ihash(ent->dr_h_ino); | |
11138 | + au_hbl_add(&ent->dr_hnode, hbl + hidx); | |
11139 | + } | |
11140 | + goto out; /* success */ | |
11141 | + | |
11142 | +out_free: | |
11143 | + au_dr_hino_free(dr); | |
11144 | +out: | |
11145 | + AuTraceErr(err); | |
11146 | + return err; | |
11147 | +} | |
11148 | + | |
11149 | +/* | |
11150 | + * @bindex/@br is a switch to distinguish whether suspending hnotify or not. | |
11151 | + * @path is a switch to distinguish load and store. | |
11152 | + */ | |
11153 | +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex, | |
11154 | + struct au_branch *br, const struct path *path) | |
11155 | +{ | |
11156 | + int err, flags; | |
11157 | + unsigned char load, suspend; | |
11158 | + struct file *hinofile; | |
11159 | + struct au_hinode *hdir; | |
11160 | + struct inode *dir, *delegated; | |
11161 | + struct path hinopath; | |
11162 | + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO, | |
11163 | + sizeof(AUFS_WH_DR_BRHINO) - 1); | |
11164 | + | |
11165 | + AuDebugOn(bindex < 0 && !br); | |
11166 | + AuDebugOn(bindex >= 0 && br); | |
11167 | + | |
11168 | + err = -EINVAL; | |
11169 | + suspend = !br; | |
11170 | + if (suspend) | |
11171 | + br = au_sbr(sb, bindex); | |
11172 | + load = !!path; | |
11173 | + if (!load) { | |
11174 | + path = &br->br_path; | |
11175 | + AuDebugOn(!au_br_writable(br->br_perm)); | |
11176 | + if (unlikely(!au_br_writable(br->br_perm))) | |
11177 | + goto out; | |
11178 | + } | |
11179 | + | |
11180 | + hdir = NULL; | |
11181 | + if (suspend) { | |
11182 | + dir = d_inode(sb->s_root); | |
11183 | + hdir = au_hinode(au_ii(dir), bindex); | |
11184 | + dir = hdir->hi_inode; | |
11185 | + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD); | |
11186 | + } else { | |
11187 | + dir = d_inode(path->dentry); | |
11188 | + inode_lock_nested(dir, AuLsc_I_CHILD); | |
11189 | + } | |
11190 | + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry); | |
11191 | + err = PTR_ERR(hinopath.dentry); | |
11192 | + if (IS_ERR(hinopath.dentry)) | |
11193 | + goto out_unlock; | |
11194 | + | |
11195 | + err = 0; | |
11196 | + flags = O_RDONLY; | |
11197 | + if (load) { | |
11198 | + if (d_is_negative(hinopath.dentry)) | |
11199 | + goto out_dput; /* success */ | |
11200 | + } else { | |
11201 | + if (au_dr_hino_test_empty(&br->br_dirren)) { | |
11202 | + if (d_is_positive(hinopath.dentry)) { | |
11203 | + delegated = NULL; | |
11204 | + err = vfsub_unlink(dir, &hinopath, &delegated, | |
11205 | + /*force*/0); | |
11206 | + AuTraceErr(err); | |
11207 | + if (unlikely(err)) | |
11208 | + pr_err("ignored err %d, %pd2\n", | |
11209 | + err, hinopath.dentry); | |
11210 | + if (unlikely(err == -EWOULDBLOCK)) | |
11211 | + iput(delegated); | |
11212 | + err = 0; | |
11213 | + } | |
11214 | + goto out_dput; | |
11215 | + } else if (!d_is_positive(hinopath.dentry)) { | |
11216 | + err = vfsub_create(dir, &hinopath, 0600, | |
11217 | + /*want_excl*/false); | |
11218 | + AuTraceErr(err); | |
11219 | + if (unlikely(err)) | |
11220 | + goto out_dput; | |
11221 | + } | |
11222 | + flags = O_WRONLY; | |
11223 | + } | |
11224 | + hinopath.mnt = path->mnt; | |
11225 | + hinofile = vfsub_dentry_open(&hinopath, flags); | |
11226 | + if (suspend) | |
11227 | + au_hn_inode_unlock(hdir); | |
11228 | + else | |
11229 | + inode_unlock(dir); | |
11230 | + dput(hinopath.dentry); | |
11231 | + AuTraceErrPtr(hinofile); | |
11232 | + if (IS_ERR(hinofile)) { | |
11233 | + err = PTR_ERR(hinofile); | |
11234 | + goto out; | |
11235 | + } | |
11236 | + | |
11237 | + if (load) | |
11238 | + err = au_dr_hino_load(&br->br_dirren, hinofile); | |
11239 | + else | |
11240 | + err = au_dr_hino_store(sb, br, hinofile); | |
11241 | + fput(hinofile); | |
11242 | + goto out; | |
11243 | + | |
11244 | +out_dput: | |
11245 | + dput(hinopath.dentry); | |
11246 | +out_unlock: | |
11247 | + if (suspend) | |
11248 | + au_hn_inode_unlock(hdir); | |
11249 | + else | |
11250 | + inode_unlock(dir); | |
11251 | +out: | |
11252 | + AuTraceErr(err); | |
11253 | + return err; | |
11254 | +} | |
11255 | + | |
11256 | +/* ---------------------------------------------------------------------- */ | |
11257 | + | |
11258 | +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path) | |
11259 | +{ | |
11260 | + int err; | |
11261 | + struct kstatfs kstfs; | |
11262 | + dev_t dev; | |
11263 | + struct dentry *dentry; | |
11264 | + struct super_block *sb; | |
11265 | + | |
11266 | + err = vfs_statfs((void *)path, &kstfs); | |
11267 | + AuTraceErr(err); | |
11268 | + if (unlikely(err)) | |
11269 | + goto out; | |
11270 | + | |
11271 | + /* todo: support for UUID */ | |
11272 | + | |
11273 | + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) { | |
11274 | + brid->type = AuBrid_FSID; | |
11275 | + brid->fsid = kstfs.f_fsid; | |
11276 | + } else { | |
11277 | + dentry = path->dentry; | |
11278 | + sb = dentry->d_sb; | |
11279 | + dev = sb->s_dev; | |
11280 | + if (dev) { | |
11281 | + brid->type = AuBrid_DEV; | |
11282 | + brid->dev = dev; | |
11283 | + } | |
11284 | + } | |
11285 | + | |
11286 | +out: | |
11287 | + return err; | |
11288 | +} | |
11289 | + | |
11290 | +int au_dr_br_init(struct super_block *sb, struct au_branch *br, | |
11291 | + const struct path *path) | |
11292 | +{ | |
11293 | + int err, i; | |
11294 | + struct au_dr_br *dr; | |
11295 | + struct hlist_bl_head *hbl; | |
11296 | + | |
11297 | + dr = &br->br_dirren; | |
11298 | + hbl = dr->dr_h_ino; | |
11299 | + for (i = 0; i < AuDirren_NHASH; i++, hbl++) | |
11300 | + INIT_HLIST_BL_HEAD(hbl); | |
11301 | + | |
11302 | + err = au_dr_brid_init(&dr->dr_brid, path); | |
11303 | + if (unlikely(err)) | |
11304 | + goto out; | |
11305 | + | |
11306 | + if (au_opt_test(au_mntflags(sb), DIRREN)) | |
11307 | + err = au_dr_hino(sb, /*bindex*/-1, br, path); | |
11308 | + | |
11309 | +out: | |
11310 | + AuTraceErr(err); | |
11311 | + return err; | |
11312 | +} | |
11313 | + | |
11314 | +int au_dr_br_fin(struct super_block *sb, struct au_branch *br) | |
11315 | +{ | |
11316 | + int err; | |
11317 | + | |
11318 | + err = 0; | |
11319 | + if (au_br_writable(br->br_perm)) | |
11320 | + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL); | |
11321 | + if (!err) | |
11322 | + au_dr_hino_free(&br->br_dirren); | |
11323 | + | |
11324 | + return err; | |
11325 | +} | |
11326 | + | |
11327 | +/* ---------------------------------------------------------------------- */ | |
11328 | + | |
11329 | +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode, | |
11330 | + char *buf, size_t sz) | |
11331 | +{ | |
11332 | + int err; | |
11333 | + unsigned int major, minor; | |
11334 | + char *p; | |
11335 | + | |
11336 | + p = buf; | |
11337 | + err = snprintf(p, sz, "%d_", brid->type); | |
11338 | + AuDebugOn(err > sz); | |
11339 | + p += err; | |
11340 | + sz -= err; | |
11341 | + switch (brid->type) { | |
11342 | + case AuBrid_Unset: | |
11343 | + return -EINVAL; | |
11344 | + case AuBrid_UUID: | |
11345 | + err = snprintf(p, sz, "%pU", brid->uuid.b); | |
11346 | + break; | |
11347 | + case AuBrid_FSID: | |
11348 | + err = snprintf(p, sz, "%08x-%08x", | |
11349 | + brid->fsid.val[0], brid->fsid.val[1]); | |
11350 | + break; | |
11351 | + case AuBrid_DEV: | |
11352 | + major = MAJOR(brid->dev); | |
11353 | + minor = MINOR(brid->dev); | |
11354 | + if (major <= 0xff && minor <= 0xff) | |
11355 | + err = snprintf(p, sz, "%02x%02x", major, minor); | |
11356 | + else | |
11357 | + err = snprintf(p, sz, "%03x:%05x", major, minor); | |
11358 | + break; | |
11359 | + } | |
11360 | + AuDebugOn(err > sz); | |
11361 | + p += err; | |
11362 | + sz -= err; | |
11363 | + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino); | |
11364 | + AuDebugOn(err > sz); | |
11365 | + p += err; | |
11366 | + sz -= err; | |
11367 | + | |
11368 | + return p - buf; | |
11369 | +} | |
11370 | + | |
11371 | +static int au_drinfo_name(struct au_branch *br, char *name, int len) | |
11372 | +{ | |
11373 | + int rlen; | |
11374 | + struct dentry *br_dentry; | |
11375 | + struct inode *br_inode; | |
11376 | + | |
11377 | + br_dentry = au_br_dentry(br); | |
11378 | + br_inode = d_inode(br_dentry); | |
11379 | + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len); | |
11380 | + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ); | |
11381 | + AuDebugOn(rlen > len); | |
11382 | + | |
11383 | + return rlen; | |
11384 | +} | |
11385 | + | |
11386 | +/* ---------------------------------------------------------------------- */ | |
11387 | + | |
11388 | +/* | |
11389 | + * from the given @h_dentry, construct drinfo at @*fdata. | |
11390 | + * when the size of @*fdata is not enough, reallocate and return new @fdata and | |
11391 | + * @allocated. | |
11392 | + */ | |
11393 | +static int au_drinfo_construct(struct au_drinfo_fdata **fdata, | |
11394 | + struct dentry *h_dentry, | |
11395 | + unsigned char *allocated) | |
11396 | +{ | |
11397 | + int err, v; | |
11398 | + struct au_drinfo_fdata *f, *p; | |
11399 | + struct au_drinfo *drinfo; | |
11400 | + struct inode *h_inode; | |
11401 | + struct qstr *qname; | |
11402 | + | |
11403 | + err = 0; | |
11404 | + f = *fdata; | |
11405 | + h_inode = d_inode(h_dentry); | |
11406 | + qname = &h_dentry->d_name; | |
11407 | + drinfo = &f->drinfo; | |
11408 | + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino); | |
11409 | + drinfo->oldnamelen = qname->len; | |
11410 | + if (*allocated < sizeof(*f) + qname->len) { | |
11411 | + v = roundup_pow_of_two(*allocated + qname->len); | |
11412 | + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0); | |
11413 | + if (unlikely(!p)) { | |
11414 | + err = -ENOMEM; | |
11415 | + AuTraceErr(err); | |
11416 | + goto out; | |
11417 | + } | |
11418 | + f = p; | |
11419 | + *fdata = f; | |
11420 | + *allocated = v; | |
11421 | + drinfo = &f->drinfo; | |
11422 | + } | |
11423 | + memcpy(drinfo->oldname, qname->name, qname->len); | |
11424 | + AuDbg("i%llu, %.*s\n", | |
11425 | + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen, | |
11426 | + drinfo->oldname); | |
11427 | + | |
11428 | +out: | |
11429 | + AuTraceErr(err); | |
11430 | + return err; | |
11431 | +} | |
11432 | + | |
11433 | +/* callers have to free the return value */ | |
11434 | +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino) | |
11435 | +{ | |
11436 | + struct au_drinfo *ret, *drinfo; | |
11437 | + struct au_drinfo_fdata fdata; | |
11438 | + int len; | |
11439 | + loff_t pos; | |
11440 | + ssize_t ssz; | |
11441 | + | |
11442 | + ret = ERR_PTR(-EIO); | |
11443 | + pos = 0; | |
11444 | + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos); | |
11445 | + if (unlikely(ssz != sizeof(fdata))) { | |
11446 | + AuIOErr("ssz %zd, %u, %pD2\n", | |
11447 | + ssz, (unsigned int)sizeof(fdata), file); | |
11448 | + goto out; | |
11449 | + } | |
11450 | + | |
11451 | + fdata.magic = ntohl((__force __be32)fdata.magic); | |
11452 | + switch (fdata.magic) { | |
11453 | + case AUFS_DRINFO_MAGIC_V1: | |
11454 | + break; | |
11455 | + default: | |
11456 | + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n", | |
11457 | + fdata.magic, AUFS_DRINFO_MAGIC_V1, file); | |
11458 | + goto out; | |
11459 | + } | |
11460 | + | |
11461 | + drinfo = &fdata.drinfo; | |
11462 | + len = drinfo->oldnamelen; | |
11463 | + if (!len) { | |
11464 | + AuIOErr("broken drinfo %pD2\n", file); | |
11465 | + goto out; | |
11466 | + } | |
11467 | + | |
11468 | + ret = NULL; | |
11469 | + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino); | |
11470 | + if (unlikely(h_ino && drinfo->ino != h_ino)) { | |
11471 | + AuDbg("ignored i%llu, i%llu, %pD2\n", | |
11472 | + (unsigned long long)drinfo->ino, | |
11473 | + (unsigned long long)h_ino, file); | |
11474 | + goto out; /* success */ | |
11475 | + } | |
11476 | + | |
11477 | + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS); | |
11478 | + if (unlikely(!ret)) { | |
11479 | + ret = ERR_PTR(-ENOMEM); | |
11480 | + AuTraceErrPtr(ret); | |
11481 | + goto out; | |
11482 | + } | |
11483 | + | |
11484 | + *ret = *drinfo; | |
11485 | + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos); | |
11486 | + if (unlikely(ssz != len)) { | |
11487 | + kfree(ret); | |
11488 | + ret = ERR_PTR(-EIO); | |
11489 | + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file); | |
11490 | + goto out; | |
11491 | + } | |
11492 | + | |
11493 | + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname); | |
11494 | + | |
11495 | +out: | |
11496 | + return ret; | |
11497 | +} | |
11498 | + | |
11499 | +/* ---------------------------------------------------------------------- */ | |
11500 | + | |
11501 | +/* in order to be revertible */ | |
11502 | +struct au_drinfo_rev_elm { | |
11503 | + int created; | |
11504 | + struct dentry *info_dentry; | |
11505 | + struct au_drinfo *info_last; | |
11506 | +}; | |
11507 | + | |
11508 | +struct au_drinfo_rev { | |
11509 | + unsigned char already; | |
11510 | + aufs_bindex_t nelm; | |
11511 | + struct au_drinfo_rev_elm elm[0]; | |
11512 | +}; | |
11513 | + | |
11514 | +/* todo: isn't it too large? */ | |
11515 | +struct au_drinfo_store { | |
11516 | + struct path h_ppath; | |
11517 | + struct dentry *h_dentry; | |
11518 | + struct au_drinfo_fdata *fdata; | |
11519 | + char *infoname; /* inside of whname, just after PFX */ | |
11520 | + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]; | |
11521 | + aufs_bindex_t btgt, btail; | |
11522 | + unsigned char no_sio, | |
11523 | + allocated, /* current size of *fdata */ | |
11524 | + infonamelen, /* room size for p */ | |
11525 | + whnamelen, /* length of the genarated name */ | |
11526 | + renameback; /* renamed back */ | |
11527 | +}; | |
11528 | + | |
11529 | +/* on rename(2) error, the caller should revert it using @elm */ | |
11530 | +static int au_drinfo_do_store(struct au_drinfo_store *w, | |
11531 | + struct au_drinfo_rev_elm *elm) | |
11532 | +{ | |
11533 | + int err, len; | |
11534 | + ssize_t ssz; | |
11535 | + loff_t pos; | |
11536 | + struct path infopath = { | |
11537 | + .mnt = w->h_ppath.mnt | |
11538 | + }; | |
11539 | + struct inode *h_dir, *h_inode, *delegated; | |
11540 | + struct file *infofile; | |
11541 | + struct qstr *qname; | |
11542 | + | |
11543 | + AuDebugOn(elm | |
11544 | + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm))); | |
11545 | + | |
11546 | + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry, | |
11547 | + w->whnamelen); | |
11548 | + AuTraceErrPtr(infopath.dentry); | |
11549 | + if (IS_ERR(infopath.dentry)) { | |
11550 | + err = PTR_ERR(infopath.dentry); | |
11551 | + goto out; | |
11552 | + } | |
11553 | + | |
11554 | + err = 0; | |
11555 | + h_dir = d_inode(w->h_ppath.dentry); | |
11556 | + if (elm && d_is_negative(infopath.dentry)) { | |
11557 | + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true); | |
11558 | + AuTraceErr(err); | |
11559 | + if (unlikely(err)) | |
11560 | + goto out_dput; | |
11561 | + elm->created = 1; | |
11562 | + elm->info_dentry = dget(infopath.dentry); | |
11563 | + } | |
11564 | + | |
11565 | + infofile = vfsub_dentry_open(&infopath, O_RDWR); | |
11566 | + AuTraceErrPtr(infofile); | |
11567 | + if (IS_ERR(infofile)) { | |
11568 | + err = PTR_ERR(infofile); | |
11569 | + goto out_dput; | |
11570 | + } | |
11571 | + | |
11572 | + h_inode = d_inode(infopath.dentry); | |
11573 | + if (elm && i_size_read(h_inode)) { | |
11574 | + h_inode = d_inode(w->h_dentry); | |
11575 | + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino); | |
11576 | + AuTraceErrPtr(elm->info_last); | |
11577 | + if (IS_ERR(elm->info_last)) { | |
11578 | + err = PTR_ERR(elm->info_last); | |
11579 | + elm->info_last = NULL; | |
11580 | + AuDebugOn(elm->info_dentry); | |
11581 | + goto out_fput; | |
11582 | + } | |
11583 | + } | |
11584 | + | |
11585 | + if (elm && w->renameback) { | |
11586 | + delegated = NULL; | |
11587 | + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0); | |
11588 | + AuTraceErr(err); | |
11589 | + if (unlikely(err == -EWOULDBLOCK)) | |
11590 | + iput(delegated); | |
11591 | + goto out_fput; | |
11592 | + } | |
11593 | + | |
11594 | + pos = 0; | |
11595 | + qname = &w->h_dentry->d_name; | |
11596 | + len = sizeof(*w->fdata) + qname->len; | |
11597 | + if (!elm) | |
11598 | + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen; | |
11599 | + ssz = vfsub_write_k(infofile, w->fdata, len, &pos); | |
11600 | + if (ssz == len) { | |
11601 | + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino, | |
11602 | + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname); | |
11603 | + goto out_fput; /* success */ | |
11604 | + } else { | |
11605 | + err = -EIO; | |
11606 | + if (ssz < 0) | |
11607 | + err = ssz; | |
11608 | + /* the caller should revert it using @elm */ | |
11609 | + } | |
11610 | + | |
11611 | +out_fput: | |
11612 | + fput(infofile); | |
11613 | +out_dput: | |
11614 | + dput(infopath.dentry); | |
11615 | +out: | |
11616 | + AuTraceErr(err); | |
11617 | + return err; | |
11618 | +} | |
11619 | + | |
11620 | +struct au_call_drinfo_do_store_args { | |
11621 | + int *errp; | |
11622 | + struct au_drinfo_store *w; | |
11623 | + struct au_drinfo_rev_elm *elm; | |
11624 | +}; | |
11625 | + | |
11626 | +static void au_call_drinfo_do_store(void *args) | |
11627 | +{ | |
11628 | + struct au_call_drinfo_do_store_args *a = args; | |
11629 | + | |
11630 | + *a->errp = au_drinfo_do_store(a->w, a->elm); | |
11631 | +} | |
11632 | + | |
11633 | +static int au_drinfo_store_sio(struct au_drinfo_store *w, | |
11634 | + struct au_drinfo_rev_elm *elm) | |
11635 | +{ | |
11636 | + int err, wkq_err; | |
11637 | + | |
11638 | + if (w->no_sio) | |
11639 | + err = au_drinfo_do_store(w, elm); | |
11640 | + else { | |
11641 | + struct au_call_drinfo_do_store_args a = { | |
11642 | + .errp = &err, | |
11643 | + .w = w, | |
11644 | + .elm = elm | |
11645 | + }; | |
11646 | + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a); | |
11647 | + if (unlikely(wkq_err)) | |
11648 | + err = wkq_err; | |
11649 | + } | |
11650 | + AuTraceErr(err); | |
11651 | + | |
11652 | + return err; | |
11653 | +} | |
11654 | + | |
11655 | +static int au_drinfo_store_work_init(struct au_drinfo_store *w, | |
11656 | + aufs_bindex_t btgt) | |
11657 | +{ | |
11658 | + int err; | |
11659 | + | |
11660 | + memset(w, 0, sizeof(*w)); | |
11661 | + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40); | |
11662 | + strcpy(w->whname, AUFS_WH_DR_INFO_PFX); | |
11663 | + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1; | |
11664 | + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX); | |
11665 | + w->btgt = btgt; | |
11666 | + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID); | |
11667 | + | |
11668 | + err = -ENOMEM; | |
11669 | + w->fdata = kcalloc(1, w->allocated, GFP_NOFS); | |
11670 | + if (unlikely(!w->fdata)) { | |
11671 | + AuTraceErr(err); | |
11672 | + goto out; | |
11673 | + } | |
11674 | + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1); | |
11675 | + err = 0; | |
11676 | + | |
11677 | +out: | |
11678 | + return err; | |
11679 | +} | |
11680 | + | |
11681 | +static void au_drinfo_store_work_fin(struct au_drinfo_store *w) | |
11682 | +{ | |
11683 | + kfree(w->fdata); | |
11684 | +} | |
11685 | + | |
11686 | +static void au_drinfo_store_rev(struct au_drinfo_rev *rev, | |
11687 | + struct au_drinfo_store *w) | |
11688 | +{ | |
11689 | + struct au_drinfo_rev_elm *elm; | |
11690 | + struct inode *h_dir, *delegated; | |
11691 | + int err, nelm; | |
11692 | + struct path infopath = { | |
11693 | + .mnt = w->h_ppath.mnt | |
11694 | + }; | |
11695 | + | |
11696 | + h_dir = d_inode(w->h_ppath.dentry); | |
11697 | + IMustLock(h_dir); | |
11698 | + | |
11699 | + err = 0; | |
11700 | + elm = rev->elm; | |
11701 | + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) { | |
11702 | + AuDebugOn(elm->created && elm->info_last); | |
11703 | + if (elm->created) { | |
11704 | + AuDbg("here\n"); | |
11705 | + delegated = NULL; | |
11706 | + infopath.dentry = elm->info_dentry; | |
11707 | + err = vfsub_unlink(h_dir, &infopath, &delegated, | |
11708 | + !w->no_sio); | |
11709 | + AuTraceErr(err); | |
11710 | + if (unlikely(err == -EWOULDBLOCK)) | |
11711 | + iput(delegated); | |
11712 | + dput(elm->info_dentry); | |
11713 | + } else if (elm->info_last) { | |
11714 | + AuDbg("here\n"); | |
11715 | + w->fdata->drinfo = *elm->info_last; | |
11716 | + memcpy(w->fdata->drinfo.oldname, | |
11717 | + elm->info_last->oldname, | |
11718 | + elm->info_last->oldnamelen); | |
11719 | + err = au_drinfo_store_sio(w, /*elm*/NULL); | |
11720 | + kfree(elm->info_last); | |
11721 | + } | |
11722 | + if (unlikely(err)) | |
11723 | + AuIOErr("%d, %s\n", err, w->whname); | |
11724 | + /* go on even if err */ | |
11725 | + } | |
11726 | +} | |
11727 | + | |
11728 | +/* caller has to call au_dr_rename_fin() later */ | |
11729 | +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt, | |
11730 | + struct qstr *dst_name, void *_rev) | |
11731 | +{ | |
11732 | + int err, sz, nelm; | |
11733 | + aufs_bindex_t bindex, btail; | |
11734 | + struct au_drinfo_store work; | |
11735 | + struct au_drinfo_rev *rev, **p; | |
11736 | + struct au_drinfo_rev_elm *elm; | |
11737 | + struct super_block *sb; | |
11738 | + struct au_branch *br; | |
11739 | + struct au_hinode *hdir; | |
11740 | + | |
11741 | + err = au_drinfo_store_work_init(&work, btgt); | |
11742 | + AuTraceErr(err); | |
11743 | + if (unlikely(err)) | |
11744 | + goto out; | |
11745 | + | |
11746 | + err = -ENOMEM; | |
11747 | + btail = au_dbtaildir(dentry); | |
11748 | + nelm = btail - btgt; | |
11749 | + sz = sizeof(*rev) + sizeof(*elm) * nelm; | |
11750 | + rev = kcalloc(1, sz, GFP_NOFS); | |
11751 | + if (unlikely(!rev)) { | |
11752 | + AuTraceErr(err); | |
11753 | + goto out_args; | |
11754 | + } | |
11755 | + rev->nelm = nelm; | |
11756 | + elm = rev->elm; | |
11757 | + p = _rev; | |
11758 | + *p = rev; | |
11759 | + | |
11760 | + err = 0; | |
11761 | + sb = dentry->d_sb; | |
11762 | + work.h_ppath.dentry = au_h_dptr(dentry, btgt); | |
11763 | + work.h_ppath.mnt = au_sbr_mnt(sb, btgt); | |
11764 | + hdir = au_hi(d_inode(dentry), btgt); | |
11765 | + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD); | |
11766 | + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) { | |
11767 | + work.h_dentry = au_h_dptr(dentry, bindex); | |
11768 | + if (!work.h_dentry) | |
11769 | + continue; | |
11770 | + | |
11771 | + err = au_drinfo_construct(&work.fdata, work.h_dentry, | |
11772 | + &work.allocated); | |
11773 | + AuTraceErr(err); | |
11774 | + if (unlikely(err)) | |
11775 | + break; | |
11776 | + | |
11777 | + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name); | |
11778 | + br = au_sbr(sb, bindex); | |
11779 | + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1; | |
11780 | + work.whnamelen += au_drinfo_name(br, work.infoname, | |
11781 | + work.infonamelen); | |
11782 | + AuDbg("whname %.*s, i%llu, %.*s\n", | |
11783 | + work.whnamelen, work.whname, | |
11784 | + be64_to_cpu((__force __be64)work.fdata->drinfo.ino), | |
11785 | + work.fdata->drinfo.oldnamelen, | |
11786 | + work.fdata->drinfo.oldname); | |
11787 | + | |
11788 | + err = au_drinfo_store_sio(&work, elm); | |
11789 | + AuTraceErr(err); | |
11790 | + if (unlikely(err)) | |
11791 | + break; | |
11792 | + } | |
11793 | + if (unlikely(err)) { | |
11794 | + /* revert all drinfo */ | |
11795 | + au_drinfo_store_rev(rev, &work); | |
11796 | + kfree(rev); | |
11797 | + *p = NULL; | |
11798 | + } | |
11799 | + au_hn_inode_unlock(hdir); | |
11800 | + | |
11801 | +out_args: | |
11802 | + au_drinfo_store_work_fin(&work); | |
11803 | +out: | |
11804 | + return err; | |
11805 | +} | |
11806 | + | |
11807 | +/* ---------------------------------------------------------------------- */ | |
11808 | + | |
11809 | +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex, | |
11810 | + struct qstr *dst_name, void *_rev) | |
11811 | +{ | |
11812 | + int err, already; | |
11813 | + ino_t ino; | |
11814 | + struct super_block *sb; | |
11815 | + struct au_branch *br; | |
11816 | + struct au_dr_br *dr; | |
11817 | + struct dentry *h_dentry; | |
11818 | + struct inode *h_inode; | |
11819 | + struct au_dr_hino *ent; | |
11820 | + struct au_drinfo_rev *rev, **p; | |
11821 | + | |
11822 | + AuDbg("bindex %d\n", bindex); | |
11823 | + | |
11824 | + err = -ENOMEM; | |
11825 | + ent = kmalloc(sizeof(*ent), GFP_NOFS); | |
11826 | + if (unlikely(!ent)) | |
11827 | + goto out; | |
11828 | + | |
11829 | + sb = src->d_sb; | |
11830 | + br = au_sbr(sb, bindex); | |
11831 | + dr = &br->br_dirren; | |
11832 | + h_dentry = au_h_dptr(src, bindex); | |
11833 | + h_inode = d_inode(h_dentry); | |
11834 | + ino = h_inode->i_ino; | |
11835 | + ent->dr_h_ino = ino; | |
11836 | + already = au_dr_hino_test_add(dr, ino, ent); | |
11837 | + AuDbg("b%d, hi%llu, already %d\n", | |
11838 | + bindex, (unsigned long long)ino, already); | |
11839 | + | |
11840 | + err = au_drinfo_store(src, bindex, dst_name, _rev); | |
11841 | + AuTraceErr(err); | |
11842 | + if (!err) { | |
11843 | + p = _rev; | |
11844 | + rev = *p; | |
11845 | + rev->already = already; | |
11846 | + goto out; /* success */ | |
11847 | + } | |
11848 | + | |
11849 | + /* revert */ | |
11850 | + if (!already) | |
11851 | + au_dr_hino_del(dr, ent); | |
11852 | + kfree(ent); | |
11853 | + | |
11854 | +out: | |
11855 | + AuTraceErr(err); | |
11856 | + return err; | |
11857 | +} | |
11858 | + | |
11859 | +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev) | |
11860 | +{ | |
11861 | + struct au_drinfo_rev *rev; | |
11862 | + struct au_drinfo_rev_elm *elm; | |
11863 | + int nelm; | |
11864 | + | |
11865 | + rev = _rev; | |
11866 | + elm = rev->elm; | |
11867 | + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) { | |
11868 | + dput(elm->info_dentry); | |
11869 | + kfree(elm->info_last); | |
11870 | + } | |
11871 | + kfree(rev); | |
11872 | +} | |
11873 | + | |
11874 | +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev) | |
11875 | +{ | |
11876 | + int err; | |
11877 | + struct au_drinfo_store work; | |
11878 | + struct au_drinfo_rev *rev = _rev; | |
11879 | + struct super_block *sb; | |
11880 | + struct au_branch *br; | |
11881 | + struct inode *h_inode; | |
11882 | + struct au_dr_br *dr; | |
11883 | + struct au_dr_hino *ent; | |
11884 | + | |
11885 | + err = au_drinfo_store_work_init(&work, btgt); | |
11886 | + if (unlikely(err)) | |
11887 | + goto out; | |
11888 | + | |
11889 | + sb = src->d_sb; | |
11890 | + br = au_sbr(sb, btgt); | |
11891 | + work.h_ppath.dentry = au_h_dptr(src, btgt); | |
11892 | + work.h_ppath.mnt = au_br_mnt(br); | |
11893 | + au_drinfo_store_rev(rev, &work); | |
11894 | + au_drinfo_store_work_fin(&work); | |
11895 | + if (rev->already) | |
11896 | + goto out; | |
11897 | + | |
11898 | + dr = &br->br_dirren; | |
11899 | + h_inode = d_inode(work.h_ppath.dentry); | |
11900 | + ent = au_dr_hino_find(dr, h_inode->i_ino); | |
11901 | + BUG_ON(!ent); | |
11902 | + au_dr_hino_del(dr, ent); | |
11903 | + kfree(ent); | |
11904 | + | |
11905 | +out: | |
11906 | + kfree(rev); | |
11907 | + if (unlikely(err)) | |
11908 | + pr_err("failed to remove dirren info\n"); | |
11909 | +} | |
11910 | + | |
11911 | +/* ---------------------------------------------------------------------- */ | |
11912 | + | |
11913 | +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath, | |
11914 | + char *whname, int whnamelen, | |
11915 | + struct dentry **info_dentry) | |
11916 | +{ | |
11917 | + struct au_drinfo *drinfo; | |
11918 | + struct file *f; | |
11919 | + struct inode *h_dir; | |
11920 | + struct path infopath; | |
11921 | + int unlocked; | |
11922 | + | |
11923 | + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname); | |
11924 | + | |
11925 | + *info_dentry = NULL; | |
11926 | + drinfo = NULL; | |
11927 | + unlocked = 0; | |
11928 | + h_dir = d_inode(h_ppath->dentry); | |
11929 | + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT); | |
11930 | + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry, | |
11931 | + whnamelen); | |
11932 | + if (IS_ERR(infopath.dentry)) { | |
11933 | + drinfo = (void *)infopath.dentry; | |
11934 | + goto out; | |
11935 | + } | |
11936 | + | |
11937 | + if (d_is_negative(infopath.dentry)) | |
11938 | + goto out_dput; /* success */ | |
11939 | + | |
11940 | + infopath.mnt = h_ppath->mnt; | |
11941 | + f = vfsub_dentry_open(&infopath, O_RDONLY); | |
11942 | + inode_unlock_shared(h_dir); | |
11943 | + unlocked = 1; | |
11944 | + if (IS_ERR(f)) { | |
11945 | + drinfo = (void *)f; | |
11946 | + goto out_dput; | |
11947 | + } | |
11948 | + | |
11949 | + drinfo = au_drinfo_read_k(f, /*h_ino*/0); | |
11950 | + if (IS_ERR_OR_NULL(drinfo)) | |
11951 | + goto out_fput; | |
11952 | + | |
11953 | + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname); | |
11954 | + *info_dentry = dget(infopath.dentry); /* keep it alive */ | |
11955 | + | |
11956 | +out_fput: | |
11957 | + fput(f); | |
11958 | +out_dput: | |
11959 | + dput(infopath.dentry); | |
11960 | +out: | |
11961 | + if (!unlocked) | |
11962 | + inode_unlock_shared(h_dir); | |
11963 | + AuTraceErrPtr(drinfo); | |
11964 | + return drinfo; | |
11965 | +} | |
11966 | + | |
11967 | +struct au_drinfo_do_load_args { | |
11968 | + struct au_drinfo **drinfop; | |
11969 | + struct path *h_ppath; | |
11970 | + char *whname; | |
11971 | + int whnamelen; | |
11972 | + struct dentry **info_dentry; | |
11973 | +}; | |
11974 | + | |
11975 | +static void au_call_drinfo_do_load(void *args) | |
11976 | +{ | |
11977 | + struct au_drinfo_do_load_args *a = args; | |
11978 | + | |
11979 | + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen, | |
11980 | + a->info_dentry); | |
11981 | +} | |
11982 | + | |
11983 | +struct au_drinfo_load { | |
11984 | + struct path h_ppath; | |
11985 | + struct qstr *qname; | |
11986 | + unsigned char no_sio; | |
11987 | + | |
11988 | + aufs_bindex_t ninfo; | |
11989 | + struct au_drinfo **drinfo; | |
11990 | +}; | |
11991 | + | |
11992 | +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex, | |
11993 | + struct au_branch *br) | |
11994 | +{ | |
11995 | + int err, wkq_err, whnamelen, e; | |
11996 | + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ] | |
11997 | + = AUFS_WH_DR_INFO_PFX; | |
11998 | + struct au_drinfo *drinfo; | |
11999 | + struct qstr oldname; | |
12000 | + struct inode *h_dir, *delegated; | |
12001 | + struct dentry *info_dentry; | |
12002 | + struct path infopath; | |
12003 | + | |
12004 | + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1; | |
12005 | + whnamelen += au_drinfo_name(br, whname + whnamelen, | |
12006 | + sizeof(whname) - whnamelen); | |
12007 | + if (w->no_sio) | |
12008 | + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen, | |
12009 | + &info_dentry); | |
12010 | + else { | |
12011 | + struct au_drinfo_do_load_args args = { | |
12012 | + .drinfop = &drinfo, | |
12013 | + .h_ppath = &w->h_ppath, | |
12014 | + .whname = whname, | |
12015 | + .whnamelen = whnamelen, | |
12016 | + .info_dentry = &info_dentry | |
12017 | + }; | |
12018 | + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args); | |
12019 | + if (unlikely(wkq_err)) | |
12020 | + drinfo = ERR_PTR(wkq_err); | |
12021 | + } | |
12022 | + err = PTR_ERR(drinfo); | |
12023 | + if (IS_ERR_OR_NULL(drinfo)) | |
12024 | + goto out; | |
12025 | + | |
12026 | + err = 0; | |
12027 | + oldname.len = drinfo->oldnamelen; | |
12028 | + oldname.name = drinfo->oldname; | |
12029 | + if (au_qstreq(w->qname, &oldname)) { | |
12030 | + /* the name is renamed back */ | |
12031 | + kfree(drinfo); | |
12032 | + drinfo = NULL; | |
12033 | + | |
12034 | + infopath.dentry = info_dentry; | |
12035 | + infopath.mnt = w->h_ppath.mnt; | |
12036 | + h_dir = d_inode(w->h_ppath.dentry); | |
12037 | + delegated = NULL; | |
12038 | + inode_lock_nested(h_dir, AuLsc_I_PARENT); | |
12039 | + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio); | |
12040 | + inode_unlock(h_dir); | |
12041 | + if (unlikely(e)) | |
12042 | + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry); | |
12043 | + if (unlikely(e == -EWOULDBLOCK)) | |
12044 | + iput(delegated); | |
12045 | + } | |
12046 | + kfree(w->drinfo[bindex]); | |
12047 | + w->drinfo[bindex] = drinfo; | |
12048 | + dput(info_dentry); | |
12049 | + | |
12050 | +out: | |
12051 | + AuTraceErr(err); | |
12052 | + return err; | |
12053 | +} | |
12054 | + | |
12055 | +/* ---------------------------------------------------------------------- */ | |
12056 | + | |
12057 | +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n) | |
12058 | +{ | |
12059 | + struct au_drinfo **p = drinfo; | |
12060 | + | |
12061 | + while (n-- > 0) | |
12062 | + kfree(*drinfo++); | |
12063 | + kfree(p); | |
12064 | +} | |
12065 | + | |
12066 | +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry, | |
12067 | + aufs_bindex_t btgt) | |
12068 | +{ | |
12069 | + int err, ninfo; | |
12070 | + struct au_drinfo_load w; | |
12071 | + aufs_bindex_t bindex, bbot; | |
12072 | + struct au_branch *br; | |
12073 | + struct inode *h_dir; | |
12074 | + struct au_dr_hino *ent; | |
12075 | + struct super_block *sb; | |
12076 | + | |
12077 | + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n", | |
12078 | + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name), | |
12079 | + AuLNPair(&lkup->whname), btgt); | |
12080 | + | |
12081 | + sb = dentry->d_sb; | |
12082 | + bbot = au_sbbot(sb); | |
12083 | + w.ninfo = bbot + 1; | |
12084 | + if (!lkup->dirren.drinfo) { | |
12085 | + lkup->dirren.drinfo = kcalloc(w.ninfo, | |
12086 | + sizeof(*lkup->dirren.drinfo), | |
12087 | + GFP_NOFS); | |
12088 | + if (unlikely(!lkup->dirren.drinfo)) { | |
12089 | + err = -ENOMEM; | |
12090 | + goto out; | |
12091 | + } | |
12092 | + lkup->dirren.ninfo = w.ninfo; | |
12093 | + } | |
12094 | + w.drinfo = lkup->dirren.drinfo; | |
12095 | + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID); | |
12096 | + w.h_ppath.dentry = au_h_dptr(dentry, btgt); | |
12097 | + AuDebugOn(!w.h_ppath.dentry); | |
12098 | + w.h_ppath.mnt = au_sbr_mnt(sb, btgt); | |
12099 | + w.qname = &dentry->d_name; | |
12100 | + | |
12101 | + ninfo = 0; | |
12102 | + for (bindex = btgt + 1; bindex <= bbot; bindex++) { | |
12103 | + br = au_sbr(sb, bindex); | |
12104 | + err = au_drinfo_load(&w, bindex, br); | |
12105 | + if (unlikely(err)) | |
12106 | + goto out_free; | |
12107 | + if (w.drinfo[bindex]) | |
12108 | + ninfo++; | |
12109 | + } | |
12110 | + if (!ninfo) { | |
12111 | + br = au_sbr(sb, btgt); | |
12112 | + h_dir = d_inode(w.h_ppath.dentry); | |
12113 | + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino); | |
12114 | + AuDebugOn(!ent); | |
12115 | + au_dr_hino_del(&br->br_dirren, ent); | |
12116 | + kfree(ent); | |
12117 | + } | |
12118 | + goto out; /* success */ | |
12119 | + | |
12120 | +out_free: | |
12121 | + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo); | |
12122 | + lkup->dirren.ninfo = 0; | |
12123 | + lkup->dirren.drinfo = NULL; | |
12124 | +out: | |
12125 | + AuTraceErr(err); | |
12126 | + return err; | |
12127 | +} | |
12128 | + | |
12129 | +void au_dr_lkup_fin(struct au_do_lookup_args *lkup) | |
12130 | +{ | |
12131 | + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo); | |
12132 | +} | |
12133 | + | |
12134 | +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt) | |
12135 | +{ | |
12136 | + int err; | |
12137 | + struct au_drinfo *drinfo; | |
12138 | + | |
12139 | + err = 0; | |
12140 | + if (!lkup->dirren.drinfo) | |
12141 | + goto out; | |
12142 | + AuDebugOn(lkup->dirren.ninfo < btgt + 1); | |
12143 | + drinfo = lkup->dirren.drinfo[btgt + 1]; | |
12144 | + if (!drinfo) | |
12145 | + goto out; | |
12146 | + | |
12147 | + kfree(lkup->whname.name); | |
12148 | + lkup->whname.name = NULL; | |
12149 | + lkup->dirren.dr_name.len = drinfo->oldnamelen; | |
12150 | + lkup->dirren.dr_name.name = drinfo->oldname; | |
12151 | + lkup->name = &lkup->dirren.dr_name; | |
12152 | + err = au_wh_name_alloc(&lkup->whname, lkup->name); | |
12153 | + if (!err) | |
12154 | + AuDbg("name %.*s, whname %.*s, b%d\n", | |
12155 | + AuLNPair(lkup->name), AuLNPair(&lkup->whname), | |
12156 | + btgt); | |
12157 | + | |
12158 | +out: | |
12159 | + AuTraceErr(err); | |
12160 | + return err; | |
12161 | +} | |
12162 | + | |
12163 | +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex, | |
12164 | + ino_t h_ino) | |
12165 | +{ | |
12166 | + int match; | |
12167 | + struct au_drinfo *drinfo; | |
12168 | + | |
12169 | + match = 1; | |
12170 | + if (!lkup->dirren.drinfo) | |
12171 | + goto out; | |
12172 | + AuDebugOn(lkup->dirren.ninfo < bindex + 1); | |
12173 | + drinfo = lkup->dirren.drinfo[bindex + 1]; | |
12174 | + if (!drinfo) | |
12175 | + goto out; | |
12176 | + | |
12177 | + match = (drinfo->ino == h_ino); | |
12178 | + AuDbg("match %d\n", match); | |
12179 | + | |
12180 | +out: | |
12181 | + return match; | |
12182 | +} | |
12183 | + | |
12184 | +/* ---------------------------------------------------------------------- */ | |
12185 | + | |
12186 | +int au_dr_opt_set(struct super_block *sb) | |
12187 | +{ | |
12188 | + int err; | |
12189 | + aufs_bindex_t bindex, bbot; | |
12190 | + struct au_branch *br; | |
12191 | + | |
12192 | + err = 0; | |
12193 | + bbot = au_sbbot(sb); | |
12194 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
12195 | + br = au_sbr(sb, bindex); | |
12196 | + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path); | |
12197 | + } | |
12198 | + | |
12199 | + return err; | |
12200 | +} | |
12201 | + | |
12202 | +int au_dr_opt_flush(struct super_block *sb) | |
12203 | +{ | |
12204 | + int err; | |
12205 | + aufs_bindex_t bindex, bbot; | |
12206 | + struct au_branch *br; | |
12207 | + | |
12208 | + err = 0; | |
12209 | + bbot = au_sbbot(sb); | |
12210 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
12211 | + br = au_sbr(sb, bindex); | |
12212 | + if (au_br_writable(br->br_perm)) | |
12213 | + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL); | |
12214 | + } | |
12215 | + | |
12216 | + return err; | |
12217 | +} | |
12218 | + | |
12219 | +int au_dr_opt_clr(struct super_block *sb, int no_flush) | |
12220 | +{ | |
12221 | + int err; | |
12222 | + aufs_bindex_t bindex, bbot; | |
12223 | + struct au_branch *br; | |
12224 | + | |
12225 | + err = 0; | |
12226 | + if (!no_flush) { | |
12227 | + err = au_dr_opt_flush(sb); | |
12228 | + if (unlikely(err)) | |
12229 | + goto out; | |
12230 | + } | |
12231 | + | |
12232 | + bbot = au_sbbot(sb); | |
12233 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
12234 | + br = au_sbr(sb, bindex); | |
12235 | + au_dr_hino_free(&br->br_dirren); | |
12236 | + } | |
12237 | + | |
12238 | +out: | |
12239 | + return err; | |
12240 | +} | |
12241 | diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h | |
12242 | --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 12243 | +++ linux/fs/aufs/dirren.h 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 AM |
12244 | @@ -0,0 +1,139 @@ |
12245 | +/* | |
12246 | + * Copyright (C) 2017 Junjiro R. Okajima | |
12247 | + * | |
12248 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12249 | + * it under the terms of the GNU General Public License as published by | |
12250 | + * the Free Software Foundation; either version 2 of the License, or | |
12251 | + * (at your option) any later version. | |
12252 | + * | |
12253 | + * This program is distributed in the hope that it will be useful, | |
12254 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12255 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12256 | + * GNU General Public License for more details. | |
12257 | + * | |
12258 | + * You should have received a copy of the GNU General Public License | |
12259 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
12260 | + */ | |
12261 | + | |
12262 | +/* | |
12263 | + * renamed dir info | |
12264 | + */ | |
12265 | + | |
12266 | +#ifndef __AUFS_DIRREN_H__ | |
12267 | +#define __AUFS_DIRREN_H__ | |
12268 | + | |
12269 | +#ifdef __KERNEL__ | |
12270 | + | |
12271 | +#include <linux/dcache.h> | |
12272 | +#include <linux/statfs.h> | |
12273 | +#include <linux/uuid.h> | |
12274 | +#include "hbl.h" | |
12275 | + | |
12276 | +#define AuDirren_NHASH 100 | |
12277 | + | |
12278 | +#ifdef CONFIG_AUFS_DIRREN | |
12279 | +enum au_brid_type { | |
12280 | + AuBrid_Unset, | |
12281 | + AuBrid_UUID, | |
12282 | + AuBrid_FSID, | |
12283 | + AuBrid_DEV | |
12284 | +}; | |
12285 | + | |
12286 | +struct au_dr_brid { | |
12287 | + enum au_brid_type type; | |
12288 | + union { | |
12289 | + uuid_t uuid; /* unimplemented yet */ | |
12290 | + fsid_t fsid; | |
12291 | + dev_t dev; | |
12292 | + }; | |
12293 | +}; | |
12294 | + | |
12295 | +/* 20 is the max digits length of ulong 64 */ | |
12296 | +/* brid-type "_" uuid "_" inum */ | |
12297 | +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20) | |
12298 | +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20) | |
12299 | + | |
12300 | +struct au_dr_hino { | |
12301 | + struct hlist_bl_node dr_hnode; | |
12302 | + ino_t dr_h_ino; | |
12303 | +}; | |
12304 | + | |
12305 | +struct au_dr_br { | |
12306 | + struct hlist_bl_head dr_h_ino[AuDirren_NHASH]; | |
12307 | + struct au_dr_brid dr_brid; | |
12308 | +}; | |
12309 | + | |
12310 | +struct au_dr_lookup { | |
12311 | + /* dr_name is pointed by struct au_do_lookup_args.name */ | |
12312 | + struct qstr dr_name; /* subset of dr_info */ | |
12313 | + aufs_bindex_t ninfo; | |
12314 | + struct au_drinfo **drinfo; | |
12315 | +}; | |
12316 | +#else | |
12317 | +struct au_dr_hino; | |
12318 | +/* empty */ | |
12319 | +struct au_dr_br { }; | |
12320 | +struct au_dr_lookup { }; | |
12321 | +#endif | |
12322 | + | |
12323 | +/* ---------------------------------------------------------------------- */ | |
12324 | + | |
12325 | +struct au_branch; | |
12326 | +struct au_do_lookup_args; | |
12327 | +struct au_hinode; | |
12328 | +#ifdef CONFIG_AUFS_DIRREN | |
12329 | +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino, | |
12330 | + struct au_dr_hino *add_ent); | |
12331 | +void au_dr_hino_free(struct au_dr_br *dr); | |
12332 | +int au_dr_br_init(struct super_block *sb, struct au_branch *br, | |
12333 | + const struct path *path); | |
12334 | +int au_dr_br_fin(struct super_block *sb, struct au_branch *br); | |
12335 | +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex, | |
12336 | + struct qstr *dst_name, void *_rev); | |
12337 | +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev); | |
12338 | +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev); | |
12339 | +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry, | |
12340 | + aufs_bindex_t bindex); | |
12341 | +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt); | |
12342 | +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex, | |
12343 | + ino_t h_ino); | |
12344 | +void au_dr_lkup_fin(struct au_do_lookup_args *lkup); | |
12345 | +int au_dr_opt_set(struct super_block *sb); | |
12346 | +int au_dr_opt_flush(struct super_block *sb); | |
12347 | +int au_dr_opt_clr(struct super_block *sb, int no_flush); | |
12348 | +#else | |
12349 | +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino, | |
12350 | + struct au_dr_hino *add_ent); | |
12351 | +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr); | |
12352 | +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br, | |
12353 | + const struct path *path); | |
12354 | +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br); | |
12355 | +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex, | |
12356 | + struct qstr *dst_name, void *_rev); | |
12357 | +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev); | |
12358 | +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex, | |
12359 | + void *rev); | |
12360 | +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry, | |
12361 | + aufs_bindex_t bindex); | |
12362 | +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt); | |
12363 | +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup, | |
12364 | + aufs_bindex_t bindex, ino_t h_ino); | |
12365 | +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup); | |
12366 | +AuStubInt0(au_dr_opt_set, struct super_block *sb); | |
12367 | +AuStubInt0(au_dr_opt_flush, struct super_block *sb); | |
12368 | +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush); | |
12369 | +#endif | |
12370 | + | |
12371 | +/* ---------------------------------------------------------------------- */ | |
12372 | + | |
12373 | +#ifdef CONFIG_AUFS_DIRREN | |
12374 | +static inline int au_dr_ihash(ino_t h_ino) | |
12375 | +{ | |
12376 | + return h_ino % AuDirren_NHASH; | |
12377 | +} | |
12378 | +#else | |
12379 | +AuStubInt0(au_dr_ihash, ino_t h_ino); | |
12380 | +#endif | |
12381 | + | |
12382 | +#endif /* __KERNEL__ */ | |
12383 | +#endif /* __AUFS_DIRREN_H__ */ | |
7f207e10 AM |
12384 | diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c |
12385 | --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 12386 | +++ linux/fs/aufs/dynop.c 2018-01-29 07:56:20.053325069 +0100 |
8b6a4947 | 12387 | @@ -0,0 +1,369 @@ |
1facf9fc | 12388 | +/* |
a2654f78 | 12389 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
1facf9fc | 12390 | + * |
12391 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12392 | + * it under the terms of the GNU General Public License as published by | |
12393 | + * the Free Software Foundation; either version 2 of the License, or | |
12394 | + * (at your option) any later version. | |
dece6358 AM |
12395 | + * |
12396 | + * This program is distributed in the hope that it will be useful, | |
12397 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12398 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12399 | + * GNU General Public License for more details. | |
12400 | + * | |
12401 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12402 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 12403 | + */ |
12404 | + | |
12405 | +/* | |
4a4d8108 | 12406 | + * dynamically customizable operations for regular files |
1facf9fc | 12407 | + */ |
12408 | + | |
1facf9fc | 12409 | +#include "aufs.h" |
12410 | + | |
4a4d8108 | 12411 | +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop) |
1facf9fc | 12412 | + |
4a4d8108 AM |
12413 | +/* |
12414 | + * How large will these lists be? | |
12415 | + * Usually just a few elements, 20-30 at most for each, I guess. | |
12416 | + */ | |
8b6a4947 | 12417 | +static struct hlist_bl_head dynop[AuDyLast]; |
4a4d8108 | 12418 | + |
8b6a4947 AM |
12419 | +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl, |
12420 | + const void *h_op) | |
1facf9fc | 12421 | +{ |
4a4d8108 | 12422 | + struct au_dykey *key, *tmp; |
8b6a4947 | 12423 | + struct hlist_bl_node *pos; |
1facf9fc | 12424 | + |
4a4d8108 | 12425 | + key = NULL; |
8b6a4947 AM |
12426 | + hlist_bl_lock(hbl); |
12427 | + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode) | |
4a4d8108 AM |
12428 | + if (tmp->dk_op.dy_hop == h_op) { |
12429 | + key = tmp; | |
12430 | + kref_get(&key->dk_kref); | |
12431 | + break; | |
12432 | + } | |
8b6a4947 | 12433 | + hlist_bl_unlock(hbl); |
4a4d8108 AM |
12434 | + |
12435 | + return key; | |
1facf9fc | 12436 | +} |
12437 | + | |
4a4d8108 | 12438 | +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key) |
1facf9fc | 12439 | +{ |
4a4d8108 AM |
12440 | + struct au_dykey **k, *found; |
12441 | + const void *h_op = key->dk_op.dy_hop; | |
12442 | + int i; | |
1facf9fc | 12443 | + |
4a4d8108 AM |
12444 | + found = NULL; |
12445 | + k = br->br_dykey; | |
12446 | + for (i = 0; i < AuBrDynOp; i++) | |
12447 | + if (k[i]) { | |
12448 | + if (k[i]->dk_op.dy_hop == h_op) { | |
12449 | + found = k[i]; | |
12450 | + break; | |
12451 | + } | |
12452 | + } else | |
12453 | + break; | |
12454 | + if (!found) { | |
12455 | + spin_lock(&br->br_dykey_lock); | |
12456 | + for (; i < AuBrDynOp; i++) | |
12457 | + if (k[i]) { | |
12458 | + if (k[i]->dk_op.dy_hop == h_op) { | |
12459 | + found = k[i]; | |
12460 | + break; | |
12461 | + } | |
12462 | + } else { | |
12463 | + k[i] = key; | |
12464 | + break; | |
12465 | + } | |
12466 | + spin_unlock(&br->br_dykey_lock); | |
12467 | + BUG_ON(i == AuBrDynOp); /* expand the array */ | |
12468 | + } | |
12469 | + | |
12470 | + return found; | |
1facf9fc | 12471 | +} |
12472 | + | |
4a4d8108 | 12473 | +/* kref_get() if @key is already added */ |
8b6a4947 | 12474 | +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key) |
4a4d8108 AM |
12475 | +{ |
12476 | + struct au_dykey *tmp, *found; | |
8b6a4947 | 12477 | + struct hlist_bl_node *pos; |
4a4d8108 | 12478 | + const void *h_op = key->dk_op.dy_hop; |
1facf9fc | 12479 | + |
4a4d8108 | 12480 | + found = NULL; |
8b6a4947 AM |
12481 | + hlist_bl_lock(hbl); |
12482 | + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode) | |
4a4d8108 AM |
12483 | + if (tmp->dk_op.dy_hop == h_op) { |
12484 | + kref_get(&tmp->dk_kref); | |
12485 | + found = tmp; | |
12486 | + break; | |
12487 | + } | |
12488 | + if (!found) | |
8b6a4947 AM |
12489 | + hlist_bl_add_head(&key->dk_hnode, hbl); |
12490 | + hlist_bl_unlock(hbl); | |
1facf9fc | 12491 | + |
4a4d8108 AM |
12492 | + if (!found) |
12493 | + DyPrSym(key); | |
12494 | + return found; | |
12495 | +} | |
12496 | + | |
12497 | +static void dy_free_rcu(struct rcu_head *rcu) | |
1facf9fc | 12498 | +{ |
4a4d8108 AM |
12499 | + struct au_dykey *key; |
12500 | + | |
12501 | + key = container_of(rcu, struct au_dykey, dk_rcu); | |
12502 | + DyPrSym(key); | |
1c60b727 | 12503 | + kfree(key); |
1facf9fc | 12504 | +} |
12505 | + | |
4a4d8108 AM |
12506 | +static void dy_free(struct kref *kref) |
12507 | +{ | |
12508 | + struct au_dykey *key; | |
8b6a4947 | 12509 | + struct hlist_bl_head *hbl; |
1facf9fc | 12510 | + |
4a4d8108 | 12511 | + key = container_of(kref, struct au_dykey, dk_kref); |
8b6a4947 AM |
12512 | + hbl = dynop + key->dk_op.dy_type; |
12513 | + au_hbl_del(&key->dk_hnode, hbl); | |
4a4d8108 AM |
12514 | + call_rcu(&key->dk_rcu, dy_free_rcu); |
12515 | +} | |
12516 | + | |
12517 | +void au_dy_put(struct au_dykey *key) | |
1facf9fc | 12518 | +{ |
4a4d8108 AM |
12519 | + kref_put(&key->dk_kref, dy_free); |
12520 | +} | |
1facf9fc | 12521 | + |
4a4d8108 AM |
12522 | +/* ---------------------------------------------------------------------- */ |
12523 | + | |
12524 | +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *)) | |
12525 | + | |
12526 | +#ifdef CONFIG_AUFS_DEBUG | |
12527 | +#define DyDbgDeclare(cnt) unsigned int cnt = 0 | |
4f0767ce | 12528 | +#define DyDbgInc(cnt) do { cnt++; } while (0) |
4a4d8108 AM |
12529 | +#else |
12530 | +#define DyDbgDeclare(cnt) do {} while (0) | |
12531 | +#define DyDbgInc(cnt) do {} while (0) | |
12532 | +#endif | |
12533 | + | |
12534 | +#define DySet(func, dst, src, h_op, h_sb) do { \ | |
12535 | + DyDbgInc(cnt); \ | |
12536 | + if (h_op->func) { \ | |
12537 | + if (src.func) \ | |
12538 | + dst.func = src.func; \ | |
12539 | + else \ | |
12540 | + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \ | |
12541 | + } \ | |
12542 | +} while (0) | |
12543 | + | |
12544 | +#define DySetForce(func, dst, src) do { \ | |
12545 | + AuDebugOn(!src.func); \ | |
12546 | + DyDbgInc(cnt); \ | |
12547 | + dst.func = src.func; \ | |
12548 | +} while (0) | |
12549 | + | |
12550 | +#define DySetAop(func) \ | |
12551 | + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb) | |
12552 | +#define DySetAopForce(func) \ | |
12553 | + DySetForce(func, dyaop->da_op, aufs_aop) | |
12554 | + | |
12555 | +static void dy_aop(struct au_dykey *key, const void *h_op, | |
12556 | + struct super_block *h_sb __maybe_unused) | |
12557 | +{ | |
12558 | + struct au_dyaop *dyaop = (void *)key; | |
12559 | + const struct address_space_operations *h_aop = h_op; | |
12560 | + DyDbgDeclare(cnt); | |
12561 | + | |
12562 | + AuDbg("%s\n", au_sbtype(h_sb)); | |
12563 | + | |
12564 | + DySetAop(writepage); | |
12565 | + DySetAopForce(readpage); /* force */ | |
4a4d8108 AM |
12566 | + DySetAop(writepages); |
12567 | + DySetAop(set_page_dirty); | |
12568 | + DySetAop(readpages); | |
12569 | + DySetAop(write_begin); | |
12570 | + DySetAop(write_end); | |
12571 | + DySetAop(bmap); | |
12572 | + DySetAop(invalidatepage); | |
12573 | + DySetAop(releasepage); | |
027c5e7a | 12574 | + DySetAop(freepage); |
7e9cd9fe | 12575 | + /* this one will be changed according to an aufs mount option */ |
4a4d8108 | 12576 | + DySetAop(direct_IO); |
4a4d8108 | 12577 | + DySetAop(migratepage); |
e2f27e51 AM |
12578 | + DySetAop(isolate_page); |
12579 | + DySetAop(putback_page); | |
4a4d8108 AM |
12580 | + DySetAop(launder_page); |
12581 | + DySetAop(is_partially_uptodate); | |
392086de | 12582 | + DySetAop(is_dirty_writeback); |
4a4d8108 | 12583 | + DySetAop(error_remove_page); |
b4510431 AM |
12584 | + DySetAop(swap_activate); |
12585 | + DySetAop(swap_deactivate); | |
4a4d8108 AM |
12586 | + |
12587 | + DyDbgSize(cnt, *h_aop); | |
4a4d8108 AM |
12588 | +} |
12589 | + | |
4a4d8108 AM |
12590 | +/* ---------------------------------------------------------------------- */ |
12591 | + | |
12592 | +static void dy_bug(struct kref *kref) | |
12593 | +{ | |
12594 | + BUG(); | |
12595 | +} | |
12596 | + | |
12597 | +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br) | |
12598 | +{ | |
12599 | + struct au_dykey *key, *old; | |
8b6a4947 | 12600 | + struct hlist_bl_head *hbl; |
b752ccd1 | 12601 | + struct op { |
4a4d8108 | 12602 | + unsigned int sz; |
b752ccd1 AM |
12603 | + void (*set)(struct au_dykey *key, const void *h_op, |
12604 | + struct super_block *h_sb __maybe_unused); | |
12605 | + }; | |
12606 | + static const struct op a[] = { | |
4a4d8108 AM |
12607 | + [AuDy_AOP] = { |
12608 | + .sz = sizeof(struct au_dyaop), | |
b752ccd1 | 12609 | + .set = dy_aop |
4a4d8108 | 12610 | + } |
b752ccd1 AM |
12611 | + }; |
12612 | + const struct op *p; | |
4a4d8108 | 12613 | + |
8b6a4947 AM |
12614 | + hbl = dynop + op->dy_type; |
12615 | + key = dy_gfind_get(hbl, op->dy_hop); | |
4a4d8108 AM |
12616 | + if (key) |
12617 | + goto out_add; /* success */ | |
12618 | + | |
12619 | + p = a + op->dy_type; | |
12620 | + key = kzalloc(p->sz, GFP_NOFS); | |
12621 | + if (unlikely(!key)) { | |
12622 | + key = ERR_PTR(-ENOMEM); | |
12623 | + goto out; | |
12624 | + } | |
12625 | + | |
12626 | + key->dk_op.dy_hop = op->dy_hop; | |
12627 | + kref_init(&key->dk_kref); | |
86dc4139 | 12628 | + p->set(key, op->dy_hop, au_br_sb(br)); |
8b6a4947 | 12629 | + old = dy_gadd(hbl, key); |
4a4d8108 | 12630 | + if (old) { |
1c60b727 | 12631 | + kfree(key); |
4a4d8108 AM |
12632 | + key = old; |
12633 | + } | |
12634 | + | |
12635 | +out_add: | |
12636 | + old = dy_bradd(br, key); | |
12637 | + if (old) | |
12638 | + /* its ref-count should never be zero here */ | |
12639 | + kref_put(&key->dk_kref, dy_bug); | |
12640 | +out: | |
12641 | + return key; | |
12642 | +} | |
12643 | + | |
12644 | +/* ---------------------------------------------------------------------- */ | |
12645 | +/* | |
12646 | + * Aufs prohibits O_DIRECT by defaut even if the branch supports it. | |
c1595e42 | 12647 | + * This behaviour is necessary to return an error from open(O_DIRECT) instead |
4a4d8108 AM |
12648 | + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes |
12649 | + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error. | |
12650 | + * See the aufs manual in detail. | |
4a4d8108 AM |
12651 | + */ |
12652 | +static void dy_adx(struct au_dyaop *dyaop, int do_dx) | |
12653 | +{ | |
7e9cd9fe | 12654 | + if (!do_dx) |
4a4d8108 | 12655 | + dyaop->da_op.direct_IO = NULL; |
7e9cd9fe | 12656 | + else |
4a4d8108 | 12657 | + dyaop->da_op.direct_IO = aufs_aop.direct_IO; |
4a4d8108 AM |
12658 | +} |
12659 | + | |
12660 | +static struct au_dyaop *dy_aget(struct au_branch *br, | |
12661 | + const struct address_space_operations *h_aop, | |
12662 | + int do_dx) | |
12663 | +{ | |
12664 | + struct au_dyaop *dyaop; | |
12665 | + struct au_dynop op; | |
12666 | + | |
12667 | + op.dy_type = AuDy_AOP; | |
12668 | + op.dy_haop = h_aop; | |
12669 | + dyaop = (void *)dy_get(&op, br); | |
12670 | + if (IS_ERR(dyaop)) | |
12671 | + goto out; | |
12672 | + dy_adx(dyaop, do_dx); | |
12673 | + | |
12674 | +out: | |
12675 | + return dyaop; | |
12676 | +} | |
12677 | + | |
12678 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
12679 | + struct inode *h_inode) | |
12680 | +{ | |
12681 | + int err, do_dx; | |
12682 | + struct super_block *sb; | |
12683 | + struct au_branch *br; | |
12684 | + struct au_dyaop *dyaop; | |
12685 | + | |
12686 | + AuDebugOn(!S_ISREG(h_inode->i_mode)); | |
12687 | + IiMustWriteLock(inode); | |
12688 | + | |
12689 | + sb = inode->i_sb; | |
12690 | + br = au_sbr(sb, bindex); | |
12691 | + do_dx = !!au_opt_test(au_mntflags(sb), DIO); | |
12692 | + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx); | |
12693 | + err = PTR_ERR(dyaop); | |
12694 | + if (IS_ERR(dyaop)) | |
12695 | + /* unnecessary to call dy_fput() */ | |
12696 | + goto out; | |
12697 | + | |
12698 | + err = 0; | |
12699 | + inode->i_mapping->a_ops = &dyaop->da_op; | |
12700 | + | |
12701 | +out: | |
12702 | + return err; | |
12703 | +} | |
12704 | + | |
b752ccd1 AM |
12705 | +/* |
12706 | + * Is it safe to replace a_ops during the inode/file is in operation? | |
12707 | + * Yes, I hope so. | |
12708 | + */ | |
12709 | +int au_dy_irefresh(struct inode *inode) | |
12710 | +{ | |
12711 | + int err; | |
5afbbe0d | 12712 | + aufs_bindex_t btop; |
b752ccd1 AM |
12713 | + struct inode *h_inode; |
12714 | + | |
12715 | + err = 0; | |
12716 | + if (S_ISREG(inode->i_mode)) { | |
5afbbe0d AM |
12717 | + btop = au_ibtop(inode); |
12718 | + h_inode = au_h_iptr(inode, btop); | |
12719 | + err = au_dy_iaop(inode, btop, h_inode); | |
b752ccd1 AM |
12720 | + } |
12721 | + return err; | |
12722 | +} | |
12723 | + | |
4a4d8108 AM |
12724 | +void au_dy_arefresh(int do_dx) |
12725 | +{ | |
8b6a4947 AM |
12726 | + struct hlist_bl_head *hbl; |
12727 | + struct hlist_bl_node *pos; | |
4a4d8108 AM |
12728 | + struct au_dykey *key; |
12729 | + | |
8b6a4947 AM |
12730 | + hbl = dynop + AuDy_AOP; |
12731 | + hlist_bl_lock(hbl); | |
12732 | + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode) | |
4a4d8108 | 12733 | + dy_adx((void *)key, do_dx); |
8b6a4947 | 12734 | + hlist_bl_unlock(hbl); |
4a4d8108 AM |
12735 | +} |
12736 | + | |
4a4d8108 AM |
12737 | +/* ---------------------------------------------------------------------- */ |
12738 | + | |
12739 | +void __init au_dy_init(void) | |
12740 | +{ | |
12741 | + int i; | |
12742 | + | |
12743 | + /* make sure that 'struct au_dykey *' can be any type */ | |
12744 | + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key)); | |
4a4d8108 AM |
12745 | + |
12746 | + for (i = 0; i < AuDyLast; i++) | |
8b6a4947 | 12747 | + INIT_HLIST_BL_HEAD(dynop + i); |
4a4d8108 AM |
12748 | +} |
12749 | + | |
12750 | +void au_dy_fin(void) | |
12751 | +{ | |
12752 | + int i; | |
12753 | + | |
12754 | + for (i = 0; i < AuDyLast; i++) | |
8b6a4947 | 12755 | + WARN_ON(!hlist_bl_empty(dynop + i)); |
4a4d8108 | 12756 | +} |
7f207e10 AM |
12757 | diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h |
12758 | --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 12759 | +++ linux/fs/aufs/dynop.h 2018-01-29 07:56:20.053325069 +0100 |
7e9cd9fe | 12760 | @@ -0,0 +1,74 @@ |
4a4d8108 | 12761 | +/* |
a2654f78 | 12762 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
4a4d8108 AM |
12763 | + * |
12764 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12765 | + * it under the terms of the GNU General Public License as published by | |
12766 | + * the Free Software Foundation; either version 2 of the License, or | |
12767 | + * (at your option) any later version. | |
12768 | + * | |
12769 | + * This program is distributed in the hope that it will be useful, | |
12770 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12771 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12772 | + * GNU General Public License for more details. | |
12773 | + * | |
12774 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12775 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
12776 | + */ |
12777 | + | |
12778 | +/* | |
12779 | + * dynamically customizable operations (for regular files only) | |
12780 | + */ | |
12781 | + | |
12782 | +#ifndef __AUFS_DYNOP_H__ | |
12783 | +#define __AUFS_DYNOP_H__ | |
12784 | + | |
12785 | +#ifdef __KERNEL__ | |
12786 | + | |
7e9cd9fe AM |
12787 | +#include <linux/fs.h> |
12788 | +#include <linux/kref.h> | |
4a4d8108 | 12789 | + |
2cbb1c4b | 12790 | +enum {AuDy_AOP, AuDyLast}; |
4a4d8108 AM |
12791 | + |
12792 | +struct au_dynop { | |
12793 | + int dy_type; | |
12794 | + union { | |
12795 | + const void *dy_hop; | |
12796 | + const struct address_space_operations *dy_haop; | |
4a4d8108 AM |
12797 | + }; |
12798 | +}; | |
12799 | + | |
12800 | +struct au_dykey { | |
12801 | + union { | |
8b6a4947 | 12802 | + struct hlist_bl_node dk_hnode; |
4a4d8108 AM |
12803 | + struct rcu_head dk_rcu; |
12804 | + }; | |
12805 | + struct au_dynop dk_op; | |
12806 | + | |
12807 | + /* | |
12808 | + * during I am in the branch local array, kref is gotten. when the | |
12809 | + * branch is removed, kref is put. | |
12810 | + */ | |
12811 | + struct kref dk_kref; | |
12812 | +}; | |
12813 | + | |
12814 | +/* stop unioning since their sizes are very different from each other */ | |
12815 | +struct au_dyaop { | |
12816 | + struct au_dykey da_key; | |
12817 | + struct address_space_operations da_op; /* not const */ | |
4a4d8108 AM |
12818 | +}; |
12819 | + | |
4a4d8108 AM |
12820 | +/* ---------------------------------------------------------------------- */ |
12821 | + | |
12822 | +/* dynop.c */ | |
12823 | +struct au_branch; | |
12824 | +void au_dy_put(struct au_dykey *key); | |
12825 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
12826 | + struct inode *h_inode); | |
b752ccd1 | 12827 | +int au_dy_irefresh(struct inode *inode); |
4a4d8108 | 12828 | +void au_dy_arefresh(int do_dio); |
4a4d8108 AM |
12829 | + |
12830 | +void __init au_dy_init(void); | |
12831 | +void au_dy_fin(void); | |
12832 | + | |
4a4d8108 AM |
12833 | +#endif /* __KERNEL__ */ |
12834 | +#endif /* __AUFS_DYNOP_H__ */ | |
7f207e10 AM |
12835 | diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c |
12836 | --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 12837 | +++ linux/fs/aufs/export.c 2018-01-29 07:56:20.053325069 +0100 |
f2c43d5f | 12838 | @@ -0,0 +1,836 @@ |
4a4d8108 | 12839 | +/* |
a2654f78 | 12840 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
12841 | + * |
12842 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12843 | + * it under the terms of the GNU General Public License as published by | |
12844 | + * the Free Software Foundation; either version 2 of the License, or | |
12845 | + * (at your option) any later version. | |
12846 | + * | |
12847 | + * This program is distributed in the hope that it will be useful, | |
12848 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12849 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12850 | + * GNU General Public License for more details. | |
12851 | + * | |
12852 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12853 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
12854 | + */ |
12855 | + | |
12856 | +/* | |
12857 | + * export via nfs | |
12858 | + */ | |
12859 | + | |
12860 | +#include <linux/exportfs.h> | |
7eafdf33 | 12861 | +#include <linux/fs_struct.h> |
4a4d8108 AM |
12862 | +#include <linux/namei.h> |
12863 | +#include <linux/nsproxy.h> | |
12864 | +#include <linux/random.h> | |
12865 | +#include <linux/writeback.h> | |
12866 | +#include "aufs.h" | |
12867 | + | |
12868 | +union conv { | |
12869 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12870 | + __u32 a[2]; | |
12871 | +#else | |
12872 | + __u32 a[1]; | |
12873 | +#endif | |
12874 | + ino_t ino; | |
12875 | +}; | |
12876 | + | |
12877 | +static ino_t decode_ino(__u32 *a) | |
12878 | +{ | |
12879 | + union conv u; | |
12880 | + | |
12881 | + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a)); | |
12882 | + u.a[0] = a[0]; | |
12883 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12884 | + u.a[1] = a[1]; | |
12885 | +#endif | |
12886 | + return u.ino; | |
12887 | +} | |
12888 | + | |
12889 | +static void encode_ino(__u32 *a, ino_t ino) | |
12890 | +{ | |
12891 | + union conv u; | |
12892 | + | |
12893 | + u.ino = ino; | |
12894 | + a[0] = u.a[0]; | |
12895 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12896 | + a[1] = u.a[1]; | |
12897 | +#endif | |
12898 | +} | |
12899 | + | |
12900 | +/* NFS file handle */ | |
12901 | +enum { | |
12902 | + Fh_br_id, | |
12903 | + Fh_sigen, | |
12904 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12905 | + /* support 64bit inode number */ | |
12906 | + Fh_ino1, | |
12907 | + Fh_ino2, | |
12908 | + Fh_dir_ino1, | |
12909 | + Fh_dir_ino2, | |
12910 | +#else | |
12911 | + Fh_ino1, | |
12912 | + Fh_dir_ino1, | |
12913 | +#endif | |
12914 | + Fh_igen, | |
12915 | + Fh_h_type, | |
12916 | + Fh_tail, | |
12917 | + | |
12918 | + Fh_ino = Fh_ino1, | |
12919 | + Fh_dir_ino = Fh_dir_ino1 | |
12920 | +}; | |
12921 | + | |
12922 | +static int au_test_anon(struct dentry *dentry) | |
12923 | +{ | |
027c5e7a | 12924 | + /* note: read d_flags without d_lock */ |
4a4d8108 AM |
12925 | + return !!(dentry->d_flags & DCACHE_DISCONNECTED); |
12926 | +} | |
12927 | + | |
a2a7ad62 AM |
12928 | +int au_test_nfsd(void) |
12929 | +{ | |
12930 | + int ret; | |
12931 | + struct task_struct *tsk = current; | |
12932 | + char comm[sizeof(tsk->comm)]; | |
12933 | + | |
12934 | + ret = 0; | |
12935 | + if (tsk->flags & PF_KTHREAD) { | |
12936 | + get_task_comm(comm, tsk); | |
12937 | + ret = !strcmp(comm, "nfsd"); | |
12938 | + } | |
12939 | + | |
12940 | + return ret; | |
12941 | +} | |
12942 | + | |
4a4d8108 AM |
12943 | +/* ---------------------------------------------------------------------- */ |
12944 | +/* inode generation external table */ | |
12945 | + | |
b752ccd1 | 12946 | +void au_xigen_inc(struct inode *inode) |
4a4d8108 | 12947 | +{ |
4a4d8108 AM |
12948 | + loff_t pos; |
12949 | + ssize_t sz; | |
12950 | + __u32 igen; | |
12951 | + struct super_block *sb; | |
12952 | + struct au_sbinfo *sbinfo; | |
12953 | + | |
4a4d8108 | 12954 | + sb = inode->i_sb; |
b752ccd1 | 12955 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); |
1facf9fc | 12956 | + |
b752ccd1 | 12957 | + sbinfo = au_sbi(sb); |
1facf9fc | 12958 | + pos = inode->i_ino; |
12959 | + pos *= sizeof(igen); | |
12960 | + igen = inode->i_generation + 1; | |
1facf9fc | 12961 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen, |
12962 | + sizeof(igen), &pos); | |
12963 | + if (sz == sizeof(igen)) | |
b752ccd1 | 12964 | + return; /* success */ |
1facf9fc | 12965 | + |
b752ccd1 | 12966 | + if (unlikely(sz >= 0)) |
1facf9fc | 12967 | + AuIOErr("xigen error (%zd)\n", sz); |
1facf9fc | 12968 | +} |
12969 | + | |
12970 | +int au_xigen_new(struct inode *inode) | |
12971 | +{ | |
12972 | + int err; | |
12973 | + loff_t pos; | |
12974 | + ssize_t sz; | |
12975 | + struct super_block *sb; | |
12976 | + struct au_sbinfo *sbinfo; | |
12977 | + struct file *file; | |
12978 | + | |
12979 | + err = 0; | |
12980 | + /* todo: dirty, at mount time */ | |
12981 | + if (inode->i_ino == AUFS_ROOT_INO) | |
12982 | + goto out; | |
12983 | + sb = inode->i_sb; | |
dece6358 | 12984 | + SiMustAnyLock(sb); |
1facf9fc | 12985 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) |
12986 | + goto out; | |
12987 | + | |
12988 | + err = -EFBIG; | |
12989 | + pos = inode->i_ino; | |
12990 | + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) { | |
12991 | + AuIOErr1("too large i%lld\n", pos); | |
12992 | + goto out; | |
12993 | + } | |
12994 | + pos *= sizeof(inode->i_generation); | |
12995 | + | |
12996 | + err = 0; | |
12997 | + sbinfo = au_sbi(sb); | |
12998 | + file = sbinfo->si_xigen; | |
12999 | + BUG_ON(!file); | |
13000 | + | |
c06a8ce3 | 13001 | + if (vfsub_f_size_read(file) |
1facf9fc | 13002 | + < pos + sizeof(inode->i_generation)) { |
13003 | + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next); | |
13004 | + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation, | |
13005 | + sizeof(inode->i_generation), &pos); | |
13006 | + } else | |
13007 | + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation, | |
13008 | + sizeof(inode->i_generation), &pos); | |
13009 | + if (sz == sizeof(inode->i_generation)) | |
13010 | + goto out; /* success */ | |
13011 | + | |
13012 | + err = sz; | |
13013 | + if (unlikely(sz >= 0)) { | |
13014 | + err = -EIO; | |
13015 | + AuIOErr("xigen error (%zd)\n", sz); | |
13016 | + } | |
13017 | + | |
4f0767ce | 13018 | +out: |
1facf9fc | 13019 | + return err; |
13020 | +} | |
13021 | + | |
13022 | +int au_xigen_set(struct super_block *sb, struct file *base) | |
13023 | +{ | |
13024 | + int err; | |
13025 | + struct au_sbinfo *sbinfo; | |
13026 | + struct file *file; | |
13027 | + | |
dece6358 AM |
13028 | + SiMustWriteLock(sb); |
13029 | + | |
1facf9fc | 13030 | + sbinfo = au_sbi(sb); |
13031 | + file = au_xino_create2(base, sbinfo->si_xigen); | |
13032 | + err = PTR_ERR(file); | |
13033 | + if (IS_ERR(file)) | |
13034 | + goto out; | |
13035 | + err = 0; | |
13036 | + if (sbinfo->si_xigen) | |
13037 | + fput(sbinfo->si_xigen); | |
13038 | + sbinfo->si_xigen = file; | |
13039 | + | |
4f0767ce | 13040 | +out: |
1facf9fc | 13041 | + return err; |
13042 | +} | |
13043 | + | |
13044 | +void au_xigen_clr(struct super_block *sb) | |
13045 | +{ | |
13046 | + struct au_sbinfo *sbinfo; | |
13047 | + | |
dece6358 AM |
13048 | + SiMustWriteLock(sb); |
13049 | + | |
1facf9fc | 13050 | + sbinfo = au_sbi(sb); |
13051 | + if (sbinfo->si_xigen) { | |
13052 | + fput(sbinfo->si_xigen); | |
13053 | + sbinfo->si_xigen = NULL; | |
13054 | + } | |
13055 | +} | |
13056 | + | |
13057 | +/* ---------------------------------------------------------------------- */ | |
13058 | + | |
13059 | +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino, | |
13060 | + ino_t dir_ino) | |
13061 | +{ | |
13062 | + struct dentry *dentry, *d; | |
13063 | + struct inode *inode; | |
13064 | + unsigned int sigen; | |
13065 | + | |
13066 | + dentry = NULL; | |
13067 | + inode = ilookup(sb, ino); | |
13068 | + if (!inode) | |
13069 | + goto out; | |
13070 | + | |
13071 | + dentry = ERR_PTR(-ESTALE); | |
13072 | + sigen = au_sigen(sb); | |
5afbbe0d | 13073 | + if (unlikely(au_is_bad_inode(inode) |
1facf9fc | 13074 | + || IS_DEADDIR(inode) |
537831f9 | 13075 | + || sigen != au_iigen(inode, NULL))) |
1facf9fc | 13076 | + goto out_iput; |
13077 | + | |
13078 | + dentry = NULL; | |
13079 | + if (!dir_ino || S_ISDIR(inode->i_mode)) | |
13080 | + dentry = d_find_alias(inode); | |
13081 | + else { | |
027c5e7a | 13082 | + spin_lock(&inode->i_lock); |
c1595e42 | 13083 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 13084 | + spin_lock(&d->d_lock); |
1facf9fc | 13085 | + if (!au_test_anon(d) |
5527c038 | 13086 | + && d_inode(d->d_parent)->i_ino == dir_ino) { |
027c5e7a AM |
13087 | + dentry = dget_dlock(d); |
13088 | + spin_unlock(&d->d_lock); | |
1facf9fc | 13089 | + break; |
13090 | + } | |
027c5e7a AM |
13091 | + spin_unlock(&d->d_lock); |
13092 | + } | |
13093 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 13094 | + } |
027c5e7a | 13095 | + if (unlikely(dentry && au_digen_test(dentry, sigen))) { |
2cbb1c4b | 13096 | + /* need to refresh */ |
1facf9fc | 13097 | + dput(dentry); |
2cbb1c4b | 13098 | + dentry = NULL; |
1facf9fc | 13099 | + } |
13100 | + | |
4f0767ce | 13101 | +out_iput: |
1facf9fc | 13102 | + iput(inode); |
4f0767ce | 13103 | +out: |
2cbb1c4b | 13104 | + AuTraceErrPtr(dentry); |
1facf9fc | 13105 | + return dentry; |
13106 | +} | |
13107 | + | |
13108 | +/* ---------------------------------------------------------------------- */ | |
13109 | + | |
13110 | +/* todo: dirty? */ | |
13111 | +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */ | |
4a4d8108 AM |
13112 | + |
13113 | +struct au_compare_mnt_args { | |
13114 | + /* input */ | |
13115 | + struct super_block *sb; | |
13116 | + | |
13117 | + /* output */ | |
13118 | + struct vfsmount *mnt; | |
13119 | +}; | |
13120 | + | |
13121 | +static int au_compare_mnt(struct vfsmount *mnt, void *arg) | |
13122 | +{ | |
13123 | + struct au_compare_mnt_args *a = arg; | |
13124 | + | |
13125 | + if (mnt->mnt_sb != a->sb) | |
13126 | + return 0; | |
13127 | + a->mnt = mntget(mnt); | |
13128 | + return 1; | |
13129 | +} | |
13130 | + | |
1facf9fc | 13131 | +static struct vfsmount *au_mnt_get(struct super_block *sb) |
13132 | +{ | |
4a4d8108 | 13133 | + int err; |
7eafdf33 | 13134 | + struct path root; |
4a4d8108 AM |
13135 | + struct au_compare_mnt_args args = { |
13136 | + .sb = sb | |
13137 | + }; | |
1facf9fc | 13138 | + |
7eafdf33 | 13139 | + get_fs_root(current->fs, &root); |
523b37e3 | 13140 | + rcu_read_lock(); |
7eafdf33 | 13141 | + err = iterate_mounts(au_compare_mnt, &args, root.mnt); |
523b37e3 | 13142 | + rcu_read_unlock(); |
7eafdf33 | 13143 | + path_put(&root); |
4a4d8108 AM |
13144 | + AuDebugOn(!err); |
13145 | + AuDebugOn(!args.mnt); | |
13146 | + return args.mnt; | |
1facf9fc | 13147 | +} |
13148 | + | |
13149 | +struct au_nfsd_si_lock { | |
4a4d8108 | 13150 | + unsigned int sigen; |
027c5e7a | 13151 | + aufs_bindex_t bindex, br_id; |
1facf9fc | 13152 | + unsigned char force_lock; |
13153 | +}; | |
13154 | + | |
027c5e7a AM |
13155 | +static int si_nfsd_read_lock(struct super_block *sb, |
13156 | + struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 13157 | +{ |
027c5e7a | 13158 | + int err; |
1facf9fc | 13159 | + aufs_bindex_t bindex; |
13160 | + | |
13161 | + si_read_lock(sb, AuLock_FLUSH); | |
13162 | + | |
13163 | + /* branch id may be wrapped around */ | |
027c5e7a | 13164 | + err = 0; |
1facf9fc | 13165 | + bindex = au_br_index(sb, nsi_lock->br_id); |
13166 | + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb)) | |
13167 | + goto out; /* success */ | |
13168 | + | |
027c5e7a AM |
13169 | + err = -ESTALE; |
13170 | + bindex = -1; | |
1facf9fc | 13171 | + if (!nsi_lock->force_lock) |
13172 | + si_read_unlock(sb); | |
1facf9fc | 13173 | + |
4f0767ce | 13174 | +out: |
027c5e7a AM |
13175 | + nsi_lock->bindex = bindex; |
13176 | + return err; | |
1facf9fc | 13177 | +} |
13178 | + | |
13179 | +struct find_name_by_ino { | |
392086de | 13180 | + struct dir_context ctx; |
1facf9fc | 13181 | + int called, found; |
13182 | + ino_t ino; | |
13183 | + char *name; | |
13184 | + int namelen; | |
13185 | +}; | |
13186 | + | |
13187 | +static int | |
392086de AM |
13188 | +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen, |
13189 | + loff_t offset, u64 ino, unsigned int d_type) | |
1facf9fc | 13190 | +{ |
392086de AM |
13191 | + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino, |
13192 | + ctx); | |
1facf9fc | 13193 | + |
13194 | + a->called++; | |
13195 | + if (a->ino != ino) | |
13196 | + return 0; | |
13197 | + | |
13198 | + memcpy(a->name, name, namelen); | |
13199 | + a->namelen = namelen; | |
13200 | + a->found = 1; | |
13201 | + return 1; | |
13202 | +} | |
13203 | + | |
13204 | +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino, | |
13205 | + struct au_nfsd_si_lock *nsi_lock) | |
13206 | +{ | |
13207 | + struct dentry *dentry, *parent; | |
13208 | + struct file *file; | |
13209 | + struct inode *dir; | |
392086de AM |
13210 | + struct find_name_by_ino arg = { |
13211 | + .ctx = { | |
2000de60 | 13212 | + .actor = find_name_by_ino |
392086de AM |
13213 | + } |
13214 | + }; | |
1facf9fc | 13215 | + int err; |
13216 | + | |
13217 | + parent = path->dentry; | |
13218 | + if (nsi_lock) | |
13219 | + si_read_unlock(parent->d_sb); | |
4a4d8108 | 13220 | + file = vfsub_dentry_open(path, au_dir_roflags); |
1facf9fc | 13221 | + dentry = (void *)file; |
13222 | + if (IS_ERR(file)) | |
13223 | + goto out; | |
13224 | + | |
13225 | + dentry = ERR_PTR(-ENOMEM); | |
537831f9 | 13226 | + arg.name = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 13227 | + if (unlikely(!arg.name)) |
13228 | + goto out_file; | |
13229 | + arg.ino = ino; | |
13230 | + arg.found = 0; | |
13231 | + do { | |
13232 | + arg.called = 0; | |
13233 | + /* smp_mb(); */ | |
392086de | 13234 | + err = vfsub_iterate_dir(file, &arg.ctx); |
1facf9fc | 13235 | + } while (!err && !arg.found && arg.called); |
13236 | + dentry = ERR_PTR(err); | |
13237 | + if (unlikely(err)) | |
13238 | + goto out_name; | |
1716fcea AM |
13239 | + /* instead of ENOENT */ |
13240 | + dentry = ERR_PTR(-ESTALE); | |
1facf9fc | 13241 | + if (!arg.found) |
13242 | + goto out_name; | |
13243 | + | |
b4510431 | 13244 | + /* do not call vfsub_lkup_one() */ |
5527c038 | 13245 | + dir = d_inode(parent); |
febd17d6 | 13246 | + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen); |
1facf9fc | 13247 | + AuTraceErrPtr(dentry); |
13248 | + if (IS_ERR(dentry)) | |
13249 | + goto out_name; | |
13250 | + AuDebugOn(au_test_anon(dentry)); | |
5527c038 | 13251 | + if (unlikely(d_really_is_negative(dentry))) { |
1facf9fc | 13252 | + dput(dentry); |
13253 | + dentry = ERR_PTR(-ENOENT); | |
13254 | + } | |
13255 | + | |
4f0767ce | 13256 | +out_name: |
1c60b727 | 13257 | + free_page((unsigned long)arg.name); |
4f0767ce | 13258 | +out_file: |
1facf9fc | 13259 | + fput(file); |
4f0767ce | 13260 | +out: |
1facf9fc | 13261 | + if (unlikely(nsi_lock |
13262 | + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0)) | |
13263 | + if (!IS_ERR(dentry)) { | |
13264 | + dput(dentry); | |
13265 | + dentry = ERR_PTR(-ESTALE); | |
13266 | + } | |
13267 | + AuTraceErrPtr(dentry); | |
13268 | + return dentry; | |
13269 | +} | |
13270 | + | |
13271 | +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino, | |
13272 | + ino_t dir_ino, | |
13273 | + struct au_nfsd_si_lock *nsi_lock) | |
13274 | +{ | |
13275 | + struct dentry *dentry; | |
13276 | + struct path path; | |
13277 | + | |
13278 | + if (dir_ino != AUFS_ROOT_INO) { | |
13279 | + path.dentry = decode_by_ino(sb, dir_ino, 0); | |
13280 | + dentry = path.dentry; | |
13281 | + if (!path.dentry || IS_ERR(path.dentry)) | |
13282 | + goto out; | |
13283 | + AuDebugOn(au_test_anon(path.dentry)); | |
13284 | + } else | |
13285 | + path.dentry = dget(sb->s_root); | |
13286 | + | |
13287 | + path.mnt = au_mnt_get(sb); | |
13288 | + dentry = au_lkup_by_ino(&path, ino, nsi_lock); | |
13289 | + path_put(&path); | |
13290 | + | |
4f0767ce | 13291 | +out: |
1facf9fc | 13292 | + AuTraceErrPtr(dentry); |
13293 | + return dentry; | |
13294 | +} | |
13295 | + | |
13296 | +/* ---------------------------------------------------------------------- */ | |
13297 | + | |
13298 | +static int h_acceptable(void *expv, struct dentry *dentry) | |
13299 | +{ | |
13300 | + return 1; | |
13301 | +} | |
13302 | + | |
13303 | +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath, | |
13304 | + char *buf, int len, struct super_block *sb) | |
13305 | +{ | |
13306 | + char *p; | |
13307 | + int n; | |
13308 | + struct path path; | |
13309 | + | |
13310 | + p = d_path(h_rootpath, buf, len); | |
13311 | + if (IS_ERR(p)) | |
13312 | + goto out; | |
13313 | + n = strlen(p); | |
13314 | + | |
13315 | + path.mnt = h_rootpath->mnt; | |
13316 | + path.dentry = h_parent; | |
13317 | + p = d_path(&path, buf, len); | |
13318 | + if (IS_ERR(p)) | |
13319 | + goto out; | |
13320 | + if (n != 1) | |
13321 | + p += n; | |
13322 | + | |
13323 | + path.mnt = au_mnt_get(sb); | |
13324 | + path.dentry = sb->s_root; | |
13325 | + p = d_path(&path, buf, len - strlen(p)); | |
13326 | + mntput(path.mnt); | |
13327 | + if (IS_ERR(p)) | |
13328 | + goto out; | |
13329 | + if (n != 1) | |
13330 | + p[strlen(p)] = '/'; | |
13331 | + | |
4f0767ce | 13332 | +out: |
1facf9fc | 13333 | + AuTraceErrPtr(p); |
13334 | + return p; | |
13335 | +} | |
13336 | + | |
13337 | +static | |
027c5e7a AM |
13338 | +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh, |
13339 | + int fh_len, struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 13340 | +{ |
13341 | + struct dentry *dentry, *h_parent, *root; | |
13342 | + struct super_block *h_sb; | |
13343 | + char *pathname, *p; | |
13344 | + struct vfsmount *h_mnt; | |
13345 | + struct au_branch *br; | |
13346 | + int err; | |
13347 | + struct path path; | |
13348 | + | |
027c5e7a | 13349 | + br = au_sbr(sb, nsi_lock->bindex); |
86dc4139 | 13350 | + h_mnt = au_br_mnt(br); |
1facf9fc | 13351 | + h_sb = h_mnt->mnt_sb; |
13352 | + /* todo: call lower fh_to_dentry()? fh_to_parent()? */ | |
5afbbe0d | 13353 | + lockdep_off(); |
1facf9fc | 13354 | + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail), |
13355 | + fh_len - Fh_tail, fh[Fh_h_type], | |
13356 | + h_acceptable, /*context*/NULL); | |
5afbbe0d | 13357 | + lockdep_on(); |
1facf9fc | 13358 | + dentry = h_parent; |
13359 | + if (unlikely(!h_parent || IS_ERR(h_parent))) { | |
13360 | + AuWarn1("%s decode_fh failed, %ld\n", | |
13361 | + au_sbtype(h_sb), PTR_ERR(h_parent)); | |
13362 | + goto out; | |
13363 | + } | |
13364 | + dentry = NULL; | |
13365 | + if (unlikely(au_test_anon(h_parent))) { | |
13366 | + AuWarn1("%s decode_fh returned a disconnected dentry\n", | |
13367 | + au_sbtype(h_sb)); | |
13368 | + goto out_h_parent; | |
13369 | + } | |
13370 | + | |
13371 | + dentry = ERR_PTR(-ENOMEM); | |
13372 | + pathname = (void *)__get_free_page(GFP_NOFS); | |
13373 | + if (unlikely(!pathname)) | |
13374 | + goto out_h_parent; | |
13375 | + | |
13376 | + root = sb->s_root; | |
13377 | + path.mnt = h_mnt; | |
13378 | + di_read_lock_parent(root, !AuLock_IR); | |
027c5e7a | 13379 | + path.dentry = au_h_dptr(root, nsi_lock->bindex); |
1facf9fc | 13380 | + di_read_unlock(root, !AuLock_IR); |
13381 | + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb); | |
13382 | + dentry = (void *)p; | |
13383 | + if (IS_ERR(p)) | |
13384 | + goto out_pathname; | |
13385 | + | |
13386 | + si_read_unlock(sb); | |
13387 | + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | |
13388 | + dentry = ERR_PTR(err); | |
13389 | + if (unlikely(err)) | |
13390 | + goto out_relock; | |
13391 | + | |
13392 | + dentry = ERR_PTR(-ENOENT); | |
13393 | + AuDebugOn(au_test_anon(path.dentry)); | |
5527c038 | 13394 | + if (unlikely(d_really_is_negative(path.dentry))) |
1facf9fc | 13395 | + goto out_path; |
13396 | + | |
5527c038 | 13397 | + if (ino != d_inode(path.dentry)->i_ino) |
1facf9fc | 13398 | + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL); |
13399 | + else | |
13400 | + dentry = dget(path.dentry); | |
13401 | + | |
4f0767ce | 13402 | +out_path: |
1facf9fc | 13403 | + path_put(&path); |
4f0767ce | 13404 | +out_relock: |
1facf9fc | 13405 | + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0)) |
13406 | + if (!IS_ERR(dentry)) { | |
13407 | + dput(dentry); | |
13408 | + dentry = ERR_PTR(-ESTALE); | |
13409 | + } | |
4f0767ce | 13410 | +out_pathname: |
1c60b727 | 13411 | + free_page((unsigned long)pathname); |
4f0767ce | 13412 | +out_h_parent: |
1facf9fc | 13413 | + dput(h_parent); |
4f0767ce | 13414 | +out: |
1facf9fc | 13415 | + AuTraceErrPtr(dentry); |
13416 | + return dentry; | |
13417 | +} | |
13418 | + | |
13419 | +/* ---------------------------------------------------------------------- */ | |
13420 | + | |
13421 | +static struct dentry * | |
13422 | +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, | |
13423 | + int fh_type) | |
13424 | +{ | |
13425 | + struct dentry *dentry; | |
13426 | + __u32 *fh = fid->raw; | |
027c5e7a | 13427 | + struct au_branch *br; |
1facf9fc | 13428 | + ino_t ino, dir_ino; |
1facf9fc | 13429 | + struct au_nfsd_si_lock nsi_lock = { |
1facf9fc | 13430 | + .force_lock = 0 |
13431 | + }; | |
13432 | + | |
1facf9fc | 13433 | + dentry = ERR_PTR(-ESTALE); |
4a4d8108 AM |
13434 | + /* it should never happen, but the file handle is unreliable */ |
13435 | + if (unlikely(fh_len < Fh_tail)) | |
13436 | + goto out; | |
13437 | + nsi_lock.sigen = fh[Fh_sigen]; | |
13438 | + nsi_lock.br_id = fh[Fh_br_id]; | |
13439 | + | |
1facf9fc | 13440 | + /* branch id may be wrapped around */ |
027c5e7a AM |
13441 | + br = NULL; |
13442 | + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock))) | |
1facf9fc | 13443 | + goto out; |
13444 | + nsi_lock.force_lock = 1; | |
13445 | + | |
13446 | + /* is this inode still cached? */ | |
13447 | + ino = decode_ino(fh + Fh_ino); | |
4a4d8108 AM |
13448 | + /* it should never happen */ |
13449 | + if (unlikely(ino == AUFS_ROOT_INO)) | |
8cdd5066 | 13450 | + goto out_unlock; |
4a4d8108 | 13451 | + |
1facf9fc | 13452 | + dir_ino = decode_ino(fh + Fh_dir_ino); |
13453 | + dentry = decode_by_ino(sb, ino, dir_ino); | |
13454 | + if (IS_ERR(dentry)) | |
13455 | + goto out_unlock; | |
13456 | + if (dentry) | |
13457 | + goto accept; | |
13458 | + | |
13459 | + /* is the parent dir cached? */ | |
027c5e7a | 13460 | + br = au_sbr(sb, nsi_lock.bindex); |
5afbbe0d | 13461 | + au_br_get(br); |
1facf9fc | 13462 | + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock); |
13463 | + if (IS_ERR(dentry)) | |
13464 | + goto out_unlock; | |
13465 | + if (dentry) | |
13466 | + goto accept; | |
13467 | + | |
13468 | + /* lookup path */ | |
027c5e7a | 13469 | + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock); |
1facf9fc | 13470 | + if (IS_ERR(dentry)) |
13471 | + goto out_unlock; | |
13472 | + if (unlikely(!dentry)) | |
13473 | + /* todo?: make it ESTALE */ | |
13474 | + goto out_unlock; | |
13475 | + | |
4f0767ce | 13476 | +accept: |
027c5e7a | 13477 | + if (!au_digen_test(dentry, au_sigen(sb)) |
5527c038 | 13478 | + && d_inode(dentry)->i_generation == fh[Fh_igen]) |
1facf9fc | 13479 | + goto out_unlock; /* success */ |
13480 | + | |
13481 | + dput(dentry); | |
13482 | + dentry = ERR_PTR(-ESTALE); | |
4f0767ce | 13483 | +out_unlock: |
027c5e7a | 13484 | + if (br) |
5afbbe0d | 13485 | + au_br_put(br); |
1facf9fc | 13486 | + si_read_unlock(sb); |
4f0767ce | 13487 | +out: |
1facf9fc | 13488 | + AuTraceErrPtr(dentry); |
13489 | + return dentry; | |
13490 | +} | |
13491 | + | |
13492 | +#if 0 /* reserved for future use */ | |
13493 | +/* support subtreecheck option */ | |
13494 | +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid, | |
13495 | + int fh_len, int fh_type) | |
13496 | +{ | |
13497 | + struct dentry *parent; | |
13498 | + __u32 *fh = fid->raw; | |
13499 | + ino_t dir_ino; | |
13500 | + | |
13501 | + dir_ino = decode_ino(fh + Fh_dir_ino); | |
13502 | + parent = decode_by_ino(sb, dir_ino, 0); | |
13503 | + if (IS_ERR(parent)) | |
13504 | + goto out; | |
13505 | + if (!parent) | |
13506 | + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]), | |
13507 | + dir_ino, fh, fh_len); | |
13508 | + | |
4f0767ce | 13509 | +out: |
1facf9fc | 13510 | + AuTraceErrPtr(parent); |
13511 | + return parent; | |
13512 | +} | |
13513 | +#endif | |
13514 | + | |
13515 | +/* ---------------------------------------------------------------------- */ | |
13516 | + | |
0c3ec466 AM |
13517 | +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, |
13518 | + struct inode *dir) | |
1facf9fc | 13519 | +{ |
13520 | + int err; | |
0c3ec466 | 13521 | + aufs_bindex_t bindex; |
1facf9fc | 13522 | + struct super_block *sb, *h_sb; |
0c3ec466 AM |
13523 | + struct dentry *dentry, *parent, *h_parent; |
13524 | + struct inode *h_dir; | |
1facf9fc | 13525 | + struct au_branch *br; |
13526 | + | |
1facf9fc | 13527 | + err = -ENOSPC; |
13528 | + if (unlikely(*max_len <= Fh_tail)) { | |
13529 | + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len); | |
13530 | + goto out; | |
13531 | + } | |
13532 | + | |
13533 | + err = FILEID_ROOT; | |
0c3ec466 AM |
13534 | + if (inode->i_ino == AUFS_ROOT_INO) { |
13535 | + AuDebugOn(inode->i_ino != AUFS_ROOT_INO); | |
1facf9fc | 13536 | + goto out; |
13537 | + } | |
13538 | + | |
1facf9fc | 13539 | + h_parent = NULL; |
0c3ec466 AM |
13540 | + sb = inode->i_sb; |
13541 | + err = si_read_lock(sb, AuLock_FLUSH); | |
027c5e7a AM |
13542 | + if (unlikely(err)) |
13543 | + goto out; | |
13544 | + | |
1facf9fc | 13545 | +#ifdef CONFIG_AUFS_DEBUG |
13546 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) | |
13547 | + AuWarn1("NFS-exporting requires xino\n"); | |
13548 | +#endif | |
027c5e7a | 13549 | + err = -EIO; |
0c3ec466 AM |
13550 | + parent = NULL; |
13551 | + ii_read_lock_child(inode); | |
5afbbe0d | 13552 | + bindex = au_ibtop(inode); |
0c3ec466 | 13553 | + if (!dir) { |
c1595e42 | 13554 | + dentry = d_find_any_alias(inode); |
0c3ec466 AM |
13555 | + if (unlikely(!dentry)) |
13556 | + goto out_unlock; | |
13557 | + AuDebugOn(au_test_anon(dentry)); | |
13558 | + parent = dget_parent(dentry); | |
13559 | + dput(dentry); | |
13560 | + if (unlikely(!parent)) | |
13561 | + goto out_unlock; | |
5527c038 JR |
13562 | + if (d_really_is_positive(parent)) |
13563 | + dir = d_inode(parent); | |
1facf9fc | 13564 | + } |
0c3ec466 AM |
13565 | + |
13566 | + ii_read_lock_parent(dir); | |
13567 | + h_dir = au_h_iptr(dir, bindex); | |
13568 | + ii_read_unlock(dir); | |
13569 | + if (unlikely(!h_dir)) | |
13570 | + goto out_parent; | |
c1595e42 | 13571 | + h_parent = d_find_any_alias(h_dir); |
1facf9fc | 13572 | + if (unlikely(!h_parent)) |
0c3ec466 | 13573 | + goto out_hparent; |
1facf9fc | 13574 | + |
13575 | + err = -EPERM; | |
13576 | + br = au_sbr(sb, bindex); | |
86dc4139 | 13577 | + h_sb = au_br_sb(br); |
1facf9fc | 13578 | + if (unlikely(!h_sb->s_export_op)) { |
13579 | + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb)); | |
0c3ec466 | 13580 | + goto out_hparent; |
1facf9fc | 13581 | + } |
13582 | + | |
13583 | + fh[Fh_br_id] = br->br_id; | |
13584 | + fh[Fh_sigen] = au_sigen(sb); | |
13585 | + encode_ino(fh + Fh_ino, inode->i_ino); | |
0c3ec466 | 13586 | + encode_ino(fh + Fh_dir_ino, dir->i_ino); |
1facf9fc | 13587 | + fh[Fh_igen] = inode->i_generation; |
13588 | + | |
13589 | + *max_len -= Fh_tail; | |
13590 | + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail), | |
13591 | + max_len, | |
13592 | + /*connectable or subtreecheck*/0); | |
13593 | + err = fh[Fh_h_type]; | |
13594 | + *max_len += Fh_tail; | |
13595 | + /* todo: macros? */ | |
1716fcea | 13596 | + if (err != FILEID_INVALID) |
1facf9fc | 13597 | + err = 99; |
13598 | + else | |
13599 | + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb)); | |
13600 | + | |
0c3ec466 | 13601 | +out_hparent: |
1facf9fc | 13602 | + dput(h_parent); |
0c3ec466 | 13603 | +out_parent: |
1facf9fc | 13604 | + dput(parent); |
0c3ec466 AM |
13605 | +out_unlock: |
13606 | + ii_read_unlock(inode); | |
13607 | + si_read_unlock(sb); | |
4f0767ce | 13608 | +out: |
1facf9fc | 13609 | + if (unlikely(err < 0)) |
1716fcea | 13610 | + err = FILEID_INVALID; |
1facf9fc | 13611 | + return err; |
13612 | +} | |
13613 | + | |
13614 | +/* ---------------------------------------------------------------------- */ | |
13615 | + | |
4a4d8108 AM |
13616 | +static int aufs_commit_metadata(struct inode *inode) |
13617 | +{ | |
13618 | + int err; | |
13619 | + aufs_bindex_t bindex; | |
13620 | + struct super_block *sb; | |
13621 | + struct inode *h_inode; | |
13622 | + int (*f)(struct inode *inode); | |
13623 | + | |
13624 | + sb = inode->i_sb; | |
e49829fe | 13625 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 13626 | + ii_write_lock_child(inode); |
5afbbe0d | 13627 | + bindex = au_ibtop(inode); |
4a4d8108 AM |
13628 | + AuDebugOn(bindex < 0); |
13629 | + h_inode = au_h_iptr(inode, bindex); | |
13630 | + | |
13631 | + f = h_inode->i_sb->s_export_op->commit_metadata; | |
13632 | + if (f) | |
13633 | + err = f(h_inode); | |
13634 | + else { | |
13635 | + struct writeback_control wbc = { | |
13636 | + .sync_mode = WB_SYNC_ALL, | |
13637 | + .nr_to_write = 0 /* metadata only */ | |
13638 | + }; | |
13639 | + | |
13640 | + err = sync_inode(h_inode, &wbc); | |
13641 | + } | |
13642 | + | |
13643 | + au_cpup_attr_timesizes(inode); | |
13644 | + ii_write_unlock(inode); | |
13645 | + si_read_unlock(sb); | |
13646 | + return err; | |
13647 | +} | |
13648 | + | |
13649 | +/* ---------------------------------------------------------------------- */ | |
13650 | + | |
1facf9fc | 13651 | +static struct export_operations aufs_export_op = { |
4a4d8108 | 13652 | + .fh_to_dentry = aufs_fh_to_dentry, |
1facf9fc | 13653 | + /* .fh_to_parent = aufs_fh_to_parent, */ |
4a4d8108 AM |
13654 | + .encode_fh = aufs_encode_fh, |
13655 | + .commit_metadata = aufs_commit_metadata | |
1facf9fc | 13656 | +}; |
13657 | + | |
13658 | +void au_export_init(struct super_block *sb) | |
13659 | +{ | |
13660 | + struct au_sbinfo *sbinfo; | |
13661 | + __u32 u; | |
13662 | + | |
5afbbe0d AM |
13663 | + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS) |
13664 | + && IS_MODULE(CONFIG_EXPORTFS), | |
13665 | + AUFS_NAME ": unsupported configuration " | |
13666 | + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y"); | |
13667 | + | |
1facf9fc | 13668 | + sb->s_export_op = &aufs_export_op; |
13669 | + sbinfo = au_sbi(sb); | |
13670 | + sbinfo->si_xigen = NULL; | |
13671 | + get_random_bytes(&u, sizeof(u)); | |
13672 | + BUILD_BUG_ON(sizeof(u) != sizeof(int)); | |
13673 | + atomic_set(&sbinfo->si_xigen_next, u); | |
13674 | +} | |
076b876e AM |
13675 | diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c |
13676 | --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 13677 | +++ linux/fs/aufs/fhsm.c 2018-01-29 07:56:20.053325069 +0100 |
c1595e42 | 13678 | @@ -0,0 +1,426 @@ |
076b876e | 13679 | +/* |
a2654f78 | 13680 | + * Copyright (C) 2011-2017 Junjiro R. Okajima |
076b876e AM |
13681 | + * |
13682 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13683 | + * it under the terms of the GNU General Public License as published by | |
13684 | + * the Free Software Foundation; either version 2 of the License, or | |
13685 | + * (at your option) any later version. | |
13686 | + * | |
13687 | + * This program is distributed in the hope that it will be useful, | |
13688 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13689 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13690 | + * GNU General Public License for more details. | |
13691 | + * | |
13692 | + * You should have received a copy of the GNU General Public License | |
13693 | + * along with this program; if not, write to the Free Software | |
13694 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
13695 | + */ | |
13696 | + | |
13697 | +/* | |
13698 | + * File-based Hierarchy Storage Management | |
13699 | + */ | |
13700 | + | |
13701 | +#include <linux/anon_inodes.h> | |
13702 | +#include <linux/poll.h> | |
13703 | +#include <linux/seq_file.h> | |
13704 | +#include <linux/statfs.h> | |
13705 | +#include "aufs.h" | |
13706 | + | |
c1595e42 JR |
13707 | +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb) |
13708 | +{ | |
13709 | + struct au_sbinfo *sbinfo; | |
13710 | + struct au_fhsm *fhsm; | |
13711 | + | |
13712 | + SiMustAnyLock(sb); | |
13713 | + | |
13714 | + sbinfo = au_sbi(sb); | |
13715 | + fhsm = &sbinfo->si_fhsm; | |
13716 | + AuDebugOn(!fhsm); | |
13717 | + return fhsm->fhsm_bottom; | |
13718 | +} | |
13719 | + | |
13720 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex) | |
13721 | +{ | |
13722 | + struct au_sbinfo *sbinfo; | |
13723 | + struct au_fhsm *fhsm; | |
13724 | + | |
13725 | + SiMustWriteLock(sb); | |
13726 | + | |
13727 | + sbinfo = au_sbi(sb); | |
13728 | + fhsm = &sbinfo->si_fhsm; | |
13729 | + AuDebugOn(!fhsm); | |
13730 | + fhsm->fhsm_bottom = bindex; | |
13731 | +} | |
13732 | + | |
13733 | +/* ---------------------------------------------------------------------- */ | |
13734 | + | |
076b876e AM |
13735 | +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br) |
13736 | +{ | |
13737 | + struct au_br_fhsm *bf; | |
13738 | + | |
13739 | + bf = br->br_fhsm; | |
13740 | + MtxMustLock(&bf->bf_lock); | |
13741 | + | |
13742 | + return !bf->bf_readable | |
13743 | + || time_after(jiffies, | |
13744 | + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire); | |
13745 | +} | |
13746 | + | |
13747 | +/* ---------------------------------------------------------------------- */ | |
13748 | + | |
13749 | +static void au_fhsm_notify(struct super_block *sb, int val) | |
13750 | +{ | |
13751 | + struct au_sbinfo *sbinfo; | |
13752 | + struct au_fhsm *fhsm; | |
13753 | + | |
13754 | + SiMustAnyLock(sb); | |
13755 | + | |
13756 | + sbinfo = au_sbi(sb); | |
13757 | + fhsm = &sbinfo->si_fhsm; | |
13758 | + if (au_fhsm_pid(fhsm) | |
13759 | + && atomic_read(&fhsm->fhsm_readable) != -1) { | |
13760 | + atomic_set(&fhsm->fhsm_readable, val); | |
13761 | + if (val) | |
13762 | + wake_up(&fhsm->fhsm_wqh); | |
13763 | + } | |
13764 | +} | |
13765 | + | |
13766 | +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex, | |
13767 | + struct aufs_stfs *rstfs, int do_lock, int do_notify) | |
13768 | +{ | |
13769 | + int err; | |
13770 | + struct au_branch *br; | |
13771 | + struct au_br_fhsm *bf; | |
13772 | + | |
13773 | + br = au_sbr(sb, bindex); | |
13774 | + AuDebugOn(au_br_rdonly(br)); | |
13775 | + bf = br->br_fhsm; | |
13776 | + AuDebugOn(!bf); | |
13777 | + | |
13778 | + if (do_lock) | |
13779 | + mutex_lock(&bf->bf_lock); | |
13780 | + else | |
13781 | + MtxMustLock(&bf->bf_lock); | |
13782 | + | |
13783 | + /* sb->s_root for NFS is unreliable */ | |
13784 | + err = au_br_stfs(br, &bf->bf_stfs); | |
13785 | + if (unlikely(err)) { | |
13786 | + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err); | |
13787 | + goto out; | |
13788 | + } | |
13789 | + | |
13790 | + bf->bf_jiffy = jiffies; | |
13791 | + bf->bf_readable = 1; | |
13792 | + if (do_notify) | |
13793 | + au_fhsm_notify(sb, /*val*/1); | |
13794 | + if (rstfs) | |
13795 | + *rstfs = bf->bf_stfs; | |
13796 | + | |
13797 | +out: | |
13798 | + if (do_lock) | |
13799 | + mutex_unlock(&bf->bf_lock); | |
13800 | + au_fhsm_notify(sb, /*val*/1); | |
13801 | + | |
13802 | + return err; | |
13803 | +} | |
13804 | + | |
13805 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force) | |
13806 | +{ | |
13807 | + int err; | |
076b876e AM |
13808 | + struct au_sbinfo *sbinfo; |
13809 | + struct au_fhsm *fhsm; | |
13810 | + struct au_branch *br; | |
13811 | + struct au_br_fhsm *bf; | |
13812 | + | |
13813 | + AuDbg("b%d, force %d\n", bindex, force); | |
13814 | + SiMustAnyLock(sb); | |
13815 | + | |
13816 | + sbinfo = au_sbi(sb); | |
13817 | + fhsm = &sbinfo->si_fhsm; | |
c1595e42 JR |
13818 | + if (!au_ftest_si(sbinfo, FHSM) |
13819 | + || fhsm->fhsm_bottom == bindex) | |
076b876e AM |
13820 | + return; |
13821 | + | |
13822 | + br = au_sbr(sb, bindex); | |
13823 | + bf = br->br_fhsm; | |
13824 | + AuDebugOn(!bf); | |
13825 | + mutex_lock(&bf->bf_lock); | |
13826 | + if (force | |
13827 | + || au_fhsm_pid(fhsm) | |
13828 | + || au_fhsm_test_jiffy(sbinfo, br)) | |
13829 | + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0, | |
13830 | + /*do_notify*/1); | |
13831 | + mutex_unlock(&bf->bf_lock); | |
13832 | +} | |
13833 | + | |
13834 | +void au_fhsm_wrote_all(struct super_block *sb, int force) | |
13835 | +{ | |
5afbbe0d | 13836 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
13837 | + struct au_branch *br; |
13838 | + | |
13839 | + /* exclude the bottom */ | |
5afbbe0d AM |
13840 | + bbot = au_fhsm_bottom(sb); |
13841 | + for (bindex = 0; bindex < bbot; bindex++) { | |
076b876e AM |
13842 | + br = au_sbr(sb, bindex); |
13843 | + if (au_br_fhsm(br->br_perm)) | |
13844 | + au_fhsm_wrote(sb, bindex, force); | |
13845 | + } | |
13846 | +} | |
13847 | + | |
13848 | +/* ---------------------------------------------------------------------- */ | |
13849 | + | |
13850 | +static unsigned int au_fhsm_poll(struct file *file, | |
13851 | + struct poll_table_struct *wait) | |
13852 | +{ | |
13853 | + unsigned int mask; | |
13854 | + struct au_sbinfo *sbinfo; | |
13855 | + struct au_fhsm *fhsm; | |
13856 | + | |
13857 | + mask = 0; | |
13858 | + sbinfo = file->private_data; | |
13859 | + fhsm = &sbinfo->si_fhsm; | |
13860 | + poll_wait(file, &fhsm->fhsm_wqh, wait); | |
13861 | + if (atomic_read(&fhsm->fhsm_readable)) | |
13862 | + mask = POLLIN /* | POLLRDNORM */; | |
13863 | + | |
13864 | + AuTraceErr((int)mask); | |
13865 | + return mask; | |
13866 | +} | |
13867 | + | |
13868 | +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr, | |
13869 | + struct aufs_stfs *stfs, __s16 brid) | |
13870 | +{ | |
13871 | + int err; | |
13872 | + | |
13873 | + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs)); | |
13874 | + if (!err) | |
13875 | + err = __put_user(brid, &stbr->brid); | |
13876 | + if (unlikely(err)) | |
13877 | + err = -EFAULT; | |
13878 | + | |
13879 | + return err; | |
13880 | +} | |
13881 | + | |
13882 | +static ssize_t au_fhsm_do_read(struct super_block *sb, | |
13883 | + struct aufs_stbr __user *stbr, size_t count) | |
13884 | +{ | |
13885 | + ssize_t err; | |
13886 | + int nstbr; | |
5afbbe0d | 13887 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
13888 | + struct au_branch *br; |
13889 | + struct au_br_fhsm *bf; | |
13890 | + | |
13891 | + /* except the bottom branch */ | |
13892 | + err = 0; | |
13893 | + nstbr = 0; | |
5afbbe0d AM |
13894 | + bbot = au_fhsm_bottom(sb); |
13895 | + for (bindex = 0; !err && bindex < bbot; bindex++) { | |
076b876e AM |
13896 | + br = au_sbr(sb, bindex); |
13897 | + if (!au_br_fhsm(br->br_perm)) | |
13898 | + continue; | |
13899 | + | |
13900 | + bf = br->br_fhsm; | |
13901 | + mutex_lock(&bf->bf_lock); | |
13902 | + if (bf->bf_readable) { | |
13903 | + err = -EFAULT; | |
13904 | + if (count >= sizeof(*stbr)) | |
13905 | + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs, | |
13906 | + br->br_id); | |
13907 | + if (!err) { | |
13908 | + bf->bf_readable = 0; | |
13909 | + count -= sizeof(*stbr); | |
13910 | + nstbr++; | |
13911 | + } | |
13912 | + } | |
13913 | + mutex_unlock(&bf->bf_lock); | |
13914 | + } | |
13915 | + if (!err) | |
13916 | + err = sizeof(*stbr) * nstbr; | |
13917 | + | |
13918 | + return err; | |
13919 | +} | |
13920 | + | |
13921 | +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count, | |
13922 | + loff_t *pos) | |
13923 | +{ | |
13924 | + ssize_t err; | |
13925 | + int readable; | |
5afbbe0d | 13926 | + aufs_bindex_t nfhsm, bindex, bbot; |
076b876e AM |
13927 | + struct au_sbinfo *sbinfo; |
13928 | + struct au_fhsm *fhsm; | |
13929 | + struct au_branch *br; | |
13930 | + struct super_block *sb; | |
13931 | + | |
13932 | + err = 0; | |
13933 | + sbinfo = file->private_data; | |
13934 | + fhsm = &sbinfo->si_fhsm; | |
13935 | +need_data: | |
13936 | + spin_lock_irq(&fhsm->fhsm_wqh.lock); | |
13937 | + if (!atomic_read(&fhsm->fhsm_readable)) { | |
13938 | + if (vfsub_file_flags(file) & O_NONBLOCK) | |
13939 | + err = -EAGAIN; | |
13940 | + else | |
13941 | + err = wait_event_interruptible_locked_irq | |
13942 | + (fhsm->fhsm_wqh, | |
13943 | + atomic_read(&fhsm->fhsm_readable)); | |
13944 | + } | |
13945 | + spin_unlock_irq(&fhsm->fhsm_wqh.lock); | |
13946 | + if (unlikely(err)) | |
13947 | + goto out; | |
13948 | + | |
13949 | + /* sb may already be dead */ | |
13950 | + au_rw_read_lock(&sbinfo->si_rwsem); | |
13951 | + readable = atomic_read(&fhsm->fhsm_readable); | |
13952 | + if (readable > 0) { | |
13953 | + sb = sbinfo->si_sb; | |
13954 | + AuDebugOn(!sb); | |
13955 | + /* exclude the bottom branch */ | |
13956 | + nfhsm = 0; | |
5afbbe0d AM |
13957 | + bbot = au_fhsm_bottom(sb); |
13958 | + for (bindex = 0; bindex < bbot; bindex++) { | |
076b876e AM |
13959 | + br = au_sbr(sb, bindex); |
13960 | + if (au_br_fhsm(br->br_perm)) | |
13961 | + nfhsm++; | |
13962 | + } | |
13963 | + err = -EMSGSIZE; | |
13964 | + if (nfhsm * sizeof(struct aufs_stbr) <= count) { | |
13965 | + atomic_set(&fhsm->fhsm_readable, 0); | |
13966 | + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf, | |
13967 | + count); | |
13968 | + } | |
13969 | + } | |
13970 | + au_rw_read_unlock(&sbinfo->si_rwsem); | |
13971 | + if (!readable) | |
13972 | + goto need_data; | |
13973 | + | |
13974 | +out: | |
13975 | + return err; | |
13976 | +} | |
13977 | + | |
13978 | +static int au_fhsm_release(struct inode *inode, struct file *file) | |
13979 | +{ | |
13980 | + struct au_sbinfo *sbinfo; | |
13981 | + struct au_fhsm *fhsm; | |
13982 | + | |
13983 | + /* sb may already be dead */ | |
13984 | + sbinfo = file->private_data; | |
13985 | + fhsm = &sbinfo->si_fhsm; | |
13986 | + spin_lock(&fhsm->fhsm_spin); | |
13987 | + fhsm->fhsm_pid = 0; | |
13988 | + spin_unlock(&fhsm->fhsm_spin); | |
13989 | + kobject_put(&sbinfo->si_kobj); | |
13990 | + | |
13991 | + return 0; | |
13992 | +} | |
13993 | + | |
13994 | +static const struct file_operations au_fhsm_fops = { | |
13995 | + .owner = THIS_MODULE, | |
13996 | + .llseek = noop_llseek, | |
13997 | + .read = au_fhsm_read, | |
13998 | + .poll = au_fhsm_poll, | |
13999 | + .release = au_fhsm_release | |
14000 | +}; | |
14001 | + | |
14002 | +int au_fhsm_fd(struct super_block *sb, int oflags) | |
14003 | +{ | |
14004 | + int err, fd; | |
14005 | + struct au_sbinfo *sbinfo; | |
14006 | + struct au_fhsm *fhsm; | |
14007 | + | |
14008 | + err = -EPERM; | |
14009 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
14010 | + goto out; | |
14011 | + | |
14012 | + err = -EINVAL; | |
14013 | + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK))) | |
14014 | + goto out; | |
14015 | + | |
14016 | + err = 0; | |
14017 | + sbinfo = au_sbi(sb); | |
14018 | + fhsm = &sbinfo->si_fhsm; | |
14019 | + spin_lock(&fhsm->fhsm_spin); | |
14020 | + if (!fhsm->fhsm_pid) | |
14021 | + fhsm->fhsm_pid = current->pid; | |
14022 | + else | |
14023 | + err = -EBUSY; | |
14024 | + spin_unlock(&fhsm->fhsm_spin); | |
14025 | + if (unlikely(err)) | |
14026 | + goto out; | |
14027 | + | |
14028 | + oflags |= O_RDONLY; | |
14029 | + /* oflags |= FMODE_NONOTIFY; */ | |
14030 | + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags); | |
14031 | + err = fd; | |
14032 | + if (unlikely(fd < 0)) | |
14033 | + goto out_pid; | |
14034 | + | |
14035 | + /* succeed reglardless 'fhsm' status */ | |
14036 | + kobject_get(&sbinfo->si_kobj); | |
14037 | + si_noflush_read_lock(sb); | |
14038 | + if (au_ftest_si(sbinfo, FHSM)) | |
14039 | + au_fhsm_wrote_all(sb, /*force*/0); | |
14040 | + si_read_unlock(sb); | |
14041 | + goto out; /* success */ | |
14042 | + | |
14043 | +out_pid: | |
14044 | + spin_lock(&fhsm->fhsm_spin); | |
14045 | + fhsm->fhsm_pid = 0; | |
14046 | + spin_unlock(&fhsm->fhsm_spin); | |
14047 | +out: | |
14048 | + AuTraceErr(err); | |
14049 | + return err; | |
14050 | +} | |
14051 | + | |
14052 | +/* ---------------------------------------------------------------------- */ | |
14053 | + | |
14054 | +int au_fhsm_br_alloc(struct au_branch *br) | |
14055 | +{ | |
14056 | + int err; | |
14057 | + | |
14058 | + err = 0; | |
14059 | + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS); | |
14060 | + if (br->br_fhsm) | |
14061 | + au_br_fhsm_init(br->br_fhsm); | |
14062 | + else | |
14063 | + err = -ENOMEM; | |
14064 | + | |
14065 | + return err; | |
14066 | +} | |
14067 | + | |
14068 | +/* ---------------------------------------------------------------------- */ | |
14069 | + | |
14070 | +void au_fhsm_fin(struct super_block *sb) | |
14071 | +{ | |
14072 | + au_fhsm_notify(sb, /*val*/-1); | |
14073 | +} | |
14074 | + | |
14075 | +void au_fhsm_init(struct au_sbinfo *sbinfo) | |
14076 | +{ | |
14077 | + struct au_fhsm *fhsm; | |
14078 | + | |
14079 | + fhsm = &sbinfo->si_fhsm; | |
14080 | + spin_lock_init(&fhsm->fhsm_spin); | |
14081 | + init_waitqueue_head(&fhsm->fhsm_wqh); | |
14082 | + atomic_set(&fhsm->fhsm_readable, 0); | |
14083 | + fhsm->fhsm_expire | |
14084 | + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC); | |
c1595e42 | 14085 | + fhsm->fhsm_bottom = -1; |
076b876e AM |
14086 | +} |
14087 | + | |
14088 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec) | |
14089 | +{ | |
14090 | + sbinfo->si_fhsm.fhsm_expire | |
14091 | + = msecs_to_jiffies(sec * MSEC_PER_SEC); | |
14092 | +} | |
14093 | + | |
14094 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo) | |
14095 | +{ | |
14096 | + unsigned int u; | |
14097 | + | |
14098 | + if (!au_ftest_si(sbinfo, FHSM)) | |
14099 | + return; | |
14100 | + | |
14101 | + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC; | |
14102 | + if (u != AUFS_FHSM_CACHE_DEF_SEC) | |
14103 | + seq_printf(seq, ",fhsm_sec=%u", u); | |
14104 | +} | |
7f207e10 AM |
14105 | diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c |
14106 | --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 14107 | +++ linux/fs/aufs/file.c 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 | 14108 | @@ -0,0 +1,856 @@ |
1facf9fc | 14109 | +/* |
a2654f78 | 14110 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 14111 | + * |
14112 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14113 | + * it under the terms of the GNU General Public License as published by | |
14114 | + * the Free Software Foundation; either version 2 of the License, or | |
14115 | + * (at your option) any later version. | |
dece6358 AM |
14116 | + * |
14117 | + * This program is distributed in the hope that it will be useful, | |
14118 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14119 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14120 | + * GNU General Public License for more details. | |
14121 | + * | |
14122 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14123 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 14124 | + */ |
14125 | + | |
14126 | +/* | |
4a4d8108 | 14127 | + * handling file/dir, and address_space operation |
1facf9fc | 14128 | + */ |
14129 | + | |
7eafdf33 AM |
14130 | +#ifdef CONFIG_AUFS_DEBUG |
14131 | +#include <linux/migrate.h> | |
14132 | +#endif | |
4a4d8108 | 14133 | +#include <linux/pagemap.h> |
1facf9fc | 14134 | +#include "aufs.h" |
14135 | + | |
4a4d8108 AM |
14136 | +/* drop flags for writing */ |
14137 | +unsigned int au_file_roflags(unsigned int flags) | |
14138 | +{ | |
14139 | + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC); | |
14140 | + flags |= O_RDONLY | O_NOATIME; | |
14141 | + return flags; | |
14142 | +} | |
14143 | + | |
14144 | +/* common functions to regular file and dir */ | |
14145 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 14146 | + struct file *file, int force_wr) |
1facf9fc | 14147 | +{ |
1308ab2a | 14148 | + struct file *h_file; |
4a4d8108 AM |
14149 | + struct dentry *h_dentry; |
14150 | + struct inode *h_inode; | |
14151 | + struct super_block *sb; | |
14152 | + struct au_branch *br; | |
14153 | + struct path h_path; | |
b912730e | 14154 | + int err; |
1facf9fc | 14155 | + |
4a4d8108 AM |
14156 | + /* a race condition can happen between open and unlink/rmdir */ |
14157 | + h_file = ERR_PTR(-ENOENT); | |
14158 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 14159 | + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry))) |
4a4d8108 | 14160 | + goto out; |
5527c038 | 14161 | + h_inode = d_inode(h_dentry); |
027c5e7a AM |
14162 | + spin_lock(&h_dentry->d_lock); |
14163 | + err = (!d_unhashed(dentry) && d_unlinked(h_dentry)) | |
5527c038 | 14164 | + /* || !d_inode(dentry)->i_nlink */ |
027c5e7a AM |
14165 | + ; |
14166 | + spin_unlock(&h_dentry->d_lock); | |
14167 | + if (unlikely(err)) | |
4a4d8108 | 14168 | + goto out; |
1facf9fc | 14169 | + |
4a4d8108 AM |
14170 | + sb = dentry->d_sb; |
14171 | + br = au_sbr(sb, bindex); | |
b912730e AM |
14172 | + err = au_br_test_oflag(flags, br); |
14173 | + h_file = ERR_PTR(err); | |
14174 | + if (unlikely(err)) | |
027c5e7a | 14175 | + goto out; |
1facf9fc | 14176 | + |
4a4d8108 | 14177 | + /* drop flags for writing */ |
5527c038 | 14178 | + if (au_test_ro(sb, bindex, d_inode(dentry))) { |
392086de AM |
14179 | + if (force_wr && !(flags & O_WRONLY)) |
14180 | + force_wr = 0; | |
4a4d8108 | 14181 | + flags = au_file_roflags(flags); |
392086de AM |
14182 | + if (force_wr) { |
14183 | + h_file = ERR_PTR(-EROFS); | |
14184 | + flags = au_file_roflags(flags); | |
14185 | + if (unlikely(vfsub_native_ro(h_inode) | |
14186 | + || IS_APPEND(h_inode))) | |
14187 | + goto out; | |
14188 | + flags &= ~O_ACCMODE; | |
14189 | + flags |= O_WRONLY; | |
14190 | + } | |
14191 | + } | |
4a4d8108 | 14192 | + flags &= ~O_CREAT; |
5afbbe0d | 14193 | + au_br_get(br); |
4a4d8108 | 14194 | + h_path.dentry = h_dentry; |
86dc4139 | 14195 | + h_path.mnt = au_br_mnt(br); |
38d290e6 | 14196 | + h_file = vfsub_dentry_open(&h_path, flags); |
4a4d8108 AM |
14197 | + if (IS_ERR(h_file)) |
14198 | + goto out_br; | |
dece6358 | 14199 | + |
b912730e | 14200 | + if (flags & __FMODE_EXEC) { |
4a4d8108 AM |
14201 | + err = deny_write_access(h_file); |
14202 | + if (unlikely(err)) { | |
14203 | + fput(h_file); | |
14204 | + h_file = ERR_PTR(err); | |
14205 | + goto out_br; | |
14206 | + } | |
14207 | + } | |
953406b4 | 14208 | + fsnotify_open(h_file); |
4a4d8108 | 14209 | + goto out; /* success */ |
1facf9fc | 14210 | + |
4f0767ce | 14211 | +out_br: |
5afbbe0d | 14212 | + au_br_put(br); |
4f0767ce | 14213 | +out: |
4a4d8108 AM |
14214 | + return h_file; |
14215 | +} | |
1308ab2a | 14216 | + |
076b876e AM |
14217 | +static int au_cmoo(struct dentry *dentry) |
14218 | +{ | |
8b6a4947 | 14219 | + int err, cmoo, matched; |
076b876e AM |
14220 | + unsigned int udba; |
14221 | + struct path h_path; | |
14222 | + struct au_pin pin; | |
14223 | + struct au_cp_generic cpg = { | |
14224 | + .dentry = dentry, | |
14225 | + .bdst = -1, | |
14226 | + .bsrc = -1, | |
14227 | + .len = -1, | |
14228 | + .pin = &pin, | |
14229 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
14230 | + }; | |
7e9cd9fe | 14231 | + struct inode *delegated; |
076b876e AM |
14232 | + struct super_block *sb; |
14233 | + struct au_sbinfo *sbinfo; | |
14234 | + struct au_fhsm *fhsm; | |
14235 | + pid_t pid; | |
14236 | + struct au_branch *br; | |
14237 | + struct dentry *parent; | |
14238 | + struct au_hinode *hdir; | |
14239 | + | |
14240 | + DiMustWriteLock(dentry); | |
5527c038 | 14241 | + IiMustWriteLock(d_inode(dentry)); |
076b876e AM |
14242 | + |
14243 | + err = 0; | |
14244 | + if (IS_ROOT(dentry)) | |
14245 | + goto out; | |
5afbbe0d | 14246 | + cpg.bsrc = au_dbtop(dentry); |
076b876e AM |
14247 | + if (!cpg.bsrc) |
14248 | + goto out; | |
14249 | + | |
14250 | + sb = dentry->d_sb; | |
14251 | + sbinfo = au_sbi(sb); | |
14252 | + fhsm = &sbinfo->si_fhsm; | |
14253 | + pid = au_fhsm_pid(fhsm); | |
8b6a4947 AM |
14254 | + rcu_read_lock(); |
14255 | + matched = (pid | |
14256 | + && (current->pid == pid | |
14257 | + || rcu_dereference(current->real_parent)->pid == pid)); | |
14258 | + rcu_read_unlock(); | |
14259 | + if (matched) | |
076b876e AM |
14260 | + goto out; |
14261 | + | |
14262 | + br = au_sbr(sb, cpg.bsrc); | |
14263 | + cmoo = au_br_cmoo(br->br_perm); | |
14264 | + if (!cmoo) | |
14265 | + goto out; | |
7e9cd9fe | 14266 | + if (!d_is_reg(dentry)) |
076b876e AM |
14267 | + cmoo &= AuBrAttr_COO_ALL; |
14268 | + if (!cmoo) | |
14269 | + goto out; | |
14270 | + | |
14271 | + parent = dget_parent(dentry); | |
14272 | + di_write_lock_parent(parent); | |
14273 | + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1); | |
14274 | + cpg.bdst = err; | |
14275 | + if (unlikely(err < 0)) { | |
14276 | + err = 0; /* there is no upper writable branch */ | |
14277 | + goto out_dgrade; | |
14278 | + } | |
14279 | + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst); | |
14280 | + | |
14281 | + /* do not respect the coo attrib for the target branch */ | |
14282 | + err = au_cpup_dirs(dentry, cpg.bdst); | |
14283 | + if (unlikely(err)) | |
14284 | + goto out_dgrade; | |
14285 | + | |
14286 | + di_downgrade_lock(parent, AuLock_IR); | |
14287 | + udba = au_opt_udba(sb); | |
14288 | + err = au_pin(&pin, dentry, cpg.bdst, udba, | |
14289 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
14290 | + if (unlikely(err)) | |
14291 | + goto out_parent; | |
14292 | + | |
14293 | + err = au_sio_cpup_simple(&cpg); | |
14294 | + au_unpin(&pin); | |
14295 | + if (unlikely(err)) | |
14296 | + goto out_parent; | |
14297 | + if (!(cmoo & AuBrWAttr_MOO)) | |
14298 | + goto out_parent; /* success */ | |
14299 | + | |
14300 | + err = au_pin(&pin, dentry, cpg.bsrc, udba, | |
14301 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
14302 | + if (unlikely(err)) | |
14303 | + goto out_parent; | |
14304 | + | |
14305 | + h_path.mnt = au_br_mnt(br); | |
14306 | + h_path.dentry = au_h_dptr(dentry, cpg.bsrc); | |
5527c038 | 14307 | + hdir = au_hi(d_inode(parent), cpg.bsrc); |
076b876e AM |
14308 | + delegated = NULL; |
14309 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1); | |
14310 | + au_unpin(&pin); | |
14311 | + /* todo: keep h_dentry or not? */ | |
14312 | + if (unlikely(err == -EWOULDBLOCK)) { | |
14313 | + pr_warn("cannot retry for NFSv4 delegation" | |
14314 | + " for an internal unlink\n"); | |
14315 | + iput(delegated); | |
14316 | + } | |
14317 | + if (unlikely(err)) { | |
14318 | + pr_err("unlink %pd after coo failed (%d), ignored\n", | |
14319 | + dentry, err); | |
14320 | + err = 0; | |
14321 | + } | |
14322 | + goto out_parent; /* success */ | |
14323 | + | |
14324 | +out_dgrade: | |
14325 | + di_downgrade_lock(parent, AuLock_IR); | |
14326 | +out_parent: | |
14327 | + di_read_unlock(parent, AuLock_IR); | |
14328 | + dput(parent); | |
14329 | +out: | |
14330 | + AuTraceErr(err); | |
14331 | + return err; | |
14332 | +} | |
14333 | + | |
b912730e | 14334 | +int au_do_open(struct file *file, struct au_do_open_args *args) |
1facf9fc | 14335 | +{ |
8b6a4947 | 14336 | + int err, aopen = args->aopen; |
1facf9fc | 14337 | + struct dentry *dentry; |
076b876e | 14338 | + struct au_finfo *finfo; |
1308ab2a | 14339 | + |
8b6a4947 | 14340 | + if (!aopen) |
b912730e AM |
14341 | + err = au_finfo_init(file, args->fidir); |
14342 | + else { | |
14343 | + lockdep_off(); | |
14344 | + err = au_finfo_init(file, args->fidir); | |
14345 | + lockdep_on(); | |
14346 | + } | |
4a4d8108 AM |
14347 | + if (unlikely(err)) |
14348 | + goto out; | |
1facf9fc | 14349 | + |
2000de60 | 14350 | + dentry = file->f_path.dentry; |
b912730e | 14351 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
8b6a4947 AM |
14352 | + di_write_lock_child(dentry); |
14353 | + err = au_cmoo(dentry); | |
14354 | + di_downgrade_lock(dentry, AuLock_IR); | |
14355 | + if (!err) { | |
14356 | + if (!aopen) | |
b912730e | 14357 | + err = args->open(file, vfsub_file_flags(file), NULL); |
8b6a4947 AM |
14358 | + else { |
14359 | + lockdep_off(); | |
14360 | + err = args->open(file, vfsub_file_flags(file), NULL); | |
14361 | + lockdep_on(); | |
14362 | + } | |
b912730e | 14363 | + } |
8b6a4947 | 14364 | + di_read_unlock(dentry, AuLock_IR); |
1facf9fc | 14365 | + |
076b876e AM |
14366 | + finfo = au_fi(file); |
14367 | + if (!err) { | |
14368 | + finfo->fi_file = file; | |
8b6a4947 AM |
14369 | + au_hbl_add(&finfo->fi_hlist, |
14370 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
076b876e | 14371 | + } |
8b6a4947 | 14372 | + if (!aopen) |
b912730e AM |
14373 | + fi_write_unlock(file); |
14374 | + else { | |
14375 | + lockdep_off(); | |
14376 | + fi_write_unlock(file); | |
14377 | + lockdep_on(); | |
14378 | + } | |
4a4d8108 | 14379 | + if (unlikely(err)) { |
076b876e | 14380 | + finfo->fi_hdir = NULL; |
1c60b727 | 14381 | + au_finfo_fin(file); |
1308ab2a | 14382 | + } |
4a4d8108 | 14383 | + |
4f0767ce | 14384 | +out: |
8b6a4947 | 14385 | + AuTraceErr(err); |
1308ab2a | 14386 | + return err; |
14387 | +} | |
dece6358 | 14388 | + |
4a4d8108 | 14389 | +int au_reopen_nondir(struct file *file) |
1308ab2a | 14390 | +{ |
4a4d8108 | 14391 | + int err; |
5afbbe0d | 14392 | + aufs_bindex_t btop; |
4a4d8108 AM |
14393 | + struct dentry *dentry; |
14394 | + struct file *h_file, *h_file_tmp; | |
1308ab2a | 14395 | + |
2000de60 | 14396 | + dentry = file->f_path.dentry; |
5afbbe0d | 14397 | + btop = au_dbtop(dentry); |
4a4d8108 | 14398 | + h_file_tmp = NULL; |
5afbbe0d | 14399 | + if (au_fbtop(file) == btop) { |
4a4d8108 AM |
14400 | + h_file = au_hf_top(file); |
14401 | + if (file->f_mode == h_file->f_mode) | |
14402 | + return 0; /* success */ | |
14403 | + h_file_tmp = h_file; | |
14404 | + get_file(h_file_tmp); | |
5afbbe0d | 14405 | + au_set_h_fptr(file, btop, NULL); |
4a4d8108 AM |
14406 | + } |
14407 | + AuDebugOn(au_fi(file)->fi_hdir); | |
86dc4139 AM |
14408 | + /* |
14409 | + * it can happen | |
14410 | + * file exists on both of rw and ro | |
5afbbe0d | 14411 | + * open --> dbtop and fbtop are both 0 |
86dc4139 AM |
14412 | + * prepend a branch as rw, "rw" become ro |
14413 | + * remove rw/file | |
14414 | + * delete the top branch, "rw" becomes rw again | |
5afbbe0d AM |
14415 | + * --> dbtop is 1, fbtop is still 0 |
14416 | + * write --> fbtop is 0 but dbtop is 1 | |
86dc4139 | 14417 | + */ |
5afbbe0d | 14418 | + /* AuDebugOn(au_fbtop(file) < btop); */ |
1308ab2a | 14419 | + |
5afbbe0d | 14420 | + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC, |
392086de | 14421 | + file, /*force_wr*/0); |
4a4d8108 | 14422 | + err = PTR_ERR(h_file); |
86dc4139 AM |
14423 | + if (IS_ERR(h_file)) { |
14424 | + if (h_file_tmp) { | |
5afbbe0d AM |
14425 | + au_sbr_get(dentry->d_sb, btop); |
14426 | + au_set_h_fptr(file, btop, h_file_tmp); | |
86dc4139 AM |
14427 | + h_file_tmp = NULL; |
14428 | + } | |
4a4d8108 | 14429 | + goto out; /* todo: close all? */ |
86dc4139 | 14430 | + } |
4a4d8108 AM |
14431 | + |
14432 | + err = 0; | |
5afbbe0d AM |
14433 | + au_set_fbtop(file, btop); |
14434 | + au_set_h_fptr(file, btop, h_file); | |
4a4d8108 AM |
14435 | + au_update_figen(file); |
14436 | + /* todo: necessary? */ | |
14437 | + /* file->f_ra = h_file->f_ra; */ | |
14438 | + | |
4f0767ce | 14439 | +out: |
4a4d8108 AM |
14440 | + if (h_file_tmp) |
14441 | + fput(h_file_tmp); | |
14442 | + return err; | |
1facf9fc | 14443 | +} |
14444 | + | |
1308ab2a | 14445 | +/* ---------------------------------------------------------------------- */ |
14446 | + | |
4a4d8108 AM |
14447 | +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt, |
14448 | + struct dentry *hi_wh) | |
1facf9fc | 14449 | +{ |
4a4d8108 | 14450 | + int err; |
5afbbe0d | 14451 | + aufs_bindex_t btop; |
4a4d8108 AM |
14452 | + struct au_dinfo *dinfo; |
14453 | + struct dentry *h_dentry; | |
14454 | + struct au_hdentry *hdp; | |
1facf9fc | 14455 | + |
2000de60 | 14456 | + dinfo = au_di(file->f_path.dentry); |
4a4d8108 | 14457 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
dece6358 | 14458 | + |
5afbbe0d AM |
14459 | + btop = dinfo->di_btop; |
14460 | + dinfo->di_btop = btgt; | |
14461 | + hdp = au_hdentry(dinfo, btgt); | |
14462 | + h_dentry = hdp->hd_dentry; | |
14463 | + hdp->hd_dentry = hi_wh; | |
4a4d8108 | 14464 | + err = au_reopen_nondir(file); |
5afbbe0d AM |
14465 | + hdp->hd_dentry = h_dentry; |
14466 | + dinfo->di_btop = btop; | |
1facf9fc | 14467 | + |
1facf9fc | 14468 | + return err; |
14469 | +} | |
14470 | + | |
4a4d8108 | 14471 | +static int au_ready_to_write_wh(struct file *file, loff_t len, |
86dc4139 | 14472 | + aufs_bindex_t bcpup, struct au_pin *pin) |
1facf9fc | 14473 | +{ |
4a4d8108 | 14474 | + int err; |
027c5e7a | 14475 | + struct inode *inode, *h_inode; |
c2b27bf2 AM |
14476 | + struct dentry *h_dentry, *hi_wh; |
14477 | + struct au_cp_generic cpg = { | |
2000de60 | 14478 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
14479 | + .bdst = bcpup, |
14480 | + .bsrc = -1, | |
14481 | + .len = len, | |
14482 | + .pin = pin | |
14483 | + }; | |
1facf9fc | 14484 | + |
5afbbe0d | 14485 | + au_update_dbtop(cpg.dentry); |
5527c038 | 14486 | + inode = d_inode(cpg.dentry); |
027c5e7a | 14487 | + h_inode = NULL; |
5afbbe0d AM |
14488 | + if (au_dbtop(cpg.dentry) <= bcpup |
14489 | + && au_dbbot(cpg.dentry) >= bcpup) { | |
c2b27bf2 | 14490 | + h_dentry = au_h_dptr(cpg.dentry, bcpup); |
5527c038 JR |
14491 | + if (h_dentry && d_is_positive(h_dentry)) |
14492 | + h_inode = d_inode(h_dentry); | |
027c5e7a | 14493 | + } |
4a4d8108 | 14494 | + hi_wh = au_hi_wh(inode, bcpup); |
027c5e7a | 14495 | + if (!hi_wh && !h_inode) |
c2b27bf2 | 14496 | + err = au_sio_cpup_wh(&cpg, file); |
4a4d8108 AM |
14497 | + else |
14498 | + /* already copied-up after unlink */ | |
14499 | + err = au_reopen_wh(file, bcpup, hi_wh); | |
1facf9fc | 14500 | + |
4a4d8108 | 14501 | + if (!err |
38d290e6 JR |
14502 | + && (inode->i_nlink > 1 |
14503 | + || (inode->i_state & I_LINKABLE)) | |
c2b27bf2 AM |
14504 | + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK)) |
14505 | + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup)); | |
1308ab2a | 14506 | + |
dece6358 | 14507 | + return err; |
1facf9fc | 14508 | +} |
14509 | + | |
4a4d8108 AM |
14510 | +/* |
14511 | + * prepare the @file for writing. | |
14512 | + */ | |
14513 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin) | |
1facf9fc | 14514 | +{ |
4a4d8108 | 14515 | + int err; |
5afbbe0d | 14516 | + aufs_bindex_t dbtop; |
c1595e42 | 14517 | + struct dentry *parent; |
86dc4139 | 14518 | + struct inode *inode; |
1facf9fc | 14519 | + struct super_block *sb; |
4a4d8108 | 14520 | + struct file *h_file; |
c2b27bf2 | 14521 | + struct au_cp_generic cpg = { |
2000de60 | 14522 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
14523 | + .bdst = -1, |
14524 | + .bsrc = -1, | |
14525 | + .len = len, | |
14526 | + .pin = pin, | |
14527 | + .flags = AuCpup_DTIME | |
14528 | + }; | |
1facf9fc | 14529 | + |
c2b27bf2 | 14530 | + sb = cpg.dentry->d_sb; |
5527c038 | 14531 | + inode = d_inode(cpg.dentry); |
5afbbe0d | 14532 | + cpg.bsrc = au_fbtop(file); |
c2b27bf2 | 14533 | + err = au_test_ro(sb, cpg.bsrc, inode); |
4a4d8108 | 14534 | + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) { |
c2b27bf2 AM |
14535 | + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE, |
14536 | + /*flags*/0); | |
1facf9fc | 14537 | + goto out; |
4a4d8108 | 14538 | + } |
1facf9fc | 14539 | + |
027c5e7a | 14540 | + /* need to cpup or reopen */ |
c2b27bf2 | 14541 | + parent = dget_parent(cpg.dentry); |
4a4d8108 | 14542 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
14543 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
14544 | + cpg.bdst = err; | |
4a4d8108 AM |
14545 | + if (unlikely(err < 0)) |
14546 | + goto out_dgrade; | |
14547 | + err = 0; | |
14548 | + | |
c2b27bf2 AM |
14549 | + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) { |
14550 | + err = au_cpup_dirs(cpg.dentry, cpg.bdst); | |
1facf9fc | 14551 | + if (unlikely(err)) |
4a4d8108 AM |
14552 | + goto out_dgrade; |
14553 | + } | |
14554 | + | |
c2b27bf2 | 14555 | + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 AM |
14556 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
14557 | + if (unlikely(err)) | |
14558 | + goto out_dgrade; | |
14559 | + | |
5afbbe0d AM |
14560 | + dbtop = au_dbtop(cpg.dentry); |
14561 | + if (dbtop <= cpg.bdst) | |
c2b27bf2 | 14562 | + cpg.bsrc = cpg.bdst; |
027c5e7a | 14563 | + |
5afbbe0d | 14564 | + if (dbtop <= cpg.bdst /* just reopen */ |
c2b27bf2 | 14565 | + || !d_unhashed(cpg.dentry) /* copyup and reopen */ |
027c5e7a | 14566 | + ) { |
392086de | 14567 | + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0); |
86dc4139 | 14568 | + if (IS_ERR(h_file)) |
027c5e7a | 14569 | + err = PTR_ERR(h_file); |
86dc4139 | 14570 | + else { |
027c5e7a | 14571 | + di_downgrade_lock(parent, AuLock_IR); |
5afbbe0d | 14572 | + if (dbtop > cpg.bdst) |
c2b27bf2 | 14573 | + err = au_sio_cpup_simple(&cpg); |
027c5e7a AM |
14574 | + if (!err) |
14575 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 14576 | + au_h_open_post(cpg.dentry, cpg.bsrc, h_file); |
027c5e7a | 14577 | + } |
027c5e7a AM |
14578 | + } else { /* copyup as wh and reopen */ |
14579 | + /* | |
14580 | + * since writable hfsplus branch is not supported, | |
14581 | + * h_open_pre/post() are unnecessary. | |
14582 | + */ | |
c2b27bf2 | 14583 | + err = au_ready_to_write_wh(file, len, cpg.bdst, pin); |
4a4d8108 | 14584 | + di_downgrade_lock(parent, AuLock_IR); |
4a4d8108 | 14585 | + } |
4a4d8108 AM |
14586 | + |
14587 | + if (!err) { | |
14588 | + au_pin_set_parent_lflag(pin, /*lflag*/0); | |
14589 | + goto out_dput; /* success */ | |
14590 | + } | |
14591 | + au_unpin(pin); | |
14592 | + goto out_unlock; | |
1facf9fc | 14593 | + |
4f0767ce | 14594 | +out_dgrade: |
4a4d8108 | 14595 | + di_downgrade_lock(parent, AuLock_IR); |
4f0767ce | 14596 | +out_unlock: |
4a4d8108 | 14597 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 14598 | +out_dput: |
4a4d8108 | 14599 | + dput(parent); |
4f0767ce | 14600 | +out: |
1facf9fc | 14601 | + return err; |
14602 | +} | |
14603 | + | |
4a4d8108 AM |
14604 | +/* ---------------------------------------------------------------------- */ |
14605 | + | |
14606 | +int au_do_flush(struct file *file, fl_owner_t id, | |
14607 | + int (*flush)(struct file *file, fl_owner_t id)) | |
1facf9fc | 14608 | +{ |
4a4d8108 | 14609 | + int err; |
1facf9fc | 14610 | + struct super_block *sb; |
4a4d8108 | 14611 | + struct inode *inode; |
1facf9fc | 14612 | + |
c06a8ce3 AM |
14613 | + inode = file_inode(file); |
14614 | + sb = inode->i_sb; | |
4a4d8108 AM |
14615 | + si_noflush_read_lock(sb); |
14616 | + fi_read_lock(file); | |
b752ccd1 | 14617 | + ii_read_lock_child(inode); |
1facf9fc | 14618 | + |
4a4d8108 AM |
14619 | + err = flush(file, id); |
14620 | + au_cpup_attr_timesizes(inode); | |
1facf9fc | 14621 | + |
b752ccd1 | 14622 | + ii_read_unlock(inode); |
4a4d8108 | 14623 | + fi_read_unlock(file); |
1308ab2a | 14624 | + si_read_unlock(sb); |
dece6358 | 14625 | + return err; |
1facf9fc | 14626 | +} |
14627 | + | |
4a4d8108 AM |
14628 | +/* ---------------------------------------------------------------------- */ |
14629 | + | |
14630 | +static int au_file_refresh_by_inode(struct file *file, int *need_reopen) | |
1facf9fc | 14631 | +{ |
4a4d8108 | 14632 | + int err; |
4a4d8108 AM |
14633 | + struct au_pin pin; |
14634 | + struct au_finfo *finfo; | |
c2b27bf2 | 14635 | + struct dentry *parent, *hi_wh; |
4a4d8108 | 14636 | + struct inode *inode; |
1facf9fc | 14637 | + struct super_block *sb; |
c2b27bf2 | 14638 | + struct au_cp_generic cpg = { |
2000de60 | 14639 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
14640 | + .bdst = -1, |
14641 | + .bsrc = -1, | |
14642 | + .len = -1, | |
14643 | + .pin = &pin, | |
14644 | + .flags = AuCpup_DTIME | |
14645 | + }; | |
1facf9fc | 14646 | + |
4a4d8108 AM |
14647 | + FiMustWriteLock(file); |
14648 | + | |
14649 | + err = 0; | |
14650 | + finfo = au_fi(file); | |
c2b27bf2 | 14651 | + sb = cpg.dentry->d_sb; |
5527c038 | 14652 | + inode = d_inode(cpg.dentry); |
5afbbe0d | 14653 | + cpg.bdst = au_ibtop(inode); |
c2b27bf2 | 14654 | + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry)) |
1308ab2a | 14655 | + goto out; |
dece6358 | 14656 | + |
c2b27bf2 AM |
14657 | + parent = dget_parent(cpg.dentry); |
14658 | + if (au_test_ro(sb, cpg.bdst, inode)) { | |
4a4d8108 | 14659 | + di_read_lock_parent(parent, !AuLock_IR); |
c2b27bf2 AM |
14660 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
14661 | + cpg.bdst = err; | |
4a4d8108 AM |
14662 | + di_read_unlock(parent, !AuLock_IR); |
14663 | + if (unlikely(err < 0)) | |
14664 | + goto out_parent; | |
14665 | + err = 0; | |
1facf9fc | 14666 | + } |
1facf9fc | 14667 | + |
4a4d8108 | 14668 | + di_read_lock_parent(parent, AuLock_IR); |
c2b27bf2 | 14669 | + hi_wh = au_hi_wh(inode, cpg.bdst); |
7f207e10 AM |
14670 | + if (!S_ISDIR(inode->i_mode) |
14671 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4a4d8108 | 14672 | + && au_plink_test(inode) |
c2b27bf2 | 14673 | + && !d_unhashed(cpg.dentry) |
5afbbe0d | 14674 | + && cpg.bdst < au_dbtop(cpg.dentry)) { |
c2b27bf2 | 14675 | + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst); |
4a4d8108 AM |
14676 | + if (unlikely(err)) |
14677 | + goto out_unlock; | |
14678 | + | |
14679 | + /* always superio. */ | |
c2b27bf2 | 14680 | + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 | 14681 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
367653fa | 14682 | + if (!err) { |
c2b27bf2 | 14683 | + err = au_sio_cpup_simple(&cpg); |
367653fa AM |
14684 | + au_unpin(&pin); |
14685 | + } | |
4a4d8108 AM |
14686 | + } else if (hi_wh) { |
14687 | + /* already copied-up after unlink */ | |
c2b27bf2 | 14688 | + err = au_reopen_wh(file, cpg.bdst, hi_wh); |
4a4d8108 AM |
14689 | + *need_reopen = 0; |
14690 | + } | |
1facf9fc | 14691 | + |
4f0767ce | 14692 | +out_unlock: |
4a4d8108 | 14693 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 14694 | +out_parent: |
4a4d8108 | 14695 | + dput(parent); |
4f0767ce | 14696 | +out: |
1308ab2a | 14697 | + return err; |
dece6358 | 14698 | +} |
1facf9fc | 14699 | + |
4a4d8108 | 14700 | +static void au_do_refresh_dir(struct file *file) |
dece6358 | 14701 | +{ |
5afbbe0d | 14702 | + aufs_bindex_t bindex, bbot, new_bindex, brid; |
4a4d8108 AM |
14703 | + struct au_hfile *p, tmp, *q; |
14704 | + struct au_finfo *finfo; | |
1308ab2a | 14705 | + struct super_block *sb; |
4a4d8108 | 14706 | + struct au_fidir *fidir; |
1facf9fc | 14707 | + |
4a4d8108 | 14708 | + FiMustWriteLock(file); |
1facf9fc | 14709 | + |
2000de60 | 14710 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 AM |
14711 | + finfo = au_fi(file); |
14712 | + fidir = finfo->fi_hdir; | |
14713 | + AuDebugOn(!fidir); | |
14714 | + p = fidir->fd_hfile + finfo->fi_btop; | |
14715 | + brid = p->hf_br->br_id; | |
5afbbe0d AM |
14716 | + bbot = fidir->fd_bbot; |
14717 | + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) { | |
4a4d8108 AM |
14718 | + if (!p->hf_file) |
14719 | + continue; | |
1308ab2a | 14720 | + |
4a4d8108 AM |
14721 | + new_bindex = au_br_index(sb, p->hf_br->br_id); |
14722 | + if (new_bindex == bindex) | |
14723 | + continue; | |
14724 | + if (new_bindex < 0) { | |
14725 | + au_set_h_fptr(file, bindex, NULL); | |
14726 | + continue; | |
14727 | + } | |
1308ab2a | 14728 | + |
4a4d8108 AM |
14729 | + /* swap two lower inode, and loop again */ |
14730 | + q = fidir->fd_hfile + new_bindex; | |
14731 | + tmp = *q; | |
14732 | + *q = *p; | |
14733 | + *p = tmp; | |
14734 | + if (tmp.hf_file) { | |
14735 | + bindex--; | |
14736 | + p--; | |
14737 | + } | |
14738 | + } | |
1308ab2a | 14739 | + |
4a4d8108 | 14740 | + p = fidir->fd_hfile; |
2000de60 | 14741 | + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) { |
5afbbe0d AM |
14742 | + bbot = au_sbbot(sb); |
14743 | + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot; | |
4a4d8108 AM |
14744 | + finfo->fi_btop++, p++) |
14745 | + if (p->hf_file) { | |
c06a8ce3 | 14746 | + if (file_inode(p->hf_file)) |
4a4d8108 | 14747 | + break; |
1c60b727 | 14748 | + au_hfput(p, /*execed*/0); |
4a4d8108 AM |
14749 | + } |
14750 | + } else { | |
5afbbe0d AM |
14751 | + bbot = au_br_index(sb, brid); |
14752 | + for (finfo->fi_btop = 0; finfo->fi_btop < bbot; | |
4a4d8108 AM |
14753 | + finfo->fi_btop++, p++) |
14754 | + if (p->hf_file) | |
1c60b727 | 14755 | + au_hfput(p, /*execed*/0); |
5afbbe0d | 14756 | + bbot = au_sbbot(sb); |
4a4d8108 | 14757 | + } |
1308ab2a | 14758 | + |
5afbbe0d AM |
14759 | + p = fidir->fd_hfile + bbot; |
14760 | + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop; | |
4a4d8108 AM |
14761 | + fidir->fd_bbot--, p--) |
14762 | + if (p->hf_file) { | |
c06a8ce3 | 14763 | + if (file_inode(p->hf_file)) |
4a4d8108 | 14764 | + break; |
1c60b727 | 14765 | + au_hfput(p, /*execed*/0); |
4a4d8108 AM |
14766 | + } |
14767 | + AuDebugOn(fidir->fd_bbot < finfo->fi_btop); | |
1308ab2a | 14768 | +} |
14769 | + | |
4a4d8108 AM |
14770 | +/* |
14771 | + * after branch manipulating, refresh the file. | |
14772 | + */ | |
14773 | +static int refresh_file(struct file *file, int (*reopen)(struct file *file)) | |
1facf9fc | 14774 | +{ |
e2f27e51 | 14775 | + int err, need_reopen, nbr; |
5afbbe0d | 14776 | + aufs_bindex_t bbot, bindex; |
4a4d8108 | 14777 | + struct dentry *dentry; |
e2f27e51 | 14778 | + struct super_block *sb; |
1308ab2a | 14779 | + struct au_finfo *finfo; |
4a4d8108 | 14780 | + struct au_hfile *hfile; |
1facf9fc | 14781 | + |
2000de60 | 14782 | + dentry = file->f_path.dentry; |
e2f27e51 AM |
14783 | + sb = dentry->d_sb; |
14784 | + nbr = au_sbbot(sb) + 1; | |
1308ab2a | 14785 | + finfo = au_fi(file); |
4a4d8108 AM |
14786 | + if (!finfo->fi_hdir) { |
14787 | + hfile = &finfo->fi_htop; | |
14788 | + AuDebugOn(!hfile->hf_file); | |
e2f27e51 | 14789 | + bindex = au_br_index(sb, hfile->hf_br->br_id); |
4a4d8108 AM |
14790 | + AuDebugOn(bindex < 0); |
14791 | + if (bindex != finfo->fi_btop) | |
5afbbe0d | 14792 | + au_set_fbtop(file, bindex); |
4a4d8108 | 14793 | + } else { |
e2f27e51 | 14794 | + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0); |
4a4d8108 AM |
14795 | + if (unlikely(err)) |
14796 | + goto out; | |
14797 | + au_do_refresh_dir(file); | |
14798 | + } | |
1facf9fc | 14799 | + |
4a4d8108 AM |
14800 | + err = 0; |
14801 | + need_reopen = 1; | |
14802 | + if (!au_test_mmapped(file)) | |
14803 | + err = au_file_refresh_by_inode(file, &need_reopen); | |
e2f27e51 AM |
14804 | + if (finfo->fi_hdir) |
14805 | + /* harmless if err */ | |
14806 | + au_fidir_realloc(finfo, nbr, /*may_shrink*/1); | |
027c5e7a | 14807 | + if (!err && need_reopen && !d_unlinked(dentry)) |
4a4d8108 AM |
14808 | + err = reopen(file); |
14809 | + if (!err) { | |
14810 | + au_update_figen(file); | |
14811 | + goto out; /* success */ | |
14812 | + } | |
14813 | + | |
14814 | + /* error, close all lower files */ | |
14815 | + if (finfo->fi_hdir) { | |
5afbbe0d AM |
14816 | + bbot = au_fbbot_dir(file); |
14817 | + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) | |
4a4d8108 AM |
14818 | + au_set_h_fptr(file, bindex, NULL); |
14819 | + } | |
1facf9fc | 14820 | + |
4f0767ce | 14821 | +out: |
1facf9fc | 14822 | + return err; |
14823 | +} | |
14824 | + | |
4a4d8108 AM |
14825 | +/* common function to regular file and dir */ |
14826 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
521ced18 | 14827 | + int wlock, unsigned int fi_lsc) |
dece6358 | 14828 | +{ |
1308ab2a | 14829 | + int err; |
4a4d8108 | 14830 | + unsigned int sigen, figen; |
5afbbe0d | 14831 | + aufs_bindex_t btop; |
4a4d8108 AM |
14832 | + unsigned char pseudo_link; |
14833 | + struct dentry *dentry; | |
14834 | + struct inode *inode; | |
1facf9fc | 14835 | + |
4a4d8108 | 14836 | + err = 0; |
2000de60 | 14837 | + dentry = file->f_path.dentry; |
5527c038 | 14838 | + inode = d_inode(dentry); |
4a4d8108 | 14839 | + sigen = au_sigen(dentry->d_sb); |
521ced18 | 14840 | + fi_write_lock_nested(file, fi_lsc); |
4a4d8108 | 14841 | + figen = au_figen(file); |
521ced18 JR |
14842 | + if (!fi_lsc) |
14843 | + di_write_lock_child(dentry); | |
14844 | + else | |
14845 | + di_write_lock_child2(dentry); | |
5afbbe0d AM |
14846 | + btop = au_dbtop(dentry); |
14847 | + pseudo_link = (btop != au_ibtop(inode)); | |
14848 | + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) { | |
4a4d8108 AM |
14849 | + if (!wlock) { |
14850 | + di_downgrade_lock(dentry, AuLock_IR); | |
14851 | + fi_downgrade_lock(file); | |
14852 | + } | |
14853 | + goto out; /* success */ | |
14854 | + } | |
dece6358 | 14855 | + |
4a4d8108 | 14856 | + AuDbg("sigen %d, figen %d\n", sigen, figen); |
027c5e7a | 14857 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 | 14858 | + err = au_reval_dpath(dentry, sigen); |
027c5e7a | 14859 | + AuDebugOn(!err && au_digen_test(dentry, sigen)); |
4a4d8108 | 14860 | + } |
dece6358 | 14861 | + |
027c5e7a AM |
14862 | + if (!err) |
14863 | + err = refresh_file(file, reopen); | |
4a4d8108 AM |
14864 | + if (!err) { |
14865 | + if (!wlock) { | |
14866 | + di_downgrade_lock(dentry, AuLock_IR); | |
14867 | + fi_downgrade_lock(file); | |
14868 | + } | |
14869 | + } else { | |
14870 | + di_write_unlock(dentry); | |
14871 | + fi_write_unlock(file); | |
14872 | + } | |
1facf9fc | 14873 | + |
4f0767ce | 14874 | +out: |
1308ab2a | 14875 | + return err; |
14876 | +} | |
1facf9fc | 14877 | + |
4a4d8108 AM |
14878 | +/* ---------------------------------------------------------------------- */ |
14879 | + | |
14880 | +/* cf. aufs_nopage() */ | |
14881 | +/* for madvise(2) */ | |
14882 | +static int aufs_readpage(struct file *file __maybe_unused, struct page *page) | |
1308ab2a | 14883 | +{ |
4a4d8108 AM |
14884 | + unlock_page(page); |
14885 | + return 0; | |
14886 | +} | |
1facf9fc | 14887 | + |
4a4d8108 | 14888 | +/* it will never be called, but necessary to support O_DIRECT */ |
5afbbe0d | 14889 | +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) |
4a4d8108 | 14890 | +{ BUG(); return 0; } |
1facf9fc | 14891 | + |
4a4d8108 AM |
14892 | +/* they will never be called. */ |
14893 | +#ifdef CONFIG_AUFS_DEBUG | |
14894 | +static int aufs_write_begin(struct file *file, struct address_space *mapping, | |
14895 | + loff_t pos, unsigned len, unsigned flags, | |
14896 | + struct page **pagep, void **fsdata) | |
14897 | +{ AuUnsupport(); return 0; } | |
14898 | +static int aufs_write_end(struct file *file, struct address_space *mapping, | |
14899 | + loff_t pos, unsigned len, unsigned copied, | |
14900 | + struct page *page, void *fsdata) | |
14901 | +{ AuUnsupport(); return 0; } | |
14902 | +static int aufs_writepage(struct page *page, struct writeback_control *wbc) | |
14903 | +{ AuUnsupport(); return 0; } | |
1308ab2a | 14904 | + |
4a4d8108 AM |
14905 | +static int aufs_set_page_dirty(struct page *page) |
14906 | +{ AuUnsupport(); return 0; } | |
392086de AM |
14907 | +static void aufs_invalidatepage(struct page *page, unsigned int offset, |
14908 | + unsigned int length) | |
4a4d8108 AM |
14909 | +{ AuUnsupport(); } |
14910 | +static int aufs_releasepage(struct page *page, gfp_t gfp) | |
14911 | +{ AuUnsupport(); return 0; } | |
79b8bda9 | 14912 | +#if 0 /* called by memory compaction regardless file */ |
4a4d8108 | 14913 | +static int aufs_migratepage(struct address_space *mapping, struct page *newpage, |
7eafdf33 | 14914 | + struct page *page, enum migrate_mode mode) |
4a4d8108 | 14915 | +{ AuUnsupport(); return 0; } |
79b8bda9 | 14916 | +#endif |
e2f27e51 AM |
14917 | +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode) |
14918 | +{ AuUnsupport(); return true; } | |
14919 | +static void aufs_putback_page(struct page *page) | |
14920 | +{ AuUnsupport(); } | |
4a4d8108 AM |
14921 | +static int aufs_launder_page(struct page *page) |
14922 | +{ AuUnsupport(); return 0; } | |
14923 | +static int aufs_is_partially_uptodate(struct page *page, | |
38d290e6 JR |
14924 | + unsigned long from, |
14925 | + unsigned long count) | |
4a4d8108 | 14926 | +{ AuUnsupport(); return 0; } |
392086de AM |
14927 | +static void aufs_is_dirty_writeback(struct page *page, bool *dirty, |
14928 | + bool *writeback) | |
14929 | +{ AuUnsupport(); } | |
4a4d8108 AM |
14930 | +static int aufs_error_remove_page(struct address_space *mapping, |
14931 | + struct page *page) | |
14932 | +{ AuUnsupport(); return 0; } | |
b4510431 AM |
14933 | +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file, |
14934 | + sector_t *span) | |
14935 | +{ AuUnsupport(); return 0; } | |
14936 | +static void aufs_swap_deactivate(struct file *file) | |
14937 | +{ AuUnsupport(); } | |
4a4d8108 AM |
14938 | +#endif /* CONFIG_AUFS_DEBUG */ |
14939 | + | |
14940 | +const struct address_space_operations aufs_aop = { | |
14941 | + .readpage = aufs_readpage, | |
14942 | + .direct_IO = aufs_direct_IO, | |
4a4d8108 AM |
14943 | +#ifdef CONFIG_AUFS_DEBUG |
14944 | + .writepage = aufs_writepage, | |
4a4d8108 AM |
14945 | + /* no writepages, because of writepage */ |
14946 | + .set_page_dirty = aufs_set_page_dirty, | |
14947 | + /* no readpages, because of readpage */ | |
14948 | + .write_begin = aufs_write_begin, | |
14949 | + .write_end = aufs_write_end, | |
14950 | + /* no bmap, no block device */ | |
14951 | + .invalidatepage = aufs_invalidatepage, | |
14952 | + .releasepage = aufs_releasepage, | |
79b8bda9 AM |
14953 | + /* is fallback_migrate_page ok? */ |
14954 | + /* .migratepage = aufs_migratepage, */ | |
e2f27e51 AM |
14955 | + .isolate_page = aufs_isolate_page, |
14956 | + .putback_page = aufs_putback_page, | |
4a4d8108 AM |
14957 | + .launder_page = aufs_launder_page, |
14958 | + .is_partially_uptodate = aufs_is_partially_uptodate, | |
392086de | 14959 | + .is_dirty_writeback = aufs_is_dirty_writeback, |
b4510431 AM |
14960 | + .error_remove_page = aufs_error_remove_page, |
14961 | + .swap_activate = aufs_swap_activate, | |
14962 | + .swap_deactivate = aufs_swap_deactivate | |
4a4d8108 | 14963 | +#endif /* CONFIG_AUFS_DEBUG */ |
dece6358 | 14964 | +}; |
7f207e10 AM |
14965 | diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h |
14966 | --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 14967 | +++ linux/fs/aufs/file.h 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 | 14968 | @@ -0,0 +1,340 @@ |
4a4d8108 | 14969 | +/* |
a2654f78 | 14970 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
14971 | + * |
14972 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14973 | + * it under the terms of the GNU General Public License as published by | |
14974 | + * the Free Software Foundation; either version 2 of the License, or | |
14975 | + * (at your option) any later version. | |
14976 | + * | |
14977 | + * This program is distributed in the hope that it will be useful, | |
14978 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14979 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14980 | + * GNU General Public License for more details. | |
14981 | + * | |
14982 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14983 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 14984 | + */ |
1facf9fc | 14985 | + |
4a4d8108 AM |
14986 | +/* |
14987 | + * file operations | |
14988 | + */ | |
1facf9fc | 14989 | + |
4a4d8108 AM |
14990 | +#ifndef __AUFS_FILE_H__ |
14991 | +#define __AUFS_FILE_H__ | |
1facf9fc | 14992 | + |
4a4d8108 | 14993 | +#ifdef __KERNEL__ |
1facf9fc | 14994 | + |
2cbb1c4b | 14995 | +#include <linux/file.h> |
4a4d8108 | 14996 | +#include <linux/fs.h> |
3c1bdaff | 14997 | +#include <linux/mm_types.h> |
4a4d8108 | 14998 | +#include <linux/poll.h> |
4a4d8108 | 14999 | +#include "rwsem.h" |
1facf9fc | 15000 | + |
4a4d8108 AM |
15001 | +struct au_branch; |
15002 | +struct au_hfile { | |
15003 | + struct file *hf_file; | |
15004 | + struct au_branch *hf_br; | |
15005 | +}; | |
1facf9fc | 15006 | + |
4a4d8108 AM |
15007 | +struct au_vdir; |
15008 | +struct au_fidir { | |
15009 | + aufs_bindex_t fd_bbot; | |
15010 | + aufs_bindex_t fd_nent; | |
15011 | + struct au_vdir *fd_vdir_cache; | |
15012 | + struct au_hfile fd_hfile[]; | |
15013 | +}; | |
1facf9fc | 15014 | + |
4a4d8108 | 15015 | +static inline int au_fidir_sz(int nent) |
dece6358 | 15016 | +{ |
4f0767ce JR |
15017 | + AuDebugOn(nent < 0); |
15018 | + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent; | |
4a4d8108 | 15019 | +} |
1facf9fc | 15020 | + |
4a4d8108 AM |
15021 | +struct au_finfo { |
15022 | + atomic_t fi_generation; | |
dece6358 | 15023 | + |
4a4d8108 AM |
15024 | + struct au_rwsem fi_rwsem; |
15025 | + aufs_bindex_t fi_btop; | |
15026 | + | |
15027 | + /* do not union them */ | |
15028 | + struct { /* for non-dir */ | |
15029 | + struct au_hfile fi_htop; | |
2cbb1c4b | 15030 | + atomic_t fi_mmapped; |
4a4d8108 AM |
15031 | + }; |
15032 | + struct au_fidir *fi_hdir; /* for dir only */ | |
523b37e3 | 15033 | + |
8b6a4947 | 15034 | + struct hlist_bl_node fi_hlist; |
1c60b727 | 15035 | + struct file *fi_file; /* very ugly */ |
4a4d8108 | 15036 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 15037 | + |
4a4d8108 | 15038 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15039 | + |
4a4d8108 AM |
15040 | +/* file.c */ |
15041 | +extern const struct address_space_operations aufs_aop; | |
15042 | +unsigned int au_file_roflags(unsigned int flags); | |
15043 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 15044 | + struct file *file, int force_wr); |
b912730e | 15045 | +struct au_do_open_args { |
8b6a4947 | 15046 | + int aopen; |
b912730e AM |
15047 | + int (*open)(struct file *file, int flags, |
15048 | + struct file *h_file); | |
15049 | + struct au_fidir *fidir; | |
15050 | + struct file *h_file; | |
15051 | +}; | |
15052 | +int au_do_open(struct file *file, struct au_do_open_args *args); | |
4a4d8108 AM |
15053 | +int au_reopen_nondir(struct file *file); |
15054 | +struct au_pin; | |
15055 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin); | |
15056 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
521ced18 | 15057 | + int wlock, unsigned int fi_lsc); |
4a4d8108 AM |
15058 | +int au_do_flush(struct file *file, fl_owner_t id, |
15059 | + int (*flush)(struct file *file, fl_owner_t id)); | |
1facf9fc | 15060 | + |
4a4d8108 AM |
15061 | +/* poll.c */ |
15062 | +#ifdef CONFIG_AUFS_POLL | |
15063 | +unsigned int aufs_poll(struct file *file, poll_table *wait); | |
15064 | +#endif | |
1facf9fc | 15065 | + |
4a4d8108 AM |
15066 | +#ifdef CONFIG_AUFS_BR_HFSPLUS |
15067 | +/* hfsplus.c */ | |
392086de AM |
15068 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
15069 | + int force_wr); | |
4a4d8108 AM |
15070 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
15071 | + struct file *h_file); | |
15072 | +#else | |
c1595e42 JR |
15073 | +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry, |
15074 | + aufs_bindex_t bindex, int force_wr) | |
4a4d8108 AM |
15075 | +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex, |
15076 | + struct file *h_file); | |
15077 | +#endif | |
1facf9fc | 15078 | + |
4a4d8108 AM |
15079 | +/* f_op.c */ |
15080 | +extern const struct file_operations aufs_file_fop; | |
b912730e | 15081 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file); |
4a4d8108 | 15082 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file); |
521ced18 | 15083 | +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc); |
4a4d8108 | 15084 | + |
4a4d8108 | 15085 | +/* finfo.c */ |
f0c0a007 | 15086 | +void au_hfput(struct au_hfile *hf, int execed); |
4a4d8108 AM |
15087 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, |
15088 | + struct file *h_file); | |
1facf9fc | 15089 | + |
4a4d8108 | 15090 | +void au_update_figen(struct file *file); |
4a4d8108 | 15091 | +struct au_fidir *au_fidir_alloc(struct super_block *sb); |
e2f27e51 | 15092 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink); |
1facf9fc | 15093 | + |
4a4d8108 | 15094 | +void au_fi_init_once(void *_fi); |
1c60b727 | 15095 | +void au_finfo_fin(struct file *file); |
4a4d8108 | 15096 | +int au_finfo_init(struct file *file, struct au_fidir *fidir); |
1facf9fc | 15097 | + |
4a4d8108 AM |
15098 | +/* ioctl.c */ |
15099 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
15100 | +#ifdef CONFIG_COMPAT |
15101 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
15102 | + unsigned long arg); | |
c2b27bf2 AM |
15103 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
15104 | + unsigned long arg); | |
b752ccd1 | 15105 | +#endif |
1facf9fc | 15106 | + |
4a4d8108 | 15107 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15108 | + |
4a4d8108 AM |
15109 | +static inline struct au_finfo *au_fi(struct file *file) |
15110 | +{ | |
38d290e6 | 15111 | + return file->private_data; |
4a4d8108 | 15112 | +} |
1facf9fc | 15113 | + |
4a4d8108 | 15114 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15115 | + |
8b6a4947 AM |
15116 | +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem) |
15117 | +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem) | |
15118 | +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem) | |
15119 | +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem) | |
4a4d8108 | 15120 | +/* |
8b6a4947 AM |
15121 | +#define fi_read_trylock_nested(f) \ |
15122 | + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem) | |
15123 | +#define fi_write_trylock_nested(f) \ | |
15124 | + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem) | |
15125 | +*/ | |
15126 | + | |
15127 | +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem) | |
15128 | +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem) | |
15129 | +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem) | |
1308ab2a | 15130 | + |
521ced18 JR |
15131 | +/* lock subclass for finfo */ |
15132 | +enum { | |
15133 | + AuLsc_FI_1, | |
15134 | + AuLsc_FI_2 | |
15135 | +}; | |
15136 | + | |
15137 | +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc) | |
15138 | +{ | |
15139 | + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc); | |
15140 | +} | |
15141 | + | |
15142 | +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc) | |
15143 | +{ | |
15144 | + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc); | |
15145 | +} | |
15146 | + | |
15147 | +/* | |
15148 | + * fi_read_lock_1, fi_write_lock_1, | |
15149 | + * fi_read_lock_2, fi_write_lock_2 | |
15150 | + */ | |
15151 | +#define AuReadLockFunc(name) \ | |
15152 | +static inline void fi_read_lock_##name(struct file *f) \ | |
15153 | +{ fi_read_lock_nested(f, AuLsc_FI_##name); } | |
15154 | + | |
15155 | +#define AuWriteLockFunc(name) \ | |
15156 | +static inline void fi_write_lock_##name(struct file *f) \ | |
15157 | +{ fi_write_lock_nested(f, AuLsc_FI_##name); } | |
15158 | + | |
15159 | +#define AuRWLockFuncs(name) \ | |
15160 | + AuReadLockFunc(name) \ | |
15161 | + AuWriteLockFunc(name) | |
15162 | + | |
15163 | +AuRWLockFuncs(1); | |
15164 | +AuRWLockFuncs(2); | |
15165 | + | |
15166 | +#undef AuReadLockFunc | |
15167 | +#undef AuWriteLockFunc | |
15168 | +#undef AuRWLockFuncs | |
15169 | + | |
4a4d8108 AM |
15170 | +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem) |
15171 | +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem) | |
15172 | +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem) | |
1facf9fc | 15173 | + |
1308ab2a | 15174 | +/* ---------------------------------------------------------------------- */ |
15175 | + | |
4a4d8108 | 15176 | +/* todo: hard/soft set? */ |
5afbbe0d | 15177 | +static inline aufs_bindex_t au_fbtop(struct file *file) |
dece6358 | 15178 | +{ |
4a4d8108 AM |
15179 | + FiMustAnyLock(file); |
15180 | + return au_fi(file)->fi_btop; | |
15181 | +} | |
dece6358 | 15182 | + |
5afbbe0d | 15183 | +static inline aufs_bindex_t au_fbbot_dir(struct file *file) |
4a4d8108 AM |
15184 | +{ |
15185 | + FiMustAnyLock(file); | |
15186 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15187 | + return au_fi(file)->fi_hdir->fd_bbot; | |
15188 | +} | |
1facf9fc | 15189 | + |
4a4d8108 AM |
15190 | +static inline struct au_vdir *au_fvdir_cache(struct file *file) |
15191 | +{ | |
15192 | + FiMustAnyLock(file); | |
15193 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15194 | + return au_fi(file)->fi_hdir->fd_vdir_cache; | |
15195 | +} | |
1facf9fc | 15196 | + |
5afbbe0d | 15197 | +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex) |
4a4d8108 AM |
15198 | +{ |
15199 | + FiMustWriteLock(file); | |
15200 | + au_fi(file)->fi_btop = bindex; | |
15201 | +} | |
1facf9fc | 15202 | + |
5afbbe0d | 15203 | +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex) |
4a4d8108 AM |
15204 | +{ |
15205 | + FiMustWriteLock(file); | |
15206 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15207 | + au_fi(file)->fi_hdir->fd_bbot = bindex; | |
15208 | +} | |
1308ab2a | 15209 | + |
4a4d8108 AM |
15210 | +static inline void au_set_fvdir_cache(struct file *file, |
15211 | + struct au_vdir *vdir_cache) | |
15212 | +{ | |
15213 | + FiMustWriteLock(file); | |
15214 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15215 | + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache; | |
15216 | +} | |
dece6358 | 15217 | + |
4a4d8108 AM |
15218 | +static inline struct file *au_hf_top(struct file *file) |
15219 | +{ | |
15220 | + FiMustAnyLock(file); | |
15221 | + AuDebugOn(au_fi(file)->fi_hdir); | |
15222 | + return au_fi(file)->fi_htop.hf_file; | |
15223 | +} | |
1facf9fc | 15224 | + |
4a4d8108 AM |
15225 | +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex) |
15226 | +{ | |
15227 | + FiMustAnyLock(file); | |
15228 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15229 | + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file; | |
dece6358 AM |
15230 | +} |
15231 | + | |
4a4d8108 AM |
15232 | +/* todo: memory barrier? */ |
15233 | +static inline unsigned int au_figen(struct file *f) | |
dece6358 | 15234 | +{ |
4a4d8108 AM |
15235 | + return atomic_read(&au_fi(f)->fi_generation); |
15236 | +} | |
dece6358 | 15237 | + |
2cbb1c4b JR |
15238 | +static inline void au_set_mmapped(struct file *f) |
15239 | +{ | |
15240 | + if (atomic_inc_return(&au_fi(f)->fi_mmapped)) | |
15241 | + return; | |
0c3ec466 | 15242 | + pr_warn("fi_mmapped wrapped around\n"); |
2cbb1c4b JR |
15243 | + while (!atomic_inc_return(&au_fi(f)->fi_mmapped)) |
15244 | + ; | |
15245 | +} | |
15246 | + | |
15247 | +static inline void au_unset_mmapped(struct file *f) | |
15248 | +{ | |
15249 | + atomic_dec(&au_fi(f)->fi_mmapped); | |
15250 | +} | |
15251 | + | |
4a4d8108 AM |
15252 | +static inline int au_test_mmapped(struct file *f) |
15253 | +{ | |
2cbb1c4b JR |
15254 | + return atomic_read(&au_fi(f)->fi_mmapped); |
15255 | +} | |
15256 | + | |
15257 | +/* customize vma->vm_file */ | |
15258 | + | |
15259 | +static inline void au_do_vm_file_reset(struct vm_area_struct *vma, | |
15260 | + struct file *file) | |
15261 | +{ | |
53392da6 AM |
15262 | + struct file *f; |
15263 | + | |
15264 | + f = vma->vm_file; | |
2cbb1c4b JR |
15265 | + get_file(file); |
15266 | + vma->vm_file = file; | |
53392da6 | 15267 | + fput(f); |
2cbb1c4b JR |
15268 | +} |
15269 | + | |
15270 | +#ifdef CONFIG_MMU | |
15271 | +#define AuDbgVmRegion(file, vma) do {} while (0) | |
15272 | + | |
15273 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
15274 | + struct file *file) | |
15275 | +{ | |
15276 | + au_do_vm_file_reset(vma, file); | |
15277 | +} | |
15278 | +#else | |
15279 | +#define AuDbgVmRegion(file, vma) \ | |
15280 | + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file)) | |
15281 | + | |
15282 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
15283 | + struct file *file) | |
15284 | +{ | |
53392da6 AM |
15285 | + struct file *f; |
15286 | + | |
2cbb1c4b | 15287 | + au_do_vm_file_reset(vma, file); |
53392da6 | 15288 | + f = vma->vm_region->vm_file; |
2cbb1c4b JR |
15289 | + get_file(file); |
15290 | + vma->vm_region->vm_file = file; | |
53392da6 | 15291 | + fput(f); |
2cbb1c4b JR |
15292 | +} |
15293 | +#endif /* CONFIG_MMU */ | |
15294 | + | |
15295 | +/* handle vma->vm_prfile */ | |
fb47a38f | 15296 | +static inline void au_vm_prfile_set(struct vm_area_struct *vma, |
2cbb1c4b JR |
15297 | + struct file *file) |
15298 | +{ | |
2cbb1c4b JR |
15299 | + get_file(file); |
15300 | + vma->vm_prfile = file; | |
15301 | +#ifndef CONFIG_MMU | |
15302 | + get_file(file); | |
15303 | + vma->vm_region->vm_prfile = file; | |
15304 | +#endif | |
fb47a38f | 15305 | +} |
1308ab2a | 15306 | + |
4a4d8108 AM |
15307 | +#endif /* __KERNEL__ */ |
15308 | +#endif /* __AUFS_FILE_H__ */ | |
7f207e10 AM |
15309 | diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c |
15310 | --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 15311 | +++ linux/fs/aufs/finfo.c 2018-01-29 07:56:20.056658502 +0100 |
1c60b727 | 15312 | @@ -0,0 +1,148 @@ |
4a4d8108 | 15313 | +/* |
a2654f78 | 15314 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
15315 | + * |
15316 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15317 | + * it under the terms of the GNU General Public License as published by | |
15318 | + * the Free Software Foundation; either version 2 of the License, or | |
15319 | + * (at your option) any later version. | |
15320 | + * | |
15321 | + * This program is distributed in the hope that it will be useful, | |
15322 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15323 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15324 | + * GNU General Public License for more details. | |
15325 | + * | |
15326 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15327 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 15328 | + */ |
1308ab2a | 15329 | + |
4a4d8108 AM |
15330 | +/* |
15331 | + * file private data | |
15332 | + */ | |
1facf9fc | 15333 | + |
4a4d8108 | 15334 | +#include "aufs.h" |
1facf9fc | 15335 | + |
f0c0a007 | 15336 | +void au_hfput(struct au_hfile *hf, int execed) |
4a4d8108 | 15337 | +{ |
f0c0a007 | 15338 | + if (execed) |
4a4d8108 AM |
15339 | + allow_write_access(hf->hf_file); |
15340 | + fput(hf->hf_file); | |
15341 | + hf->hf_file = NULL; | |
5afbbe0d | 15342 | + au_br_put(hf->hf_br); |
4a4d8108 AM |
15343 | + hf->hf_br = NULL; |
15344 | +} | |
1facf9fc | 15345 | + |
4a4d8108 AM |
15346 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val) |
15347 | +{ | |
15348 | + struct au_finfo *finfo = au_fi(file); | |
15349 | + struct au_hfile *hf; | |
15350 | + struct au_fidir *fidir; | |
15351 | + | |
15352 | + fidir = finfo->fi_hdir; | |
15353 | + if (!fidir) { | |
15354 | + AuDebugOn(finfo->fi_btop != bindex); | |
15355 | + hf = &finfo->fi_htop; | |
15356 | + } else | |
15357 | + hf = fidir->fd_hfile + bindex; | |
15358 | + | |
15359 | + if (hf && hf->hf_file) | |
f0c0a007 | 15360 | + au_hfput(hf, vfsub_file_execed(file)); |
4a4d8108 AM |
15361 | + if (val) { |
15362 | + FiMustWriteLock(file); | |
b912730e | 15363 | + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry)); |
4a4d8108 | 15364 | + hf->hf_file = val; |
2000de60 | 15365 | + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex); |
1308ab2a | 15366 | + } |
4a4d8108 | 15367 | +} |
1facf9fc | 15368 | + |
4a4d8108 AM |
15369 | +void au_update_figen(struct file *file) |
15370 | +{ | |
2000de60 | 15371 | + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry)); |
4a4d8108 | 15372 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 15373 | +} |
15374 | + | |
4a4d8108 AM |
15375 | +/* ---------------------------------------------------------------------- */ |
15376 | + | |
4a4d8108 AM |
15377 | +struct au_fidir *au_fidir_alloc(struct super_block *sb) |
15378 | +{ | |
15379 | + struct au_fidir *fidir; | |
15380 | + int nbr; | |
15381 | + | |
5afbbe0d | 15382 | + nbr = au_sbbot(sb) + 1; |
4a4d8108 AM |
15383 | + if (nbr < 2) |
15384 | + nbr = 2; /* initial allocate for 2 branches */ | |
15385 | + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS); | |
15386 | + if (fidir) { | |
15387 | + fidir->fd_bbot = -1; | |
15388 | + fidir->fd_nent = nbr; | |
4a4d8108 AM |
15389 | + } |
15390 | + | |
15391 | + return fidir; | |
15392 | +} | |
15393 | + | |
e2f27e51 | 15394 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink) |
4a4d8108 AM |
15395 | +{ |
15396 | + int err; | |
15397 | + struct au_fidir *fidir, *p; | |
15398 | + | |
15399 | + AuRwMustWriteLock(&finfo->fi_rwsem); | |
15400 | + fidir = finfo->fi_hdir; | |
15401 | + AuDebugOn(!fidir); | |
15402 | + | |
15403 | + err = -ENOMEM; | |
15404 | + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr), | |
e2f27e51 | 15405 | + GFP_NOFS, may_shrink); |
4a4d8108 AM |
15406 | + if (p) { |
15407 | + p->fd_nent = nbr; | |
15408 | + finfo->fi_hdir = p; | |
15409 | + err = 0; | |
15410 | + } | |
1facf9fc | 15411 | + |
dece6358 | 15412 | + return err; |
1facf9fc | 15413 | +} |
1308ab2a | 15414 | + |
15415 | +/* ---------------------------------------------------------------------- */ | |
15416 | + | |
1c60b727 | 15417 | +void au_finfo_fin(struct file *file) |
1308ab2a | 15418 | +{ |
4a4d8108 AM |
15419 | + struct au_finfo *finfo; |
15420 | + | |
2000de60 | 15421 | + au_nfiles_dec(file->f_path.dentry->d_sb); |
7f207e10 | 15422 | + |
4a4d8108 AM |
15423 | + finfo = au_fi(file); |
15424 | + AuDebugOn(finfo->fi_hdir); | |
15425 | + AuRwDestroy(&finfo->fi_rwsem); | |
1c60b727 | 15426 | + au_cache_free_finfo(finfo); |
1308ab2a | 15427 | +} |
1308ab2a | 15428 | + |
e49829fe | 15429 | +void au_fi_init_once(void *_finfo) |
4a4d8108 | 15430 | +{ |
e49829fe | 15431 | + struct au_finfo *finfo = _finfo; |
1308ab2a | 15432 | + |
e49829fe | 15433 | + au_rw_init(&finfo->fi_rwsem); |
4a4d8108 | 15434 | +} |
1308ab2a | 15435 | + |
4a4d8108 AM |
15436 | +int au_finfo_init(struct file *file, struct au_fidir *fidir) |
15437 | +{ | |
1716fcea | 15438 | + int err; |
4a4d8108 AM |
15439 | + struct au_finfo *finfo; |
15440 | + struct dentry *dentry; | |
15441 | + | |
15442 | + err = -ENOMEM; | |
2000de60 | 15443 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
15444 | + finfo = au_cache_alloc_finfo(); |
15445 | + if (unlikely(!finfo)) | |
15446 | + goto out; | |
15447 | + | |
15448 | + err = 0; | |
7f207e10 | 15449 | + au_nfiles_inc(dentry->d_sb); |
4a4d8108 AM |
15450 | + au_rw_write_lock(&finfo->fi_rwsem); |
15451 | + finfo->fi_btop = -1; | |
15452 | + finfo->fi_hdir = fidir; | |
15453 | + atomic_set(&finfo->fi_generation, au_digen(dentry)); | |
15454 | + /* smp_mb(); */ /* atomic_set */ | |
15455 | + | |
15456 | + file->private_data = finfo; | |
15457 | + | |
15458 | +out: | |
15459 | + return err; | |
15460 | +} | |
7f207e10 AM |
15461 | diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c |
15462 | --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 15463 | +++ linux/fs/aufs/f_op.c 2018-01-29 07:56:20.053325069 +0100 |
1c60b727 | 15464 | @@ -0,0 +1,817 @@ |
dece6358 | 15465 | +/* |
a2654f78 | 15466 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
dece6358 AM |
15467 | + * |
15468 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15469 | + * it under the terms of the GNU General Public License as published by | |
15470 | + * the Free Software Foundation; either version 2 of the License, or | |
15471 | + * (at your option) any later version. | |
15472 | + * | |
15473 | + * This program is distributed in the hope that it will be useful, | |
15474 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15475 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15476 | + * GNU General Public License for more details. | |
15477 | + * | |
15478 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15479 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 15480 | + */ |
1facf9fc | 15481 | + |
15482 | +/* | |
4a4d8108 | 15483 | + * file and vm operations |
1facf9fc | 15484 | + */ |
dece6358 | 15485 | + |
86dc4139 | 15486 | +#include <linux/aio.h> |
4a4d8108 AM |
15487 | +#include <linux/fs_stack.h> |
15488 | +#include <linux/mman.h> | |
4a4d8108 | 15489 | +#include <linux/security.h> |
dece6358 AM |
15490 | +#include "aufs.h" |
15491 | + | |
b912730e | 15492 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 15493 | +{ |
4a4d8108 AM |
15494 | + int err; |
15495 | + aufs_bindex_t bindex; | |
8cdd5066 | 15496 | + struct dentry *dentry, *h_dentry; |
4a4d8108 | 15497 | + struct au_finfo *finfo; |
38d290e6 | 15498 | + struct inode *h_inode; |
4a4d8108 AM |
15499 | + |
15500 | + FiMustWriteLock(file); | |
15501 | + | |
523b37e3 | 15502 | + err = 0; |
2000de60 | 15503 | + dentry = file->f_path.dentry; |
b912730e | 15504 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
4a4d8108 AM |
15505 | + finfo = au_fi(file); |
15506 | + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop)); | |
2cbb1c4b | 15507 | + atomic_set(&finfo->fi_mmapped, 0); |
5afbbe0d | 15508 | + bindex = au_dbtop(dentry); |
8cdd5066 JR |
15509 | + if (!h_file) { |
15510 | + h_dentry = au_h_dptr(dentry, bindex); | |
15511 | + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb); | |
15512 | + if (unlikely(err)) | |
15513 | + goto out; | |
b912730e | 15514 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
8cdd5066 JR |
15515 | + } else { |
15516 | + h_dentry = h_file->f_path.dentry; | |
15517 | + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb); | |
15518 | + if (unlikely(err)) | |
15519 | + goto out; | |
b912730e | 15520 | + get_file(h_file); |
8cdd5066 | 15521 | + } |
4a4d8108 AM |
15522 | + if (IS_ERR(h_file)) |
15523 | + err = PTR_ERR(h_file); | |
15524 | + else { | |
38d290e6 JR |
15525 | + if ((flags & __O_TMPFILE) |
15526 | + && !(flags & O_EXCL)) { | |
15527 | + h_inode = file_inode(h_file); | |
15528 | + spin_lock(&h_inode->i_lock); | |
15529 | + h_inode->i_state |= I_LINKABLE; | |
15530 | + spin_unlock(&h_inode->i_lock); | |
15531 | + } | |
5afbbe0d | 15532 | + au_set_fbtop(file, bindex); |
4a4d8108 AM |
15533 | + au_set_h_fptr(file, bindex, h_file); |
15534 | + au_update_figen(file); | |
15535 | + /* todo: necessary? */ | |
15536 | + /* file->f_ra = h_file->f_ra; */ | |
15537 | + } | |
027c5e7a | 15538 | + |
8cdd5066 | 15539 | +out: |
4a4d8108 | 15540 | + return err; |
1facf9fc | 15541 | +} |
15542 | + | |
4a4d8108 AM |
15543 | +static int aufs_open_nondir(struct inode *inode __maybe_unused, |
15544 | + struct file *file) | |
1facf9fc | 15545 | +{ |
4a4d8108 | 15546 | + int err; |
1308ab2a | 15547 | + struct super_block *sb; |
b912730e AM |
15548 | + struct au_do_open_args args = { |
15549 | + .open = au_do_open_nondir | |
15550 | + }; | |
1facf9fc | 15551 | + |
523b37e3 AM |
15552 | + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n", |
15553 | + file, vfsub_file_flags(file), file->f_mode); | |
1facf9fc | 15554 | + |
2000de60 | 15555 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 15556 | + si_read_lock(sb, AuLock_FLUSH); |
b912730e | 15557 | + err = au_do_open(file, &args); |
4a4d8108 AM |
15558 | + si_read_unlock(sb); |
15559 | + return err; | |
15560 | +} | |
1facf9fc | 15561 | + |
4a4d8108 AM |
15562 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file) |
15563 | +{ | |
15564 | + struct au_finfo *finfo; | |
15565 | + aufs_bindex_t bindex; | |
1facf9fc | 15566 | + |
4a4d8108 | 15567 | + finfo = au_fi(file); |
8b6a4947 AM |
15568 | + au_hbl_del(&finfo->fi_hlist, |
15569 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 | 15570 | + bindex = finfo->fi_btop; |
b4510431 | 15571 | + if (bindex >= 0) |
4a4d8108 | 15572 | + au_set_h_fptr(file, bindex, NULL); |
7f207e10 | 15573 | + |
1c60b727 | 15574 | + au_finfo_fin(file); |
4a4d8108 | 15575 | + return 0; |
1facf9fc | 15576 | +} |
15577 | + | |
4a4d8108 AM |
15578 | +/* ---------------------------------------------------------------------- */ |
15579 | + | |
15580 | +static int au_do_flush_nondir(struct file *file, fl_owner_t id) | |
dece6358 | 15581 | +{ |
1308ab2a | 15582 | + int err; |
4a4d8108 AM |
15583 | + struct file *h_file; |
15584 | + | |
15585 | + err = 0; | |
15586 | + h_file = au_hf_top(file); | |
15587 | + if (h_file) | |
15588 | + err = vfsub_flush(h_file, id); | |
15589 | + return err; | |
15590 | +} | |
15591 | + | |
15592 | +static int aufs_flush_nondir(struct file *file, fl_owner_t id) | |
15593 | +{ | |
15594 | + return au_do_flush(file, id, au_do_flush_nondir); | |
15595 | +} | |
15596 | + | |
15597 | +/* ---------------------------------------------------------------------- */ | |
9dbd164d AM |
15598 | +/* |
15599 | + * read and write functions acquire [fdi]_rwsem once, but release before | |
15600 | + * mmap_sem. This is because to stop a race condition between mmap(2). | |
15601 | + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping | |
15602 | + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in | |
15603 | + * read functions after [fdi]_rwsem are released, but it should be harmless. | |
15604 | + */ | |
4a4d8108 | 15605 | + |
b912730e | 15606 | +/* Callers should call au_read_post() or fput() in the end */ |
521ced18 | 15607 | +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc) |
4a4d8108 | 15608 | +{ |
4a4d8108 | 15609 | + struct file *h_file; |
b912730e | 15610 | + int err; |
1facf9fc | 15611 | + |
521ced18 | 15612 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc); |
b912730e AM |
15613 | + if (!err) { |
15614 | + di_read_unlock(file->f_path.dentry, AuLock_IR); | |
15615 | + h_file = au_hf_top(file); | |
15616 | + get_file(h_file); | |
15617 | + if (!keep_fi) | |
15618 | + fi_read_unlock(file); | |
15619 | + } else | |
15620 | + h_file = ERR_PTR(err); | |
15621 | + | |
15622 | + return h_file; | |
15623 | +} | |
15624 | + | |
15625 | +static void au_read_post(struct inode *inode, struct file *h_file) | |
15626 | +{ | |
15627 | + /* update without lock, I don't think it a problem */ | |
15628 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
15629 | + fput(h_file); | |
15630 | +} | |
15631 | + | |
15632 | +struct au_write_pre { | |
521ced18 JR |
15633 | + /* input */ |
15634 | + unsigned int lsc; | |
15635 | + | |
15636 | + /* output */ | |
b912730e | 15637 | + blkcnt_t blks; |
5afbbe0d | 15638 | + aufs_bindex_t btop; |
b912730e AM |
15639 | +}; |
15640 | + | |
15641 | +/* | |
15642 | + * return with iinfo is write-locked | |
15643 | + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the | |
15644 | + * end | |
15645 | + */ | |
15646 | +static struct file *au_write_pre(struct file *file, int do_ready, | |
15647 | + struct au_write_pre *wpre) | |
15648 | +{ | |
15649 | + struct file *h_file; | |
15650 | + struct dentry *dentry; | |
15651 | + int err; | |
521ced18 | 15652 | + unsigned int lsc; |
b912730e AM |
15653 | + struct au_pin pin; |
15654 | + | |
521ced18 JR |
15655 | + lsc = 0; |
15656 | + if (wpre) | |
15657 | + lsc = wpre->lsc; | |
15658 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc); | |
b912730e | 15659 | + h_file = ERR_PTR(err); |
dece6358 AM |
15660 | + if (unlikely(err)) |
15661 | + goto out; | |
1facf9fc | 15662 | + |
b912730e AM |
15663 | + dentry = file->f_path.dentry; |
15664 | + if (do_ready) { | |
15665 | + err = au_ready_to_write(file, -1, &pin); | |
15666 | + if (unlikely(err)) { | |
15667 | + h_file = ERR_PTR(err); | |
15668 | + di_write_unlock(dentry); | |
15669 | + goto out_fi; | |
15670 | + } | |
15671 | + } | |
15672 | + | |
15673 | + di_downgrade_lock(dentry, /*flags*/0); | |
15674 | + if (wpre) | |
5afbbe0d | 15675 | + wpre->btop = au_fbtop(file); |
4a4d8108 | 15676 | + h_file = au_hf_top(file); |
9dbd164d | 15677 | + get_file(h_file); |
b912730e AM |
15678 | + if (wpre) |
15679 | + wpre->blks = file_inode(h_file)->i_blocks; | |
15680 | + if (do_ready) | |
15681 | + au_unpin(&pin); | |
15682 | + di_read_unlock(dentry, /*flags*/0); | |
15683 | + | |
15684 | +out_fi: | |
15685 | + fi_write_unlock(file); | |
15686 | +out: | |
15687 | + return h_file; | |
15688 | +} | |
15689 | + | |
15690 | +static void au_write_post(struct inode *inode, struct file *h_file, | |
15691 | + struct au_write_pre *wpre, ssize_t written) | |
15692 | +{ | |
15693 | + struct inode *h_inode; | |
15694 | + | |
15695 | + au_cpup_attr_timesizes(inode); | |
5afbbe0d | 15696 | + AuDebugOn(au_ibtop(inode) != wpre->btop); |
b912730e AM |
15697 | + h_inode = file_inode(h_file); |
15698 | + inode->i_mode = h_inode->i_mode; | |
15699 | + ii_write_unlock(inode); | |
b912730e AM |
15700 | + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */ |
15701 | + if (written > 0) | |
5afbbe0d | 15702 | + au_fhsm_wrote(inode->i_sb, wpre->btop, |
b912730e | 15703 | + /*force*/h_inode->i_blocks > wpre->blks); |
1c60b727 | 15704 | + fput(h_file); |
b912730e AM |
15705 | +} |
15706 | + | |
15707 | +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count, | |
15708 | + loff_t *ppos) | |
15709 | +{ | |
15710 | + ssize_t err; | |
15711 | + struct inode *inode; | |
15712 | + struct file *h_file; | |
15713 | + struct super_block *sb; | |
15714 | + | |
15715 | + inode = file_inode(file); | |
15716 | + sb = inode->i_sb; | |
15717 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
15718 | + | |
521ced18 | 15719 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
15720 | + err = PTR_ERR(h_file); |
15721 | + if (IS_ERR(h_file)) | |
15722 | + goto out; | |
9dbd164d AM |
15723 | + |
15724 | + /* filedata may be obsoleted by concurrent copyup, but no problem */ | |
4a4d8108 AM |
15725 | + err = vfsub_read_u(h_file, buf, count, ppos); |
15726 | + /* todo: necessary? */ | |
15727 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 15728 | + au_read_post(inode, h_file); |
1308ab2a | 15729 | + |
4f0767ce | 15730 | +out: |
dece6358 AM |
15731 | + si_read_unlock(sb); |
15732 | + return err; | |
15733 | +} | |
1facf9fc | 15734 | + |
e49829fe JR |
15735 | +/* |
15736 | + * todo: very ugly | |
15737 | + * it locks both of i_mutex and si_rwsem for read in safe. | |
15738 | + * if the plink maintenance mode continues forever (that is the problem), | |
15739 | + * may loop forever. | |
15740 | + */ | |
15741 | +static void au_mtx_and_read_lock(struct inode *inode) | |
15742 | +{ | |
15743 | + int err; | |
15744 | + struct super_block *sb = inode->i_sb; | |
15745 | + | |
15746 | + while (1) { | |
febd17d6 | 15747 | + inode_lock(inode); |
e49829fe JR |
15748 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
15749 | + if (!err) | |
15750 | + break; | |
febd17d6 | 15751 | + inode_unlock(inode); |
e49829fe JR |
15752 | + si_read_lock(sb, AuLock_NOPLMW); |
15753 | + si_read_unlock(sb); | |
15754 | + } | |
15755 | +} | |
15756 | + | |
4a4d8108 AM |
15757 | +static ssize_t aufs_write(struct file *file, const char __user *ubuf, |
15758 | + size_t count, loff_t *ppos) | |
dece6358 | 15759 | +{ |
4a4d8108 | 15760 | + ssize_t err; |
b912730e AM |
15761 | + struct au_write_pre wpre; |
15762 | + struct inode *inode; | |
4a4d8108 AM |
15763 | + struct file *h_file; |
15764 | + char __user *buf = (char __user *)ubuf; | |
1facf9fc | 15765 | + |
b912730e | 15766 | + inode = file_inode(file); |
e49829fe | 15767 | + au_mtx_and_read_lock(inode); |
1facf9fc | 15768 | + |
521ced18 | 15769 | + wpre.lsc = 0; |
b912730e AM |
15770 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15771 | + err = PTR_ERR(h_file); | |
15772 | + if (IS_ERR(h_file)) | |
9dbd164d | 15773 | + goto out; |
9dbd164d | 15774 | + |
4a4d8108 | 15775 | + err = vfsub_write_u(h_file, buf, count, ppos); |
b912730e | 15776 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 15777 | + |
4f0767ce | 15778 | +out: |
b912730e | 15779 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15780 | + inode_unlock(inode); |
dece6358 AM |
15781 | + return err; |
15782 | +} | |
1facf9fc | 15783 | + |
076b876e AM |
15784 | +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio, |
15785 | + struct iov_iter *iov_iter) | |
dece6358 | 15786 | +{ |
4a4d8108 AM |
15787 | + ssize_t err; |
15788 | + struct file *file; | |
076b876e | 15789 | + ssize_t (*iter)(struct kiocb *, struct iov_iter *); |
1facf9fc | 15790 | + |
4a4d8108 AM |
15791 | + err = security_file_permission(h_file, rw); |
15792 | + if (unlikely(err)) | |
15793 | + goto out; | |
1facf9fc | 15794 | + |
4a4d8108 | 15795 | + err = -ENOSYS; |
076b876e | 15796 | + iter = NULL; |
5527c038 | 15797 | + if (rw == MAY_READ) |
076b876e | 15798 | + iter = h_file->f_op->read_iter; |
5527c038 | 15799 | + else if (rw == MAY_WRITE) |
076b876e | 15800 | + iter = h_file->f_op->write_iter; |
076b876e AM |
15801 | + |
15802 | + file = kio->ki_filp; | |
15803 | + kio->ki_filp = h_file; | |
15804 | + if (iter) { | |
2cbb1c4b | 15805 | + lockdep_off(); |
076b876e AM |
15806 | + err = iter(kio, iov_iter); |
15807 | + lockdep_on(); | |
4a4d8108 AM |
15808 | + } else |
15809 | + /* currently there is no such fs */ | |
15810 | + WARN_ON_ONCE(1); | |
076b876e | 15811 | + kio->ki_filp = file; |
1facf9fc | 15812 | + |
4f0767ce | 15813 | +out: |
dece6358 AM |
15814 | + return err; |
15815 | +} | |
1facf9fc | 15816 | + |
076b876e | 15817 | +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1facf9fc | 15818 | +{ |
4a4d8108 AM |
15819 | + ssize_t err; |
15820 | + struct file *file, *h_file; | |
b912730e | 15821 | + struct inode *inode; |
dece6358 | 15822 | + struct super_block *sb; |
1facf9fc | 15823 | + |
4a4d8108 | 15824 | + file = kio->ki_filp; |
b912730e AM |
15825 | + inode = file_inode(file); |
15826 | + sb = inode->i_sb; | |
e49829fe | 15827 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 15828 | + |
521ced18 | 15829 | + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0); |
b912730e AM |
15830 | + err = PTR_ERR(h_file); |
15831 | + if (IS_ERR(h_file)) | |
15832 | + goto out; | |
9dbd164d | 15833 | + |
5afbbe0d AM |
15834 | + if (au_test_loopback_kthread()) { |
15835 | + au_warn_loopback(h_file->f_path.dentry->d_sb); | |
15836 | + if (file->f_mapping != h_file->f_mapping) { | |
15837 | + file->f_mapping = h_file->f_mapping; | |
15838 | + smp_mb(); /* unnecessary? */ | |
15839 | + } | |
15840 | + } | |
15841 | + fi_read_unlock(file); | |
15842 | + | |
076b876e | 15843 | + err = au_do_iter(h_file, MAY_READ, kio, iov_iter); |
4a4d8108 AM |
15844 | + /* todo: necessary? */ |
15845 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 15846 | + au_read_post(inode, h_file); |
1facf9fc | 15847 | + |
4f0767ce | 15848 | +out: |
4a4d8108 | 15849 | + si_read_unlock(sb); |
1308ab2a | 15850 | + return err; |
15851 | +} | |
1facf9fc | 15852 | + |
076b876e | 15853 | +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1308ab2a | 15854 | +{ |
4a4d8108 | 15855 | + ssize_t err; |
b912730e AM |
15856 | + struct au_write_pre wpre; |
15857 | + struct inode *inode; | |
4a4d8108 | 15858 | + struct file *file, *h_file; |
1308ab2a | 15859 | + |
4a4d8108 | 15860 | + file = kio->ki_filp; |
b912730e | 15861 | + inode = file_inode(file); |
e49829fe JR |
15862 | + au_mtx_and_read_lock(inode); |
15863 | + | |
521ced18 | 15864 | + wpre.lsc = 0; |
b912730e AM |
15865 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15866 | + err = PTR_ERR(h_file); | |
15867 | + if (IS_ERR(h_file)) | |
9dbd164d | 15868 | + goto out; |
9dbd164d | 15869 | + |
076b876e | 15870 | + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter); |
b912730e | 15871 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 15872 | + |
4f0767ce | 15873 | +out: |
b912730e | 15874 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15875 | + inode_unlock(inode); |
dece6358 | 15876 | + return err; |
1facf9fc | 15877 | +} |
15878 | + | |
4a4d8108 AM |
15879 | +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
15880 | + struct pipe_inode_info *pipe, size_t len, | |
15881 | + unsigned int flags) | |
1facf9fc | 15882 | +{ |
4a4d8108 AM |
15883 | + ssize_t err; |
15884 | + struct file *h_file; | |
b912730e | 15885 | + struct inode *inode; |
dece6358 | 15886 | + struct super_block *sb; |
1facf9fc | 15887 | + |
b912730e AM |
15888 | + inode = file_inode(file); |
15889 | + sb = inode->i_sb; | |
e49829fe | 15890 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 15891 | + |
521ced18 | 15892 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
15893 | + err = PTR_ERR(h_file); |
15894 | + if (IS_ERR(h_file)) | |
dece6358 | 15895 | + goto out; |
1facf9fc | 15896 | + |
4a4d8108 AM |
15897 | + err = vfsub_splice_to(h_file, ppos, pipe, len, flags); |
15898 | + /* todo: necessasry? */ | |
15899 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 15900 | + au_read_post(inode, h_file); |
1facf9fc | 15901 | + |
4f0767ce | 15902 | +out: |
4a4d8108 | 15903 | + si_read_unlock(sb); |
dece6358 | 15904 | + return err; |
1facf9fc | 15905 | +} |
15906 | + | |
4a4d8108 AM |
15907 | +static ssize_t |
15908 | +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos, | |
15909 | + size_t len, unsigned int flags) | |
1facf9fc | 15910 | +{ |
4a4d8108 | 15911 | + ssize_t err; |
b912730e AM |
15912 | + struct au_write_pre wpre; |
15913 | + struct inode *inode; | |
076b876e | 15914 | + struct file *h_file; |
1facf9fc | 15915 | + |
b912730e | 15916 | + inode = file_inode(file); |
e49829fe | 15917 | + au_mtx_and_read_lock(inode); |
9dbd164d | 15918 | + |
521ced18 | 15919 | + wpre.lsc = 0; |
b912730e AM |
15920 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15921 | + err = PTR_ERR(h_file); | |
15922 | + if (IS_ERR(h_file)) | |
9dbd164d | 15923 | + goto out; |
9dbd164d | 15924 | + |
4a4d8108 | 15925 | + err = vfsub_splice_from(pipe, h_file, ppos, len, flags); |
b912730e | 15926 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 15927 | + |
4f0767ce | 15928 | +out: |
b912730e | 15929 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15930 | + inode_unlock(inode); |
4a4d8108 AM |
15931 | + return err; |
15932 | +} | |
1facf9fc | 15933 | + |
38d290e6 JR |
15934 | +static long aufs_fallocate(struct file *file, int mode, loff_t offset, |
15935 | + loff_t len) | |
15936 | +{ | |
15937 | + long err; | |
b912730e | 15938 | + struct au_write_pre wpre; |
38d290e6 JR |
15939 | + struct inode *inode; |
15940 | + struct file *h_file; | |
15941 | + | |
b912730e | 15942 | + inode = file_inode(file); |
38d290e6 JR |
15943 | + au_mtx_and_read_lock(inode); |
15944 | + | |
521ced18 | 15945 | + wpre.lsc = 0; |
b912730e AM |
15946 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15947 | + err = PTR_ERR(h_file); | |
15948 | + if (IS_ERR(h_file)) | |
38d290e6 | 15949 | + goto out; |
38d290e6 JR |
15950 | + |
15951 | + lockdep_off(); | |
03673fb0 | 15952 | + err = vfs_fallocate(h_file, mode, offset, len); |
38d290e6 | 15953 | + lockdep_on(); |
b912730e | 15954 | + au_write_post(inode, h_file, &wpre, /*written*/1); |
38d290e6 JR |
15955 | + |
15956 | +out: | |
b912730e | 15957 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15958 | + inode_unlock(inode); |
38d290e6 JR |
15959 | + return err; |
15960 | +} | |
15961 | + | |
521ced18 JR |
15962 | +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos, |
15963 | + struct file *dst, loff_t dst_pos, | |
15964 | + size_t len, unsigned int flags) | |
15965 | +{ | |
15966 | + ssize_t err; | |
15967 | + struct au_write_pre wpre; | |
15968 | + enum { SRC, DST }; | |
15969 | + struct { | |
15970 | + struct inode *inode; | |
15971 | + struct file *h_file; | |
15972 | + struct super_block *h_sb; | |
15973 | + } a[2]; | |
15974 | +#define a_src a[SRC] | |
15975 | +#define a_dst a[DST] | |
15976 | + | |
15977 | + err = -EINVAL; | |
15978 | + a_src.inode = file_inode(src); | |
15979 | + if (unlikely(!S_ISREG(a_src.inode->i_mode))) | |
15980 | + goto out; | |
15981 | + a_dst.inode = file_inode(dst); | |
15982 | + if (unlikely(!S_ISREG(a_dst.inode->i_mode))) | |
15983 | + goto out; | |
15984 | + | |
15985 | + au_mtx_and_read_lock(a_dst.inode); | |
15986 | + /* | |
15987 | + * in order to match the order in di_write_lock2_{child,parent}(), | |
15988 | + * use f_path.dentry for this comparision. | |
15989 | + */ | |
15990 | + if (src->f_path.dentry < dst->f_path.dentry) { | |
15991 | + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1); | |
15992 | + err = PTR_ERR(a_src.h_file); | |
15993 | + if (IS_ERR(a_src.h_file)) | |
15994 | + goto out_si; | |
15995 | + | |
15996 | + wpre.lsc = AuLsc_FI_2; | |
15997 | + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre); | |
15998 | + err = PTR_ERR(a_dst.h_file); | |
15999 | + if (IS_ERR(a_dst.h_file)) { | |
16000 | + au_read_post(a_src.inode, a_src.h_file); | |
16001 | + goto out_si; | |
16002 | + } | |
16003 | + } else { | |
16004 | + wpre.lsc = AuLsc_FI_1; | |
16005 | + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre); | |
16006 | + err = PTR_ERR(a_dst.h_file); | |
16007 | + if (IS_ERR(a_dst.h_file)) | |
16008 | + goto out_si; | |
16009 | + | |
16010 | + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2); | |
16011 | + err = PTR_ERR(a_src.h_file); | |
16012 | + if (IS_ERR(a_src.h_file)) { | |
16013 | + au_write_post(a_dst.inode, a_dst.h_file, &wpre, | |
16014 | + /*written*/0); | |
16015 | + goto out_si; | |
16016 | + } | |
16017 | + } | |
16018 | + | |
16019 | + err = -EXDEV; | |
16020 | + a_src.h_sb = file_inode(a_src.h_file)->i_sb; | |
16021 | + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb; | |
16022 | + if (unlikely(a_src.h_sb != a_dst.h_sb)) { | |
16023 | + AuDbgFile(src); | |
16024 | + AuDbgFile(dst); | |
16025 | + goto out_file; | |
16026 | + } | |
16027 | + | |
16028 | + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file, | |
16029 | + dst_pos, len, flags); | |
16030 | + | |
16031 | +out_file: | |
16032 | + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err); | |
16033 | + fi_read_unlock(src); | |
16034 | + au_read_post(a_src.inode, a_src.h_file); | |
16035 | +out_si: | |
16036 | + si_read_unlock(a_dst.inode->i_sb); | |
16037 | + inode_unlock(a_dst.inode); | |
16038 | +out: | |
16039 | + return err; | |
16040 | +#undef a_src | |
16041 | +#undef a_dst | |
16042 | +} | |
16043 | + | |
4a4d8108 AM |
16044 | +/* ---------------------------------------------------------------------- */ |
16045 | + | |
9dbd164d AM |
16046 | +/* |
16047 | + * The locking order around current->mmap_sem. | |
16048 | + * - in most and regular cases | |
16049 | + * file I/O syscall -- aufs_read() or something | |
16050 | + * -- si_rwsem for read -- mmap_sem | |
16051 | + * (Note that [fdi]i_rwsem are released before mmap_sem). | |
16052 | + * - in mmap case | |
16053 | + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem | |
16054 | + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for | |
16055 | + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in | |
16056 | + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though. | |
16057 | + * It means that when aufs acquires si_rwsem for write, the process should never | |
16058 | + * acquire mmap_sem. | |
16059 | + * | |
392086de | 16060 | + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a |
9dbd164d AM |
16061 | + * problem either since any directory is not able to be mmap-ed. |
16062 | + * The similar scenario is applied to aufs_readlink() too. | |
16063 | + */ | |
16064 | + | |
38d290e6 | 16065 | +#if 0 /* stop calling security_file_mmap() */ |
2dfbb274 AM |
16066 | +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */ |
16067 | +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b) | |
16068 | + | |
16069 | +static unsigned long au_arch_prot_conv(unsigned long flags) | |
16070 | +{ | |
16071 | + /* currently ppc64 only */ | |
16072 | +#ifdef CONFIG_PPC64 | |
16073 | + /* cf. linux/arch/powerpc/include/asm/mman.h */ | |
16074 | + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO); | |
16075 | + return AuConv_VM_PROT(flags, SAO); | |
16076 | +#else | |
16077 | + AuDebugOn(arch_calc_vm_prot_bits(-1)); | |
16078 | + return 0; | |
16079 | +#endif | |
16080 | +} | |
16081 | + | |
16082 | +static unsigned long au_prot_conv(unsigned long flags) | |
16083 | +{ | |
16084 | + return AuConv_VM_PROT(flags, READ) | |
16085 | + | AuConv_VM_PROT(flags, WRITE) | |
16086 | + | AuConv_VM_PROT(flags, EXEC) | |
16087 | + | au_arch_prot_conv(flags); | |
16088 | +} | |
16089 | + | |
16090 | +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */ | |
16091 | +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b) | |
16092 | + | |
16093 | +static unsigned long au_flag_conv(unsigned long flags) | |
16094 | +{ | |
16095 | + return AuConv_VM_MAP(flags, GROWSDOWN) | |
16096 | + | AuConv_VM_MAP(flags, DENYWRITE) | |
2dfbb274 AM |
16097 | + | AuConv_VM_MAP(flags, LOCKED); |
16098 | +} | |
38d290e6 | 16099 | +#endif |
2dfbb274 | 16100 | + |
9dbd164d | 16101 | +static int aufs_mmap(struct file *file, struct vm_area_struct *vma) |
dece6358 | 16102 | +{ |
4a4d8108 | 16103 | + int err; |
4a4d8108 | 16104 | + const unsigned char wlock |
9dbd164d | 16105 | + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED); |
4a4d8108 | 16106 | + struct super_block *sb; |
9dbd164d | 16107 | + struct file *h_file; |
b912730e | 16108 | + struct inode *inode; |
9dbd164d AM |
16109 | + |
16110 | + AuDbgVmRegion(file, vma); | |
1308ab2a | 16111 | + |
b912730e AM |
16112 | + inode = file_inode(file); |
16113 | + sb = inode->i_sb; | |
9dbd164d | 16114 | + lockdep_off(); |
e49829fe | 16115 | + si_read_lock(sb, AuLock_NOPLMW); |
4a4d8108 | 16116 | + |
b912730e | 16117 | + h_file = au_write_pre(file, wlock, /*wpre*/NULL); |
9dbd164d | 16118 | + lockdep_on(); |
b912730e AM |
16119 | + err = PTR_ERR(h_file); |
16120 | + if (IS_ERR(h_file)) | |
16121 | + goto out; | |
1308ab2a | 16122 | + |
b912730e AM |
16123 | + err = 0; |
16124 | + au_set_mmapped(file); | |
9dbd164d | 16125 | + au_vm_file_reset(vma, h_file); |
38d290e6 JR |
16126 | + /* |
16127 | + * we cannot call security_mmap_file() here since it may acquire | |
16128 | + * mmap_sem or i_mutex. | |
16129 | + * | |
16130 | + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags), | |
16131 | + * au_flag_conv(vma->vm_flags)); | |
16132 | + */ | |
9dbd164d | 16133 | + if (!err) |
521ced18 | 16134 | + err = call_mmap(h_file, vma); |
b912730e AM |
16135 | + if (!err) { |
16136 | + au_vm_prfile_set(vma, file); | |
16137 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
16138 | + goto out_fput; /* success */ | |
16139 | + } | |
2cbb1c4b JR |
16140 | + au_unset_mmapped(file); |
16141 | + au_vm_file_reset(vma, file); | |
b912730e | 16142 | + |
2cbb1c4b | 16143 | +out_fput: |
9dbd164d | 16144 | + lockdep_off(); |
b912730e AM |
16145 | + ii_write_unlock(inode); |
16146 | + lockdep_on(); | |
16147 | + fput(h_file); | |
4f0767ce | 16148 | +out: |
b912730e | 16149 | + lockdep_off(); |
9dbd164d AM |
16150 | + si_read_unlock(sb); |
16151 | + lockdep_on(); | |
16152 | + AuTraceErr(err); | |
4a4d8108 AM |
16153 | + return err; |
16154 | +} | |
16155 | + | |
16156 | +/* ---------------------------------------------------------------------- */ | |
16157 | + | |
1e00d052 AM |
16158 | +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end, |
16159 | + int datasync) | |
4a4d8108 AM |
16160 | +{ |
16161 | + int err; | |
b912730e | 16162 | + struct au_write_pre wpre; |
4a4d8108 AM |
16163 | + struct inode *inode; |
16164 | + struct file *h_file; | |
4a4d8108 AM |
16165 | + |
16166 | + err = 0; /* -EBADF; */ /* posix? */ | |
16167 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
b912730e | 16168 | + goto out; |
4a4d8108 | 16169 | + |
b912730e AM |
16170 | + inode = file_inode(file); |
16171 | + au_mtx_and_read_lock(inode); | |
16172 | + | |
521ced18 | 16173 | + wpre.lsc = 0; |
b912730e AM |
16174 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
16175 | + err = PTR_ERR(h_file); | |
16176 | + if (IS_ERR(h_file)) | |
4a4d8108 | 16177 | + goto out_unlock; |
4a4d8108 | 16178 | + |
53392da6 | 16179 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
b912730e | 16180 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
4a4d8108 | 16181 | + |
4f0767ce | 16182 | +out_unlock: |
b912730e | 16183 | + si_read_unlock(inode->i_sb); |
febd17d6 | 16184 | + inode_unlock(inode); |
b912730e | 16185 | +out: |
4a4d8108 | 16186 | + return err; |
dece6358 AM |
16187 | +} |
16188 | + | |
4a4d8108 | 16189 | +static int aufs_fasync(int fd, struct file *file, int flag) |
dece6358 | 16190 | +{ |
4a4d8108 AM |
16191 | + int err; |
16192 | + struct file *h_file; | |
4a4d8108 | 16193 | + struct super_block *sb; |
1308ab2a | 16194 | + |
b912730e | 16195 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 16196 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 16197 | + |
521ced18 | 16198 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
16199 | + err = PTR_ERR(h_file); |
16200 | + if (IS_ERR(h_file)) | |
4a4d8108 AM |
16201 | + goto out; |
16202 | + | |
523b37e3 | 16203 | + if (h_file->f_op->fasync) |
4a4d8108 | 16204 | + err = h_file->f_op->fasync(fd, h_file, flag); |
b912730e | 16205 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 16206 | + |
4f0767ce | 16207 | +out: |
4a4d8108 | 16208 | + si_read_unlock(sb); |
1308ab2a | 16209 | + return err; |
dece6358 | 16210 | +} |
4a4d8108 | 16211 | + |
febd17d6 JR |
16212 | +static int aufs_setfl(struct file *file, unsigned long arg) |
16213 | +{ | |
16214 | + int err; | |
16215 | + struct file *h_file; | |
16216 | + struct super_block *sb; | |
16217 | + | |
16218 | + sb = file->f_path.dentry->d_sb; | |
16219 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
16220 | + | |
521ced18 | 16221 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
febd17d6 JR |
16222 | + err = PTR_ERR(h_file); |
16223 | + if (IS_ERR(h_file)) | |
16224 | + goto out; | |
16225 | + | |
1c60b727 AM |
16226 | + /* stop calling h_file->fasync */ |
16227 | + arg |= vfsub_file_flags(file) & FASYNC; | |
febd17d6 JR |
16228 | + err = setfl(/*unused fd*/-1, h_file, arg); |
16229 | + fput(h_file); /* instead of au_read_post() */ | |
16230 | + | |
16231 | +out: | |
16232 | + si_read_unlock(sb); | |
16233 | + return err; | |
16234 | +} | |
16235 | + | |
4a4d8108 AM |
16236 | +/* ---------------------------------------------------------------------- */ |
16237 | + | |
16238 | +/* no one supports this operation, currently */ | |
16239 | +#if 0 | |
16240 | +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset, | |
2000de60 | 16241 | + size_t len, loff_t *pos, int more) |
4a4d8108 AM |
16242 | +{ |
16243 | +} | |
16244 | +#endif | |
16245 | + | |
16246 | +/* ---------------------------------------------------------------------- */ | |
16247 | + | |
16248 | +const struct file_operations aufs_file_fop = { | |
16249 | + .owner = THIS_MODULE, | |
2cbb1c4b | 16250 | + |
027c5e7a | 16251 | + .llseek = default_llseek, |
4a4d8108 AM |
16252 | + |
16253 | + .read = aufs_read, | |
16254 | + .write = aufs_write, | |
076b876e AM |
16255 | + .read_iter = aufs_read_iter, |
16256 | + .write_iter = aufs_write_iter, | |
16257 | + | |
4a4d8108 AM |
16258 | +#ifdef CONFIG_AUFS_POLL |
16259 | + .poll = aufs_poll, | |
16260 | +#endif | |
16261 | + .unlocked_ioctl = aufs_ioctl_nondir, | |
b752ccd1 | 16262 | +#ifdef CONFIG_COMPAT |
c2b27bf2 | 16263 | + .compat_ioctl = aufs_compat_ioctl_nondir, |
b752ccd1 | 16264 | +#endif |
4a4d8108 AM |
16265 | + .mmap = aufs_mmap, |
16266 | + .open = aufs_open_nondir, | |
16267 | + .flush = aufs_flush_nondir, | |
16268 | + .release = aufs_release_nondir, | |
16269 | + .fsync = aufs_fsync_nondir, | |
4a4d8108 AM |
16270 | + .fasync = aufs_fasync, |
16271 | + /* .sendpage = aufs_sendpage, */ | |
febd17d6 | 16272 | + .setfl = aufs_setfl, |
4a4d8108 AM |
16273 | + .splice_write = aufs_splice_write, |
16274 | + .splice_read = aufs_splice_read, | |
16275 | +#if 0 | |
16276 | + .aio_splice_write = aufs_aio_splice_write, | |
38d290e6 | 16277 | + .aio_splice_read = aufs_aio_splice_read, |
4a4d8108 | 16278 | +#endif |
521ced18 JR |
16279 | + .fallocate = aufs_fallocate, |
16280 | + .copy_file_range = aufs_copy_file_range | |
4a4d8108 | 16281 | +}; |
7f207e10 AM |
16282 | diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h |
16283 | --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 16284 | +++ linux/fs/aufs/fstype.h 2018-01-29 07:56:20.056658502 +0100 |
b912730e | 16285 | @@ -0,0 +1,400 @@ |
4a4d8108 | 16286 | +/* |
a2654f78 | 16287 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
16288 | + * |
16289 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16290 | + * it under the terms of the GNU General Public License as published by | |
16291 | + * the Free Software Foundation; either version 2 of the License, or | |
16292 | + * (at your option) any later version. | |
16293 | + * | |
16294 | + * This program is distributed in the hope that it will be useful, | |
16295 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16296 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16297 | + * GNU General Public License for more details. | |
16298 | + * | |
16299 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16300 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
16301 | + */ |
16302 | + | |
16303 | +/* | |
16304 | + * judging filesystem type | |
16305 | + */ | |
16306 | + | |
16307 | +#ifndef __AUFS_FSTYPE_H__ | |
16308 | +#define __AUFS_FSTYPE_H__ | |
16309 | + | |
16310 | +#ifdef __KERNEL__ | |
16311 | + | |
16312 | +#include <linux/fs.h> | |
16313 | +#include <linux/magic.h> | |
b912730e | 16314 | +#include <linux/nfs_fs.h> |
b95c5147 | 16315 | +#include <linux/romfs_fs.h> |
4a4d8108 AM |
16316 | + |
16317 | +static inline int au_test_aufs(struct super_block *sb) | |
16318 | +{ | |
16319 | + return sb->s_magic == AUFS_SUPER_MAGIC; | |
16320 | +} | |
16321 | + | |
16322 | +static inline const char *au_sbtype(struct super_block *sb) | |
16323 | +{ | |
16324 | + return sb->s_type->name; | |
16325 | +} | |
1308ab2a | 16326 | + |
16327 | +static inline int au_test_iso9660(struct super_block *sb __maybe_unused) | |
16328 | +{ | |
f0c0a007 | 16329 | +#if IS_ENABLED(CONFIG_ISO9660_FS) |
2000de60 | 16330 | + return sb->s_magic == ISOFS_SUPER_MAGIC; |
dece6358 AM |
16331 | +#else |
16332 | + return 0; | |
16333 | +#endif | |
16334 | +} | |
16335 | + | |
1308ab2a | 16336 | +static inline int au_test_romfs(struct super_block *sb __maybe_unused) |
dece6358 | 16337 | +{ |
f0c0a007 | 16338 | +#if IS_ENABLED(CONFIG_ROMFS_FS) |
2000de60 | 16339 | + return sb->s_magic == ROMFS_MAGIC; |
dece6358 AM |
16340 | +#else |
16341 | + return 0; | |
16342 | +#endif | |
16343 | +} | |
16344 | + | |
1308ab2a | 16345 | +static inline int au_test_cramfs(struct super_block *sb __maybe_unused) |
dece6358 | 16346 | +{ |
f0c0a007 | 16347 | +#if IS_ENABLED(CONFIG_CRAMFS) |
1308ab2a | 16348 | + return sb->s_magic == CRAMFS_MAGIC; |
16349 | +#endif | |
16350 | + return 0; | |
16351 | +} | |
16352 | + | |
16353 | +static inline int au_test_nfs(struct super_block *sb __maybe_unused) | |
16354 | +{ | |
f0c0a007 | 16355 | +#if IS_ENABLED(CONFIG_NFS_FS) |
1308ab2a | 16356 | + return sb->s_magic == NFS_SUPER_MAGIC; |
dece6358 AM |
16357 | +#else |
16358 | + return 0; | |
16359 | +#endif | |
16360 | +} | |
16361 | + | |
1308ab2a | 16362 | +static inline int au_test_fuse(struct super_block *sb __maybe_unused) |
dece6358 | 16363 | +{ |
f0c0a007 | 16364 | +#if IS_ENABLED(CONFIG_FUSE_FS) |
1308ab2a | 16365 | + return sb->s_magic == FUSE_SUPER_MAGIC; |
dece6358 AM |
16366 | +#else |
16367 | + return 0; | |
16368 | +#endif | |
16369 | +} | |
16370 | + | |
1308ab2a | 16371 | +static inline int au_test_xfs(struct super_block *sb __maybe_unused) |
dece6358 | 16372 | +{ |
f0c0a007 | 16373 | +#if IS_ENABLED(CONFIG_XFS_FS) |
1308ab2a | 16374 | + return sb->s_magic == XFS_SB_MAGIC; |
dece6358 AM |
16375 | +#else |
16376 | + return 0; | |
16377 | +#endif | |
16378 | +} | |
16379 | + | |
1308ab2a | 16380 | +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused) |
dece6358 | 16381 | +{ |
1308ab2a | 16382 | +#ifdef CONFIG_TMPFS |
16383 | + return sb->s_magic == TMPFS_MAGIC; | |
16384 | +#else | |
16385 | + return 0; | |
dece6358 | 16386 | +#endif |
dece6358 AM |
16387 | +} |
16388 | + | |
1308ab2a | 16389 | +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused) |
1facf9fc | 16390 | +{ |
f0c0a007 | 16391 | +#if IS_ENABLED(CONFIG_ECRYPT_FS) |
1308ab2a | 16392 | + return !strcmp(au_sbtype(sb), "ecryptfs"); |
16393 | +#else | |
16394 | + return 0; | |
16395 | +#endif | |
1facf9fc | 16396 | +} |
16397 | + | |
1308ab2a | 16398 | +static inline int au_test_ramfs(struct super_block *sb) |
16399 | +{ | |
16400 | + return sb->s_magic == RAMFS_MAGIC; | |
16401 | +} | |
16402 | + | |
16403 | +static inline int au_test_ubifs(struct super_block *sb __maybe_unused) | |
16404 | +{ | |
f0c0a007 | 16405 | +#if IS_ENABLED(CONFIG_UBIFS_FS) |
1308ab2a | 16406 | + return sb->s_magic == UBIFS_SUPER_MAGIC; |
16407 | +#else | |
16408 | + return 0; | |
16409 | +#endif | |
16410 | +} | |
16411 | + | |
16412 | +static inline int au_test_procfs(struct super_block *sb __maybe_unused) | |
16413 | +{ | |
16414 | +#ifdef CONFIG_PROC_FS | |
16415 | + return sb->s_magic == PROC_SUPER_MAGIC; | |
16416 | +#else | |
16417 | + return 0; | |
16418 | +#endif | |
16419 | +} | |
16420 | + | |
16421 | +static inline int au_test_sysfs(struct super_block *sb __maybe_unused) | |
16422 | +{ | |
16423 | +#ifdef CONFIG_SYSFS | |
16424 | + return sb->s_magic == SYSFS_MAGIC; | |
16425 | +#else | |
16426 | + return 0; | |
16427 | +#endif | |
16428 | +} | |
16429 | + | |
16430 | +static inline int au_test_configfs(struct super_block *sb __maybe_unused) | |
16431 | +{ | |
f0c0a007 | 16432 | +#if IS_ENABLED(CONFIG_CONFIGFS_FS) |
1308ab2a | 16433 | + return sb->s_magic == CONFIGFS_MAGIC; |
16434 | +#else | |
16435 | + return 0; | |
16436 | +#endif | |
16437 | +} | |
16438 | + | |
16439 | +static inline int au_test_minix(struct super_block *sb __maybe_unused) | |
16440 | +{ | |
f0c0a007 | 16441 | +#if IS_ENABLED(CONFIG_MINIX_FS) |
1308ab2a | 16442 | + return sb->s_magic == MINIX3_SUPER_MAGIC |
16443 | + || sb->s_magic == MINIX2_SUPER_MAGIC | |
16444 | + || sb->s_magic == MINIX2_SUPER_MAGIC2 | |
16445 | + || sb->s_magic == MINIX_SUPER_MAGIC | |
16446 | + || sb->s_magic == MINIX_SUPER_MAGIC2; | |
16447 | +#else | |
16448 | + return 0; | |
16449 | +#endif | |
16450 | +} | |
16451 | + | |
1308ab2a | 16452 | +static inline int au_test_fat(struct super_block *sb __maybe_unused) |
16453 | +{ | |
f0c0a007 | 16454 | +#if IS_ENABLED(CONFIG_FAT_FS) |
1308ab2a | 16455 | + return sb->s_magic == MSDOS_SUPER_MAGIC; |
16456 | +#else | |
16457 | + return 0; | |
16458 | +#endif | |
16459 | +} | |
16460 | + | |
16461 | +static inline int au_test_msdos(struct super_block *sb) | |
16462 | +{ | |
16463 | + return au_test_fat(sb); | |
16464 | +} | |
16465 | + | |
16466 | +static inline int au_test_vfat(struct super_block *sb) | |
16467 | +{ | |
16468 | + return au_test_fat(sb); | |
16469 | +} | |
16470 | + | |
16471 | +static inline int au_test_securityfs(struct super_block *sb __maybe_unused) | |
16472 | +{ | |
16473 | +#ifdef CONFIG_SECURITYFS | |
16474 | + return sb->s_magic == SECURITYFS_MAGIC; | |
16475 | +#else | |
16476 | + return 0; | |
16477 | +#endif | |
16478 | +} | |
16479 | + | |
16480 | +static inline int au_test_squashfs(struct super_block *sb __maybe_unused) | |
16481 | +{ | |
f0c0a007 | 16482 | +#if IS_ENABLED(CONFIG_SQUASHFS) |
1308ab2a | 16483 | + return sb->s_magic == SQUASHFS_MAGIC; |
16484 | +#else | |
16485 | + return 0; | |
16486 | +#endif | |
16487 | +} | |
16488 | + | |
16489 | +static inline int au_test_btrfs(struct super_block *sb __maybe_unused) | |
16490 | +{ | |
f0c0a007 | 16491 | +#if IS_ENABLED(CONFIG_BTRFS_FS) |
1308ab2a | 16492 | + return sb->s_magic == BTRFS_SUPER_MAGIC; |
16493 | +#else | |
16494 | + return 0; | |
16495 | +#endif | |
16496 | +} | |
16497 | + | |
16498 | +static inline int au_test_xenfs(struct super_block *sb __maybe_unused) | |
16499 | +{ | |
f0c0a007 | 16500 | +#if IS_ENABLED(CONFIG_XENFS) |
1308ab2a | 16501 | + return sb->s_magic == XENFS_SUPER_MAGIC; |
16502 | +#else | |
16503 | + return 0; | |
16504 | +#endif | |
16505 | +} | |
16506 | + | |
16507 | +static inline int au_test_debugfs(struct super_block *sb __maybe_unused) | |
16508 | +{ | |
16509 | +#ifdef CONFIG_DEBUG_FS | |
16510 | + return sb->s_magic == DEBUGFS_MAGIC; | |
16511 | +#else | |
16512 | + return 0; | |
16513 | +#endif | |
16514 | +} | |
16515 | + | |
16516 | +static inline int au_test_nilfs(struct super_block *sb __maybe_unused) | |
16517 | +{ | |
f0c0a007 | 16518 | +#if IS_ENABLED(CONFIG_NILFS) |
1308ab2a | 16519 | + return sb->s_magic == NILFS_SUPER_MAGIC; |
16520 | +#else | |
16521 | + return 0; | |
16522 | +#endif | |
16523 | +} | |
16524 | + | |
4a4d8108 AM |
16525 | +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused) |
16526 | +{ | |
f0c0a007 | 16527 | +#if IS_ENABLED(CONFIG_HFSPLUS_FS) |
4a4d8108 AM |
16528 | + return sb->s_magic == HFSPLUS_SUPER_MAGIC; |
16529 | +#else | |
16530 | + return 0; | |
16531 | +#endif | |
16532 | +} | |
16533 | + | |
1308ab2a | 16534 | +/* ---------------------------------------------------------------------- */ |
16535 | +/* | |
16536 | + * they can't be an aufs branch. | |
16537 | + */ | |
16538 | +static inline int au_test_fs_unsuppoted(struct super_block *sb) | |
16539 | +{ | |
16540 | + return | |
16541 | +#ifndef CONFIG_AUFS_BR_RAMFS | |
16542 | + au_test_ramfs(sb) || | |
16543 | +#endif | |
16544 | + au_test_procfs(sb) | |
16545 | + || au_test_sysfs(sb) | |
16546 | + || au_test_configfs(sb) | |
16547 | + || au_test_debugfs(sb) | |
16548 | + || au_test_securityfs(sb) | |
16549 | + || au_test_xenfs(sb) | |
16550 | + || au_test_ecryptfs(sb) | |
16551 | + /* || !strcmp(au_sbtype(sb), "unionfs") */ | |
16552 | + || au_test_aufs(sb); /* will be supported in next version */ | |
16553 | +} | |
16554 | + | |
1308ab2a | 16555 | +static inline int au_test_fs_remote(struct super_block *sb) |
16556 | +{ | |
16557 | + return !au_test_tmpfs(sb) | |
16558 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
16559 | + && !au_test_ramfs(sb) | |
16560 | +#endif | |
16561 | + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV); | |
16562 | +} | |
16563 | + | |
16564 | +/* ---------------------------------------------------------------------- */ | |
16565 | + | |
16566 | +/* | |
16567 | + * Note: these functions (below) are created after reading ->getattr() in all | |
16568 | + * filesystems under linux/fs. it means we have to do so in every update... | |
16569 | + */ | |
16570 | + | |
16571 | +/* | |
16572 | + * some filesystems require getattr to refresh the inode attributes before | |
16573 | + * referencing. | |
16574 | + * in most cases, we can rely on the inode attribute in NFS (or every remote fs) | |
16575 | + * and leave the work for d_revalidate() | |
16576 | + */ | |
16577 | +static inline int au_test_fs_refresh_iattr(struct super_block *sb) | |
16578 | +{ | |
16579 | + return au_test_nfs(sb) | |
16580 | + || au_test_fuse(sb) | |
1308ab2a | 16581 | + /* || au_test_btrfs(sb) */ /* untested */ |
1308ab2a | 16582 | + ; |
16583 | +} | |
16584 | + | |
16585 | +/* | |
16586 | + * filesystems which don't maintain i_size or i_blocks. | |
16587 | + */ | |
16588 | +static inline int au_test_fs_bad_iattr_size(struct super_block *sb) | |
16589 | +{ | |
16590 | + return au_test_xfs(sb) | |
4a4d8108 AM |
16591 | + || au_test_btrfs(sb) |
16592 | + || au_test_ubifs(sb) | |
16593 | + || au_test_hfsplus(sb) /* maintained, but incorrect */ | |
1308ab2a | 16594 | + /* || au_test_minix(sb) */ /* untested */ |
16595 | + ; | |
16596 | +} | |
16597 | + | |
16598 | +/* | |
16599 | + * filesystems which don't store the correct value in some of their inode | |
16600 | + * attributes. | |
16601 | + */ | |
16602 | +static inline int au_test_fs_bad_iattr(struct super_block *sb) | |
16603 | +{ | |
16604 | + return au_test_fs_bad_iattr_size(sb) | |
1308ab2a | 16605 | + || au_test_fat(sb) |
16606 | + || au_test_msdos(sb) | |
16607 | + || au_test_vfat(sb); | |
1facf9fc | 16608 | +} |
16609 | + | |
16610 | +/* they don't check i_nlink in link(2) */ | |
16611 | +static inline int au_test_fs_no_limit_nlink(struct super_block *sb) | |
16612 | +{ | |
16613 | + return au_test_tmpfs(sb) | |
16614 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
16615 | + || au_test_ramfs(sb) | |
16616 | +#endif | |
4a4d8108 | 16617 | + || au_test_ubifs(sb) |
4a4d8108 | 16618 | + || au_test_hfsplus(sb); |
1facf9fc | 16619 | +} |
16620 | + | |
16621 | +/* | |
16622 | + * filesystems which sets S_NOATIME and S_NOCMTIME. | |
16623 | + */ | |
16624 | +static inline int au_test_fs_notime(struct super_block *sb) | |
16625 | +{ | |
16626 | + return au_test_nfs(sb) | |
16627 | + || au_test_fuse(sb) | |
dece6358 | 16628 | + || au_test_ubifs(sb) |
1facf9fc | 16629 | + ; |
16630 | +} | |
16631 | + | |
1facf9fc | 16632 | +/* temporary support for i#1 in cramfs */ |
16633 | +static inline int au_test_fs_unique_ino(struct inode *inode) | |
16634 | +{ | |
16635 | + if (au_test_cramfs(inode->i_sb)) | |
16636 | + return inode->i_ino != 1; | |
16637 | + return 1; | |
16638 | +} | |
16639 | + | |
16640 | +/* ---------------------------------------------------------------------- */ | |
16641 | + | |
16642 | +/* | |
16643 | + * the filesystem where the xino files placed must support i/o after unlink and | |
16644 | + * maintain i_size and i_blocks. | |
16645 | + */ | |
16646 | +static inline int au_test_fs_bad_xino(struct super_block *sb) | |
16647 | +{ | |
16648 | + return au_test_fs_remote(sb) | |
16649 | + || au_test_fs_bad_iattr_size(sb) | |
1facf9fc | 16650 | + /* don't want unnecessary work for xino */ |
16651 | + || au_test_aufs(sb) | |
1308ab2a | 16652 | + || au_test_ecryptfs(sb) |
16653 | + || au_test_nilfs(sb); | |
1facf9fc | 16654 | +} |
16655 | + | |
16656 | +static inline int au_test_fs_trunc_xino(struct super_block *sb) | |
16657 | +{ | |
16658 | + return au_test_tmpfs(sb) | |
16659 | + || au_test_ramfs(sb); | |
16660 | +} | |
16661 | + | |
16662 | +/* | |
16663 | + * test if the @sb is real-readonly. | |
16664 | + */ | |
16665 | +static inline int au_test_fs_rr(struct super_block *sb) | |
16666 | +{ | |
16667 | + return au_test_squashfs(sb) | |
16668 | + || au_test_iso9660(sb) | |
16669 | + || au_test_cramfs(sb) | |
16670 | + || au_test_romfs(sb); | |
16671 | +} | |
16672 | + | |
b912730e AM |
16673 | +/* |
16674 | + * test if the @inode is nfs with 'noacl' option | |
2121bcd9 | 16675 | + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.' |
b912730e AM |
16676 | + */ |
16677 | +static inline int au_test_nfs_noacl(struct inode *inode) | |
16678 | +{ | |
16679 | + return au_test_nfs(inode->i_sb) | |
16680 | + /* && IS_POSIXACL(inode) */ | |
16681 | + && !nfs_server_capable(inode, NFS_CAP_ACLS); | |
16682 | +} | |
16683 | + | |
1facf9fc | 16684 | +#endif /* __KERNEL__ */ |
16685 | +#endif /* __AUFS_FSTYPE_H__ */ | |
8b6a4947 AM |
16686 | diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h |
16687 | --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 16688 | +++ linux/fs/aufs/hbl.h 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 AM |
16689 | @@ -0,0 +1,64 @@ |
16690 | +/* | |
16691 | + * Copyright (C) 2017 Junjiro R. Okajima | |
16692 | + * | |
16693 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16694 | + * it under the terms of the GNU General Public License as published by | |
16695 | + * the Free Software Foundation; either version 2 of the License, or | |
16696 | + * (at your option) any later version. | |
16697 | + * | |
16698 | + * This program is distributed in the hope that it will be useful, | |
16699 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16700 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16701 | + * GNU General Public License for more details. | |
16702 | + * | |
16703 | + * You should have received a copy of the GNU General Public License | |
16704 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16705 | + */ | |
16706 | + | |
16707 | +/* | |
16708 | + * helpers for hlist_bl.h | |
16709 | + */ | |
16710 | + | |
16711 | +#ifndef __AUFS_HBL_H__ | |
16712 | +#define __AUFS_HBL_H__ | |
16713 | + | |
16714 | +#ifdef __KERNEL__ | |
16715 | + | |
16716 | +#include <linux/list_bl.h> | |
16717 | + | |
16718 | +static inline void au_hbl_add(struct hlist_bl_node *node, | |
16719 | + struct hlist_bl_head *hbl) | |
16720 | +{ | |
16721 | + hlist_bl_lock(hbl); | |
16722 | + hlist_bl_add_head(node, hbl); | |
16723 | + hlist_bl_unlock(hbl); | |
16724 | +} | |
16725 | + | |
16726 | +static inline void au_hbl_del(struct hlist_bl_node *node, | |
16727 | + struct hlist_bl_head *hbl) | |
16728 | +{ | |
16729 | + hlist_bl_lock(hbl); | |
16730 | + hlist_bl_del(node); | |
16731 | + hlist_bl_unlock(hbl); | |
16732 | +} | |
16733 | + | |
16734 | +#define au_hbl_for_each(pos, head) \ | |
16735 | + for (pos = hlist_bl_first(head); \ | |
16736 | + pos; \ | |
16737 | + pos = pos->next) | |
16738 | + | |
16739 | +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl) | |
16740 | +{ | |
16741 | + unsigned long cnt; | |
16742 | + struct hlist_bl_node *pos; | |
16743 | + | |
16744 | + cnt = 0; | |
16745 | + hlist_bl_lock(hbl); | |
16746 | + au_hbl_for_each(pos, hbl) | |
16747 | + cnt++; | |
16748 | + hlist_bl_unlock(hbl); | |
16749 | + return cnt; | |
16750 | +} | |
16751 | + | |
16752 | +#endif /* __KERNEL__ */ | |
16753 | +#endif /* __AUFS_HBL_H__ */ | |
7f207e10 AM |
16754 | diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c |
16755 | --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 16756 | +++ linux/fs/aufs/hfsnotify.c 2018-01-29 07:56:20.056658502 +0100 |
ffa93bbd | 16757 | @@ -0,0 +1,289 @@ |
1facf9fc | 16758 | +/* |
a2654f78 | 16759 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 16760 | + * |
16761 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16762 | + * it under the terms of the GNU General Public License as published by | |
16763 | + * the Free Software Foundation; either version 2 of the License, or | |
16764 | + * (at your option) any later version. | |
dece6358 AM |
16765 | + * |
16766 | + * This program is distributed in the hope that it will be useful, | |
16767 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16768 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16769 | + * GNU General Public License for more details. | |
16770 | + * | |
16771 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16772 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 16773 | + */ |
16774 | + | |
16775 | +/* | |
4a4d8108 | 16776 | + * fsnotify for the lower directories |
1facf9fc | 16777 | + */ |
16778 | + | |
16779 | +#include "aufs.h" | |
16780 | + | |
4a4d8108 AM |
16781 | +/* FS_IN_IGNORED is unnecessary */ |
16782 | +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE | |
16783 | + | FS_CREATE | FS_EVENT_ON_CHILD); | |
7f207e10 | 16784 | +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq); |
7eafdf33 | 16785 | +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0); |
1facf9fc | 16786 | + |
0c5527e5 | 16787 | +static void au_hfsn_free_mark(struct fsnotify_mark *mark) |
1facf9fc | 16788 | +{ |
0c5527e5 AM |
16789 | + struct au_hnotify *hn = container_of(mark, struct au_hnotify, |
16790 | + hn_mark); | |
5afbbe0d | 16791 | + /* AuDbg("here\n"); */ |
1c60b727 | 16792 | + au_cache_free_hnotify(hn); |
8b6a4947 | 16793 | + smp_mb__before_atomic(); /* for atomic64_dec */ |
1716fcea AM |
16794 | + if (atomic64_dec_and_test(&au_hfsn_ifree)) |
16795 | + wake_up(&au_hfsn_wq); | |
4a4d8108 | 16796 | +} |
1facf9fc | 16797 | + |
027c5e7a | 16798 | +static int au_hfsn_alloc(struct au_hinode *hinode) |
4a4d8108 | 16799 | +{ |
1716fcea | 16800 | + int err; |
027c5e7a AM |
16801 | + struct au_hnotify *hn; |
16802 | + struct super_block *sb; | |
16803 | + struct au_branch *br; | |
0c5527e5 | 16804 | + struct fsnotify_mark *mark; |
027c5e7a | 16805 | + aufs_bindex_t bindex; |
1facf9fc | 16806 | + |
027c5e7a AM |
16807 | + hn = hinode->hi_notify; |
16808 | + sb = hn->hn_aufs_inode->i_sb; | |
16809 | + bindex = au_br_index(sb, hinode->hi_id); | |
16810 | + br = au_sbr(sb, bindex); | |
1716fcea AM |
16811 | + AuDebugOn(!br->br_hfsn); |
16812 | + | |
0c5527e5 | 16813 | + mark = &hn->hn_mark; |
ffa93bbd | 16814 | + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group); |
0c5527e5 | 16815 | + mark->mask = AuHfsnMask; |
7f207e10 AM |
16816 | + /* |
16817 | + * by udba rename or rmdir, aufs assign a new inode to the known | |
16818 | + * h_inode, so specify 1 to allow dups. | |
16819 | + */ | |
c1595e42 | 16820 | + lockdep_off(); |
ffa93bbd AM |
16821 | + err = fsnotify_add_mark(mark, hinode->hi_inode, /*mnt*/NULL, |
16822 | + /*allow_dups*/1); | |
c1595e42 | 16823 | + lockdep_on(); |
1716fcea AM |
16824 | + |
16825 | + return err; | |
1facf9fc | 16826 | +} |
16827 | + | |
7eafdf33 | 16828 | +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn) |
1facf9fc | 16829 | +{ |
0c5527e5 | 16830 | + struct fsnotify_mark *mark; |
7eafdf33 | 16831 | + unsigned long long ull; |
1716fcea | 16832 | + struct fsnotify_group *group; |
7eafdf33 AM |
16833 | + |
16834 | + ull = atomic64_inc_return(&au_hfsn_ifree); | |
16835 | + BUG_ON(!ull); | |
953406b4 | 16836 | + |
0c5527e5 | 16837 | + mark = &hn->hn_mark; |
1716fcea AM |
16838 | + spin_lock(&mark->lock); |
16839 | + group = mark->group; | |
16840 | + fsnotify_get_group(group); | |
16841 | + spin_unlock(&mark->lock); | |
c1595e42 | 16842 | + lockdep_off(); |
1716fcea | 16843 | + fsnotify_destroy_mark(mark, group); |
5afbbe0d | 16844 | + fsnotify_put_mark(mark); |
1716fcea | 16845 | + fsnotify_put_group(group); |
c1595e42 | 16846 | + lockdep_on(); |
7f207e10 | 16847 | + |
7eafdf33 AM |
16848 | + /* free hn by myself */ |
16849 | + return 0; | |
1facf9fc | 16850 | +} |
16851 | + | |
16852 | +/* ---------------------------------------------------------------------- */ | |
16853 | + | |
4a4d8108 | 16854 | +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set) |
1facf9fc | 16855 | +{ |
0c5527e5 | 16856 | + struct fsnotify_mark *mark; |
1facf9fc | 16857 | + |
0c5527e5 AM |
16858 | + mark = &hinode->hi_notify->hn_mark; |
16859 | + spin_lock(&mark->lock); | |
1facf9fc | 16860 | + if (do_set) { |
0c5527e5 AM |
16861 | + AuDebugOn(mark->mask & AuHfsnMask); |
16862 | + mark->mask |= AuHfsnMask; | |
1facf9fc | 16863 | + } else { |
0c5527e5 AM |
16864 | + AuDebugOn(!(mark->mask & AuHfsnMask)); |
16865 | + mark->mask &= ~AuHfsnMask; | |
1facf9fc | 16866 | + } |
0c5527e5 | 16867 | + spin_unlock(&mark->lock); |
4a4d8108 | 16868 | + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */ |
1facf9fc | 16869 | +} |
16870 | + | |
4a4d8108 | 16871 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16872 | + |
4a4d8108 AM |
16873 | +/* #define AuDbgHnotify */ |
16874 | +#ifdef AuDbgHnotify | |
16875 | +static char *au_hfsn_name(u32 mask) | |
16876 | +{ | |
16877 | +#ifdef CONFIG_AUFS_DEBUG | |
c06a8ce3 AM |
16878 | +#define test_ret(flag) \ |
16879 | + do { \ | |
16880 | + if (mask & flag) \ | |
16881 | + return #flag; \ | |
16882 | + } while (0) | |
4a4d8108 AM |
16883 | + test_ret(FS_ACCESS); |
16884 | + test_ret(FS_MODIFY); | |
16885 | + test_ret(FS_ATTRIB); | |
16886 | + test_ret(FS_CLOSE_WRITE); | |
16887 | + test_ret(FS_CLOSE_NOWRITE); | |
16888 | + test_ret(FS_OPEN); | |
16889 | + test_ret(FS_MOVED_FROM); | |
16890 | + test_ret(FS_MOVED_TO); | |
16891 | + test_ret(FS_CREATE); | |
16892 | + test_ret(FS_DELETE); | |
16893 | + test_ret(FS_DELETE_SELF); | |
16894 | + test_ret(FS_MOVE_SELF); | |
16895 | + test_ret(FS_UNMOUNT); | |
16896 | + test_ret(FS_Q_OVERFLOW); | |
16897 | + test_ret(FS_IN_IGNORED); | |
b912730e | 16898 | + test_ret(FS_ISDIR); |
4a4d8108 AM |
16899 | + test_ret(FS_IN_ONESHOT); |
16900 | + test_ret(FS_EVENT_ON_CHILD); | |
16901 | + return ""; | |
16902 | +#undef test_ret | |
16903 | +#else | |
16904 | + return "??"; | |
16905 | +#endif | |
1facf9fc | 16906 | +} |
4a4d8108 | 16907 | +#endif |
1facf9fc | 16908 | + |
16909 | +/* ---------------------------------------------------------------------- */ | |
16910 | + | |
1716fcea AM |
16911 | +static void au_hfsn_free_group(struct fsnotify_group *group) |
16912 | +{ | |
16913 | + struct au_br_hfsnotify *hfsn = group->private; | |
16914 | + | |
5afbbe0d | 16915 | + /* AuDbg("here\n"); */ |
1c60b727 | 16916 | + kfree(hfsn); |
1716fcea AM |
16917 | +} |
16918 | + | |
4a4d8108 | 16919 | +static int au_hfsn_handle_event(struct fsnotify_group *group, |
fb47a38f | 16920 | + struct inode *inode, |
0c5527e5 AM |
16921 | + struct fsnotify_mark *inode_mark, |
16922 | + struct fsnotify_mark *vfsmount_mark, | |
a2654f78 | 16923 | + u32 mask, const void *data, int data_type, |
ffa93bbd AM |
16924 | + const unsigned char *file_name, u32 cookie, |
16925 | + struct fsnotify_iter_info *iter_info) | |
1facf9fc | 16926 | +{ |
16927 | + int err; | |
4a4d8108 AM |
16928 | + struct au_hnotify *hnotify; |
16929 | + struct inode *h_dir, *h_inode; | |
fb47a38f | 16930 | + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name)); |
4a4d8108 | 16931 | + |
fb47a38f | 16932 | + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE); |
1facf9fc | 16933 | + |
16934 | + err = 0; | |
0c5527e5 | 16935 | + /* if FS_UNMOUNT happens, there must be another bug */ |
4a4d8108 | 16936 | + AuDebugOn(mask & FS_UNMOUNT); |
0c5527e5 | 16937 | + if (mask & (FS_IN_IGNORED | FS_UNMOUNT)) |
1facf9fc | 16938 | + goto out; |
1facf9fc | 16939 | + |
fb47a38f JR |
16940 | + h_dir = inode; |
16941 | + h_inode = NULL; | |
4a4d8108 | 16942 | +#ifdef AuDbgHnotify |
392086de | 16943 | + au_debug_on(); |
4a4d8108 AM |
16944 | + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1 |
16945 | + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) { | |
16946 | + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n", | |
16947 | + h_dir->i_ino, mask, au_hfsn_name(mask), | |
16948 | + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0); | |
16949 | + /* WARN_ON(1); */ | |
1facf9fc | 16950 | + } |
392086de | 16951 | + au_debug_off(); |
1facf9fc | 16952 | +#endif |
4a4d8108 | 16953 | + |
0c5527e5 AM |
16954 | + AuDebugOn(!inode_mark); |
16955 | + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark); | |
16956 | + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode); | |
1facf9fc | 16957 | + |
4a4d8108 AM |
16958 | +out: |
16959 | + return err; | |
16960 | +} | |
1facf9fc | 16961 | + |
4a4d8108 | 16962 | +static struct fsnotify_ops au_hfsn_ops = { |
1716fcea | 16963 | + .handle_event = au_hfsn_handle_event, |
ffa93bbd AM |
16964 | + .free_group_priv = au_hfsn_free_group, |
16965 | + .free_mark = au_hfsn_free_mark | |
4a4d8108 AM |
16966 | +}; |
16967 | + | |
16968 | +/* ---------------------------------------------------------------------- */ | |
16969 | + | |
027c5e7a AM |
16970 | +static void au_hfsn_fin_br(struct au_branch *br) |
16971 | +{ | |
1716fcea | 16972 | + struct au_br_hfsnotify *hfsn; |
027c5e7a | 16973 | + |
1716fcea | 16974 | + hfsn = br->br_hfsn; |
c1595e42 JR |
16975 | + if (hfsn) { |
16976 | + lockdep_off(); | |
1716fcea | 16977 | + fsnotify_put_group(hfsn->hfsn_group); |
c1595e42 JR |
16978 | + lockdep_on(); |
16979 | + } | |
027c5e7a AM |
16980 | +} |
16981 | + | |
1716fcea | 16982 | +static int au_hfsn_init_br(struct au_branch *br, int perm) |
4a4d8108 AM |
16983 | +{ |
16984 | + int err; | |
1716fcea AM |
16985 | + struct fsnotify_group *group; |
16986 | + struct au_br_hfsnotify *hfsn; | |
1facf9fc | 16987 | + |
4a4d8108 | 16988 | + err = 0; |
1716fcea AM |
16989 | + br->br_hfsn = NULL; |
16990 | + if (!au_br_hnotifyable(perm)) | |
027c5e7a | 16991 | + goto out; |
027c5e7a | 16992 | + |
1716fcea AM |
16993 | + err = -ENOMEM; |
16994 | + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS); | |
16995 | + if (unlikely(!hfsn)) | |
027c5e7a AM |
16996 | + goto out; |
16997 | + | |
1716fcea AM |
16998 | + err = 0; |
16999 | + group = fsnotify_alloc_group(&au_hfsn_ops); | |
17000 | + if (IS_ERR(group)) { | |
17001 | + err = PTR_ERR(group); | |
0c5527e5 | 17002 | + pr_err("fsnotify_alloc_group() failed, %d\n", err); |
1716fcea | 17003 | + goto out_hfsn; |
4a4d8108 | 17004 | + } |
1facf9fc | 17005 | + |
1716fcea AM |
17006 | + group->private = hfsn; |
17007 | + hfsn->hfsn_group = group; | |
17008 | + br->br_hfsn = hfsn; | |
17009 | + goto out; /* success */ | |
17010 | + | |
17011 | +out_hfsn: | |
1c60b727 | 17012 | + kfree(hfsn); |
027c5e7a | 17013 | +out: |
1716fcea AM |
17014 | + return err; |
17015 | +} | |
17016 | + | |
17017 | +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
17018 | +{ | |
17019 | + int err; | |
17020 | + | |
17021 | + err = 0; | |
17022 | + if (!br->br_hfsn) | |
17023 | + err = au_hfsn_init_br(br, perm); | |
17024 | + | |
1facf9fc | 17025 | + return err; |
17026 | +} | |
17027 | + | |
7eafdf33 AM |
17028 | +/* ---------------------------------------------------------------------- */ |
17029 | + | |
17030 | +static void au_hfsn_fin(void) | |
17031 | +{ | |
17032 | + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree)); | |
17033 | + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree)); | |
17034 | +} | |
17035 | + | |
4a4d8108 AM |
17036 | +const struct au_hnotify_op au_hnotify_op = { |
17037 | + .ctl = au_hfsn_ctl, | |
17038 | + .alloc = au_hfsn_alloc, | |
17039 | + .free = au_hfsn_free, | |
1facf9fc | 17040 | + |
7eafdf33 AM |
17041 | + .fin = au_hfsn_fin, |
17042 | + | |
027c5e7a AM |
17043 | + .reset_br = au_hfsn_reset_br, |
17044 | + .fin_br = au_hfsn_fin_br, | |
17045 | + .init_br = au_hfsn_init_br | |
4a4d8108 | 17046 | +}; |
7f207e10 AM |
17047 | diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c |
17048 | --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 17049 | +++ linux/fs/aufs/hfsplus.c 2018-01-29 07:56:20.056658502 +0100 |
523b37e3 | 17050 | @@ -0,0 +1,56 @@ |
4a4d8108 | 17051 | +/* |
a2654f78 | 17052 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
4a4d8108 AM |
17053 | + * |
17054 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17055 | + * it under the terms of the GNU General Public License as published by | |
17056 | + * the Free Software Foundation; either version 2 of the License, or | |
17057 | + * (at your option) any later version. | |
17058 | + * | |
17059 | + * This program is distributed in the hope that it will be useful, | |
17060 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17061 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17062 | + * GNU General Public License for more details. | |
17063 | + * | |
17064 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17065 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 17066 | + */ |
1facf9fc | 17067 | + |
4a4d8108 AM |
17068 | +/* |
17069 | + * special support for filesystems which aqucires an inode mutex | |
17070 | + * at final closing a file, eg, hfsplus. | |
17071 | + * | |
17072 | + * This trick is very simple and stupid, just to open the file before really | |
17073 | + * neceeary open to tell hfsplus that this is not the final closing. | |
17074 | + * The caller should call au_h_open_pre() after acquiring the inode mutex, | |
17075 | + * and au_h_open_post() after releasing it. | |
17076 | + */ | |
1facf9fc | 17077 | + |
4a4d8108 | 17078 | +#include "aufs.h" |
1facf9fc | 17079 | + |
392086de AM |
17080 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
17081 | + int force_wr) | |
4a4d8108 AM |
17082 | +{ |
17083 | + struct file *h_file; | |
17084 | + struct dentry *h_dentry; | |
1facf9fc | 17085 | + |
4a4d8108 AM |
17086 | + h_dentry = au_h_dptr(dentry, bindex); |
17087 | + AuDebugOn(!h_dentry); | |
5527c038 | 17088 | + AuDebugOn(d_is_negative(h_dentry)); |
4a4d8108 AM |
17089 | + |
17090 | + h_file = NULL; | |
17091 | + if (au_test_hfsplus(h_dentry->d_sb) | |
7e9cd9fe | 17092 | + && d_is_reg(h_dentry)) |
4a4d8108 AM |
17093 | + h_file = au_h_open(dentry, bindex, |
17094 | + O_RDONLY | O_NOATIME | O_LARGEFILE, | |
392086de | 17095 | + /*file*/NULL, force_wr); |
4a4d8108 | 17096 | + return h_file; |
1facf9fc | 17097 | +} |
17098 | + | |
4a4d8108 AM |
17099 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
17100 | + struct file *h_file) | |
17101 | +{ | |
17102 | + if (h_file) { | |
17103 | + fput(h_file); | |
17104 | + au_sbr_put(dentry->d_sb, bindex); | |
17105 | + } | |
17106 | +} | |
7f207e10 AM |
17107 | diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c |
17108 | --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 17109 | +++ linux/fs/aufs/hnotify.c 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 | 17110 | @@ -0,0 +1,719 @@ |
e49829fe | 17111 | +/* |
a2654f78 | 17112 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
e49829fe JR |
17113 | + * |
17114 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17115 | + * it under the terms of the GNU General Public License as published by | |
17116 | + * the Free Software Foundation; either version 2 of the License, or | |
17117 | + * (at your option) any later version. | |
17118 | + * | |
17119 | + * This program is distributed in the hope that it will be useful, | |
17120 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17121 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17122 | + * GNU General Public License for more details. | |
17123 | + * | |
17124 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17125 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
17126 | + */ |
17127 | + | |
17128 | +/* | |
7f207e10 | 17129 | + * abstraction to notify the direct changes on lower directories |
e49829fe JR |
17130 | + */ |
17131 | + | |
17132 | +#include "aufs.h" | |
17133 | + | |
027c5e7a | 17134 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode) |
e49829fe JR |
17135 | +{ |
17136 | + int err; | |
7f207e10 | 17137 | + struct au_hnotify *hn; |
1facf9fc | 17138 | + |
4a4d8108 AM |
17139 | + err = -ENOMEM; |
17140 | + hn = au_cache_alloc_hnotify(); | |
17141 | + if (hn) { | |
17142 | + hn->hn_aufs_inode = inode; | |
027c5e7a AM |
17143 | + hinode->hi_notify = hn; |
17144 | + err = au_hnotify_op.alloc(hinode); | |
17145 | + AuTraceErr(err); | |
17146 | + if (unlikely(err)) { | |
17147 | + hinode->hi_notify = NULL; | |
1c60b727 | 17148 | + au_cache_free_hnotify(hn); |
4a4d8108 AM |
17149 | + /* |
17150 | + * The upper dir was removed by udba, but the same named | |
17151 | + * dir left. In this case, aufs assignes a new inode | |
17152 | + * number and set the monitor again. | |
17153 | + * For the lower dir, the old monitnor is still left. | |
17154 | + */ | |
17155 | + if (err == -EEXIST) | |
17156 | + err = 0; | |
17157 | + } | |
1308ab2a | 17158 | + } |
1308ab2a | 17159 | + |
027c5e7a | 17160 | + AuTraceErr(err); |
1308ab2a | 17161 | + return err; |
dece6358 | 17162 | +} |
1facf9fc | 17163 | + |
4a4d8108 | 17164 | +void au_hn_free(struct au_hinode *hinode) |
dece6358 | 17165 | +{ |
4a4d8108 | 17166 | + struct au_hnotify *hn; |
1facf9fc | 17167 | + |
4a4d8108 AM |
17168 | + hn = hinode->hi_notify; |
17169 | + if (hn) { | |
4a4d8108 | 17170 | + hinode->hi_notify = NULL; |
7eafdf33 | 17171 | + if (au_hnotify_op.free(hinode, hn)) |
1c60b727 | 17172 | + au_cache_free_hnotify(hn); |
4a4d8108 AM |
17173 | + } |
17174 | +} | |
dece6358 | 17175 | + |
4a4d8108 | 17176 | +/* ---------------------------------------------------------------------- */ |
dece6358 | 17177 | + |
4a4d8108 AM |
17178 | +void au_hn_ctl(struct au_hinode *hinode, int do_set) |
17179 | +{ | |
17180 | + if (hinode->hi_notify) | |
17181 | + au_hnotify_op.ctl(hinode, do_set); | |
17182 | +} | |
17183 | + | |
17184 | +void au_hn_reset(struct inode *inode, unsigned int flags) | |
17185 | +{ | |
5afbbe0d | 17186 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
17187 | + struct inode *hi; |
17188 | + struct dentry *iwhdentry; | |
1facf9fc | 17189 | + |
5afbbe0d AM |
17190 | + bbot = au_ibbot(inode); |
17191 | + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) { | |
4a4d8108 AM |
17192 | + hi = au_h_iptr(inode, bindex); |
17193 | + if (!hi) | |
17194 | + continue; | |
1308ab2a | 17195 | + |
febd17d6 | 17196 | + /* inode_lock_nested(hi, AuLsc_I_CHILD); */ |
4a4d8108 AM |
17197 | + iwhdentry = au_hi_wh(inode, bindex); |
17198 | + if (iwhdentry) | |
17199 | + dget(iwhdentry); | |
17200 | + au_igrab(hi); | |
17201 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
17202 | + au_set_h_iptr(inode, bindex, au_igrab(hi), | |
17203 | + flags & ~AuHi_XINO); | |
17204 | + iput(hi); | |
17205 | + dput(iwhdentry); | |
febd17d6 | 17206 | + /* inode_unlock(hi); */ |
1facf9fc | 17207 | + } |
1facf9fc | 17208 | +} |
17209 | + | |
1308ab2a | 17210 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17211 | + |
4a4d8108 | 17212 | +static int hn_xino(struct inode *inode, struct inode *h_inode) |
1facf9fc | 17213 | +{ |
4a4d8108 | 17214 | + int err; |
5afbbe0d | 17215 | + aufs_bindex_t bindex, bbot, bfound, btop; |
4a4d8108 | 17216 | + struct inode *h_i; |
1facf9fc | 17217 | + |
4a4d8108 AM |
17218 | + err = 0; |
17219 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 17220 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
17221 | + goto out; |
17222 | + } | |
1facf9fc | 17223 | + |
4a4d8108 | 17224 | + bfound = -1; |
5afbbe0d AM |
17225 | + bbot = au_ibbot(inode); |
17226 | + btop = au_ibtop(inode); | |
4a4d8108 | 17227 | +#if 0 /* reserved for future use */ |
5afbbe0d | 17228 | + if (bindex == bbot) { |
4a4d8108 AM |
17229 | + /* keep this ino in rename case */ |
17230 | + goto out; | |
17231 | + } | |
17232 | +#endif | |
5afbbe0d | 17233 | + for (bindex = btop; bindex <= bbot; bindex++) |
4a4d8108 AM |
17234 | + if (au_h_iptr(inode, bindex) == h_inode) { |
17235 | + bfound = bindex; | |
17236 | + break; | |
17237 | + } | |
17238 | + if (bfound < 0) | |
1308ab2a | 17239 | + goto out; |
1facf9fc | 17240 | + |
5afbbe0d | 17241 | + for (bindex = btop; bindex <= bbot; bindex++) { |
4a4d8108 AM |
17242 | + h_i = au_h_iptr(inode, bindex); |
17243 | + if (!h_i) | |
17244 | + continue; | |
1facf9fc | 17245 | + |
4a4d8108 AM |
17246 | + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0); |
17247 | + /* ignore this error */ | |
17248 | + /* bad action? */ | |
1facf9fc | 17249 | + } |
1facf9fc | 17250 | + |
4a4d8108 | 17251 | + /* children inode number will be broken */ |
1facf9fc | 17252 | + |
4f0767ce | 17253 | +out: |
4a4d8108 AM |
17254 | + AuTraceErr(err); |
17255 | + return err; | |
1facf9fc | 17256 | +} |
17257 | + | |
4a4d8108 | 17258 | +static int hn_gen_tree(struct dentry *dentry) |
1facf9fc | 17259 | +{ |
4a4d8108 AM |
17260 | + int err, i, j, ndentry; |
17261 | + struct au_dcsub_pages dpages; | |
17262 | + struct au_dpage *dpage; | |
17263 | + struct dentry **dentries; | |
1facf9fc | 17264 | + |
4a4d8108 AM |
17265 | + err = au_dpages_init(&dpages, GFP_NOFS); |
17266 | + if (unlikely(err)) | |
17267 | + goto out; | |
17268 | + err = au_dcsub_pages(&dpages, dentry, NULL, NULL); | |
17269 | + if (unlikely(err)) | |
17270 | + goto out_dpages; | |
1facf9fc | 17271 | + |
4a4d8108 AM |
17272 | + for (i = 0; i < dpages.ndpage; i++) { |
17273 | + dpage = dpages.dpages + i; | |
17274 | + dentries = dpage->dentries; | |
17275 | + ndentry = dpage->ndentry; | |
17276 | + for (j = 0; j < ndentry; j++) { | |
17277 | + struct dentry *d; | |
17278 | + | |
17279 | + d = dentries[j]; | |
17280 | + if (IS_ROOT(d)) | |
17281 | + continue; | |
17282 | + | |
4a4d8108 | 17283 | + au_digen_dec(d); |
5527c038 | 17284 | + if (d_really_is_positive(d)) |
4a4d8108 AM |
17285 | + /* todo: reset children xino? |
17286 | + cached children only? */ | |
5527c038 | 17287 | + au_iigen_dec(d_inode(d)); |
1308ab2a | 17288 | + } |
dece6358 | 17289 | + } |
1facf9fc | 17290 | + |
4f0767ce | 17291 | +out_dpages: |
4a4d8108 | 17292 | + au_dpages_free(&dpages); |
dece6358 | 17293 | + |
027c5e7a | 17294 | +#if 0 |
4a4d8108 AM |
17295 | + /* discard children */ |
17296 | + dentry_unhash(dentry); | |
17297 | + dput(dentry); | |
027c5e7a | 17298 | +#endif |
4f0767ce | 17299 | +out: |
dece6358 AM |
17300 | + return err; |
17301 | +} | |
17302 | + | |
1308ab2a | 17303 | +/* |
4a4d8108 | 17304 | + * return 0 if processed. |
1308ab2a | 17305 | + */ |
4a4d8108 AM |
17306 | +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode, |
17307 | + const unsigned int isdir) | |
dece6358 | 17308 | +{ |
1308ab2a | 17309 | + int err; |
4a4d8108 AM |
17310 | + struct dentry *d; |
17311 | + struct qstr *dname; | |
1facf9fc | 17312 | + |
4a4d8108 AM |
17313 | + err = 1; |
17314 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 17315 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
17316 | + err = 0; |
17317 | + goto out; | |
17318 | + } | |
dece6358 | 17319 | + |
4a4d8108 AM |
17320 | + if (!isdir) { |
17321 | + AuDebugOn(!name); | |
17322 | + au_iigen_dec(inode); | |
027c5e7a | 17323 | + spin_lock(&inode->i_lock); |
c1595e42 | 17324 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 17325 | + spin_lock(&d->d_lock); |
4a4d8108 AM |
17326 | + dname = &d->d_name; |
17327 | + if (dname->len != nlen | |
027c5e7a AM |
17328 | + && memcmp(dname->name, name, nlen)) { |
17329 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 17330 | + continue; |
027c5e7a | 17331 | + } |
4a4d8108 | 17332 | + err = 0; |
4a4d8108 AM |
17333 | + au_digen_dec(d); |
17334 | + spin_unlock(&d->d_lock); | |
17335 | + break; | |
1facf9fc | 17336 | + } |
027c5e7a | 17337 | + spin_unlock(&inode->i_lock); |
1308ab2a | 17338 | + } else { |
027c5e7a | 17339 | + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR); |
c1595e42 | 17340 | + d = d_find_any_alias(inode); |
4a4d8108 AM |
17341 | + if (!d) { |
17342 | + au_iigen_dec(inode); | |
17343 | + goto out; | |
17344 | + } | |
1facf9fc | 17345 | + |
027c5e7a | 17346 | + spin_lock(&d->d_lock); |
4a4d8108 | 17347 | + dname = &d->d_name; |
027c5e7a AM |
17348 | + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) { |
17349 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 17350 | + err = hn_gen_tree(d); |
027c5e7a AM |
17351 | + spin_lock(&d->d_lock); |
17352 | + } | |
17353 | + spin_unlock(&d->d_lock); | |
4a4d8108 AM |
17354 | + dput(d); |
17355 | + } | |
1facf9fc | 17356 | + |
4f0767ce | 17357 | +out: |
4a4d8108 | 17358 | + AuTraceErr(err); |
1308ab2a | 17359 | + return err; |
17360 | +} | |
dece6358 | 17361 | + |
4a4d8108 | 17362 | +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir) |
1facf9fc | 17363 | +{ |
4a4d8108 | 17364 | + int err; |
1facf9fc | 17365 | + |
5527c038 | 17366 | + if (IS_ROOT(dentry)) { |
0c3ec466 | 17367 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
17368 | + return 0; |
17369 | + } | |
1308ab2a | 17370 | + |
4a4d8108 AM |
17371 | + err = 0; |
17372 | + if (!isdir) { | |
4a4d8108 | 17373 | + au_digen_dec(dentry); |
5527c038 JR |
17374 | + if (d_really_is_positive(dentry)) |
17375 | + au_iigen_dec(d_inode(dentry)); | |
4a4d8108 | 17376 | + } else { |
027c5e7a | 17377 | + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR); |
5527c038 | 17378 | + if (d_really_is_positive(dentry)) |
4a4d8108 AM |
17379 | + err = hn_gen_tree(dentry); |
17380 | + } | |
17381 | + | |
17382 | + AuTraceErr(err); | |
17383 | + return err; | |
1facf9fc | 17384 | +} |
17385 | + | |
4a4d8108 | 17386 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17387 | + |
4a4d8108 AM |
17388 | +/* hnotify job flags */ |
17389 | +#define AuHnJob_XINO0 1 | |
17390 | +#define AuHnJob_GEN (1 << 1) | |
17391 | +#define AuHnJob_DIRENT (1 << 2) | |
17392 | +#define AuHnJob_ISDIR (1 << 3) | |
17393 | +#define AuHnJob_TRYXINO0 (1 << 4) | |
17394 | +#define AuHnJob_MNTPNT (1 << 5) | |
17395 | +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name) | |
7f207e10 AM |
17396 | +#define au_fset_hnjob(flags, name) \ |
17397 | + do { (flags) |= AuHnJob_##name; } while (0) | |
17398 | +#define au_fclr_hnjob(flags, name) \ | |
17399 | + do { (flags) &= ~AuHnJob_##name; } while (0) | |
1facf9fc | 17400 | + |
4a4d8108 AM |
17401 | +enum { |
17402 | + AuHn_CHILD, | |
17403 | + AuHn_PARENT, | |
17404 | + AuHnLast | |
17405 | +}; | |
1facf9fc | 17406 | + |
4a4d8108 AM |
17407 | +struct au_hnotify_args { |
17408 | + struct inode *h_dir, *dir, *h_child_inode; | |
17409 | + u32 mask; | |
17410 | + unsigned int flags[AuHnLast]; | |
17411 | + unsigned int h_child_nlen; | |
17412 | + char h_child_name[]; | |
17413 | +}; | |
1facf9fc | 17414 | + |
4a4d8108 AM |
17415 | +struct hn_job_args { |
17416 | + unsigned int flags; | |
17417 | + struct inode *inode, *h_inode, *dir, *h_dir; | |
17418 | + struct dentry *dentry; | |
17419 | + char *h_name; | |
17420 | + int h_nlen; | |
17421 | +}; | |
1308ab2a | 17422 | + |
4a4d8108 AM |
17423 | +static int hn_job(struct hn_job_args *a) |
17424 | +{ | |
17425 | + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR); | |
076b876e | 17426 | + int e; |
1308ab2a | 17427 | + |
4a4d8108 AM |
17428 | + /* reset xino */ |
17429 | + if (au_ftest_hnjob(a->flags, XINO0) && a->inode) | |
17430 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ | |
1308ab2a | 17431 | + |
4a4d8108 AM |
17432 | + if (au_ftest_hnjob(a->flags, TRYXINO0) |
17433 | + && a->inode | |
17434 | + && a->h_inode) { | |
3c1bdaff | 17435 | + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD); |
38d290e6 JR |
17436 | + if (!a->h_inode->i_nlink |
17437 | + && !(a->h_inode->i_state & I_LINKABLE)) | |
4a4d8108 | 17438 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ |
3c1bdaff | 17439 | + inode_unlock_shared(a->h_inode); |
1308ab2a | 17440 | + } |
1facf9fc | 17441 | + |
4a4d8108 AM |
17442 | + /* make the generation obsolete */ |
17443 | + if (au_ftest_hnjob(a->flags, GEN)) { | |
076b876e | 17444 | + e = -1; |
4a4d8108 | 17445 | + if (a->inode) |
076b876e | 17446 | + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode, |
4a4d8108 | 17447 | + isdir); |
076b876e | 17448 | + if (e && a->dentry) |
4a4d8108 AM |
17449 | + hn_gen_by_name(a->dentry, isdir); |
17450 | + /* ignore this error */ | |
1facf9fc | 17451 | + } |
1facf9fc | 17452 | + |
4a4d8108 AM |
17453 | + /* make dir entries obsolete */ |
17454 | + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) { | |
17455 | + struct au_vdir *vdir; | |
1facf9fc | 17456 | + |
4a4d8108 AM |
17457 | + vdir = au_ivdir(a->inode); |
17458 | + if (vdir) | |
17459 | + vdir->vd_jiffy = 0; | |
17460 | + /* IMustLock(a->inode); */ | |
17461 | + /* a->inode->i_version++; */ | |
17462 | + } | |
1facf9fc | 17463 | + |
4a4d8108 AM |
17464 | + /* can do nothing but warn */ |
17465 | + if (au_ftest_hnjob(a->flags, MNTPNT) | |
17466 | + && a->dentry | |
17467 | + && d_mountpoint(a->dentry)) | |
523b37e3 | 17468 | + pr_warn("mount-point %pd is removed or renamed\n", a->dentry); |
1facf9fc | 17469 | + |
4a4d8108 | 17470 | + return 0; |
1308ab2a | 17471 | +} |
1facf9fc | 17472 | + |
1308ab2a | 17473 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17474 | + |
4a4d8108 AM |
17475 | +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen, |
17476 | + struct inode *dir) | |
1308ab2a | 17477 | +{ |
4a4d8108 AM |
17478 | + struct dentry *dentry, *d, *parent; |
17479 | + struct qstr *dname; | |
1308ab2a | 17480 | + |
c1595e42 | 17481 | + parent = d_find_any_alias(dir); |
4a4d8108 AM |
17482 | + if (!parent) |
17483 | + return NULL; | |
1308ab2a | 17484 | + |
4a4d8108 | 17485 | + dentry = NULL; |
027c5e7a | 17486 | + spin_lock(&parent->d_lock); |
c1595e42 | 17487 | + list_for_each_entry(d, &parent->d_subdirs, d_child) { |
523b37e3 | 17488 | + /* AuDbg("%pd\n", d); */ |
027c5e7a | 17489 | + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED); |
4a4d8108 AM |
17490 | + dname = &d->d_name; |
17491 | + if (dname->len != nlen || memcmp(dname->name, name, nlen)) | |
027c5e7a AM |
17492 | + goto cont_unlock; |
17493 | + if (au_di(d)) | |
17494 | + au_digen_dec(d); | |
17495 | + else | |
17496 | + goto cont_unlock; | |
c1595e42 | 17497 | + if (au_dcount(d) > 0) { |
027c5e7a | 17498 | + dentry = dget_dlock(d); |
4a4d8108 | 17499 | + spin_unlock(&d->d_lock); |
027c5e7a | 17500 | + break; |
dece6358 | 17501 | + } |
1facf9fc | 17502 | + |
f6b6e03d | 17503 | +cont_unlock: |
027c5e7a | 17504 | + spin_unlock(&d->d_lock); |
1308ab2a | 17505 | + } |
027c5e7a | 17506 | + spin_unlock(&parent->d_lock); |
4a4d8108 | 17507 | + dput(parent); |
1facf9fc | 17508 | + |
4a4d8108 AM |
17509 | + if (dentry) |
17510 | + di_write_lock_child(dentry); | |
1308ab2a | 17511 | + |
4a4d8108 AM |
17512 | + return dentry; |
17513 | +} | |
dece6358 | 17514 | + |
4a4d8108 AM |
17515 | +static struct inode *lookup_wlock_by_ino(struct super_block *sb, |
17516 | + aufs_bindex_t bindex, ino_t h_ino) | |
17517 | +{ | |
17518 | + struct inode *inode; | |
17519 | + ino_t ino; | |
17520 | + int err; | |
17521 | + | |
17522 | + inode = NULL; | |
17523 | + err = au_xino_read(sb, bindex, h_ino, &ino); | |
17524 | + if (!err && ino) | |
17525 | + inode = ilookup(sb, ino); | |
17526 | + if (!inode) | |
17527 | + goto out; | |
17528 | + | |
17529 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 17530 | + pr_warn("wrong root branch\n"); |
4a4d8108 AM |
17531 | + iput(inode); |
17532 | + inode = NULL; | |
17533 | + goto out; | |
1308ab2a | 17534 | + } |
17535 | + | |
4a4d8108 | 17536 | + ii_write_lock_child(inode); |
1308ab2a | 17537 | + |
4f0767ce | 17538 | +out: |
4a4d8108 | 17539 | + return inode; |
dece6358 AM |
17540 | +} |
17541 | + | |
4a4d8108 | 17542 | +static void au_hn_bh(void *_args) |
1facf9fc | 17543 | +{ |
4a4d8108 AM |
17544 | + struct au_hnotify_args *a = _args; |
17545 | + struct super_block *sb; | |
5afbbe0d | 17546 | + aufs_bindex_t bindex, bbot, bfound; |
4a4d8108 | 17547 | + unsigned char xino, try_iput; |
1facf9fc | 17548 | + int err; |
1308ab2a | 17549 | + struct inode *inode; |
4a4d8108 AM |
17550 | + ino_t h_ino; |
17551 | + struct hn_job_args args; | |
17552 | + struct dentry *dentry; | |
17553 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 17554 | + |
4a4d8108 AM |
17555 | + AuDebugOn(!_args); |
17556 | + AuDebugOn(!a->h_dir); | |
17557 | + AuDebugOn(!a->dir); | |
17558 | + AuDebugOn(!a->mask); | |
17559 | + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n", | |
17560 | + a->mask, a->dir->i_ino, a->h_dir->i_ino, | |
17561 | + a->h_child_inode ? a->h_child_inode->i_ino : 0); | |
1facf9fc | 17562 | + |
4a4d8108 AM |
17563 | + inode = NULL; |
17564 | + dentry = NULL; | |
17565 | + /* | |
17566 | + * do not lock a->dir->i_mutex here | |
17567 | + * because of d_revalidate() may cause a deadlock. | |
17568 | + */ | |
17569 | + sb = a->dir->i_sb; | |
17570 | + AuDebugOn(!sb); | |
17571 | + sbinfo = au_sbi(sb); | |
17572 | + AuDebugOn(!sbinfo); | |
7f207e10 | 17573 | + si_write_lock(sb, AuLock_NOPLMW); |
1facf9fc | 17574 | + |
8b6a4947 AM |
17575 | + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) |
17576 | + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) { | |
17577 | + case FS_MOVED_FROM: | |
17578 | + case FS_MOVED_TO: | |
17579 | + AuWarn1("DIRREN with UDBA may not work correctly " | |
17580 | + "for the direct rename(2)\n"); | |
17581 | + } | |
17582 | + | |
4a4d8108 AM |
17583 | + ii_read_lock_parent(a->dir); |
17584 | + bfound = -1; | |
5afbbe0d AM |
17585 | + bbot = au_ibbot(a->dir); |
17586 | + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++) | |
4a4d8108 AM |
17587 | + if (au_h_iptr(a->dir, bindex) == a->h_dir) { |
17588 | + bfound = bindex; | |
17589 | + break; | |
17590 | + } | |
17591 | + ii_read_unlock(a->dir); | |
17592 | + if (unlikely(bfound < 0)) | |
17593 | + goto out; | |
1facf9fc | 17594 | + |
4a4d8108 AM |
17595 | + xino = !!au_opt_test(au_mntflags(sb), XINO); |
17596 | + h_ino = 0; | |
17597 | + if (a->h_child_inode) | |
17598 | + h_ino = a->h_child_inode->i_ino; | |
1facf9fc | 17599 | + |
4a4d8108 AM |
17600 | + if (a->h_child_nlen |
17601 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN) | |
17602 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT))) | |
17603 | + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen, | |
17604 | + a->dir); | |
17605 | + try_iput = 0; | |
5527c038 JR |
17606 | + if (dentry && d_really_is_positive(dentry)) |
17607 | + inode = d_inode(dentry); | |
4a4d8108 AM |
17608 | + if (xino && !inode && h_ino |
17609 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0) | |
17610 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0) | |
17611 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) { | |
17612 | + inode = lookup_wlock_by_ino(sb, bfound, h_ino); | |
17613 | + try_iput = 1; | |
f0c0a007 | 17614 | + } |
1facf9fc | 17615 | + |
4a4d8108 AM |
17616 | + args.flags = a->flags[AuHn_CHILD]; |
17617 | + args.dentry = dentry; | |
17618 | + args.inode = inode; | |
17619 | + args.h_inode = a->h_child_inode; | |
17620 | + args.dir = a->dir; | |
17621 | + args.h_dir = a->h_dir; | |
17622 | + args.h_name = a->h_child_name; | |
17623 | + args.h_nlen = a->h_child_nlen; | |
17624 | + err = hn_job(&args); | |
17625 | + if (dentry) { | |
027c5e7a | 17626 | + if (au_di(dentry)) |
4a4d8108 AM |
17627 | + di_write_unlock(dentry); |
17628 | + dput(dentry); | |
17629 | + } | |
17630 | + if (inode && try_iput) { | |
17631 | + ii_write_unlock(inode); | |
17632 | + iput(inode); | |
17633 | + } | |
1facf9fc | 17634 | + |
4a4d8108 AM |
17635 | + ii_write_lock_parent(a->dir); |
17636 | + args.flags = a->flags[AuHn_PARENT]; | |
17637 | + args.dentry = NULL; | |
17638 | + args.inode = a->dir; | |
17639 | + args.h_inode = a->h_dir; | |
17640 | + args.dir = NULL; | |
17641 | + args.h_dir = NULL; | |
17642 | + args.h_name = NULL; | |
17643 | + args.h_nlen = 0; | |
17644 | + err = hn_job(&args); | |
17645 | + ii_write_unlock(a->dir); | |
1facf9fc | 17646 | + |
4f0767ce | 17647 | +out: |
4a4d8108 AM |
17648 | + iput(a->h_child_inode); |
17649 | + iput(a->h_dir); | |
17650 | + iput(a->dir); | |
027c5e7a AM |
17651 | + si_write_unlock(sb); |
17652 | + au_nwt_done(&sbinfo->si_nowait); | |
1c60b727 | 17653 | + kfree(a); |
dece6358 | 17654 | +} |
1facf9fc | 17655 | + |
4a4d8108 AM |
17656 | +/* ---------------------------------------------------------------------- */ |
17657 | + | |
17658 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
17659 | + struct qstr *h_child_qstr, struct inode *h_child_inode) | |
dece6358 | 17660 | +{ |
4a4d8108 | 17661 | + int err, len; |
53392da6 | 17662 | + unsigned int flags[AuHnLast], f; |
4a4d8108 AM |
17663 | + unsigned char isdir, isroot, wh; |
17664 | + struct inode *dir; | |
17665 | + struct au_hnotify_args *args; | |
17666 | + char *p, *h_child_name; | |
dece6358 | 17667 | + |
1308ab2a | 17668 | + err = 0; |
4a4d8108 AM |
17669 | + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode); |
17670 | + dir = igrab(hnotify->hn_aufs_inode); | |
17671 | + if (!dir) | |
17672 | + goto out; | |
1facf9fc | 17673 | + |
4a4d8108 AM |
17674 | + isroot = (dir->i_ino == AUFS_ROOT_INO); |
17675 | + wh = 0; | |
17676 | + h_child_name = (void *)h_child_qstr->name; | |
17677 | + len = h_child_qstr->len; | |
17678 | + if (h_child_name) { | |
17679 | + if (len > AUFS_WH_PFX_LEN | |
17680 | + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
17681 | + h_child_name += AUFS_WH_PFX_LEN; | |
17682 | + len -= AUFS_WH_PFX_LEN; | |
17683 | + wh = 1; | |
17684 | + } | |
1facf9fc | 17685 | + } |
dece6358 | 17686 | + |
4a4d8108 AM |
17687 | + isdir = 0; |
17688 | + if (h_child_inode) | |
17689 | + isdir = !!S_ISDIR(h_child_inode->i_mode); | |
17690 | + flags[AuHn_PARENT] = AuHnJob_ISDIR; | |
17691 | + flags[AuHn_CHILD] = 0; | |
17692 | + if (isdir) | |
17693 | + flags[AuHn_CHILD] = AuHnJob_ISDIR; | |
17694 | + au_fset_hnjob(flags[AuHn_PARENT], DIRENT); | |
17695 | + au_fset_hnjob(flags[AuHn_CHILD], GEN); | |
17696 | + switch (mask & FS_EVENTS_POSS_ON_CHILD) { | |
17697 | + case FS_MOVED_FROM: | |
17698 | + case FS_MOVED_TO: | |
17699 | + au_fset_hnjob(flags[AuHn_CHILD], XINO0); | |
17700 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
17701 | + /*FALLTHROUGH*/ | |
17702 | + case FS_CREATE: | |
fb47a38f | 17703 | + AuDebugOn(!h_child_name); |
4a4d8108 | 17704 | + break; |
1facf9fc | 17705 | + |
4a4d8108 AM |
17706 | + case FS_DELETE: |
17707 | + /* | |
17708 | + * aufs never be able to get this child inode. | |
17709 | + * revalidation should be in d_revalidate() | |
17710 | + * by checking i_nlink, i_generation or d_unhashed(). | |
17711 | + */ | |
17712 | + AuDebugOn(!h_child_name); | |
17713 | + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0); | |
17714 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
17715 | + break; | |
dece6358 | 17716 | + |
4a4d8108 AM |
17717 | + default: |
17718 | + AuDebugOn(1); | |
17719 | + } | |
1308ab2a | 17720 | + |
4a4d8108 AM |
17721 | + if (wh) |
17722 | + h_child_inode = NULL; | |
1308ab2a | 17723 | + |
4a4d8108 AM |
17724 | + err = -ENOMEM; |
17725 | + /* iput() and kfree() will be called in au_hnotify() */ | |
4a4d8108 | 17726 | + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS); |
4a4d8108 AM |
17727 | + if (unlikely(!args)) { |
17728 | + AuErr1("no memory\n"); | |
17729 | + iput(dir); | |
17730 | + goto out; | |
17731 | + } | |
17732 | + args->flags[AuHn_PARENT] = flags[AuHn_PARENT]; | |
17733 | + args->flags[AuHn_CHILD] = flags[AuHn_CHILD]; | |
17734 | + args->mask = mask; | |
17735 | + args->dir = dir; | |
17736 | + args->h_dir = igrab(h_dir); | |
17737 | + if (h_child_inode) | |
17738 | + h_child_inode = igrab(h_child_inode); /* can be NULL */ | |
17739 | + args->h_child_inode = h_child_inode; | |
17740 | + args->h_child_nlen = len; | |
17741 | + if (len) { | |
17742 | + p = (void *)args; | |
17743 | + p += sizeof(*args); | |
17744 | + memcpy(p, h_child_name, len); | |
17745 | + p[len] = 0; | |
1308ab2a | 17746 | + } |
1308ab2a | 17747 | + |
38d290e6 | 17748 | + /* NFS fires the event for silly-renamed one from kworker */ |
53392da6 | 17749 | + f = 0; |
38d290e6 JR |
17750 | + if (!dir->i_nlink |
17751 | + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE))) | |
53392da6 AM |
17752 | + f = AuWkq_NEST; |
17753 | + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f); | |
4a4d8108 AM |
17754 | + if (unlikely(err)) { |
17755 | + pr_err("wkq %d\n", err); | |
17756 | + iput(args->h_child_inode); | |
17757 | + iput(args->h_dir); | |
17758 | + iput(args->dir); | |
1c60b727 | 17759 | + kfree(args); |
1facf9fc | 17760 | + } |
1facf9fc | 17761 | + |
4a4d8108 | 17762 | +out: |
1facf9fc | 17763 | + return err; |
17764 | +} | |
17765 | + | |
027c5e7a AM |
17766 | +/* ---------------------------------------------------------------------- */ |
17767 | + | |
17768 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
17769 | +{ | |
17770 | + int err; | |
17771 | + | |
17772 | + AuDebugOn(!(udba & AuOptMask_UDBA)); | |
17773 | + | |
17774 | + err = 0; | |
17775 | + if (au_hnotify_op.reset_br) | |
17776 | + err = au_hnotify_op.reset_br(udba, br, perm); | |
17777 | + | |
17778 | + return err; | |
17779 | +} | |
17780 | + | |
17781 | +int au_hnotify_init_br(struct au_branch *br, int perm) | |
17782 | +{ | |
17783 | + int err; | |
17784 | + | |
17785 | + err = 0; | |
17786 | + if (au_hnotify_op.init_br) | |
17787 | + err = au_hnotify_op.init_br(br, perm); | |
17788 | + | |
17789 | + return err; | |
17790 | +} | |
17791 | + | |
17792 | +void au_hnotify_fin_br(struct au_branch *br) | |
17793 | +{ | |
17794 | + if (au_hnotify_op.fin_br) | |
17795 | + au_hnotify_op.fin_br(br); | |
17796 | +} | |
17797 | + | |
4a4d8108 AM |
17798 | +static void au_hn_destroy_cache(void) |
17799 | +{ | |
1c60b727 AM |
17800 | + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]); |
17801 | + au_cache[AuCache_HNOTIFY] = NULL; | |
4a4d8108 | 17802 | +} |
1308ab2a | 17803 | + |
4a4d8108 | 17804 | +int __init au_hnotify_init(void) |
1facf9fc | 17805 | +{ |
1308ab2a | 17806 | + int err; |
1308ab2a | 17807 | + |
4a4d8108 | 17808 | + err = -ENOMEM; |
1c60b727 AM |
17809 | + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify); |
17810 | + if (au_cache[AuCache_HNOTIFY]) { | |
027c5e7a AM |
17811 | + err = 0; |
17812 | + if (au_hnotify_op.init) | |
17813 | + err = au_hnotify_op.init(); | |
4a4d8108 AM |
17814 | + if (unlikely(err)) |
17815 | + au_hn_destroy_cache(); | |
1308ab2a | 17816 | + } |
1308ab2a | 17817 | + AuTraceErr(err); |
4a4d8108 | 17818 | + return err; |
1308ab2a | 17819 | +} |
17820 | + | |
4a4d8108 | 17821 | +void au_hnotify_fin(void) |
1308ab2a | 17822 | +{ |
027c5e7a AM |
17823 | + if (au_hnotify_op.fin) |
17824 | + au_hnotify_op.fin(); | |
f0c0a007 | 17825 | + |
4a4d8108 | 17826 | + /* cf. au_cache_fin() */ |
1c60b727 | 17827 | + if (au_cache[AuCache_HNOTIFY]) |
4a4d8108 | 17828 | + au_hn_destroy_cache(); |
dece6358 | 17829 | +} |
7f207e10 AM |
17830 | diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c |
17831 | --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 17832 | +++ linux/fs/aufs/iinfo.c 2018-01-29 07:56:20.056658502 +0100 |
e2f27e51 | 17833 | @@ -0,0 +1,285 @@ |
dece6358 | 17834 | +/* |
a2654f78 | 17835 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
dece6358 AM |
17836 | + * |
17837 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17838 | + * it under the terms of the GNU General Public License as published by | |
17839 | + * the Free Software Foundation; either version 2 of the License, or | |
17840 | + * (at your option) any later version. | |
17841 | + * | |
17842 | + * This program is distributed in the hope that it will be useful, | |
17843 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17844 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17845 | + * GNU General Public License for more details. | |
17846 | + * | |
17847 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17848 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 17849 | + */ |
1facf9fc | 17850 | + |
dece6358 | 17851 | +/* |
4a4d8108 | 17852 | + * inode private data |
dece6358 | 17853 | + */ |
1facf9fc | 17854 | + |
1308ab2a | 17855 | +#include "aufs.h" |
1facf9fc | 17856 | + |
4a4d8108 | 17857 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 17858 | +{ |
4a4d8108 | 17859 | + struct inode *h_inode; |
5afbbe0d | 17860 | + struct au_hinode *hinode; |
1facf9fc | 17861 | + |
4a4d8108 | 17862 | + IiMustAnyLock(inode); |
1facf9fc | 17863 | + |
5afbbe0d AM |
17864 | + hinode = au_hinode(au_ii(inode), bindex); |
17865 | + h_inode = hinode->hi_inode; | |
4a4d8108 AM |
17866 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); |
17867 | + return h_inode; | |
17868 | +} | |
1facf9fc | 17869 | + |
4a4d8108 AM |
17870 | +/* todo: hard/soft set? */ |
17871 | +void au_hiput(struct au_hinode *hinode) | |
17872 | +{ | |
17873 | + au_hn_free(hinode); | |
17874 | + dput(hinode->hi_whdentry); | |
17875 | + iput(hinode->hi_inode); | |
17876 | +} | |
1facf9fc | 17877 | + |
4a4d8108 AM |
17878 | +unsigned int au_hi_flags(struct inode *inode, int isdir) |
17879 | +{ | |
17880 | + unsigned int flags; | |
17881 | + const unsigned int mnt_flags = au_mntflags(inode->i_sb); | |
1facf9fc | 17882 | + |
4a4d8108 AM |
17883 | + flags = 0; |
17884 | + if (au_opt_test(mnt_flags, XINO)) | |
17885 | + au_fset_hi(flags, XINO); | |
17886 | + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY)) | |
17887 | + au_fset_hi(flags, HNOTIFY); | |
17888 | + return flags; | |
1facf9fc | 17889 | +} |
17890 | + | |
4a4d8108 AM |
17891 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
17892 | + struct inode *h_inode, unsigned int flags) | |
1308ab2a | 17893 | +{ |
4a4d8108 AM |
17894 | + struct au_hinode *hinode; |
17895 | + struct inode *hi; | |
17896 | + struct au_iinfo *iinfo = au_ii(inode); | |
1facf9fc | 17897 | + |
4a4d8108 | 17898 | + IiMustWriteLock(inode); |
dece6358 | 17899 | + |
5afbbe0d | 17900 | + hinode = au_hinode(iinfo, bindex); |
4a4d8108 AM |
17901 | + hi = hinode->hi_inode; |
17902 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
17903 | + | |
17904 | + if (hi) | |
17905 | + au_hiput(hinode); | |
17906 | + hinode->hi_inode = h_inode; | |
17907 | + if (h_inode) { | |
17908 | + int err; | |
17909 | + struct super_block *sb = inode->i_sb; | |
17910 | + struct au_branch *br; | |
17911 | + | |
027c5e7a AM |
17912 | + AuDebugOn(inode->i_mode |
17913 | + && (h_inode->i_mode & S_IFMT) | |
17914 | + != (inode->i_mode & S_IFMT)); | |
5afbbe0d | 17915 | + if (bindex == iinfo->ii_btop) |
4a4d8108 AM |
17916 | + au_cpup_igen(inode, h_inode); |
17917 | + br = au_sbr(sb, bindex); | |
17918 | + hinode->hi_id = br->br_id; | |
17919 | + if (au_ftest_hi(flags, XINO)) { | |
17920 | + err = au_xino_write(sb, bindex, h_inode->i_ino, | |
17921 | + inode->i_ino); | |
17922 | + if (unlikely(err)) | |
17923 | + AuIOErr1("failed au_xino_write() %d\n", err); | |
17924 | + } | |
17925 | + | |
17926 | + if (au_ftest_hi(flags, HNOTIFY) | |
17927 | + && au_br_hnotifyable(br->br_perm)) { | |
027c5e7a | 17928 | + err = au_hn_alloc(hinode, inode); |
4a4d8108 AM |
17929 | + if (unlikely(err)) |
17930 | + AuIOErr1("au_hn_alloc() %d\n", err); | |
1308ab2a | 17931 | + } |
17932 | + } | |
4a4d8108 | 17933 | +} |
dece6358 | 17934 | + |
4a4d8108 AM |
17935 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, |
17936 | + struct dentry *h_wh) | |
17937 | +{ | |
17938 | + struct au_hinode *hinode; | |
dece6358 | 17939 | + |
4a4d8108 AM |
17940 | + IiMustWriteLock(inode); |
17941 | + | |
5afbbe0d | 17942 | + hinode = au_hinode(au_ii(inode), bindex); |
4a4d8108 AM |
17943 | + AuDebugOn(hinode->hi_whdentry); |
17944 | + hinode->hi_whdentry = h_wh; | |
1facf9fc | 17945 | +} |
17946 | + | |
537831f9 | 17947 | +void au_update_iigen(struct inode *inode, int half) |
1308ab2a | 17948 | +{ |
537831f9 AM |
17949 | + struct au_iinfo *iinfo; |
17950 | + struct au_iigen *iigen; | |
17951 | + unsigned int sigen; | |
17952 | + | |
17953 | + sigen = au_sigen(inode->i_sb); | |
17954 | + iinfo = au_ii(inode); | |
17955 | + iigen = &iinfo->ii_generation; | |
be52b249 | 17956 | + spin_lock(&iigen->ig_spin); |
537831f9 AM |
17957 | + iigen->ig_generation = sigen; |
17958 | + if (half) | |
17959 | + au_ig_fset(iigen->ig_flags, HALF_REFRESHED); | |
17960 | + else | |
17961 | + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED); | |
be52b249 | 17962 | + spin_unlock(&iigen->ig_spin); |
4a4d8108 | 17963 | +} |
1facf9fc | 17964 | + |
4a4d8108 AM |
17965 | +/* it may be called at remount time, too */ |
17966 | +void au_update_ibrange(struct inode *inode, int do_put_zero) | |
17967 | +{ | |
17968 | + struct au_iinfo *iinfo; | |
5afbbe0d | 17969 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 17970 | + |
5afbbe0d | 17971 | + AuDebugOn(au_is_bad_inode(inode)); |
4a4d8108 | 17972 | + IiMustWriteLock(inode); |
1facf9fc | 17973 | + |
5afbbe0d AM |
17974 | + iinfo = au_ii(inode); |
17975 | + if (do_put_zero && iinfo->ii_btop >= 0) { | |
17976 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; | |
4a4d8108 AM |
17977 | + bindex++) { |
17978 | + struct inode *h_i; | |
1facf9fc | 17979 | + |
5afbbe0d | 17980 | + h_i = au_hinode(iinfo, bindex)->hi_inode; |
38d290e6 JR |
17981 | + if (h_i |
17982 | + && !h_i->i_nlink | |
17983 | + && !(h_i->i_state & I_LINKABLE)) | |
027c5e7a AM |
17984 | + au_set_h_iptr(inode, bindex, NULL, 0); |
17985 | + } | |
4a4d8108 AM |
17986 | + } |
17987 | + | |
5afbbe0d AM |
17988 | + iinfo->ii_btop = -1; |
17989 | + iinfo->ii_bbot = -1; | |
17990 | + bbot = au_sbbot(inode->i_sb); | |
17991 | + for (bindex = 0; bindex <= bbot; bindex++) | |
17992 | + if (au_hinode(iinfo, bindex)->hi_inode) { | |
17993 | + iinfo->ii_btop = bindex; | |
4a4d8108 | 17994 | + break; |
027c5e7a | 17995 | + } |
5afbbe0d AM |
17996 | + if (iinfo->ii_btop >= 0) |
17997 | + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--) | |
17998 | + if (au_hinode(iinfo, bindex)->hi_inode) { | |
17999 | + iinfo->ii_bbot = bindex; | |
027c5e7a AM |
18000 | + break; |
18001 | + } | |
5afbbe0d | 18002 | + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot); |
1308ab2a | 18003 | +} |
1facf9fc | 18004 | + |
dece6358 | 18005 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18006 | + |
4a4d8108 | 18007 | +void au_icntnr_init_once(void *_c) |
dece6358 | 18008 | +{ |
4a4d8108 AM |
18009 | + struct au_icntnr *c = _c; |
18010 | + struct au_iinfo *iinfo = &c->iinfo; | |
1facf9fc | 18011 | + |
be52b249 | 18012 | + spin_lock_init(&iinfo->ii_generation.ig_spin); |
4a4d8108 AM |
18013 | + au_rw_init(&iinfo->ii_rwsem); |
18014 | + inode_init_once(&c->vfs_inode); | |
18015 | +} | |
1facf9fc | 18016 | + |
5afbbe0d AM |
18017 | +void au_hinode_init(struct au_hinode *hinode) |
18018 | +{ | |
18019 | + hinode->hi_inode = NULL; | |
18020 | + hinode->hi_id = -1; | |
18021 | + au_hn_init(hinode); | |
18022 | + hinode->hi_whdentry = NULL; | |
18023 | +} | |
18024 | + | |
4a4d8108 AM |
18025 | +int au_iinfo_init(struct inode *inode) |
18026 | +{ | |
18027 | + struct au_iinfo *iinfo; | |
18028 | + struct super_block *sb; | |
5afbbe0d | 18029 | + struct au_hinode *hi; |
4a4d8108 | 18030 | + int nbr, i; |
1facf9fc | 18031 | + |
4a4d8108 AM |
18032 | + sb = inode->i_sb; |
18033 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
5afbbe0d | 18034 | + nbr = au_sbbot(sb) + 1; |
4a4d8108 AM |
18035 | + if (unlikely(nbr <= 0)) |
18036 | + nbr = 1; | |
5afbbe0d AM |
18037 | + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS); |
18038 | + if (hi) { | |
7f207e10 | 18039 | + au_ninodes_inc(sb); |
5afbbe0d AM |
18040 | + |
18041 | + iinfo->ii_hinode = hi; | |
18042 | + for (i = 0; i < nbr; i++, hi++) | |
18043 | + au_hinode_init(hi); | |
1facf9fc | 18044 | + |
537831f9 | 18045 | + iinfo->ii_generation.ig_generation = au_sigen(sb); |
5afbbe0d AM |
18046 | + iinfo->ii_btop = -1; |
18047 | + iinfo->ii_bbot = -1; | |
4a4d8108 AM |
18048 | + iinfo->ii_vdir = NULL; |
18049 | + return 0; | |
1308ab2a | 18050 | + } |
4a4d8108 AM |
18051 | + return -ENOMEM; |
18052 | +} | |
1facf9fc | 18053 | + |
e2f27e51 | 18054 | +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink) |
4a4d8108 | 18055 | +{ |
5afbbe0d | 18056 | + int err, i; |
4a4d8108 | 18057 | + struct au_hinode *hip; |
1facf9fc | 18058 | + |
4a4d8108 AM |
18059 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
18060 | + | |
18061 | + err = -ENOMEM; | |
e2f27e51 AM |
18062 | + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS, |
18063 | + may_shrink); | |
4a4d8108 AM |
18064 | + if (hip) { |
18065 | + iinfo->ii_hinode = hip; | |
5afbbe0d AM |
18066 | + i = iinfo->ii_bbot + 1; |
18067 | + hip += i; | |
18068 | + for (; i < nbr; i++, hip++) | |
18069 | + au_hinode_init(hip); | |
4a4d8108 | 18070 | + err = 0; |
1308ab2a | 18071 | + } |
4a4d8108 | 18072 | + |
1308ab2a | 18073 | + return err; |
1facf9fc | 18074 | +} |
18075 | + | |
4a4d8108 | 18076 | +void au_iinfo_fin(struct inode *inode) |
1facf9fc | 18077 | +{ |
4a4d8108 AM |
18078 | + struct au_iinfo *iinfo; |
18079 | + struct au_hinode *hi; | |
18080 | + struct super_block *sb; | |
5afbbe0d | 18081 | + aufs_bindex_t bindex, bbot; |
b752ccd1 | 18082 | + const unsigned char unlinked = !inode->i_nlink; |
1308ab2a | 18083 | + |
5afbbe0d | 18084 | + AuDebugOn(au_is_bad_inode(inode)); |
1308ab2a | 18085 | + |
b752ccd1 | 18086 | + sb = inode->i_sb; |
7f207e10 | 18087 | + au_ninodes_dec(sb); |
b752ccd1 AM |
18088 | + if (si_pid_test(sb)) |
18089 | + au_xino_delete_inode(inode, unlinked); | |
18090 | + else { | |
18091 | + /* | |
18092 | + * it is safe to hide the dependency between sbinfo and | |
18093 | + * sb->s_umount. | |
18094 | + */ | |
18095 | + lockdep_off(); | |
18096 | + si_noflush_read_lock(sb); | |
18097 | + au_xino_delete_inode(inode, unlinked); | |
18098 | + si_read_unlock(sb); | |
18099 | + lockdep_on(); | |
18100 | + } | |
18101 | + | |
5afbbe0d | 18102 | + iinfo = au_ii(inode); |
4a4d8108 | 18103 | + if (iinfo->ii_vdir) |
1c60b727 | 18104 | + au_vdir_free(iinfo->ii_vdir); |
1308ab2a | 18105 | + |
5afbbe0d | 18106 | + bindex = iinfo->ii_btop; |
b752ccd1 | 18107 | + if (bindex >= 0) { |
5afbbe0d AM |
18108 | + hi = au_hinode(iinfo, bindex); |
18109 | + bbot = iinfo->ii_bbot; | |
18110 | + while (bindex++ <= bbot) { | |
b752ccd1 | 18111 | + if (hi->hi_inode) |
4a4d8108 | 18112 | + au_hiput(hi); |
4a4d8108 AM |
18113 | + hi++; |
18114 | + } | |
18115 | + } | |
1c60b727 | 18116 | + kfree(iinfo->ii_hinode); |
4a4d8108 | 18117 | + AuRwDestroy(&iinfo->ii_rwsem); |
dece6358 | 18118 | +} |
7f207e10 AM |
18119 | diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c |
18120 | --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 18121 | +++ linux/fs/aufs/inode.c 2018-01-29 07:56:20.056658502 +0100 |
521ced18 | 18122 | @@ -0,0 +1,527 @@ |
4a4d8108 | 18123 | +/* |
a2654f78 | 18124 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
18125 | + * |
18126 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18127 | + * it under the terms of the GNU General Public License as published by | |
18128 | + * the Free Software Foundation; either version 2 of the License, or | |
18129 | + * (at your option) any later version. | |
18130 | + * | |
18131 | + * This program is distributed in the hope that it will be useful, | |
18132 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18133 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18134 | + * GNU General Public License for more details. | |
18135 | + * | |
18136 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18137 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18138 | + */ |
1facf9fc | 18139 | + |
4a4d8108 AM |
18140 | +/* |
18141 | + * inode functions | |
18142 | + */ | |
1facf9fc | 18143 | + |
4a4d8108 | 18144 | +#include "aufs.h" |
1308ab2a | 18145 | + |
4a4d8108 AM |
18146 | +struct inode *au_igrab(struct inode *inode) |
18147 | +{ | |
18148 | + if (inode) { | |
18149 | + AuDebugOn(!atomic_read(&inode->i_count)); | |
027c5e7a | 18150 | + ihold(inode); |
1facf9fc | 18151 | + } |
4a4d8108 AM |
18152 | + return inode; |
18153 | +} | |
1facf9fc | 18154 | + |
4a4d8108 AM |
18155 | +static void au_refresh_hinode_attr(struct inode *inode, int do_version) |
18156 | +{ | |
18157 | + au_cpup_attr_all(inode, /*force*/0); | |
537831f9 | 18158 | + au_update_iigen(inode, /*half*/1); |
4a4d8108 AM |
18159 | + if (do_version) |
18160 | + inode->i_version++; | |
dece6358 | 18161 | +} |
1facf9fc | 18162 | + |
027c5e7a | 18163 | +static int au_ii_refresh(struct inode *inode, int *update) |
dece6358 | 18164 | +{ |
e2f27e51 | 18165 | + int err, e, nbr; |
027c5e7a | 18166 | + umode_t type; |
4a4d8108 | 18167 | + aufs_bindex_t bindex, new_bindex; |
1308ab2a | 18168 | + struct super_block *sb; |
4a4d8108 | 18169 | + struct au_iinfo *iinfo; |
027c5e7a | 18170 | + struct au_hinode *p, *q, tmp; |
1facf9fc | 18171 | + |
5afbbe0d | 18172 | + AuDebugOn(au_is_bad_inode(inode)); |
4a4d8108 | 18173 | + IiMustWriteLock(inode); |
1facf9fc | 18174 | + |
027c5e7a | 18175 | + *update = 0; |
4a4d8108 | 18176 | + sb = inode->i_sb; |
e2f27e51 | 18177 | + nbr = au_sbbot(sb) + 1; |
027c5e7a | 18178 | + type = inode->i_mode & S_IFMT; |
4a4d8108 | 18179 | + iinfo = au_ii(inode); |
e2f27e51 | 18180 | + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0); |
4a4d8108 | 18181 | + if (unlikely(err)) |
1308ab2a | 18182 | + goto out; |
1facf9fc | 18183 | + |
5afbbe0d AM |
18184 | + AuDebugOn(iinfo->ii_btop < 0); |
18185 | + p = au_hinode(iinfo, iinfo->ii_btop); | |
18186 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; | |
4a4d8108 AM |
18187 | + bindex++, p++) { |
18188 | + if (!p->hi_inode) | |
18189 | + continue; | |
1facf9fc | 18190 | + |
027c5e7a | 18191 | + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT)); |
4a4d8108 AM |
18192 | + new_bindex = au_br_index(sb, p->hi_id); |
18193 | + if (new_bindex == bindex) | |
18194 | + continue; | |
1facf9fc | 18195 | + |
4a4d8108 | 18196 | + if (new_bindex < 0) { |
027c5e7a | 18197 | + *update = 1; |
4a4d8108 AM |
18198 | + au_hiput(p); |
18199 | + p->hi_inode = NULL; | |
18200 | + continue; | |
1308ab2a | 18201 | + } |
4a4d8108 | 18202 | + |
5afbbe0d AM |
18203 | + if (new_bindex < iinfo->ii_btop) |
18204 | + iinfo->ii_btop = new_bindex; | |
18205 | + if (iinfo->ii_bbot < new_bindex) | |
18206 | + iinfo->ii_bbot = new_bindex; | |
4a4d8108 | 18207 | + /* swap two lower inode, and loop again */ |
5afbbe0d | 18208 | + q = au_hinode(iinfo, new_bindex); |
4a4d8108 AM |
18209 | + tmp = *q; |
18210 | + *q = *p; | |
18211 | + *p = tmp; | |
18212 | + if (tmp.hi_inode) { | |
18213 | + bindex--; | |
18214 | + p--; | |
1308ab2a | 18215 | + } |
18216 | + } | |
4a4d8108 | 18217 | + au_update_ibrange(inode, /*do_put_zero*/0); |
e2f27e51 | 18218 | + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */ |
4a4d8108 AM |
18219 | + e = au_dy_irefresh(inode); |
18220 | + if (unlikely(e && !err)) | |
18221 | + err = e; | |
1facf9fc | 18222 | + |
4f0767ce | 18223 | +out: |
027c5e7a AM |
18224 | + AuTraceErr(err); |
18225 | + return err; | |
18226 | +} | |
18227 | + | |
b95c5147 AM |
18228 | +void au_refresh_iop(struct inode *inode, int force_getattr) |
18229 | +{ | |
18230 | + int type; | |
18231 | + struct au_sbinfo *sbi = au_sbi(inode->i_sb); | |
18232 | + const struct inode_operations *iop | |
18233 | + = force_getattr ? aufs_iop : sbi->si_iop_array; | |
18234 | + | |
18235 | + if (inode->i_op == iop) | |
18236 | + return; | |
18237 | + | |
18238 | + switch (inode->i_mode & S_IFMT) { | |
18239 | + case S_IFDIR: | |
18240 | + type = AuIop_DIR; | |
18241 | + break; | |
18242 | + case S_IFLNK: | |
18243 | + type = AuIop_SYMLINK; | |
18244 | + break; | |
18245 | + default: | |
18246 | + type = AuIop_OTHER; | |
18247 | + break; | |
18248 | + } | |
18249 | + | |
18250 | + inode->i_op = iop + type; | |
18251 | + /* unnecessary smp_wmb() */ | |
18252 | +} | |
18253 | + | |
027c5e7a AM |
18254 | +int au_refresh_hinode_self(struct inode *inode) |
18255 | +{ | |
18256 | + int err, update; | |
18257 | + | |
18258 | + err = au_ii_refresh(inode, &update); | |
18259 | + if (!err) | |
18260 | + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode)); | |
18261 | + | |
18262 | + AuTraceErr(err); | |
4a4d8108 AM |
18263 | + return err; |
18264 | +} | |
1facf9fc | 18265 | + |
4a4d8108 AM |
18266 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry) |
18267 | +{ | |
027c5e7a | 18268 | + int err, e, update; |
4a4d8108 | 18269 | + unsigned int flags; |
027c5e7a | 18270 | + umode_t mode; |
5afbbe0d | 18271 | + aufs_bindex_t bindex, bbot; |
027c5e7a | 18272 | + unsigned char isdir; |
4a4d8108 AM |
18273 | + struct au_hinode *p; |
18274 | + struct au_iinfo *iinfo; | |
1facf9fc | 18275 | + |
027c5e7a | 18276 | + err = au_ii_refresh(inode, &update); |
4a4d8108 AM |
18277 | + if (unlikely(err)) |
18278 | + goto out; | |
18279 | + | |
18280 | + update = 0; | |
18281 | + iinfo = au_ii(inode); | |
5afbbe0d | 18282 | + p = au_hinode(iinfo, iinfo->ii_btop); |
027c5e7a AM |
18283 | + mode = (inode->i_mode & S_IFMT); |
18284 | + isdir = S_ISDIR(mode); | |
4a4d8108 | 18285 | + flags = au_hi_flags(inode, isdir); |
5afbbe0d AM |
18286 | + bbot = au_dbbot(dentry); |
18287 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) { | |
5527c038 | 18288 | + struct inode *h_i, *h_inode; |
4a4d8108 AM |
18289 | + struct dentry *h_d; |
18290 | + | |
18291 | + h_d = au_h_dptr(dentry, bindex); | |
5527c038 | 18292 | + if (!h_d || d_is_negative(h_d)) |
4a4d8108 AM |
18293 | + continue; |
18294 | + | |
5527c038 JR |
18295 | + h_inode = d_inode(h_d); |
18296 | + AuDebugOn(mode != (h_inode->i_mode & S_IFMT)); | |
5afbbe0d | 18297 | + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) { |
4a4d8108 AM |
18298 | + h_i = au_h_iptr(inode, bindex); |
18299 | + if (h_i) { | |
5527c038 | 18300 | + if (h_i == h_inode) |
4a4d8108 AM |
18301 | + continue; |
18302 | + err = -EIO; | |
18303 | + break; | |
18304 | + } | |
18305 | + } | |
5afbbe0d AM |
18306 | + if (bindex < iinfo->ii_btop) |
18307 | + iinfo->ii_btop = bindex; | |
18308 | + if (iinfo->ii_bbot < bindex) | |
18309 | + iinfo->ii_bbot = bindex; | |
5527c038 | 18310 | + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags); |
4a4d8108 | 18311 | + update = 1; |
1308ab2a | 18312 | + } |
4a4d8108 AM |
18313 | + au_update_ibrange(inode, /*do_put_zero*/0); |
18314 | + e = au_dy_irefresh(inode); | |
18315 | + if (unlikely(e && !err)) | |
18316 | + err = e; | |
027c5e7a AM |
18317 | + if (!err) |
18318 | + au_refresh_hinode_attr(inode, update && isdir); | |
4a4d8108 | 18319 | + |
4f0767ce | 18320 | +out: |
4a4d8108 | 18321 | + AuTraceErr(err); |
1308ab2a | 18322 | + return err; |
dece6358 AM |
18323 | +} |
18324 | + | |
4a4d8108 | 18325 | +static int set_inode(struct inode *inode, struct dentry *dentry) |
dece6358 | 18326 | +{ |
4a4d8108 AM |
18327 | + int err; |
18328 | + unsigned int flags; | |
18329 | + umode_t mode; | |
5afbbe0d | 18330 | + aufs_bindex_t bindex, btop, btail; |
4a4d8108 AM |
18331 | + unsigned char isdir; |
18332 | + struct dentry *h_dentry; | |
18333 | + struct inode *h_inode; | |
18334 | + struct au_iinfo *iinfo; | |
b95c5147 | 18335 | + struct inode_operations *iop; |
dece6358 | 18336 | + |
4a4d8108 | 18337 | + IiMustWriteLock(inode); |
dece6358 | 18338 | + |
4a4d8108 AM |
18339 | + err = 0; |
18340 | + isdir = 0; | |
b95c5147 | 18341 | + iop = au_sbi(inode->i_sb)->si_iop_array; |
5afbbe0d AM |
18342 | + btop = au_dbtop(dentry); |
18343 | + h_dentry = au_h_dptr(dentry, btop); | |
5527c038 | 18344 | + h_inode = d_inode(h_dentry); |
4a4d8108 AM |
18345 | + mode = h_inode->i_mode; |
18346 | + switch (mode & S_IFMT) { | |
18347 | + case S_IFREG: | |
18348 | + btail = au_dbtail(dentry); | |
b95c5147 | 18349 | + inode->i_op = iop + AuIop_OTHER; |
4a4d8108 | 18350 | + inode->i_fop = &aufs_file_fop; |
5afbbe0d | 18351 | + err = au_dy_iaop(inode, btop, h_inode); |
4a4d8108 AM |
18352 | + if (unlikely(err)) |
18353 | + goto out; | |
18354 | + break; | |
18355 | + case S_IFDIR: | |
18356 | + isdir = 1; | |
18357 | + btail = au_dbtaildir(dentry); | |
b95c5147 | 18358 | + inode->i_op = iop + AuIop_DIR; |
4a4d8108 AM |
18359 | + inode->i_fop = &aufs_dir_fop; |
18360 | + break; | |
18361 | + case S_IFLNK: | |
18362 | + btail = au_dbtail(dentry); | |
b95c5147 | 18363 | + inode->i_op = iop + AuIop_SYMLINK; |
4a4d8108 AM |
18364 | + break; |
18365 | + case S_IFBLK: | |
18366 | + case S_IFCHR: | |
18367 | + case S_IFIFO: | |
18368 | + case S_IFSOCK: | |
18369 | + btail = au_dbtail(dentry); | |
b95c5147 | 18370 | + inode->i_op = iop + AuIop_OTHER; |
38d290e6 | 18371 | + init_special_inode(inode, mode, h_inode->i_rdev); |
4a4d8108 AM |
18372 | + break; |
18373 | + default: | |
18374 | + AuIOErr("Unknown file type 0%o\n", mode); | |
18375 | + err = -EIO; | |
1308ab2a | 18376 | + goto out; |
4a4d8108 | 18377 | + } |
dece6358 | 18378 | + |
4a4d8108 AM |
18379 | + /* do not set hnotify for whiteouted dirs (SHWH mode) */ |
18380 | + flags = au_hi_flags(inode, isdir); | |
18381 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH) | |
18382 | + && au_ftest_hi(flags, HNOTIFY) | |
18383 | + && dentry->d_name.len > AUFS_WH_PFX_LEN | |
18384 | + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) | |
18385 | + au_fclr_hi(flags, HNOTIFY); | |
18386 | + iinfo = au_ii(inode); | |
5afbbe0d AM |
18387 | + iinfo->ii_btop = btop; |
18388 | + iinfo->ii_bbot = btail; | |
18389 | + for (bindex = btop; bindex <= btail; bindex++) { | |
4a4d8108 AM |
18390 | + h_dentry = au_h_dptr(dentry, bindex); |
18391 | + if (h_dentry) | |
18392 | + au_set_h_iptr(inode, bindex, | |
5527c038 | 18393 | + au_igrab(d_inode(h_dentry)), flags); |
4a4d8108 AM |
18394 | + } |
18395 | + au_cpup_attr_all(inode, /*force*/1); | |
c1595e42 JR |
18396 | + /* |
18397 | + * to force calling aufs_get_acl() every time, | |
18398 | + * do not call cache_no_acl() for aufs inode. | |
18399 | + */ | |
dece6358 | 18400 | + |
4f0767ce | 18401 | +out: |
4a4d8108 AM |
18402 | + return err; |
18403 | +} | |
dece6358 | 18404 | + |
027c5e7a AM |
18405 | +/* |
18406 | + * successful returns with iinfo write_locked | |
18407 | + * minus: errno | |
18408 | + * zero: success, matched | |
18409 | + * plus: no error, but unmatched | |
18410 | + */ | |
18411 | +static int reval_inode(struct inode *inode, struct dentry *dentry) | |
4a4d8108 AM |
18412 | +{ |
18413 | + int err; | |
cfc41e69 | 18414 | + unsigned int gen, igflags; |
5afbbe0d | 18415 | + aufs_bindex_t bindex, bbot; |
4a4d8108 | 18416 | + struct inode *h_inode, *h_dinode; |
5527c038 | 18417 | + struct dentry *h_dentry; |
dece6358 | 18418 | + |
4a4d8108 AM |
18419 | + /* |
18420 | + * before this function, if aufs got any iinfo lock, it must be only | |
18421 | + * one, the parent dir. | |
18422 | + * it can happen by UDBA and the obsoleted inode number. | |
18423 | + */ | |
18424 | + err = -EIO; | |
18425 | + if (unlikely(inode->i_ino == parent_ino(dentry))) | |
18426 | + goto out; | |
18427 | + | |
027c5e7a | 18428 | + err = 1; |
4a4d8108 | 18429 | + ii_write_lock_new_child(inode); |
5afbbe0d | 18430 | + h_dentry = au_h_dptr(dentry, au_dbtop(dentry)); |
5527c038 | 18431 | + h_dinode = d_inode(h_dentry); |
5afbbe0d AM |
18432 | + bbot = au_ibbot(inode); |
18433 | + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) { | |
4a4d8108 | 18434 | + h_inode = au_h_iptr(inode, bindex); |
537831f9 AM |
18435 | + if (!h_inode || h_inode != h_dinode) |
18436 | + continue; | |
18437 | + | |
18438 | + err = 0; | |
cfc41e69 | 18439 | + gen = au_iigen(inode, &igflags); |
537831f9 | 18440 | + if (gen == au_digen(dentry) |
cfc41e69 | 18441 | + && !au_ig_ftest(igflags, HALF_REFRESHED)) |
4a4d8108 | 18442 | + break; |
537831f9 AM |
18443 | + |
18444 | + /* fully refresh inode using dentry */ | |
18445 | + err = au_refresh_hinode(inode, dentry); | |
18446 | + if (!err) | |
18447 | + au_update_iigen(inode, /*half*/0); | |
18448 | + break; | |
1facf9fc | 18449 | + } |
dece6358 | 18450 | + |
4a4d8108 AM |
18451 | + if (unlikely(err)) |
18452 | + ii_write_unlock(inode); | |
4f0767ce | 18453 | +out: |
1facf9fc | 18454 | + return err; |
18455 | +} | |
1facf9fc | 18456 | + |
4a4d8108 AM |
18457 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
18458 | + unsigned int d_type, ino_t *ino) | |
1facf9fc | 18459 | +{ |
521ced18 JR |
18460 | + int err, idx; |
18461 | + const int isnondir = d_type != DT_DIR; | |
1facf9fc | 18462 | + |
b752ccd1 | 18463 | + /* prevent hardlinked inode number from race condition */ |
521ced18 JR |
18464 | + if (isnondir) { |
18465 | + err = au_xinondir_enter(sb, bindex, h_ino, &idx); | |
18466 | + if (unlikely(err)) | |
18467 | + goto out; | |
4a4d8108 | 18468 | + } |
521ced18 | 18469 | + |
4a4d8108 AM |
18470 | + err = au_xino_read(sb, bindex, h_ino, ino); |
18471 | + if (unlikely(err)) | |
521ced18 | 18472 | + goto out_xinondir; |
1308ab2a | 18473 | + |
4a4d8108 AM |
18474 | + if (!*ino) { |
18475 | + err = -EIO; | |
18476 | + *ino = au_xino_new_ino(sb); | |
18477 | + if (unlikely(!*ino)) | |
521ced18 | 18478 | + goto out_xinondir; |
4a4d8108 AM |
18479 | + err = au_xino_write(sb, bindex, h_ino, *ino); |
18480 | + if (unlikely(err)) | |
521ced18 | 18481 | + goto out_xinondir; |
1308ab2a | 18482 | + } |
1facf9fc | 18483 | + |
521ced18 JR |
18484 | +out_xinondir: |
18485 | + if (isnondir && idx >= 0) | |
18486 | + au_xinondir_leave(sb, bindex, h_ino, idx); | |
4f0767ce | 18487 | +out: |
1facf9fc | 18488 | + return err; |
18489 | +} | |
18490 | + | |
4a4d8108 AM |
18491 | +/* successful returns with iinfo write_locked */ |
18492 | +/* todo: return with unlocked? */ | |
18493 | +struct inode *au_new_inode(struct dentry *dentry, int must_new) | |
1facf9fc | 18494 | +{ |
5527c038 | 18495 | + struct inode *inode, *h_inode; |
4a4d8108 AM |
18496 | + struct dentry *h_dentry; |
18497 | + struct super_block *sb; | |
18498 | + ino_t h_ino, ino; | |
521ced18 | 18499 | + int err, idx, hlinked; |
5afbbe0d | 18500 | + aufs_bindex_t btop; |
1facf9fc | 18501 | + |
4a4d8108 | 18502 | + sb = dentry->d_sb; |
5afbbe0d AM |
18503 | + btop = au_dbtop(dentry); |
18504 | + h_dentry = au_h_dptr(dentry, btop); | |
5527c038 JR |
18505 | + h_inode = d_inode(h_dentry); |
18506 | + h_ino = h_inode->i_ino; | |
521ced18 | 18507 | + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1; |
b752ccd1 | 18508 | + |
521ced18 | 18509 | +new_ino: |
b752ccd1 AM |
18510 | + /* |
18511 | + * stop 'race'-ing between hardlinks under different | |
18512 | + * parents. | |
18513 | + */ | |
521ced18 JR |
18514 | + if (hlinked) { |
18515 | + err = au_xinondir_enter(sb, btop, h_ino, &idx); | |
18516 | + inode = ERR_PTR(err); | |
18517 | + if (unlikely(err)) | |
18518 | + goto out; | |
18519 | + } | |
b752ccd1 | 18520 | + |
5afbbe0d | 18521 | + err = au_xino_read(sb, btop, h_ino, &ino); |
4a4d8108 AM |
18522 | + inode = ERR_PTR(err); |
18523 | + if (unlikely(err)) | |
521ced18 | 18524 | + goto out_xinondir; |
b752ccd1 | 18525 | + |
4a4d8108 AM |
18526 | + if (!ino) { |
18527 | + ino = au_xino_new_ino(sb); | |
18528 | + if (unlikely(!ino)) { | |
18529 | + inode = ERR_PTR(-EIO); | |
521ced18 | 18530 | + goto out_xinondir; |
dece6358 AM |
18531 | + } |
18532 | + } | |
1facf9fc | 18533 | + |
4a4d8108 AM |
18534 | + AuDbg("i%lu\n", (unsigned long)ino); |
18535 | + inode = au_iget_locked(sb, ino); | |
18536 | + err = PTR_ERR(inode); | |
18537 | + if (IS_ERR(inode)) | |
521ced18 | 18538 | + goto out_xinondir; |
1facf9fc | 18539 | + |
4a4d8108 AM |
18540 | + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW)); |
18541 | + if (inode->i_state & I_NEW) { | |
18542 | + ii_write_lock_new_child(inode); | |
18543 | + err = set_inode(inode, dentry); | |
18544 | + if (!err) { | |
18545 | + unlock_new_inode(inode); | |
521ced18 | 18546 | + goto out_xinondir; /* success */ |
4a4d8108 | 18547 | + } |
1308ab2a | 18548 | + |
027c5e7a AM |
18549 | + /* |
18550 | + * iget_failed() calls iput(), but we need to call | |
18551 | + * ii_write_unlock() after iget_failed(). so dirty hack for | |
18552 | + * i_count. | |
18553 | + */ | |
18554 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 18555 | + iget_failed(inode); |
027c5e7a | 18556 | + ii_write_unlock(inode); |
5afbbe0d | 18557 | + au_xino_write(sb, btop, h_ino, /*ino*/0); |
027c5e7a AM |
18558 | + /* ignore this error */ |
18559 | + goto out_iput; | |
18560 | + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) { | |
b752ccd1 AM |
18561 | + /* |
18562 | + * horrible race condition between lookup, readdir and copyup | |
18563 | + * (or something). | |
18564 | + */ | |
521ced18 JR |
18565 | + if (hlinked && idx >= 0) |
18566 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
027c5e7a AM |
18567 | + err = reval_inode(inode, dentry); |
18568 | + if (unlikely(err < 0)) { | |
521ced18 | 18569 | + hlinked = 0; |
027c5e7a AM |
18570 | + goto out_iput; |
18571 | + } | |
521ced18 | 18572 | + if (!err) |
4a4d8108 | 18573 | + goto out; /* success */ |
521ced18 JR |
18574 | + else if (hlinked && idx >= 0) { |
18575 | + err = au_xinondir_enter(sb, btop, h_ino, &idx); | |
18576 | + if (unlikely(err)) { | |
18577 | + iput(inode); | |
18578 | + inode = ERR_PTR(err); | |
18579 | + goto out; | |
18580 | + } | |
18581 | + } | |
4a4d8108 AM |
18582 | + } |
18583 | + | |
5527c038 | 18584 | + if (unlikely(au_test_fs_unique_ino(h_inode))) |
4a4d8108 | 18585 | + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir," |
523b37e3 | 18586 | + " b%d, %s, %pd, hi%lu, i%lu.\n", |
5afbbe0d | 18587 | + btop, au_sbtype(h_dentry->d_sb), dentry, |
4a4d8108 AM |
18588 | + (unsigned long)h_ino, (unsigned long)ino); |
18589 | + ino = 0; | |
5afbbe0d | 18590 | + err = au_xino_write(sb, btop, h_ino, /*ino*/0); |
4a4d8108 AM |
18591 | + if (!err) { |
18592 | + iput(inode); | |
521ced18 JR |
18593 | + if (hlinked && idx >= 0) |
18594 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
4a4d8108 AM |
18595 | + goto new_ino; |
18596 | + } | |
1308ab2a | 18597 | + |
4f0767ce | 18598 | +out_iput: |
4a4d8108 | 18599 | + iput(inode); |
4a4d8108 | 18600 | + inode = ERR_PTR(err); |
521ced18 JR |
18601 | +out_xinondir: |
18602 | + if (hlinked && idx >= 0) | |
18603 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
4f0767ce | 18604 | +out: |
4a4d8108 | 18605 | + return inode; |
1facf9fc | 18606 | +} |
18607 | + | |
4a4d8108 | 18608 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18609 | + |
4a4d8108 AM |
18610 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, |
18611 | + struct inode *inode) | |
18612 | +{ | |
18613 | + int err; | |
076b876e | 18614 | + struct inode *hi; |
1facf9fc | 18615 | + |
4a4d8108 | 18616 | + err = au_br_rdonly(au_sbr(sb, bindex)); |
1facf9fc | 18617 | + |
4a4d8108 AM |
18618 | + /* pseudo-link after flushed may happen out of bounds */ |
18619 | + if (!err | |
18620 | + && inode | |
5afbbe0d AM |
18621 | + && au_ibtop(inode) <= bindex |
18622 | + && bindex <= au_ibbot(inode)) { | |
4a4d8108 AM |
18623 | + /* |
18624 | + * permission check is unnecessary since vfsub routine | |
18625 | + * will be called later | |
18626 | + */ | |
076b876e | 18627 | + hi = au_h_iptr(inode, bindex); |
4a4d8108 AM |
18628 | + if (hi) |
18629 | + err = IS_IMMUTABLE(hi) ? -EROFS : 0; | |
1facf9fc | 18630 | + } |
18631 | + | |
4a4d8108 AM |
18632 | + return err; |
18633 | +} | |
dece6358 | 18634 | + |
4a4d8108 AM |
18635 | +int au_test_h_perm(struct inode *h_inode, int mask) |
18636 | +{ | |
2dfbb274 | 18637 | + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) |
4a4d8108 AM |
18638 | + return 0; |
18639 | + return inode_permission(h_inode, mask); | |
18640 | +} | |
1facf9fc | 18641 | + |
4a4d8108 AM |
18642 | +int au_test_h_perm_sio(struct inode *h_inode, int mask) |
18643 | +{ | |
18644 | + if (au_test_nfs(h_inode->i_sb) | |
18645 | + && (mask & MAY_WRITE) | |
18646 | + && S_ISDIR(h_inode->i_mode)) | |
18647 | + mask |= MAY_READ; /* force permission check */ | |
18648 | + return au_test_h_perm(h_inode, mask); | |
1facf9fc | 18649 | +} |
7f207e10 AM |
18650 | diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h |
18651 | --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 18652 | +++ linux/fs/aufs/inode.h 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 | 18653 | @@ -0,0 +1,695 @@ |
4a4d8108 | 18654 | +/* |
a2654f78 | 18655 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
18656 | + * |
18657 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18658 | + * it under the terms of the GNU General Public License as published by | |
18659 | + * the Free Software Foundation; either version 2 of the License, or | |
18660 | + * (at your option) any later version. | |
18661 | + * | |
18662 | + * This program is distributed in the hope that it will be useful, | |
18663 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18664 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18665 | + * GNU General Public License for more details. | |
18666 | + * | |
18667 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18668 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18669 | + */ |
1facf9fc | 18670 | + |
1308ab2a | 18671 | +/* |
4a4d8108 | 18672 | + * inode operations |
1308ab2a | 18673 | + */ |
dece6358 | 18674 | + |
4a4d8108 AM |
18675 | +#ifndef __AUFS_INODE_H__ |
18676 | +#define __AUFS_INODE_H__ | |
dece6358 | 18677 | + |
4a4d8108 | 18678 | +#ifdef __KERNEL__ |
1308ab2a | 18679 | + |
4a4d8108 | 18680 | +#include <linux/fsnotify.h> |
4a4d8108 | 18681 | +#include "rwsem.h" |
1308ab2a | 18682 | + |
4a4d8108 | 18683 | +struct vfsmount; |
1facf9fc | 18684 | + |
4a4d8108 AM |
18685 | +struct au_hnotify { |
18686 | +#ifdef CONFIG_AUFS_HNOTIFY | |
18687 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
7f207e10 | 18688 | + /* never use fsnotify_add_vfsmount_mark() */ |
0c5527e5 | 18689 | + struct fsnotify_mark hn_mark; |
4a4d8108 | 18690 | +#endif |
1c60b727 | 18691 | + struct inode *hn_aufs_inode; /* no get/put */ |
4a4d8108 AM |
18692 | +#endif |
18693 | +} ____cacheline_aligned_in_smp; | |
1facf9fc | 18694 | + |
4a4d8108 AM |
18695 | +struct au_hinode { |
18696 | + struct inode *hi_inode; | |
18697 | + aufs_bindex_t hi_id; | |
18698 | +#ifdef CONFIG_AUFS_HNOTIFY | |
18699 | + struct au_hnotify *hi_notify; | |
18700 | +#endif | |
dece6358 | 18701 | + |
4a4d8108 AM |
18702 | + /* reference to the copied-up whiteout with get/put */ |
18703 | + struct dentry *hi_whdentry; | |
18704 | +}; | |
dece6358 | 18705 | + |
537831f9 AM |
18706 | +/* ig_flags */ |
18707 | +#define AuIG_HALF_REFRESHED 1 | |
18708 | +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name) | |
18709 | +#define au_ig_fset(flags, name) \ | |
18710 | + do { (flags) |= AuIG_##name; } while (0) | |
18711 | +#define au_ig_fclr(flags, name) \ | |
18712 | + do { (flags) &= ~AuIG_##name; } while (0) | |
18713 | + | |
18714 | +struct au_iigen { | |
be52b249 | 18715 | + spinlock_t ig_spin; |
537831f9 AM |
18716 | + __u32 ig_generation, ig_flags; |
18717 | +}; | |
18718 | + | |
4a4d8108 AM |
18719 | +struct au_vdir; |
18720 | +struct au_iinfo { | |
7a9e40b8 | 18721 | + struct au_iigen ii_generation; |
4a4d8108 | 18722 | + struct super_block *ii_hsb1; /* no get/put */ |
1facf9fc | 18723 | + |
4a4d8108 | 18724 | + struct au_rwsem ii_rwsem; |
5afbbe0d | 18725 | + aufs_bindex_t ii_btop, ii_bbot; |
4a4d8108 AM |
18726 | + __u32 ii_higen; |
18727 | + struct au_hinode *ii_hinode; | |
18728 | + struct au_vdir *ii_vdir; | |
18729 | +}; | |
1facf9fc | 18730 | + |
4a4d8108 AM |
18731 | +struct au_icntnr { |
18732 | + struct au_iinfo iinfo; | |
18733 | + struct inode vfs_inode; | |
8b6a4947 | 18734 | + struct hlist_bl_node plink; |
4a4d8108 | 18735 | +} ____cacheline_aligned_in_smp; |
1308ab2a | 18736 | + |
4a4d8108 AM |
18737 | +/* au_pin flags */ |
18738 | +#define AuPin_DI_LOCKED 1 | |
18739 | +#define AuPin_MNT_WRITE (1 << 1) | |
18740 | +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name) | |
7f207e10 AM |
18741 | +#define au_fset_pin(flags, name) \ |
18742 | + do { (flags) |= AuPin_##name; } while (0) | |
18743 | +#define au_fclr_pin(flags, name) \ | |
18744 | + do { (flags) &= ~AuPin_##name; } while (0) | |
4a4d8108 AM |
18745 | + |
18746 | +struct au_pin { | |
18747 | + /* input */ | |
18748 | + struct dentry *dentry; | |
18749 | + unsigned int udba; | |
18750 | + unsigned char lsc_di, lsc_hi, flags; | |
18751 | + aufs_bindex_t bindex; | |
18752 | + | |
18753 | + /* output */ | |
18754 | + struct dentry *parent; | |
18755 | + struct au_hinode *hdir; | |
18756 | + struct vfsmount *h_mnt; | |
86dc4139 AM |
18757 | + |
18758 | + /* temporary unlock/relock for copyup */ | |
18759 | + struct dentry *h_dentry, *h_parent; | |
18760 | + struct au_branch *br; | |
18761 | + struct task_struct *task; | |
4a4d8108 | 18762 | +}; |
1facf9fc | 18763 | + |
86dc4139 | 18764 | +void au_pin_hdir_unlock(struct au_pin *p); |
c1595e42 | 18765 | +int au_pin_hdir_lock(struct au_pin *p); |
86dc4139 | 18766 | +int au_pin_hdir_relock(struct au_pin *p); |
86dc4139 AM |
18767 | +void au_pin_hdir_acquire_nest(struct au_pin *p); |
18768 | +void au_pin_hdir_release(struct au_pin *p); | |
18769 | + | |
1308ab2a | 18770 | +/* ---------------------------------------------------------------------- */ |
18771 | + | |
4a4d8108 | 18772 | +static inline struct au_iinfo *au_ii(struct inode *inode) |
1facf9fc | 18773 | +{ |
5afbbe0d AM |
18774 | + BUG_ON(is_bad_inode(inode)); |
18775 | + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
4a4d8108 | 18776 | +} |
1facf9fc | 18777 | + |
4a4d8108 | 18778 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18779 | + |
4a4d8108 AM |
18780 | +/* inode.c */ |
18781 | +struct inode *au_igrab(struct inode *inode); | |
b95c5147 | 18782 | +void au_refresh_iop(struct inode *inode, int force_getattr); |
027c5e7a | 18783 | +int au_refresh_hinode_self(struct inode *inode); |
4a4d8108 AM |
18784 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry); |
18785 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
18786 | + unsigned int d_type, ino_t *ino); | |
18787 | +struct inode *au_new_inode(struct dentry *dentry, int must_new); | |
18788 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, | |
18789 | + struct inode *inode); | |
18790 | +int au_test_h_perm(struct inode *h_inode, int mask); | |
18791 | +int au_test_h_perm_sio(struct inode *h_inode, int mask); | |
1facf9fc | 18792 | + |
4a4d8108 AM |
18793 | +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, |
18794 | + ino_t h_ino, unsigned int d_type, ino_t *ino) | |
18795 | +{ | |
18796 | +#ifdef CONFIG_AUFS_SHWH | |
18797 | + return au_ino(sb, bindex, h_ino, d_type, ino); | |
18798 | +#else | |
18799 | + return 0; | |
18800 | +#endif | |
18801 | +} | |
1facf9fc | 18802 | + |
4a4d8108 | 18803 | +/* i_op.c */ |
b95c5147 AM |
18804 | +enum { |
18805 | + AuIop_SYMLINK, | |
18806 | + AuIop_DIR, | |
18807 | + AuIop_OTHER, | |
18808 | + AuIop_Last | |
18809 | +}; | |
18810 | +extern struct inode_operations aufs_iop[AuIop_Last], | |
18811 | + aufs_iop_nogetattr[AuIop_Last]; | |
1308ab2a | 18812 | + |
4a4d8108 AM |
18813 | +/* au_wr_dir flags */ |
18814 | +#define AuWrDir_ADD_ENTRY 1 | |
7e9cd9fe AM |
18815 | +#define AuWrDir_ISDIR (1 << 1) |
18816 | +#define AuWrDir_TMPFILE (1 << 2) | |
4a4d8108 | 18817 | +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name) |
7f207e10 AM |
18818 | +#define au_fset_wrdir(flags, name) \ |
18819 | + do { (flags) |= AuWrDir_##name; } while (0) | |
18820 | +#define au_fclr_wrdir(flags, name) \ | |
18821 | + do { (flags) &= ~AuWrDir_##name; } while (0) | |
1facf9fc | 18822 | + |
4a4d8108 AM |
18823 | +struct au_wr_dir_args { |
18824 | + aufs_bindex_t force_btgt; | |
18825 | + unsigned char flags; | |
18826 | +}; | |
18827 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
18828 | + struct au_wr_dir_args *args); | |
dece6358 | 18829 | + |
4a4d8108 AM |
18830 | +struct dentry *au_pinned_h_parent(struct au_pin *pin); |
18831 | +void au_pin_init(struct au_pin *pin, struct dentry *dentry, | |
18832 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
18833 | + unsigned int udba, unsigned char flags); | |
18834 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
18835 | + unsigned int udba, unsigned char flags) __must_check; | |
18836 | +int au_do_pin(struct au_pin *pin) __must_check; | |
18837 | +void au_unpin(struct au_pin *pin); | |
c1595e42 JR |
18838 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen); |
18839 | + | |
18840 | +#define AuIcpup_DID_CPUP 1 | |
18841 | +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name) | |
18842 | +#define au_fset_icpup(flags, name) \ | |
18843 | + do { (flags) |= AuIcpup_##name; } while (0) | |
18844 | +#define au_fclr_icpup(flags, name) \ | |
18845 | + do { (flags) &= ~AuIcpup_##name; } while (0) | |
18846 | + | |
18847 | +struct au_icpup_args { | |
18848 | + unsigned char flags; | |
18849 | + unsigned char pin_flags; | |
18850 | + aufs_bindex_t btgt; | |
18851 | + unsigned int udba; | |
18852 | + struct au_pin pin; | |
18853 | + struct path h_path; | |
18854 | + struct inode *h_inode; | |
18855 | +}; | |
18856 | + | |
18857 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, | |
18858 | + struct au_icpup_args *a); | |
18859 | + | |
a2654f78 AM |
18860 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path, |
18861 | + int locked); | |
1facf9fc | 18862 | + |
4a4d8108 AM |
18863 | +/* i_op_add.c */ |
18864 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
18865 | + struct dentry *h_parent, int isdir); | |
7eafdf33 AM |
18866 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
18867 | + dev_t dev); | |
4a4d8108 | 18868 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname); |
7eafdf33 | 18869 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 18870 | + bool want_excl); |
b912730e AM |
18871 | +struct vfsub_aopen_args; |
18872 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, | |
18873 | + struct vfsub_aopen_args *args); | |
38d290e6 | 18874 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode); |
4a4d8108 AM |
18875 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, |
18876 | + struct dentry *dentry); | |
7eafdf33 | 18877 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
1facf9fc | 18878 | + |
4a4d8108 AM |
18879 | +/* i_op_del.c */ |
18880 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup); | |
18881 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
18882 | + struct dentry *h_parent, int isdir); | |
18883 | +int aufs_unlink(struct inode *dir, struct dentry *dentry); | |
18884 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry); | |
1308ab2a | 18885 | + |
4a4d8108 AM |
18886 | +/* i_op_ren.c */ |
18887 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt); | |
18888 | +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry, | |
f2c43d5f AM |
18889 | + struct inode *dir, struct dentry *dentry, |
18890 | + unsigned int flags); | |
1facf9fc | 18891 | + |
4a4d8108 AM |
18892 | +/* iinfo.c */ |
18893 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex); | |
18894 | +void au_hiput(struct au_hinode *hinode); | |
18895 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, | |
18896 | + struct dentry *h_wh); | |
18897 | +unsigned int au_hi_flags(struct inode *inode, int isdir); | |
1308ab2a | 18898 | + |
4a4d8108 AM |
18899 | +/* hinode flags */ |
18900 | +#define AuHi_XINO 1 | |
18901 | +#define AuHi_HNOTIFY (1 << 1) | |
18902 | +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name) | |
7f207e10 AM |
18903 | +#define au_fset_hi(flags, name) \ |
18904 | + do { (flags) |= AuHi_##name; } while (0) | |
18905 | +#define au_fclr_hi(flags, name) \ | |
18906 | + do { (flags) &= ~AuHi_##name; } while (0) | |
1facf9fc | 18907 | + |
4a4d8108 AM |
18908 | +#ifndef CONFIG_AUFS_HNOTIFY |
18909 | +#undef AuHi_HNOTIFY | |
18910 | +#define AuHi_HNOTIFY 0 | |
18911 | +#endif | |
1facf9fc | 18912 | + |
4a4d8108 AM |
18913 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
18914 | + struct inode *h_inode, unsigned int flags); | |
1facf9fc | 18915 | + |
537831f9 | 18916 | +void au_update_iigen(struct inode *inode, int half); |
4a4d8108 | 18917 | +void au_update_ibrange(struct inode *inode, int do_put_zero); |
1facf9fc | 18918 | + |
4a4d8108 | 18919 | +void au_icntnr_init_once(void *_c); |
5afbbe0d | 18920 | +void au_hinode_init(struct au_hinode *hinode); |
4a4d8108 AM |
18921 | +int au_iinfo_init(struct inode *inode); |
18922 | +void au_iinfo_fin(struct inode *inode); | |
e2f27e51 | 18923 | +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink); |
1308ab2a | 18924 | + |
e49829fe | 18925 | +#ifdef CONFIG_PROC_FS |
4a4d8108 | 18926 | +/* plink.c */ |
e49829fe | 18927 | +int au_plink_maint(struct super_block *sb, int flags); |
7e9cd9fe | 18928 | +struct au_sbinfo; |
e49829fe JR |
18929 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo); |
18930 | +int au_plink_maint_enter(struct super_block *sb); | |
4a4d8108 AM |
18931 | +#ifdef CONFIG_AUFS_DEBUG |
18932 | +void au_plink_list(struct super_block *sb); | |
18933 | +#else | |
18934 | +AuStubVoid(au_plink_list, struct super_block *sb) | |
18935 | +#endif | |
18936 | +int au_plink_test(struct inode *inode); | |
18937 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex); | |
18938 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
18939 | + struct dentry *h_dentry); | |
e49829fe JR |
18940 | +void au_plink_put(struct super_block *sb, int verbose); |
18941 | +void au_plink_clean(struct super_block *sb, int verbose); | |
4a4d8108 | 18942 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id); |
e49829fe JR |
18943 | +#else |
18944 | +AuStubInt0(au_plink_maint, struct super_block *sb, int flags); | |
18945 | +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo); | |
18946 | +AuStubInt0(au_plink_maint_enter, struct super_block *sb); | |
18947 | +AuStubVoid(au_plink_list, struct super_block *sb); | |
18948 | +AuStubInt0(au_plink_test, struct inode *inode); | |
18949 | +AuStub(struct dentry *, au_plink_lkup, return NULL, | |
18950 | + struct inode *inode, aufs_bindex_t bindex); | |
18951 | +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex, | |
18952 | + struct dentry *h_dentry); | |
18953 | +AuStubVoid(au_plink_put, struct super_block *sb, int verbose); | |
18954 | +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose); | |
18955 | +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id); | |
18956 | +#endif /* CONFIG_PROC_FS */ | |
1facf9fc | 18957 | + |
c1595e42 JR |
18958 | +#ifdef CONFIG_AUFS_XATTR |
18959 | +/* xattr.c */ | |
7e9cd9fe AM |
18960 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
18961 | + unsigned int verbose); | |
c1595e42 | 18962 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size); |
f2c43d5f | 18963 | +void au_xattr_init(struct super_block *sb); |
c1595e42 JR |
18964 | +#else |
18965 | +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe | 18966 | + int ignore_flags, unsigned int verbose); |
f2c43d5f | 18967 | +AuStubVoid(au_xattr_init, struct super_block *sb); |
c1595e42 JR |
18968 | +#endif |
18969 | + | |
18970 | +#ifdef CONFIG_FS_POSIX_ACL | |
18971 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type); | |
18972 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
18973 | +#endif | |
18974 | + | |
18975 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) | |
18976 | +enum { | |
18977 | + AU_XATTR_SET, | |
c1595e42 JR |
18978 | + AU_ACL_SET |
18979 | +}; | |
18980 | + | |
f2c43d5f | 18981 | +struct au_sxattr { |
c1595e42 JR |
18982 | + int type; |
18983 | + union { | |
18984 | + struct { | |
18985 | + const char *name; | |
18986 | + const void *value; | |
18987 | + size_t size; | |
18988 | + int flags; | |
18989 | + } set; | |
18990 | + struct { | |
c1595e42 JR |
18991 | + struct posix_acl *acl; |
18992 | + int type; | |
18993 | + } acl_set; | |
18994 | + } u; | |
18995 | +}; | |
f2c43d5f AM |
18996 | +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode, |
18997 | + struct au_sxattr *arg); | |
c1595e42 JR |
18998 | +#endif |
18999 | + | |
4a4d8108 | 19000 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19001 | + |
4a4d8108 AM |
19002 | +/* lock subclass for iinfo */ |
19003 | +enum { | |
19004 | + AuLsc_II_CHILD, /* child first */ | |
19005 | + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */ | |
19006 | + AuLsc_II_CHILD3, /* copyup dirs */ | |
19007 | + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */ | |
19008 | + AuLsc_II_PARENT2, | |
19009 | + AuLsc_II_PARENT3, /* copyup dirs */ | |
19010 | + AuLsc_II_NEW_CHILD | |
19011 | +}; | |
1308ab2a | 19012 | + |
1facf9fc | 19013 | +/* |
4a4d8108 AM |
19014 | + * ii_read_lock_child, ii_write_lock_child, |
19015 | + * ii_read_lock_child2, ii_write_lock_child2, | |
19016 | + * ii_read_lock_child3, ii_write_lock_child3, | |
19017 | + * ii_read_lock_parent, ii_write_lock_parent, | |
19018 | + * ii_read_lock_parent2, ii_write_lock_parent2, | |
19019 | + * ii_read_lock_parent3, ii_write_lock_parent3, | |
19020 | + * ii_read_lock_new_child, ii_write_lock_new_child, | |
1facf9fc | 19021 | + */ |
4a4d8108 AM |
19022 | +#define AuReadLockFunc(name, lsc) \ |
19023 | +static inline void ii_read_lock_##name(struct inode *i) \ | |
19024 | +{ \ | |
19025 | + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
19026 | +} | |
19027 | + | |
19028 | +#define AuWriteLockFunc(name, lsc) \ | |
19029 | +static inline void ii_write_lock_##name(struct inode *i) \ | |
19030 | +{ \ | |
19031 | + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
19032 | +} | |
19033 | + | |
19034 | +#define AuRWLockFuncs(name, lsc) \ | |
19035 | + AuReadLockFunc(name, lsc) \ | |
19036 | + AuWriteLockFunc(name, lsc) | |
19037 | + | |
19038 | +AuRWLockFuncs(child, CHILD); | |
19039 | +AuRWLockFuncs(child2, CHILD2); | |
19040 | +AuRWLockFuncs(child3, CHILD3); | |
19041 | +AuRWLockFuncs(parent, PARENT); | |
19042 | +AuRWLockFuncs(parent2, PARENT2); | |
19043 | +AuRWLockFuncs(parent3, PARENT3); | |
19044 | +AuRWLockFuncs(new_child, NEW_CHILD); | |
19045 | + | |
19046 | +#undef AuReadLockFunc | |
19047 | +#undef AuWriteLockFunc | |
19048 | +#undef AuRWLockFuncs | |
1facf9fc | 19049 | + |
8b6a4947 AM |
19050 | +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem) |
19051 | +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem) | |
19052 | +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 19053 | + |
4a4d8108 AM |
19054 | +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem) |
19055 | +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem) | |
19056 | +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 19057 | + |
4a4d8108 | 19058 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19059 | + |
027c5e7a AM |
19060 | +static inline void au_icntnr_init(struct au_icntnr *c) |
19061 | +{ | |
19062 | +#ifdef CONFIG_AUFS_DEBUG | |
19063 | + c->vfs_inode.i_mode = 0; | |
19064 | +#endif | |
19065 | +} | |
19066 | + | |
cfc41e69 | 19067 | +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags) |
4a4d8108 | 19068 | +{ |
537831f9 AM |
19069 | + unsigned int gen; |
19070 | + struct au_iinfo *iinfo; | |
be52b249 | 19071 | + struct au_iigen *iigen; |
537831f9 AM |
19072 | + |
19073 | + iinfo = au_ii(inode); | |
be52b249 AM |
19074 | + iigen = &iinfo->ii_generation; |
19075 | + spin_lock(&iigen->ig_spin); | |
cfc41e69 AM |
19076 | + if (igflags) |
19077 | + *igflags = iigen->ig_flags; | |
be52b249 AM |
19078 | + gen = iigen->ig_generation; |
19079 | + spin_unlock(&iigen->ig_spin); | |
537831f9 AM |
19080 | + |
19081 | + return gen; | |
4a4d8108 | 19082 | +} |
1308ab2a | 19083 | + |
4a4d8108 AM |
19084 | +/* tiny test for inode number */ |
19085 | +/* tmpfs generation is too rough */ | |
19086 | +static inline int au_test_higen(struct inode *inode, struct inode *h_inode) | |
19087 | +{ | |
19088 | + struct au_iinfo *iinfo; | |
1308ab2a | 19089 | + |
4a4d8108 AM |
19090 | + iinfo = au_ii(inode); |
19091 | + AuRwMustAnyLock(&iinfo->ii_rwsem); | |
19092 | + return !(iinfo->ii_hsb1 == h_inode->i_sb | |
19093 | + && iinfo->ii_higen == h_inode->i_generation); | |
19094 | +} | |
1308ab2a | 19095 | + |
4a4d8108 AM |
19096 | +static inline void au_iigen_dec(struct inode *inode) |
19097 | +{ | |
537831f9 | 19098 | + struct au_iinfo *iinfo; |
be52b249 | 19099 | + struct au_iigen *iigen; |
537831f9 AM |
19100 | + |
19101 | + iinfo = au_ii(inode); | |
be52b249 AM |
19102 | + iigen = &iinfo->ii_generation; |
19103 | + spin_lock(&iigen->ig_spin); | |
19104 | + iigen->ig_generation--; | |
19105 | + spin_unlock(&iigen->ig_spin); | |
027c5e7a AM |
19106 | +} |
19107 | + | |
19108 | +static inline int au_iigen_test(struct inode *inode, unsigned int sigen) | |
19109 | +{ | |
19110 | + int err; | |
19111 | + | |
19112 | + err = 0; | |
537831f9 | 19113 | + if (unlikely(inode && au_iigen(inode, NULL) != sigen)) |
027c5e7a AM |
19114 | + err = -EIO; |
19115 | + | |
19116 | + return err; | |
4a4d8108 | 19117 | +} |
1308ab2a | 19118 | + |
4a4d8108 | 19119 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19120 | + |
5afbbe0d AM |
19121 | +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo, |
19122 | + aufs_bindex_t bindex) | |
19123 | +{ | |
19124 | + return iinfo->ii_hinode + bindex; | |
19125 | +} | |
19126 | + | |
19127 | +static inline int au_is_bad_inode(struct inode *inode) | |
19128 | +{ | |
19129 | + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0)); | |
19130 | +} | |
19131 | + | |
4a4d8108 AM |
19132 | +static inline aufs_bindex_t au_ii_br_id(struct inode *inode, |
19133 | + aufs_bindex_t bindex) | |
19134 | +{ | |
19135 | + IiMustAnyLock(inode); | |
5afbbe0d | 19136 | + return au_hinode(au_ii(inode), bindex)->hi_id; |
4a4d8108 | 19137 | +} |
1308ab2a | 19138 | + |
5afbbe0d | 19139 | +static inline aufs_bindex_t au_ibtop(struct inode *inode) |
4a4d8108 AM |
19140 | +{ |
19141 | + IiMustAnyLock(inode); | |
5afbbe0d | 19142 | + return au_ii(inode)->ii_btop; |
4a4d8108 | 19143 | +} |
1308ab2a | 19144 | + |
5afbbe0d | 19145 | +static inline aufs_bindex_t au_ibbot(struct inode *inode) |
4a4d8108 AM |
19146 | +{ |
19147 | + IiMustAnyLock(inode); | |
5afbbe0d | 19148 | + return au_ii(inode)->ii_bbot; |
4a4d8108 | 19149 | +} |
1308ab2a | 19150 | + |
4a4d8108 AM |
19151 | +static inline struct au_vdir *au_ivdir(struct inode *inode) |
19152 | +{ | |
19153 | + IiMustAnyLock(inode); | |
19154 | + return au_ii(inode)->ii_vdir; | |
19155 | +} | |
1308ab2a | 19156 | + |
4a4d8108 AM |
19157 | +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex) |
19158 | +{ | |
19159 | + IiMustAnyLock(inode); | |
5afbbe0d | 19160 | + return au_hinode(au_ii(inode), bindex)->hi_whdentry; |
4a4d8108 | 19161 | +} |
1308ab2a | 19162 | + |
5afbbe0d | 19163 | +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 19164 | +{ |
4a4d8108 | 19165 | + IiMustWriteLock(inode); |
5afbbe0d | 19166 | + au_ii(inode)->ii_btop = bindex; |
4a4d8108 | 19167 | +} |
1308ab2a | 19168 | + |
5afbbe0d | 19169 | +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex) |
4a4d8108 AM |
19170 | +{ |
19171 | + IiMustWriteLock(inode); | |
5afbbe0d | 19172 | + au_ii(inode)->ii_bbot = bindex; |
1308ab2a | 19173 | +} |
19174 | + | |
4a4d8108 AM |
19175 | +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir) |
19176 | +{ | |
19177 | + IiMustWriteLock(inode); | |
19178 | + au_ii(inode)->ii_vdir = vdir; | |
19179 | +} | |
1facf9fc | 19180 | + |
4a4d8108 | 19181 | +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 19182 | +{ |
4a4d8108 | 19183 | + IiMustAnyLock(inode); |
5afbbe0d | 19184 | + return au_hinode(au_ii(inode), bindex); |
4a4d8108 | 19185 | +} |
dece6358 | 19186 | + |
4a4d8108 | 19187 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19188 | + |
4a4d8108 AM |
19189 | +static inline struct dentry *au_pinned_parent(struct au_pin *pin) |
19190 | +{ | |
19191 | + if (pin) | |
19192 | + return pin->parent; | |
19193 | + return NULL; | |
1facf9fc | 19194 | +} |
19195 | + | |
4a4d8108 | 19196 | +static inline struct inode *au_pinned_h_dir(struct au_pin *pin) |
1facf9fc | 19197 | +{ |
4a4d8108 AM |
19198 | + if (pin && pin->hdir) |
19199 | + return pin->hdir->hi_inode; | |
19200 | + return NULL; | |
1308ab2a | 19201 | +} |
1facf9fc | 19202 | + |
4a4d8108 AM |
19203 | +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin) |
19204 | +{ | |
19205 | + if (pin) | |
19206 | + return pin->hdir; | |
19207 | + return NULL; | |
19208 | +} | |
1facf9fc | 19209 | + |
4a4d8108 | 19210 | +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry) |
1308ab2a | 19211 | +{ |
4a4d8108 AM |
19212 | + if (pin) |
19213 | + pin->dentry = dentry; | |
19214 | +} | |
1308ab2a | 19215 | + |
4a4d8108 AM |
19216 | +static inline void au_pin_set_parent_lflag(struct au_pin *pin, |
19217 | + unsigned char lflag) | |
19218 | +{ | |
19219 | + if (pin) { | |
7f207e10 | 19220 | + if (lflag) |
4a4d8108 | 19221 | + au_fset_pin(pin->flags, DI_LOCKED); |
7f207e10 | 19222 | + else |
4a4d8108 | 19223 | + au_fclr_pin(pin->flags, DI_LOCKED); |
1308ab2a | 19224 | + } |
4a4d8108 AM |
19225 | +} |
19226 | + | |
7e9cd9fe | 19227 | +#if 0 /* reserved */ |
4a4d8108 AM |
19228 | +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent) |
19229 | +{ | |
19230 | + if (pin) { | |
19231 | + dput(pin->parent); | |
19232 | + pin->parent = dget(parent); | |
1facf9fc | 19233 | + } |
4a4d8108 | 19234 | +} |
7e9cd9fe | 19235 | +#endif |
1facf9fc | 19236 | + |
4a4d8108 AM |
19237 | +/* ---------------------------------------------------------------------- */ |
19238 | + | |
027c5e7a | 19239 | +struct au_branch; |
4a4d8108 AM |
19240 | +#ifdef CONFIG_AUFS_HNOTIFY |
19241 | +struct au_hnotify_op { | |
19242 | + void (*ctl)(struct au_hinode *hinode, int do_set); | |
027c5e7a | 19243 | + int (*alloc)(struct au_hinode *hinode); |
7eafdf33 AM |
19244 | + |
19245 | + /* | |
19246 | + * if it returns true, the the caller should free hinode->hi_notify, | |
19247 | + * otherwise ->free() frees it. | |
19248 | + */ | |
19249 | + int (*free)(struct au_hinode *hinode, | |
19250 | + struct au_hnotify *hn) __must_check; | |
4a4d8108 AM |
19251 | + |
19252 | + void (*fin)(void); | |
19253 | + int (*init)(void); | |
027c5e7a AM |
19254 | + |
19255 | + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm); | |
19256 | + void (*fin_br)(struct au_branch *br); | |
19257 | + int (*init_br)(struct au_branch *br, int perm); | |
4a4d8108 AM |
19258 | +}; |
19259 | + | |
19260 | +/* hnotify.c */ | |
027c5e7a | 19261 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode); |
4a4d8108 AM |
19262 | +void au_hn_free(struct au_hinode *hinode); |
19263 | +void au_hn_ctl(struct au_hinode *hinode, int do_set); | |
19264 | +void au_hn_reset(struct inode *inode, unsigned int flags); | |
19265 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
19266 | + struct qstr *h_child_qstr, struct inode *h_child_inode); | |
027c5e7a AM |
19267 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm); |
19268 | +int au_hnotify_init_br(struct au_branch *br, int perm); | |
19269 | +void au_hnotify_fin_br(struct au_branch *br); | |
4a4d8108 AM |
19270 | +int __init au_hnotify_init(void); |
19271 | +void au_hnotify_fin(void); | |
19272 | + | |
7f207e10 | 19273 | +/* hfsnotify.c */ |
4a4d8108 AM |
19274 | +extern const struct au_hnotify_op au_hnotify_op; |
19275 | + | |
19276 | +static inline | |
19277 | +void au_hn_init(struct au_hinode *hinode) | |
19278 | +{ | |
19279 | + hinode->hi_notify = NULL; | |
1308ab2a | 19280 | +} |
19281 | + | |
53392da6 AM |
19282 | +static inline struct au_hnotify *au_hn(struct au_hinode *hinode) |
19283 | +{ | |
19284 | + return hinode->hi_notify; | |
19285 | +} | |
19286 | + | |
4a4d8108 | 19287 | +#else |
c1595e42 JR |
19288 | +AuStub(int, au_hn_alloc, return -EOPNOTSUPP, |
19289 | + struct au_hinode *hinode __maybe_unused, | |
19290 | + struct inode *inode __maybe_unused) | |
19291 | +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode) | |
4a4d8108 AM |
19292 | +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused) |
19293 | +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused, | |
19294 | + int do_set __maybe_unused) | |
19295 | +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused, | |
19296 | + unsigned int flags __maybe_unused) | |
027c5e7a AM |
19297 | +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused, |
19298 | + struct au_branch *br __maybe_unused, | |
19299 | + int perm __maybe_unused) | |
19300 | +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused, | |
19301 | + int perm __maybe_unused) | |
19302 | +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused) | |
4a4d8108 AM |
19303 | +AuStubInt0(__init au_hnotify_init, void) |
19304 | +AuStubVoid(au_hnotify_fin, void) | |
19305 | +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused) | |
19306 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
19307 | + | |
19308 | +static inline void au_hn_suspend(struct au_hinode *hdir) | |
19309 | +{ | |
19310 | + au_hn_ctl(hdir, /*do_set*/0); | |
1308ab2a | 19311 | +} |
19312 | + | |
4a4d8108 | 19313 | +static inline void au_hn_resume(struct au_hinode *hdir) |
1308ab2a | 19314 | +{ |
4a4d8108 AM |
19315 | + au_hn_ctl(hdir, /*do_set*/1); |
19316 | +} | |
1308ab2a | 19317 | + |
5afbbe0d | 19318 | +static inline void au_hn_inode_lock(struct au_hinode *hdir) |
4a4d8108 | 19319 | +{ |
febd17d6 | 19320 | + inode_lock(hdir->hi_inode); |
4a4d8108 AM |
19321 | + au_hn_suspend(hdir); |
19322 | +} | |
dece6358 | 19323 | + |
5afbbe0d | 19324 | +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir, |
4a4d8108 AM |
19325 | + unsigned int sc __maybe_unused) |
19326 | +{ | |
febd17d6 | 19327 | + inode_lock_nested(hdir->hi_inode, sc); |
4a4d8108 | 19328 | + au_hn_suspend(hdir); |
1facf9fc | 19329 | +} |
1facf9fc | 19330 | + |
8b6a4947 AM |
19331 | +#if 0 /* unused */ |
19332 | +#include "vfsub.h" | |
3c1bdaff AM |
19333 | +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir, |
19334 | + unsigned int sc) | |
19335 | +{ | |
19336 | + vfsub_inode_lock_shared_nested(hdir->hi_inode, sc); | |
19337 | + au_hn_suspend(hdir); | |
19338 | +} | |
8b6a4947 | 19339 | +#endif |
3c1bdaff | 19340 | + |
5afbbe0d | 19341 | +static inline void au_hn_inode_unlock(struct au_hinode *hdir) |
4a4d8108 AM |
19342 | +{ |
19343 | + au_hn_resume(hdir); | |
febd17d6 | 19344 | + inode_unlock(hdir->hi_inode); |
4a4d8108 AM |
19345 | +} |
19346 | + | |
19347 | +#endif /* __KERNEL__ */ | |
19348 | +#endif /* __AUFS_INODE_H__ */ | |
7f207e10 AM |
19349 | diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c |
19350 | --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 19351 | +++ linux/fs/aufs/ioctl.c 2018-01-29 07:56:20.056658502 +0100 |
c1595e42 | 19352 | @@ -0,0 +1,219 @@ |
4a4d8108 | 19353 | +/* |
a2654f78 | 19354 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
19355 | + * |
19356 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19357 | + * it under the terms of the GNU General Public License as published by | |
19358 | + * the Free Software Foundation; either version 2 of the License, or | |
19359 | + * (at your option) any later version. | |
19360 | + * | |
19361 | + * This program is distributed in the hope that it will be useful, | |
19362 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19363 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19364 | + * GNU General Public License for more details. | |
19365 | + * | |
19366 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19367 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
19368 | + */ |
19369 | + | |
19370 | +/* | |
19371 | + * ioctl | |
19372 | + * plink-management and readdir in userspace. | |
19373 | + * assist the pathconf(3) wrapper library. | |
c2b27bf2 | 19374 | + * move-down |
076b876e | 19375 | + * File-based Hierarchical Storage Management. |
4a4d8108 AM |
19376 | + */ |
19377 | + | |
c2b27bf2 AM |
19378 | +#include <linux/compat.h> |
19379 | +#include <linux/file.h> | |
4a4d8108 AM |
19380 | +#include "aufs.h" |
19381 | + | |
1e00d052 | 19382 | +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg) |
4a4d8108 AM |
19383 | +{ |
19384 | + int err, fd; | |
5afbbe0d | 19385 | + aufs_bindex_t wbi, bindex, bbot; |
4a4d8108 AM |
19386 | + struct file *h_file; |
19387 | + struct super_block *sb; | |
19388 | + struct dentry *root; | |
1e00d052 AM |
19389 | + struct au_branch *br; |
19390 | + struct aufs_wbr_fd wbrfd = { | |
19391 | + .oflags = au_dir_roflags, | |
19392 | + .brid = -1 | |
19393 | + }; | |
19394 | + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY | |
19395 | + | O_NOATIME | O_CLOEXEC; | |
4a4d8108 | 19396 | + |
1e00d052 AM |
19397 | + AuDebugOn(wbrfd.oflags & ~valid); |
19398 | + | |
19399 | + if (arg) { | |
19400 | + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd)); | |
19401 | + if (unlikely(err)) { | |
19402 | + err = -EFAULT; | |
19403 | + goto out; | |
19404 | + } | |
19405 | + | |
19406 | + err = -EINVAL; | |
19407 | + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid); | |
19408 | + wbrfd.oflags |= au_dir_roflags; | |
19409 | + AuDbg("0%o\n", wbrfd.oflags); | |
19410 | + if (unlikely(wbrfd.oflags & ~valid)) | |
19411 | + goto out; | |
19412 | + } | |
19413 | + | |
2000de60 | 19414 | + fd = get_unused_fd_flags(0); |
1e00d052 AM |
19415 | + err = fd; |
19416 | + if (unlikely(fd < 0)) | |
4a4d8108 | 19417 | + goto out; |
4a4d8108 | 19418 | + |
1e00d052 | 19419 | + h_file = ERR_PTR(-EINVAL); |
4a4d8108 | 19420 | + wbi = 0; |
1e00d052 | 19421 | + br = NULL; |
4a4d8108 AM |
19422 | + sb = path->dentry->d_sb; |
19423 | + root = sb->s_root; | |
19424 | + aufs_read_lock(root, AuLock_IR); | |
5afbbe0d | 19425 | + bbot = au_sbbot(sb); |
1e00d052 AM |
19426 | + if (wbrfd.brid >= 0) { |
19427 | + wbi = au_br_index(sb, wbrfd.brid); | |
5afbbe0d | 19428 | + if (unlikely(wbi < 0 || wbi > bbot)) |
1e00d052 AM |
19429 | + goto out_unlock; |
19430 | + } | |
19431 | + | |
19432 | + h_file = ERR_PTR(-ENOENT); | |
19433 | + br = au_sbr(sb, wbi); | |
19434 | + if (!au_br_writable(br->br_perm)) { | |
19435 | + if (arg) | |
19436 | + goto out_unlock; | |
19437 | + | |
19438 | + bindex = wbi + 1; | |
19439 | + wbi = -1; | |
5afbbe0d | 19440 | + for (; bindex <= bbot; bindex++) { |
1e00d052 AM |
19441 | + br = au_sbr(sb, bindex); |
19442 | + if (au_br_writable(br->br_perm)) { | |
4a4d8108 | 19443 | + wbi = bindex; |
1e00d052 | 19444 | + br = au_sbr(sb, wbi); |
4a4d8108 AM |
19445 | + break; |
19446 | + } | |
19447 | + } | |
4a4d8108 AM |
19448 | + } |
19449 | + AuDbg("wbi %d\n", wbi); | |
1e00d052 | 19450 | + if (wbi >= 0) |
392086de AM |
19451 | + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL, |
19452 | + /*force_wr*/0); | |
1e00d052 AM |
19453 | + |
19454 | +out_unlock: | |
4a4d8108 AM |
19455 | + aufs_read_unlock(root, AuLock_IR); |
19456 | + err = PTR_ERR(h_file); | |
19457 | + if (IS_ERR(h_file)) | |
19458 | + goto out_fd; | |
19459 | + | |
5afbbe0d | 19460 | + au_br_put(br); /* cf. au_h_open() */ |
4a4d8108 AM |
19461 | + fd_install(fd, h_file); |
19462 | + err = fd; | |
19463 | + goto out; /* success */ | |
19464 | + | |
4f0767ce | 19465 | +out_fd: |
4a4d8108 | 19466 | + put_unused_fd(fd); |
4f0767ce | 19467 | +out: |
1e00d052 | 19468 | + AuTraceErr(err); |
4a4d8108 AM |
19469 | + return err; |
19470 | +} | |
19471 | + | |
19472 | +/* ---------------------------------------------------------------------- */ | |
19473 | + | |
19474 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg) | |
19475 | +{ | |
19476 | + long err; | |
c1595e42 | 19477 | + struct dentry *dentry; |
4a4d8108 AM |
19478 | + |
19479 | + switch (cmd) { | |
4a4d8108 AM |
19480 | + case AUFS_CTL_RDU: |
19481 | + case AUFS_CTL_RDU_INO: | |
19482 | + err = au_rdu_ioctl(file, cmd, arg); | |
19483 | + break; | |
19484 | + | |
19485 | + case AUFS_CTL_WBR_FD: | |
1e00d052 | 19486 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
19487 | + break; |
19488 | + | |
027c5e7a AM |
19489 | + case AUFS_CTL_IBUSY: |
19490 | + err = au_ibusy_ioctl(file, arg); | |
19491 | + break; | |
19492 | + | |
076b876e AM |
19493 | + case AUFS_CTL_BRINFO: |
19494 | + err = au_brinfo_ioctl(file, arg); | |
19495 | + break; | |
19496 | + | |
19497 | + case AUFS_CTL_FHSM_FD: | |
2000de60 | 19498 | + dentry = file->f_path.dentry; |
c1595e42 JR |
19499 | + if (IS_ROOT(dentry)) |
19500 | + err = au_fhsm_fd(dentry->d_sb, arg); | |
19501 | + else | |
19502 | + err = -ENOTTY; | |
076b876e AM |
19503 | + break; |
19504 | + | |
4a4d8108 AM |
19505 | + default: |
19506 | + /* do not call the lower */ | |
19507 | + AuDbg("0x%x\n", cmd); | |
19508 | + err = -ENOTTY; | |
19509 | + } | |
19510 | + | |
19511 | + AuTraceErr(err); | |
19512 | + return err; | |
19513 | +} | |
19514 | + | |
19515 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg) | |
19516 | +{ | |
19517 | + long err; | |
19518 | + | |
19519 | + switch (cmd) { | |
c2b27bf2 | 19520 | + case AUFS_CTL_MVDOWN: |
2000de60 | 19521 | + err = au_mvdown(file->f_path.dentry, (void __user *)arg); |
c2b27bf2 AM |
19522 | + break; |
19523 | + | |
4a4d8108 | 19524 | + case AUFS_CTL_WBR_FD: |
1e00d052 | 19525 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
19526 | + break; |
19527 | + | |
19528 | + default: | |
19529 | + /* do not call the lower */ | |
19530 | + AuDbg("0x%x\n", cmd); | |
19531 | + err = -ENOTTY; | |
19532 | + } | |
19533 | + | |
19534 | + AuTraceErr(err); | |
19535 | + return err; | |
19536 | +} | |
b752ccd1 AM |
19537 | + |
19538 | +#ifdef CONFIG_COMPAT | |
19539 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
19540 | + unsigned long arg) | |
19541 | +{ | |
19542 | + long err; | |
19543 | + | |
19544 | + switch (cmd) { | |
19545 | + case AUFS_CTL_RDU: | |
19546 | + case AUFS_CTL_RDU_INO: | |
19547 | + err = au_rdu_compat_ioctl(file, cmd, arg); | |
19548 | + break; | |
19549 | + | |
027c5e7a AM |
19550 | + case AUFS_CTL_IBUSY: |
19551 | + err = au_ibusy_compat_ioctl(file, arg); | |
19552 | + break; | |
19553 | + | |
076b876e AM |
19554 | + case AUFS_CTL_BRINFO: |
19555 | + err = au_brinfo_compat_ioctl(file, arg); | |
19556 | + break; | |
19557 | + | |
b752ccd1 AM |
19558 | + default: |
19559 | + err = aufs_ioctl_dir(file, cmd, arg); | |
19560 | + } | |
19561 | + | |
19562 | + AuTraceErr(err); | |
19563 | + return err; | |
19564 | +} | |
19565 | + | |
b752ccd1 AM |
19566 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
19567 | + unsigned long arg) | |
19568 | +{ | |
19569 | + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg)); | |
19570 | +} | |
19571 | +#endif | |
7f207e10 AM |
19572 | diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c |
19573 | --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 19574 | +++ linux/fs/aufs/i_op_add.c 2018-01-29 07:56:20.056658502 +0100 |
521ced18 | 19575 | @@ -0,0 +1,920 @@ |
4a4d8108 | 19576 | +/* |
a2654f78 | 19577 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
19578 | + * |
19579 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19580 | + * it under the terms of the GNU General Public License as published by | |
19581 | + * the Free Software Foundation; either version 2 of the License, or | |
19582 | + * (at your option) any later version. | |
19583 | + * | |
19584 | + * This program is distributed in the hope that it will be useful, | |
19585 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19586 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19587 | + * GNU General Public License for more details. | |
19588 | + * | |
19589 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19590 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
19591 | + */ |
19592 | + | |
19593 | +/* | |
19594 | + * inode operations (add entry) | |
19595 | + */ | |
19596 | + | |
19597 | +#include "aufs.h" | |
19598 | + | |
19599 | +/* | |
19600 | + * final procedure of adding a new entry, except link(2). | |
19601 | + * remove whiteout, instantiate, copyup the parent dir's times and size | |
19602 | + * and update version. | |
19603 | + * if it failed, re-create the removed whiteout. | |
19604 | + */ | |
19605 | +static int epilog(struct inode *dir, aufs_bindex_t bindex, | |
19606 | + struct dentry *wh_dentry, struct dentry *dentry) | |
19607 | +{ | |
19608 | + int err, rerr; | |
19609 | + aufs_bindex_t bwh; | |
19610 | + struct path h_path; | |
076b876e | 19611 | + struct super_block *sb; |
4a4d8108 AM |
19612 | + struct inode *inode, *h_dir; |
19613 | + struct dentry *wh; | |
19614 | + | |
19615 | + bwh = -1; | |
076b876e | 19616 | + sb = dir->i_sb; |
4a4d8108 | 19617 | + if (wh_dentry) { |
5527c038 | 19618 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
4a4d8108 AM |
19619 | + IMustLock(h_dir); |
19620 | + AuDebugOn(au_h_iptr(dir, bindex) != h_dir); | |
19621 | + bwh = au_dbwh(dentry); | |
19622 | + h_path.dentry = wh_dentry; | |
076b876e | 19623 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
4a4d8108 AM |
19624 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, |
19625 | + dentry); | |
19626 | + if (unlikely(err)) | |
19627 | + goto out; | |
19628 | + } | |
19629 | + | |
19630 | + inode = au_new_inode(dentry, /*must_new*/1); | |
19631 | + if (!IS_ERR(inode)) { | |
19632 | + d_instantiate(dentry, inode); | |
5527c038 | 19633 | + dir = d_inode(dentry->d_parent); /* dir inode is locked */ |
4a4d8108 | 19634 | + IMustLock(dir); |
b912730e | 19635 | + au_dir_ts(dir, bindex); |
4a4d8108 | 19636 | + dir->i_version++; |
076b876e | 19637 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
4a4d8108 AM |
19638 | + return 0; /* success */ |
19639 | + } | |
19640 | + | |
19641 | + err = PTR_ERR(inode); | |
19642 | + if (!wh_dentry) | |
19643 | + goto out; | |
19644 | + | |
19645 | + /* revert */ | |
19646 | + /* dir inode is locked */ | |
19647 | + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent); | |
19648 | + rerr = PTR_ERR(wh); | |
19649 | + if (IS_ERR(wh)) { | |
523b37e3 AM |
19650 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", |
19651 | + dentry, err, rerr); | |
4a4d8108 AM |
19652 | + err = -EIO; |
19653 | + } else | |
19654 | + dput(wh); | |
19655 | + | |
4f0767ce | 19656 | +out: |
4a4d8108 AM |
19657 | + return err; |
19658 | +} | |
19659 | + | |
027c5e7a AM |
19660 | +static int au_d_may_add(struct dentry *dentry) |
19661 | +{ | |
19662 | + int err; | |
19663 | + | |
19664 | + err = 0; | |
19665 | + if (unlikely(d_unhashed(dentry))) | |
19666 | + err = -ENOENT; | |
5527c038 | 19667 | + if (unlikely(d_really_is_positive(dentry))) |
027c5e7a AM |
19668 | + err = -EEXIST; |
19669 | + return err; | |
19670 | +} | |
19671 | + | |
4a4d8108 AM |
19672 | +/* |
19673 | + * simple tests for the adding inode operations. | |
19674 | + * following the checks in vfs, plus the parent-child relationship. | |
19675 | + */ | |
19676 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
19677 | + struct dentry *h_parent, int isdir) | |
19678 | +{ | |
19679 | + int err; | |
19680 | + umode_t h_mode; | |
19681 | + struct dentry *h_dentry; | |
19682 | + struct inode *h_inode; | |
19683 | + | |
19684 | + err = -ENAMETOOLONG; | |
19685 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
19686 | + goto out; | |
19687 | + | |
19688 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 19689 | + if (d_really_is_negative(dentry)) { |
4a4d8108 | 19690 | + err = -EEXIST; |
5527c038 | 19691 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
19692 | + goto out; |
19693 | + } else { | |
19694 | + /* rename(2) case */ | |
19695 | + err = -EIO; | |
5527c038 JR |
19696 | + if (unlikely(d_is_negative(h_dentry))) |
19697 | + goto out; | |
19698 | + h_inode = d_inode(h_dentry); | |
19699 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 AM |
19700 | + goto out; |
19701 | + | |
19702 | + h_mode = h_inode->i_mode; | |
19703 | + if (!isdir) { | |
19704 | + err = -EISDIR; | |
19705 | + if (unlikely(S_ISDIR(h_mode))) | |
19706 | + goto out; | |
19707 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
19708 | + err = -ENOTDIR; | |
19709 | + goto out; | |
19710 | + } | |
19711 | + } | |
19712 | + | |
19713 | + err = 0; | |
19714 | + /* expected parent dir is locked */ | |
19715 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
19716 | + err = -EIO; | |
19717 | + | |
4f0767ce | 19718 | +out: |
4a4d8108 AM |
19719 | + AuTraceErr(err); |
19720 | + return err; | |
19721 | +} | |
19722 | + | |
19723 | +/* | |
19724 | + * initial procedure of adding a new entry. | |
19725 | + * prepare writable branch and the parent dir, lock it, | |
19726 | + * and lookup whiteout for the new entry. | |
19727 | + */ | |
19728 | +static struct dentry* | |
19729 | +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt, | |
19730 | + struct dentry *src_dentry, struct au_pin *pin, | |
19731 | + struct au_wr_dir_args *wr_dir_args) | |
19732 | +{ | |
19733 | + struct dentry *wh_dentry, *h_parent; | |
19734 | + struct super_block *sb; | |
19735 | + struct au_branch *br; | |
19736 | + int err; | |
19737 | + unsigned int udba; | |
19738 | + aufs_bindex_t bcpup; | |
19739 | + | |
523b37e3 | 19740 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
19741 | + |
19742 | + err = au_wr_dir(dentry, src_dentry, wr_dir_args); | |
19743 | + bcpup = err; | |
19744 | + wh_dentry = ERR_PTR(err); | |
19745 | + if (unlikely(err < 0)) | |
19746 | + goto out; | |
19747 | + | |
19748 | + sb = dentry->d_sb; | |
19749 | + udba = au_opt_udba(sb); | |
19750 | + err = au_pin(pin, dentry, bcpup, udba, | |
19751 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
19752 | + wh_dentry = ERR_PTR(err); | |
19753 | + if (unlikely(err)) | |
19754 | + goto out; | |
19755 | + | |
19756 | + h_parent = au_pinned_h_parent(pin); | |
19757 | + if (udba != AuOpt_UDBA_NONE | |
5afbbe0d | 19758 | + && au_dbtop(dentry) == bcpup) |
4a4d8108 AM |
19759 | + err = au_may_add(dentry, bcpup, h_parent, |
19760 | + au_ftest_wrdir(wr_dir_args->flags, ISDIR)); | |
19761 | + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
19762 | + err = -ENAMETOOLONG; | |
19763 | + wh_dentry = ERR_PTR(err); | |
19764 | + if (unlikely(err)) | |
19765 | + goto out_unpin; | |
19766 | + | |
19767 | + br = au_sbr(sb, bcpup); | |
19768 | + if (dt) { | |
19769 | + struct path tmp = { | |
19770 | + .dentry = h_parent, | |
86dc4139 | 19771 | + .mnt = au_br_mnt(br) |
4a4d8108 AM |
19772 | + }; |
19773 | + au_dtime_store(dt, au_pinned_parent(pin), &tmp); | |
19774 | + } | |
19775 | + | |
19776 | + wh_dentry = NULL; | |
19777 | + if (bcpup != au_dbwh(dentry)) | |
19778 | + goto out; /* success */ | |
19779 | + | |
2000de60 JR |
19780 | + /* |
19781 | + * ENAMETOOLONG here means that if we allowed create such name, then it | |
19782 | + * would not be able to removed in the future. So we don't allow such | |
19783 | + * name here and we don't handle ENAMETOOLONG differently here. | |
19784 | + */ | |
4a4d8108 AM |
19785 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br); |
19786 | + | |
4f0767ce | 19787 | +out_unpin: |
4a4d8108 AM |
19788 | + if (IS_ERR(wh_dentry)) |
19789 | + au_unpin(pin); | |
4f0767ce | 19790 | +out: |
4a4d8108 AM |
19791 | + return wh_dentry; |
19792 | +} | |
19793 | + | |
19794 | +/* ---------------------------------------------------------------------- */ | |
19795 | + | |
19796 | +enum { Mknod, Symlink, Creat }; | |
19797 | +struct simple_arg { | |
19798 | + int type; | |
19799 | + union { | |
19800 | + struct { | |
b912730e AM |
19801 | + umode_t mode; |
19802 | + bool want_excl; | |
19803 | + bool try_aopen; | |
19804 | + struct vfsub_aopen_args *aopen; | |
4a4d8108 AM |
19805 | + } c; |
19806 | + struct { | |
19807 | + const char *symname; | |
19808 | + } s; | |
19809 | + struct { | |
7eafdf33 | 19810 | + umode_t mode; |
4a4d8108 AM |
19811 | + dev_t dev; |
19812 | + } m; | |
19813 | + } u; | |
19814 | +}; | |
19815 | + | |
19816 | +static int add_simple(struct inode *dir, struct dentry *dentry, | |
19817 | + struct simple_arg *arg) | |
19818 | +{ | |
076b876e | 19819 | + int err, rerr; |
5afbbe0d | 19820 | + aufs_bindex_t btop; |
4a4d8108 | 19821 | + unsigned char created; |
b912730e AM |
19822 | + const unsigned char try_aopen |
19823 | + = (arg->type == Creat && arg->u.c.try_aopen); | |
4a4d8108 AM |
19824 | + struct dentry *wh_dentry, *parent; |
19825 | + struct inode *h_dir; | |
b912730e AM |
19826 | + struct super_block *sb; |
19827 | + struct au_branch *br; | |
c2b27bf2 AM |
19828 | + /* to reuduce stack size */ |
19829 | + struct { | |
19830 | + struct au_dtime dt; | |
19831 | + struct au_pin pin; | |
19832 | + struct path h_path; | |
19833 | + struct au_wr_dir_args wr_dir_args; | |
19834 | + } *a; | |
4a4d8108 | 19835 | + |
523b37e3 | 19836 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
19837 | + IMustLock(dir); |
19838 | + | |
c2b27bf2 AM |
19839 | + err = -ENOMEM; |
19840 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19841 | + if (unlikely(!a)) | |
19842 | + goto out; | |
19843 | + a->wr_dir_args.force_btgt = -1; | |
19844 | + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY; | |
19845 | + | |
4a4d8108 | 19846 | + parent = dentry->d_parent; /* dir inode is locked */ |
b912730e AM |
19847 | + if (!try_aopen) { |
19848 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); | |
19849 | + if (unlikely(err)) | |
19850 | + goto out_free; | |
19851 | + } | |
027c5e7a AM |
19852 | + err = au_d_may_add(dentry); |
19853 | + if (unlikely(err)) | |
19854 | + goto out_unlock; | |
b912730e AM |
19855 | + if (!try_aopen) |
19856 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
19857 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, |
19858 | + &a->pin, &a->wr_dir_args); | |
4a4d8108 AM |
19859 | + err = PTR_ERR(wh_dentry); |
19860 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 19861 | + goto out_parent; |
4a4d8108 | 19862 | + |
5afbbe0d | 19863 | + btop = au_dbtop(dentry); |
b912730e | 19864 | + sb = dentry->d_sb; |
5afbbe0d AM |
19865 | + br = au_sbr(sb, btop); |
19866 | + a->h_path.dentry = au_h_dptr(dentry, btop); | |
b912730e | 19867 | + a->h_path.mnt = au_br_mnt(br); |
c2b27bf2 | 19868 | + h_dir = au_pinned_h_dir(&a->pin); |
4a4d8108 AM |
19869 | + switch (arg->type) { |
19870 | + case Creat: | |
b912730e AM |
19871 | + err = 0; |
19872 | + if (!try_aopen || !h_dir->i_op->atomic_open) | |
19873 | + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode, | |
19874 | + arg->u.c.want_excl); | |
19875 | + else | |
19876 | + err = vfsub_atomic_open(h_dir, a->h_path.dentry, | |
19877 | + arg->u.c.aopen, br); | |
4a4d8108 AM |
19878 | + break; |
19879 | + case Symlink: | |
c2b27bf2 | 19880 | + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname); |
4a4d8108 AM |
19881 | + break; |
19882 | + case Mknod: | |
c2b27bf2 AM |
19883 | + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode, |
19884 | + arg->u.m.dev); | |
4a4d8108 AM |
19885 | + break; |
19886 | + default: | |
19887 | + BUG(); | |
19888 | + } | |
19889 | + created = !err; | |
19890 | + if (!err) | |
5afbbe0d | 19891 | + err = epilog(dir, btop, wh_dentry, dentry); |
4a4d8108 AM |
19892 | + |
19893 | + /* revert */ | |
5527c038 | 19894 | + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) { |
523b37e3 AM |
19895 | + /* no delegation since it is just created */ |
19896 | + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL, | |
19897 | + /*force*/0); | |
4a4d8108 | 19898 | + if (rerr) { |
523b37e3 AM |
19899 | + AuIOErr("%pd revert failure(%d, %d)\n", |
19900 | + dentry, err, rerr); | |
4a4d8108 AM |
19901 | + err = -EIO; |
19902 | + } | |
c2b27bf2 | 19903 | + au_dtime_revert(&a->dt); |
4a4d8108 AM |
19904 | + } |
19905 | + | |
b912730e AM |
19906 | + if (!err && try_aopen && !h_dir->i_op->atomic_open) |
19907 | + *arg->u.c.aopen->opened |= FILE_CREATED; | |
19908 | + | |
c2b27bf2 | 19909 | + au_unpin(&a->pin); |
4a4d8108 AM |
19910 | + dput(wh_dentry); |
19911 | + | |
027c5e7a | 19912 | +out_parent: |
b912730e AM |
19913 | + if (!try_aopen) |
19914 | + di_write_unlock(parent); | |
027c5e7a | 19915 | +out_unlock: |
4a4d8108 | 19916 | + if (unlikely(err)) { |
5afbbe0d | 19917 | + au_update_dbtop(dentry); |
4a4d8108 AM |
19918 | + d_drop(dentry); |
19919 | + } | |
b912730e AM |
19920 | + if (!try_aopen) |
19921 | + aufs_read_unlock(dentry, AuLock_DW); | |
c2b27bf2 | 19922 | +out_free: |
1c60b727 | 19923 | + kfree(a); |
027c5e7a | 19924 | +out: |
4a4d8108 AM |
19925 | + return err; |
19926 | +} | |
19927 | + | |
7eafdf33 AM |
19928 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
19929 | + dev_t dev) | |
4a4d8108 AM |
19930 | +{ |
19931 | + struct simple_arg arg = { | |
19932 | + .type = Mknod, | |
19933 | + .u.m = { | |
19934 | + .mode = mode, | |
19935 | + .dev = dev | |
19936 | + } | |
19937 | + }; | |
19938 | + return add_simple(dir, dentry, &arg); | |
19939 | +} | |
19940 | + | |
19941 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |
19942 | +{ | |
19943 | + struct simple_arg arg = { | |
19944 | + .type = Symlink, | |
19945 | + .u.s.symname = symname | |
19946 | + }; | |
19947 | + return add_simple(dir, dentry, &arg); | |
19948 | +} | |
19949 | + | |
7eafdf33 | 19950 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 19951 | + bool want_excl) |
4a4d8108 AM |
19952 | +{ |
19953 | + struct simple_arg arg = { | |
19954 | + .type = Creat, | |
19955 | + .u.c = { | |
b4510431 AM |
19956 | + .mode = mode, |
19957 | + .want_excl = want_excl | |
4a4d8108 AM |
19958 | + } |
19959 | + }; | |
19960 | + return add_simple(dir, dentry, &arg); | |
19961 | +} | |
19962 | + | |
b912730e AM |
19963 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, |
19964 | + struct vfsub_aopen_args *aopen_args) | |
19965 | +{ | |
19966 | + struct simple_arg arg = { | |
19967 | + .type = Creat, | |
19968 | + .u.c = { | |
19969 | + .mode = aopen_args->create_mode, | |
19970 | + .want_excl = aopen_args->open_flag & O_EXCL, | |
19971 | + .try_aopen = true, | |
19972 | + .aopen = aopen_args | |
19973 | + } | |
19974 | + }; | |
19975 | + return add_simple(dir, dentry, &arg); | |
19976 | +} | |
19977 | + | |
38d290e6 JR |
19978 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
19979 | +{ | |
19980 | + int err; | |
19981 | + aufs_bindex_t bindex; | |
19982 | + struct super_block *sb; | |
19983 | + struct dentry *parent, *h_parent, *h_dentry; | |
19984 | + struct inode *h_dir, *inode; | |
19985 | + struct vfsmount *h_mnt; | |
19986 | + struct au_wr_dir_args wr_dir_args = { | |
19987 | + .force_btgt = -1, | |
19988 | + .flags = AuWrDir_TMPFILE | |
19989 | + }; | |
19990 | + | |
19991 | + /* copy-up may happen */ | |
febd17d6 | 19992 | + inode_lock(dir); |
38d290e6 JR |
19993 | + |
19994 | + sb = dir->i_sb; | |
19995 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
19996 | + if (unlikely(err)) | |
19997 | + goto out; | |
19998 | + | |
19999 | + err = au_di_init(dentry); | |
20000 | + if (unlikely(err)) | |
20001 | + goto out_si; | |
20002 | + | |
20003 | + err = -EBUSY; | |
20004 | + parent = d_find_any_alias(dir); | |
20005 | + AuDebugOn(!parent); | |
20006 | + di_write_lock_parent(parent); | |
5527c038 | 20007 | + if (unlikely(d_inode(parent) != dir)) |
38d290e6 JR |
20008 | + goto out_parent; |
20009 | + | |
20010 | + err = au_digen_test(parent, au_sigen(sb)); | |
20011 | + if (unlikely(err)) | |
20012 | + goto out_parent; | |
20013 | + | |
5afbbe0d AM |
20014 | + bindex = au_dbtop(parent); |
20015 | + au_set_dbtop(dentry, bindex); | |
20016 | + au_set_dbbot(dentry, bindex); | |
38d290e6 JR |
20017 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
20018 | + bindex = err; | |
20019 | + if (unlikely(err < 0)) | |
20020 | + goto out_parent; | |
20021 | + | |
20022 | + err = -EOPNOTSUPP; | |
20023 | + h_dir = au_h_iptr(dir, bindex); | |
20024 | + if (unlikely(!h_dir->i_op->tmpfile)) | |
20025 | + goto out_parent; | |
20026 | + | |
20027 | + h_mnt = au_sbr_mnt(sb, bindex); | |
20028 | + err = vfsub_mnt_want_write(h_mnt); | |
20029 | + if (unlikely(err)) | |
20030 | + goto out_parent; | |
20031 | + | |
20032 | + h_parent = au_h_dptr(parent, bindex); | |
521ced18 JR |
20033 | + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0); |
20034 | + if (IS_ERR(h_dentry)) { | |
20035 | + err = PTR_ERR(h_dentry); | |
38d290e6 | 20036 | + goto out_mnt; |
521ced18 | 20037 | + } |
38d290e6 | 20038 | + |
5afbbe0d AM |
20039 | + au_set_dbtop(dentry, bindex); |
20040 | + au_set_dbbot(dentry, bindex); | |
38d290e6 JR |
20041 | + au_set_h_dptr(dentry, bindex, dget(h_dentry)); |
20042 | + inode = au_new_inode(dentry, /*must_new*/1); | |
20043 | + if (IS_ERR(inode)) { | |
20044 | + err = PTR_ERR(inode); | |
20045 | + au_set_h_dptr(dentry, bindex, NULL); | |
5afbbe0d AM |
20046 | + au_set_dbtop(dentry, -1); |
20047 | + au_set_dbbot(dentry, -1); | |
38d290e6 JR |
20048 | + } else { |
20049 | + if (!inode->i_nlink) | |
20050 | + set_nlink(inode, 1); | |
20051 | + d_tmpfile(dentry, inode); | |
20052 | + au_di(dentry)->di_tmpfile = 1; | |
20053 | + | |
20054 | + /* update without i_mutex */ | |
5afbbe0d | 20055 | + if (au_ibtop(dir) == au_dbtop(dentry)) |
38d290e6 JR |
20056 | + au_cpup_attr_timesizes(dir); |
20057 | + } | |
38d290e6 | 20058 | + dput(h_dentry); |
521ced18 | 20059 | + |
38d290e6 JR |
20060 | +out_mnt: |
20061 | + vfsub_mnt_drop_write(h_mnt); | |
20062 | +out_parent: | |
20063 | + di_write_unlock(parent); | |
20064 | + dput(parent); | |
20065 | + di_write_unlock(dentry); | |
5afbbe0d | 20066 | + if (unlikely(err)) { |
38d290e6 JR |
20067 | + au_di_fin(dentry); |
20068 | + dentry->d_fsdata = NULL; | |
20069 | + } | |
20070 | +out_si: | |
20071 | + si_read_unlock(sb); | |
20072 | +out: | |
febd17d6 | 20073 | + inode_unlock(dir); |
38d290e6 JR |
20074 | + return err; |
20075 | +} | |
20076 | + | |
4a4d8108 AM |
20077 | +/* ---------------------------------------------------------------------- */ |
20078 | + | |
20079 | +struct au_link_args { | |
20080 | + aufs_bindex_t bdst, bsrc; | |
20081 | + struct au_pin pin; | |
20082 | + struct path h_path; | |
20083 | + struct dentry *src_parent, *parent; | |
20084 | +}; | |
20085 | + | |
20086 | +static int au_cpup_before_link(struct dentry *src_dentry, | |
20087 | + struct au_link_args *a) | |
20088 | +{ | |
20089 | + int err; | |
20090 | + struct dentry *h_src_dentry; | |
c2b27bf2 AM |
20091 | + struct au_cp_generic cpg = { |
20092 | + .dentry = src_dentry, | |
20093 | + .bdst = a->bdst, | |
20094 | + .bsrc = a->bsrc, | |
20095 | + .len = -1, | |
20096 | + .pin = &a->pin, | |
20097 | + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */ | |
20098 | + }; | |
4a4d8108 AM |
20099 | + |
20100 | + di_read_lock_parent(a->src_parent, AuLock_IR); | |
20101 | + err = au_test_and_cpup_dirs(src_dentry, a->bdst); | |
20102 | + if (unlikely(err)) | |
20103 | + goto out; | |
20104 | + | |
20105 | + h_src_dentry = au_h_dptr(src_dentry, a->bsrc); | |
4a4d8108 AM |
20106 | + err = au_pin(&a->pin, src_dentry, a->bdst, |
20107 | + au_opt_udba(src_dentry->d_sb), | |
20108 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
20109 | + if (unlikely(err)) | |
20110 | + goto out; | |
367653fa | 20111 | + |
c2b27bf2 | 20112 | + err = au_sio_cpup_simple(&cpg); |
4a4d8108 AM |
20113 | + au_unpin(&a->pin); |
20114 | + | |
4f0767ce | 20115 | +out: |
4a4d8108 AM |
20116 | + di_read_unlock(a->src_parent, AuLock_IR); |
20117 | + return err; | |
20118 | +} | |
20119 | + | |
86dc4139 AM |
20120 | +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry, |
20121 | + struct au_link_args *a) | |
4a4d8108 AM |
20122 | +{ |
20123 | + int err; | |
20124 | + unsigned char plink; | |
5afbbe0d | 20125 | + aufs_bindex_t bbot; |
4a4d8108 | 20126 | + struct dentry *h_src_dentry; |
523b37e3 | 20127 | + struct inode *h_inode, *inode, *delegated; |
4a4d8108 AM |
20128 | + struct super_block *sb; |
20129 | + struct file *h_file; | |
20130 | + | |
20131 | + plink = 0; | |
20132 | + h_inode = NULL; | |
20133 | + sb = src_dentry->d_sb; | |
5527c038 | 20134 | + inode = d_inode(src_dentry); |
5afbbe0d | 20135 | + if (au_ibtop(inode) <= a->bdst) |
4a4d8108 AM |
20136 | + h_inode = au_h_iptr(inode, a->bdst); |
20137 | + if (!h_inode || !h_inode->i_nlink) { | |
20138 | + /* copyup src_dentry as the name of dentry. */ | |
5afbbe0d AM |
20139 | + bbot = au_dbbot(dentry); |
20140 | + if (bbot < a->bsrc) | |
20141 | + au_set_dbbot(dentry, a->bsrc); | |
86dc4139 AM |
20142 | + au_set_h_dptr(dentry, a->bsrc, |
20143 | + dget(au_h_dptr(src_dentry, a->bsrc))); | |
20144 | + dget(a->h_path.dentry); | |
20145 | + au_set_h_dptr(dentry, a->bdst, NULL); | |
c1595e42 JR |
20146 | + AuDbg("temporary d_inode...\n"); |
20147 | + spin_lock(&dentry->d_lock); | |
5527c038 | 20148 | + dentry->d_inode = d_inode(src_dentry); /* tmp */ |
c1595e42 | 20149 | + spin_unlock(&dentry->d_lock); |
392086de | 20150 | + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0); |
86dc4139 | 20151 | + if (IS_ERR(h_file)) |
4a4d8108 | 20152 | + err = PTR_ERR(h_file); |
86dc4139 | 20153 | + else { |
c2b27bf2 AM |
20154 | + struct au_cp_generic cpg = { |
20155 | + .dentry = dentry, | |
20156 | + .bdst = a->bdst, | |
20157 | + .bsrc = -1, | |
20158 | + .len = -1, | |
20159 | + .pin = &a->pin, | |
20160 | + .flags = AuCpup_KEEPLINO | |
20161 | + }; | |
20162 | + err = au_sio_cpup_simple(&cpg); | |
86dc4139 AM |
20163 | + au_h_open_post(dentry, a->bsrc, h_file); |
20164 | + if (!err) { | |
20165 | + dput(a->h_path.dentry); | |
20166 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
20167 | + } else | |
20168 | + au_set_h_dptr(dentry, a->bdst, | |
20169 | + a->h_path.dentry); | |
20170 | + } | |
c1595e42 | 20171 | + spin_lock(&dentry->d_lock); |
86dc4139 | 20172 | + dentry->d_inode = NULL; /* restore */ |
c1595e42 JR |
20173 | + spin_unlock(&dentry->d_lock); |
20174 | + AuDbg("temporary d_inode...done\n"); | |
86dc4139 | 20175 | + au_set_h_dptr(dentry, a->bsrc, NULL); |
5afbbe0d | 20176 | + au_set_dbbot(dentry, bbot); |
4a4d8108 AM |
20177 | + } else { |
20178 | + /* the inode of src_dentry already exists on a.bdst branch */ | |
20179 | + h_src_dentry = d_find_alias(h_inode); | |
20180 | + if (!h_src_dentry && au_plink_test(inode)) { | |
20181 | + plink = 1; | |
20182 | + h_src_dentry = au_plink_lkup(inode, a->bdst); | |
20183 | + err = PTR_ERR(h_src_dentry); | |
20184 | + if (IS_ERR(h_src_dentry)) | |
20185 | + goto out; | |
20186 | + | |
5527c038 | 20187 | + if (unlikely(d_is_negative(h_src_dentry))) { |
4a4d8108 AM |
20188 | + dput(h_src_dentry); |
20189 | + h_src_dentry = NULL; | |
20190 | + } | |
20191 | + | |
20192 | + } | |
20193 | + if (h_src_dentry) { | |
523b37e3 | 20194 | + delegated = NULL; |
4a4d8108 | 20195 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
20196 | + &a->h_path, &delegated); |
20197 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20198 | + pr_warn("cannot retry for NFSv4 delegation" | |
20199 | + " for an internal link\n"); | |
20200 | + iput(delegated); | |
20201 | + } | |
4a4d8108 AM |
20202 | + dput(h_src_dentry); |
20203 | + } else { | |
20204 | + AuIOErr("no dentry found for hi%lu on b%d\n", | |
20205 | + h_inode->i_ino, a->bdst); | |
20206 | + err = -EIO; | |
20207 | + } | |
20208 | + } | |
20209 | + | |
20210 | + if (!err && !plink) | |
20211 | + au_plink_append(inode, a->bdst, a->h_path.dentry); | |
20212 | + | |
20213 | +out: | |
2cbb1c4b | 20214 | + AuTraceErr(err); |
4a4d8108 AM |
20215 | + return err; |
20216 | +} | |
20217 | + | |
20218 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, | |
20219 | + struct dentry *dentry) | |
20220 | +{ | |
20221 | + int err, rerr; | |
20222 | + struct au_dtime dt; | |
20223 | + struct au_link_args *a; | |
20224 | + struct dentry *wh_dentry, *h_src_dentry; | |
523b37e3 | 20225 | + struct inode *inode, *delegated; |
4a4d8108 AM |
20226 | + struct super_block *sb; |
20227 | + struct au_wr_dir_args wr_dir_args = { | |
20228 | + /* .force_btgt = -1, */ | |
20229 | + .flags = AuWrDir_ADD_ENTRY | |
20230 | + }; | |
20231 | + | |
20232 | + IMustLock(dir); | |
5527c038 | 20233 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
20234 | + IMustLock(inode); |
20235 | + | |
4a4d8108 AM |
20236 | + err = -ENOMEM; |
20237 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
20238 | + if (unlikely(!a)) | |
20239 | + goto out; | |
20240 | + | |
20241 | + a->parent = dentry->d_parent; /* dir inode is locked */ | |
027c5e7a AM |
20242 | + err = aufs_read_and_write_lock2(dentry, src_dentry, |
20243 | + AuLock_NOPLM | AuLock_GEN); | |
e49829fe JR |
20244 | + if (unlikely(err)) |
20245 | + goto out_kfree; | |
38d290e6 | 20246 | + err = au_d_linkable(src_dentry); |
027c5e7a AM |
20247 | + if (unlikely(err)) |
20248 | + goto out_unlock; | |
20249 | + err = au_d_may_add(dentry); | |
20250 | + if (unlikely(err)) | |
20251 | + goto out_unlock; | |
e49829fe | 20252 | + |
4a4d8108 | 20253 | + a->src_parent = dget_parent(src_dentry); |
5afbbe0d | 20254 | + wr_dir_args.force_btgt = au_ibtop(inode); |
4a4d8108 AM |
20255 | + |
20256 | + di_write_lock_parent(a->parent); | |
20257 | + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt); | |
20258 | + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin, | |
20259 | + &wr_dir_args); | |
20260 | + err = PTR_ERR(wh_dentry); | |
20261 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20262 | + goto out_parent; |
4a4d8108 AM |
20263 | + |
20264 | + err = 0; | |
20265 | + sb = dentry->d_sb; | |
5afbbe0d | 20266 | + a->bdst = au_dbtop(dentry); |
4a4d8108 AM |
20267 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); |
20268 | + a->h_path.mnt = au_sbr_mnt(sb, a->bdst); | |
5afbbe0d | 20269 | + a->bsrc = au_ibtop(inode); |
2cbb1c4b | 20270 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); |
38d290e6 JR |
20271 | + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile) |
20272 | + h_src_dentry = dget(au_hi_wh(inode, a->bsrc)); | |
2cbb1c4b | 20273 | + if (!h_src_dentry) { |
5afbbe0d | 20274 | + a->bsrc = au_dbtop(src_dentry); |
2cbb1c4b JR |
20275 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); |
20276 | + AuDebugOn(!h_src_dentry); | |
38d290e6 JR |
20277 | + } else if (IS_ERR(h_src_dentry)) { |
20278 | + err = PTR_ERR(h_src_dentry); | |
2cbb1c4b | 20279 | + goto out_parent; |
38d290e6 | 20280 | + } |
2cbb1c4b | 20281 | + |
f2c43d5f AM |
20282 | + /* |
20283 | + * aufs doesn't touch the credential so | |
20284 | + * security_dentry_create_files_as() is unnecrssary. | |
20285 | + */ | |
4a4d8108 AM |
20286 | + if (au_opt_test(au_mntflags(sb), PLINK)) { |
20287 | + if (a->bdst < a->bsrc | |
20288 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) | |
86dc4139 | 20289 | + err = au_cpup_or_link(src_dentry, dentry, a); |
523b37e3 AM |
20290 | + else { |
20291 | + delegated = NULL; | |
4a4d8108 | 20292 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
20293 | + &a->h_path, &delegated); |
20294 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20295 | + pr_warn("cannot retry for NFSv4 delegation" | |
20296 | + " for an internal link\n"); | |
20297 | + iput(delegated); | |
20298 | + } | |
20299 | + } | |
2cbb1c4b | 20300 | + dput(h_src_dentry); |
4a4d8108 AM |
20301 | + } else { |
20302 | + /* | |
20303 | + * copyup src_dentry to the branch we process, | |
20304 | + * and then link(2) to it. | |
20305 | + */ | |
2cbb1c4b | 20306 | + dput(h_src_dentry); |
4a4d8108 AM |
20307 | + if (a->bdst < a->bsrc |
20308 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) { | |
20309 | + au_unpin(&a->pin); | |
20310 | + di_write_unlock(a->parent); | |
20311 | + err = au_cpup_before_link(src_dentry, a); | |
20312 | + di_write_lock_parent(a->parent); | |
20313 | + if (!err) | |
20314 | + err = au_pin(&a->pin, dentry, a->bdst, | |
20315 | + au_opt_udba(sb), | |
20316 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
20317 | + if (unlikely(err)) | |
20318 | + goto out_wh; | |
20319 | + } | |
20320 | + if (!err) { | |
20321 | + h_src_dentry = au_h_dptr(src_dentry, a->bdst); | |
20322 | + err = -ENOENT; | |
5527c038 | 20323 | + if (h_src_dentry && d_is_positive(h_src_dentry)) { |
523b37e3 | 20324 | + delegated = NULL; |
4a4d8108 AM |
20325 | + err = vfsub_link(h_src_dentry, |
20326 | + au_pinned_h_dir(&a->pin), | |
523b37e3 AM |
20327 | + &a->h_path, &delegated); |
20328 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20329 | + pr_warn("cannot retry" | |
20330 | + " for NFSv4 delegation" | |
20331 | + " for an internal link\n"); | |
20332 | + iput(delegated); | |
20333 | + } | |
20334 | + } | |
4a4d8108 AM |
20335 | + } |
20336 | + } | |
20337 | + if (unlikely(err)) | |
20338 | + goto out_unpin; | |
20339 | + | |
20340 | + if (wh_dentry) { | |
20341 | + a->h_path.dentry = wh_dentry; | |
20342 | + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path, | |
20343 | + dentry); | |
20344 | + if (unlikely(err)) | |
20345 | + goto out_revert; | |
20346 | + } | |
20347 | + | |
b912730e | 20348 | + au_dir_ts(dir, a->bdst); |
4a4d8108 | 20349 | + dir->i_version++; |
4a4d8108 AM |
20350 | + inc_nlink(inode); |
20351 | + inode->i_ctime = dir->i_ctime; | |
027c5e7a AM |
20352 | + d_instantiate(dentry, au_igrab(inode)); |
20353 | + if (d_unhashed(a->h_path.dentry)) | |
4a4d8108 AM |
20354 | + /* some filesystem calls d_drop() */ |
20355 | + d_drop(dentry); | |
076b876e AM |
20356 | + /* some filesystems consume an inode even hardlink */ |
20357 | + au_fhsm_wrote(sb, a->bdst, /*force*/0); | |
4a4d8108 AM |
20358 | + goto out_unpin; /* success */ |
20359 | + | |
4f0767ce | 20360 | +out_revert: |
523b37e3 AM |
20361 | + /* no delegation since it is just created */ |
20362 | + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, | |
20363 | + /*delegated*/NULL, /*force*/0); | |
027c5e7a | 20364 | + if (unlikely(rerr)) { |
523b37e3 | 20365 | + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr); |
027c5e7a AM |
20366 | + err = -EIO; |
20367 | + } | |
4a4d8108 | 20368 | + au_dtime_revert(&dt); |
4f0767ce | 20369 | +out_unpin: |
4a4d8108 | 20370 | + au_unpin(&a->pin); |
4f0767ce | 20371 | +out_wh: |
4a4d8108 | 20372 | + dput(wh_dentry); |
027c5e7a AM |
20373 | +out_parent: |
20374 | + di_write_unlock(a->parent); | |
20375 | + dput(a->src_parent); | |
4f0767ce | 20376 | +out_unlock: |
4a4d8108 | 20377 | + if (unlikely(err)) { |
5afbbe0d | 20378 | + au_update_dbtop(dentry); |
4a4d8108 AM |
20379 | + d_drop(dentry); |
20380 | + } | |
4a4d8108 | 20381 | + aufs_read_and_write_unlock2(dentry, src_dentry); |
e49829fe | 20382 | +out_kfree: |
1c60b727 | 20383 | + kfree(a); |
4f0767ce | 20384 | +out: |
86dc4139 | 20385 | + AuTraceErr(err); |
4a4d8108 AM |
20386 | + return err; |
20387 | +} | |
20388 | + | |
7eafdf33 | 20389 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
4a4d8108 AM |
20390 | +{ |
20391 | + int err, rerr; | |
20392 | + aufs_bindex_t bindex; | |
20393 | + unsigned char diropq; | |
20394 | + struct path h_path; | |
20395 | + struct dentry *wh_dentry, *parent, *opq_dentry; | |
febd17d6 | 20396 | + struct inode *h_inode; |
4a4d8108 AM |
20397 | + struct super_block *sb; |
20398 | + struct { | |
20399 | + struct au_pin pin; | |
20400 | + struct au_dtime dt; | |
20401 | + } *a; /* reduce the stack usage */ | |
20402 | + struct au_wr_dir_args wr_dir_args = { | |
20403 | + .force_btgt = -1, | |
20404 | + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR | |
20405 | + }; | |
20406 | + | |
20407 | + IMustLock(dir); | |
20408 | + | |
20409 | + err = -ENOMEM; | |
20410 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
20411 | + if (unlikely(!a)) | |
20412 | + goto out; | |
20413 | + | |
027c5e7a AM |
20414 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
20415 | + if (unlikely(err)) | |
20416 | + goto out_free; | |
20417 | + err = au_d_may_add(dentry); | |
20418 | + if (unlikely(err)) | |
20419 | + goto out_unlock; | |
20420 | + | |
4a4d8108 AM |
20421 | + parent = dentry->d_parent; /* dir inode is locked */ |
20422 | + di_write_lock_parent(parent); | |
20423 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, | |
20424 | + &a->pin, &wr_dir_args); | |
20425 | + err = PTR_ERR(wh_dentry); | |
20426 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20427 | + goto out_parent; |
4a4d8108 AM |
20428 | + |
20429 | + sb = dentry->d_sb; | |
5afbbe0d | 20430 | + bindex = au_dbtop(dentry); |
4a4d8108 AM |
20431 | + h_path.dentry = au_h_dptr(dentry, bindex); |
20432 | + h_path.mnt = au_sbr_mnt(sb, bindex); | |
20433 | + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode); | |
20434 | + if (unlikely(err)) | |
027c5e7a | 20435 | + goto out_unpin; |
4a4d8108 AM |
20436 | + |
20437 | + /* make the dir opaque */ | |
20438 | + diropq = 0; | |
febd17d6 | 20439 | + h_inode = d_inode(h_path.dentry); |
4a4d8108 AM |
20440 | + if (wh_dentry |
20441 | + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) { | |
febd17d6 | 20442 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
4a4d8108 | 20443 | + opq_dentry = au_diropq_create(dentry, bindex); |
febd17d6 | 20444 | + inode_unlock(h_inode); |
4a4d8108 AM |
20445 | + err = PTR_ERR(opq_dentry); |
20446 | + if (IS_ERR(opq_dentry)) | |
20447 | + goto out_dir; | |
20448 | + dput(opq_dentry); | |
20449 | + diropq = 1; | |
20450 | + } | |
20451 | + | |
20452 | + err = epilog(dir, bindex, wh_dentry, dentry); | |
20453 | + if (!err) { | |
20454 | + inc_nlink(dir); | |
027c5e7a | 20455 | + goto out_unpin; /* success */ |
4a4d8108 AM |
20456 | + } |
20457 | + | |
20458 | + /* revert */ | |
20459 | + if (diropq) { | |
20460 | + AuLabel(revert opq); | |
febd17d6 | 20461 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
4a4d8108 | 20462 | + rerr = au_diropq_remove(dentry, bindex); |
febd17d6 | 20463 | + inode_unlock(h_inode); |
4a4d8108 | 20464 | + if (rerr) { |
523b37e3 AM |
20465 | + AuIOErr("%pd reverting diropq failed(%d, %d)\n", |
20466 | + dentry, err, rerr); | |
4a4d8108 AM |
20467 | + err = -EIO; |
20468 | + } | |
20469 | + } | |
20470 | + | |
4f0767ce | 20471 | +out_dir: |
4a4d8108 AM |
20472 | + AuLabel(revert dir); |
20473 | + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path); | |
20474 | + if (rerr) { | |
523b37e3 AM |
20475 | + AuIOErr("%pd reverting dir failed(%d, %d)\n", |
20476 | + dentry, err, rerr); | |
4a4d8108 AM |
20477 | + err = -EIO; |
20478 | + } | |
4a4d8108 | 20479 | + au_dtime_revert(&a->dt); |
027c5e7a | 20480 | +out_unpin: |
4a4d8108 AM |
20481 | + au_unpin(&a->pin); |
20482 | + dput(wh_dentry); | |
027c5e7a AM |
20483 | +out_parent: |
20484 | + di_write_unlock(parent); | |
20485 | +out_unlock: | |
4a4d8108 | 20486 | + if (unlikely(err)) { |
5afbbe0d | 20487 | + au_update_dbtop(dentry); |
4a4d8108 AM |
20488 | + d_drop(dentry); |
20489 | + } | |
4a4d8108 | 20490 | + aufs_read_unlock(dentry, AuLock_DW); |
027c5e7a | 20491 | +out_free: |
1c60b727 | 20492 | + kfree(a); |
4f0767ce | 20493 | +out: |
4a4d8108 AM |
20494 | + return err; |
20495 | +} | |
7f207e10 AM |
20496 | diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c |
20497 | --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 20498 | +++ linux/fs/aufs/i_op.c 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 | 20499 | @@ -0,0 +1,1459 @@ |
4a4d8108 | 20500 | +/* |
a2654f78 | 20501 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
4a4d8108 AM |
20502 | + * |
20503 | + * This program, aufs is free software; you can redistribute it and/or modify | |
20504 | + * it under the terms of the GNU General Public License as published by | |
20505 | + * the Free Software Foundation; either version 2 of the License, or | |
20506 | + * (at your option) any later version. | |
20507 | + * | |
20508 | + * This program is distributed in the hope that it will be useful, | |
20509 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20510 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20511 | + * GNU General Public License for more details. | |
20512 | + * | |
20513 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 20514 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 20515 | + */ |
1facf9fc | 20516 | + |
1308ab2a | 20517 | +/* |
4a4d8108 | 20518 | + * inode operations (except add/del/rename) |
1308ab2a | 20519 | + */ |
4a4d8108 AM |
20520 | + |
20521 | +#include <linux/device_cgroup.h> | |
20522 | +#include <linux/fs_stack.h> | |
4a4d8108 AM |
20523 | +#include <linux/namei.h> |
20524 | +#include <linux/security.h> | |
4a4d8108 AM |
20525 | +#include "aufs.h" |
20526 | + | |
1e00d052 | 20527 | +static int h_permission(struct inode *h_inode, int mask, |
79b8bda9 | 20528 | + struct path *h_path, int brperm) |
1facf9fc | 20529 | +{ |
1308ab2a | 20530 | + int err; |
4a4d8108 | 20531 | + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); |
1facf9fc | 20532 | + |
e2f27e51 AM |
20533 | + err = -EPERM; |
20534 | + if (write_mask && IS_IMMUTABLE(h_inode)) | |
20535 | + goto out; | |
20536 | + | |
4a4d8108 | 20537 | + err = -EACCES; |
e2f27e51 AM |
20538 | + if (((mask & MAY_EXEC) |
20539 | + && S_ISREG(h_inode->i_mode) | |
20540 | + && (path_noexec(h_path) | |
20541 | + || !(h_inode->i_mode & S_IXUGO)))) | |
4a4d8108 AM |
20542 | + goto out; |
20543 | + | |
20544 | + /* | |
20545 | + * - skip the lower fs test in the case of write to ro branch. | |
20546 | + * - nfs dir permission write check is optimized, but a policy for | |
20547 | + * link/rename requires a real check. | |
2121bcd9 | 20548 | + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.' |
b912730e | 20549 | + * in this case, generic_permission() returns -EOPNOTSUPP. |
4a4d8108 AM |
20550 | + */ |
20551 | + if ((write_mask && !au_br_writable(brperm)) | |
20552 | + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode) | |
20553 | + && write_mask && !(mask & MAY_READ)) | |
20554 | + || !h_inode->i_op->permission) { | |
20555 | + /* AuLabel(generic_permission); */ | |
b912730e | 20556 | + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */ |
1e00d052 | 20557 | + err = generic_permission(h_inode, mask); |
b912730e AM |
20558 | + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode)) |
20559 | + err = h_inode->i_op->permission(h_inode, mask); | |
20560 | + AuTraceErr(err); | |
1308ab2a | 20561 | + } else { |
4a4d8108 | 20562 | + /* AuLabel(h_inode->permission); */ |
1e00d052 | 20563 | + err = h_inode->i_op->permission(h_inode, mask); |
4a4d8108 AM |
20564 | + AuTraceErr(err); |
20565 | + } | |
1facf9fc | 20566 | + |
4a4d8108 AM |
20567 | + if (!err) |
20568 | + err = devcgroup_inode_permission(h_inode, mask); | |
7f207e10 | 20569 | + if (!err) |
4a4d8108 | 20570 | + err = security_inode_permission(h_inode, mask); |
4a4d8108 AM |
20571 | + |
20572 | +#if 0 | |
20573 | + if (!err) { | |
20574 | + /* todo: do we need to call ima_path_check()? */ | |
20575 | + struct path h_path = { | |
20576 | + .dentry = | |
20577 | + .mnt = h_mnt | |
20578 | + }; | |
20579 | + err = ima_path_check(&h_path, | |
20580 | + mask & (MAY_READ | MAY_WRITE | MAY_EXEC), | |
20581 | + IMA_COUNT_LEAVE); | |
1308ab2a | 20582 | + } |
4a4d8108 | 20583 | +#endif |
dece6358 | 20584 | + |
4f0767ce | 20585 | +out: |
1308ab2a | 20586 | + return err; |
20587 | +} | |
dece6358 | 20588 | + |
1e00d052 | 20589 | +static int aufs_permission(struct inode *inode, int mask) |
1308ab2a | 20590 | +{ |
20591 | + int err; | |
5afbbe0d | 20592 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
20593 | + const unsigned char isdir = !!S_ISDIR(inode->i_mode), |
20594 | + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); | |
20595 | + struct inode *h_inode; | |
20596 | + struct super_block *sb; | |
20597 | + struct au_branch *br; | |
1facf9fc | 20598 | + |
027c5e7a | 20599 | + /* todo: support rcu-walk? */ |
1e00d052 | 20600 | + if (mask & MAY_NOT_BLOCK) |
027c5e7a AM |
20601 | + return -ECHILD; |
20602 | + | |
4a4d8108 AM |
20603 | + sb = inode->i_sb; |
20604 | + si_read_lock(sb, AuLock_FLUSH); | |
20605 | + ii_read_lock_child(inode); | |
027c5e7a AM |
20606 | +#if 0 |
20607 | + err = au_iigen_test(inode, au_sigen(sb)); | |
20608 | + if (unlikely(err)) | |
20609 | + goto out; | |
20610 | +#endif | |
dece6358 | 20611 | + |
076b876e AM |
20612 | + if (!isdir |
20613 | + || write_mask | |
20614 | + || au_opt_test(au_mntflags(sb), DIRPERM1)) { | |
4a4d8108 | 20615 | + err = au_busy_or_stale(); |
5afbbe0d | 20616 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
4a4d8108 AM |
20617 | + if (unlikely(!h_inode |
20618 | + || (h_inode->i_mode & S_IFMT) | |
20619 | + != (inode->i_mode & S_IFMT))) | |
20620 | + goto out; | |
1facf9fc | 20621 | + |
4a4d8108 | 20622 | + err = 0; |
5afbbe0d | 20623 | + bindex = au_ibtop(inode); |
4a4d8108 | 20624 | + br = au_sbr(sb, bindex); |
79b8bda9 | 20625 | + err = h_permission(h_inode, mask, &br->br_path, br->br_perm); |
4a4d8108 AM |
20626 | + if (write_mask |
20627 | + && !err | |
20628 | + && !special_file(h_inode->i_mode)) { | |
20629 | + /* test whether the upper writable branch exists */ | |
20630 | + err = -EROFS; | |
20631 | + for (; bindex >= 0; bindex--) | |
20632 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
20633 | + err = 0; | |
20634 | + break; | |
20635 | + } | |
20636 | + } | |
20637 | + goto out; | |
20638 | + } | |
dece6358 | 20639 | + |
4a4d8108 | 20640 | + /* non-write to dir */ |
1308ab2a | 20641 | + err = 0; |
5afbbe0d AM |
20642 | + bbot = au_ibbot(inode); |
20643 | + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) { | |
4a4d8108 AM |
20644 | + h_inode = au_h_iptr(inode, bindex); |
20645 | + if (h_inode) { | |
20646 | + err = au_busy_or_stale(); | |
20647 | + if (unlikely(!S_ISDIR(h_inode->i_mode))) | |
20648 | + break; | |
20649 | + | |
20650 | + br = au_sbr(sb, bindex); | |
79b8bda9 | 20651 | + err = h_permission(h_inode, mask, &br->br_path, |
4a4d8108 AM |
20652 | + br->br_perm); |
20653 | + } | |
20654 | + } | |
1308ab2a | 20655 | + |
4f0767ce | 20656 | +out: |
4a4d8108 AM |
20657 | + ii_read_unlock(inode); |
20658 | + si_read_unlock(sb); | |
1308ab2a | 20659 | + return err; |
20660 | +} | |
20661 | + | |
4a4d8108 | 20662 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20663 | + |
4a4d8108 | 20664 | +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry, |
b4510431 | 20665 | + unsigned int flags) |
4a4d8108 AM |
20666 | +{ |
20667 | + struct dentry *ret, *parent; | |
b752ccd1 | 20668 | + struct inode *inode; |
4a4d8108 | 20669 | + struct super_block *sb; |
1716fcea | 20670 | + int err, npositive; |
dece6358 | 20671 | + |
4a4d8108 | 20672 | + IMustLock(dir); |
1308ab2a | 20673 | + |
537831f9 AM |
20674 | + /* todo: support rcu-walk? */ |
20675 | + ret = ERR_PTR(-ECHILD); | |
20676 | + if (flags & LOOKUP_RCU) | |
20677 | + goto out; | |
20678 | + | |
20679 | + ret = ERR_PTR(-ENAMETOOLONG); | |
20680 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
20681 | + goto out; | |
20682 | + | |
4a4d8108 | 20683 | + sb = dir->i_sb; |
7f207e10 AM |
20684 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
20685 | + ret = ERR_PTR(err); | |
20686 | + if (unlikely(err)) | |
20687 | + goto out; | |
20688 | + | |
4a4d8108 AM |
20689 | + err = au_di_init(dentry); |
20690 | + ret = ERR_PTR(err); | |
20691 | + if (unlikely(err)) | |
7f207e10 | 20692 | + goto out_si; |
1308ab2a | 20693 | + |
9dbd164d | 20694 | + inode = NULL; |
027c5e7a | 20695 | + npositive = 0; /* suppress a warning */ |
4a4d8108 AM |
20696 | + parent = dentry->d_parent; /* dir inode is locked */ |
20697 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a AM |
20698 | + err = au_alive_dir(parent); |
20699 | + if (!err) | |
20700 | + err = au_digen_test(parent, au_sigen(sb)); | |
20701 | + if (!err) { | |
5afbbe0d AM |
20702 | + /* regardless LOOKUP_CREATE, always ALLOW_NEG */ |
20703 | + npositive = au_lkup_dentry(dentry, au_dbtop(parent), | |
20704 | + AuLkup_ALLOW_NEG); | |
027c5e7a AM |
20705 | + err = npositive; |
20706 | + } | |
4a4d8108 | 20707 | + di_read_unlock(parent, AuLock_IR); |
4a4d8108 AM |
20708 | + ret = ERR_PTR(err); |
20709 | + if (unlikely(err < 0)) | |
20710 | + goto out_unlock; | |
1308ab2a | 20711 | + |
4a4d8108 | 20712 | + if (npositive) { |
b752ccd1 | 20713 | + inode = au_new_inode(dentry, /*must_new*/0); |
c1595e42 JR |
20714 | + if (IS_ERR(inode)) { |
20715 | + ret = (void *)inode; | |
20716 | + inode = NULL; | |
20717 | + goto out_unlock; | |
20718 | + } | |
9dbd164d | 20719 | + } |
4a4d8108 | 20720 | + |
c1595e42 JR |
20721 | + if (inode) |
20722 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 20723 | + ret = d_splice_alias(inode, dentry); |
537831f9 AM |
20724 | +#if 0 |
20725 | + if (unlikely(d_need_lookup(dentry))) { | |
20726 | + spin_lock(&dentry->d_lock); | |
20727 | + dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | |
20728 | + spin_unlock(&dentry->d_lock); | |
20729 | + } else | |
20730 | +#endif | |
c1595e42 | 20731 | + if (inode) { |
2000de60 | 20732 | + if (!IS_ERR(ret)) { |
c1595e42 | 20733 | + iput(inode); |
2000de60 JR |
20734 | + if (ret && ret != dentry) |
20735 | + ii_write_unlock(inode); | |
20736 | + } else { | |
c1595e42 JR |
20737 | + ii_write_unlock(inode); |
20738 | + iput(inode); | |
20739 | + inode = NULL; | |
20740 | + } | |
7f207e10 | 20741 | + } |
1facf9fc | 20742 | + |
4f0767ce | 20743 | +out_unlock: |
4a4d8108 | 20744 | + di_write_unlock(dentry); |
7f207e10 | 20745 | +out_si: |
4a4d8108 | 20746 | + si_read_unlock(sb); |
7f207e10 | 20747 | +out: |
4a4d8108 AM |
20748 | + return ret; |
20749 | +} | |
1facf9fc | 20750 | + |
4a4d8108 | 20751 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20752 | + |
b912730e | 20753 | +struct aopen_node { |
8b6a4947 | 20754 | + struct hlist_bl_node hblist; |
b912730e AM |
20755 | + struct file *file, *h_file; |
20756 | +}; | |
20757 | + | |
20758 | +static int au_do_aopen(struct inode *inode, struct file *file) | |
20759 | +{ | |
8b6a4947 AM |
20760 | + struct hlist_bl_head *aopen; |
20761 | + struct hlist_bl_node *pos; | |
b912730e AM |
20762 | + struct aopen_node *node; |
20763 | + struct au_do_open_args args = { | |
8b6a4947 AM |
20764 | + .aopen = 1, |
20765 | + .open = au_do_open_nondir | |
b912730e AM |
20766 | + }; |
20767 | + | |
20768 | + aopen = &au_sbi(inode->i_sb)->si_aopen; | |
8b6a4947 AM |
20769 | + hlist_bl_lock(aopen); |
20770 | + hlist_bl_for_each_entry(node, pos, aopen, hblist) | |
b912730e AM |
20771 | + if (node->file == file) { |
20772 | + args.h_file = node->h_file; | |
20773 | + break; | |
20774 | + } | |
8b6a4947 | 20775 | + hlist_bl_unlock(aopen); |
b912730e AM |
20776 | + /* AuDebugOn(!args.h_file); */ |
20777 | + | |
20778 | + return au_do_open(file, &args); | |
20779 | +} | |
20780 | + | |
20781 | +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry, | |
20782 | + struct file *file, unsigned int open_flag, | |
20783 | + umode_t create_mode, int *opened) | |
20784 | +{ | |
8b6a4947 | 20785 | + int err, unlocked, h_opened = *opened; |
5afbbe0d | 20786 | + unsigned int lkup_flags; |
f0c0a007 | 20787 | + struct dentry *parent, *d; |
8b6a4947 | 20788 | + struct hlist_bl_head *aopen; |
b912730e AM |
20789 | + struct vfsub_aopen_args args = { |
20790 | + .open_flag = open_flag, | |
20791 | + .create_mode = create_mode, | |
20792 | + .opened = &h_opened | |
20793 | + }; | |
20794 | + struct aopen_node aopen_node = { | |
20795 | + .file = file | |
20796 | + }; | |
20797 | + | |
20798 | + IMustLock(dir); | |
5afbbe0d | 20799 | + AuDbg("open_flag 0%o\n", open_flag); |
b912730e AM |
20800 | + AuDbgDentry(dentry); |
20801 | + | |
20802 | + err = 0; | |
20803 | + if (!au_di(dentry)) { | |
5afbbe0d AM |
20804 | + lkup_flags = LOOKUP_OPEN; |
20805 | + if (open_flag & O_CREAT) | |
20806 | + lkup_flags |= LOOKUP_CREATE; | |
20807 | + d = aufs_lookup(dir, dentry, lkup_flags); | |
b912730e AM |
20808 | + if (IS_ERR(d)) { |
20809 | + err = PTR_ERR(d); | |
5afbbe0d | 20810 | + AuTraceErr(err); |
b912730e AM |
20811 | + goto out; |
20812 | + } else if (d) { | |
20813 | + /* | |
20814 | + * obsoleted dentry found. | |
20815 | + * another error will be returned later. | |
20816 | + */ | |
20817 | + d_drop(d); | |
b912730e | 20818 | + AuDbgDentry(d); |
5afbbe0d | 20819 | + dput(d); |
b912730e AM |
20820 | + } |
20821 | + AuDbgDentry(dentry); | |
20822 | + } | |
20823 | + | |
20824 | + if (d_is_positive(dentry) | |
20825 | + || d_unhashed(dentry) | |
20826 | + || d_unlinked(dentry) | |
20827 | + || !(open_flag & O_CREAT)) | |
20828 | + goto out_no_open; | |
20829 | + | |
8b6a4947 | 20830 | + unlocked = 0; |
b912730e AM |
20831 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
20832 | + if (unlikely(err)) | |
20833 | + goto out; | |
20834 | + | |
20835 | + parent = dentry->d_parent; /* dir is locked */ | |
20836 | + di_write_lock_parent(parent); | |
5afbbe0d | 20837 | + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG); |
b912730e AM |
20838 | + if (unlikely(err)) |
20839 | + goto out_unlock; | |
20840 | + | |
20841 | + AuDbgDentry(dentry); | |
20842 | + if (d_is_positive(dentry)) | |
20843 | + goto out_unlock; | |
20844 | + | |
20845 | + args.file = get_empty_filp(); | |
20846 | + err = PTR_ERR(args.file); | |
20847 | + if (IS_ERR(args.file)) | |
20848 | + goto out_unlock; | |
20849 | + | |
20850 | + args.file->f_flags = file->f_flags; | |
20851 | + err = au_aopen_or_create(dir, dentry, &args); | |
20852 | + AuTraceErr(err); | |
20853 | + AuDbgFile(args.file); | |
20854 | + if (unlikely(err < 0)) { | |
20855 | + if (h_opened & FILE_OPENED) | |
20856 | + fput(args.file); | |
20857 | + else | |
20858 | + put_filp(args.file); | |
20859 | + goto out_unlock; | |
20860 | + } | |
8b6a4947 AM |
20861 | + di_write_unlock(parent); |
20862 | + di_write_unlock(dentry); | |
20863 | + unlocked = 1; | |
b912730e AM |
20864 | + |
20865 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
20866 | + *opened |= FILE_CREATED; | |
20867 | + if (h_opened & FILE_OPENED) | |
20868 | + aopen_node.h_file = args.file; | |
20869 | + else { | |
20870 | + put_filp(args.file); | |
20871 | + args.file = NULL; | |
20872 | + } | |
20873 | + aopen = &au_sbi(dir->i_sb)->si_aopen; | |
8b6a4947 | 20874 | + au_hbl_add(&aopen_node.hblist, aopen); |
b912730e | 20875 | + err = finish_open(file, dentry, au_do_aopen, opened); |
8b6a4947 | 20876 | + au_hbl_del(&aopen_node.hblist, aopen); |
b912730e AM |
20877 | + AuTraceErr(err); |
20878 | + AuDbgFile(file); | |
20879 | + if (aopen_node.h_file) | |
20880 | + fput(aopen_node.h_file); | |
20881 | + | |
20882 | +out_unlock: | |
8b6a4947 AM |
20883 | + if (unlocked) |
20884 | + si_read_unlock(dentry->d_sb); | |
20885 | + else { | |
20886 | + di_write_unlock(parent); | |
20887 | + aufs_read_unlock(dentry, AuLock_DW); | |
20888 | + } | |
b912730e | 20889 | + AuDbgDentry(dentry); |
f0c0a007 | 20890 | + if (unlikely(err < 0)) |
b912730e AM |
20891 | + goto out; |
20892 | +out_no_open: | |
f0c0a007 | 20893 | + if (err >= 0 && !(*opened & FILE_CREATED)) { |
b912730e AM |
20894 | + AuLabel(out_no_open); |
20895 | + dget(dentry); | |
20896 | + err = finish_no_open(file, dentry); | |
20897 | + } | |
20898 | +out: | |
20899 | + AuDbg("%pd%s%s\n", dentry, | |
20900 | + (*opened & FILE_CREATED) ? " created" : "", | |
20901 | + (*opened & FILE_OPENED) ? " opened" : ""); | |
20902 | + AuTraceErr(err); | |
20903 | + return err; | |
20904 | +} | |
20905 | + | |
20906 | + | |
20907 | +/* ---------------------------------------------------------------------- */ | |
20908 | + | |
4a4d8108 AM |
20909 | +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent, |
20910 | + const unsigned char add_entry, aufs_bindex_t bcpup, | |
5afbbe0d | 20911 | + aufs_bindex_t btop) |
4a4d8108 AM |
20912 | +{ |
20913 | + int err; | |
20914 | + struct dentry *h_parent; | |
20915 | + struct inode *h_dir; | |
1facf9fc | 20916 | + |
027c5e7a | 20917 | + if (add_entry) |
5527c038 | 20918 | + IMustLock(d_inode(parent)); |
027c5e7a | 20919 | + else |
4a4d8108 AM |
20920 | + di_write_lock_parent(parent); |
20921 | + | |
20922 | + err = 0; | |
20923 | + if (!au_h_dptr(parent, bcpup)) { | |
5afbbe0d | 20924 | + if (btop > bcpup) |
c2b27bf2 | 20925 | + err = au_cpup_dirs(dentry, bcpup); |
5afbbe0d | 20926 | + else if (btop < bcpup) |
4a4d8108 AM |
20927 | + err = au_cpdown_dirs(dentry, bcpup); |
20928 | + else | |
c2b27bf2 | 20929 | + BUG(); |
4a4d8108 | 20930 | + } |
38d290e6 | 20931 | + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) { |
4a4d8108 | 20932 | + h_parent = au_h_dptr(parent, bcpup); |
5527c038 | 20933 | + h_dir = d_inode(h_parent); |
3c1bdaff | 20934 | + vfsub_inode_lock_shared_nested(h_dir, AuLsc_I_PARENT); |
7e9cd9fe | 20935 | + err = au_lkup_neg(dentry, bcpup, /*wh*/0); |
4a4d8108 | 20936 | + /* todo: no unlock here */ |
3c1bdaff | 20937 | + inode_unlock_shared(h_dir); |
027c5e7a AM |
20938 | + |
20939 | + AuDbg("bcpup %d\n", bcpup); | |
20940 | + if (!err) { | |
5527c038 | 20941 | + if (d_really_is_negative(dentry)) |
5afbbe0d | 20942 | + au_set_h_dptr(dentry, btop, NULL); |
4a4d8108 AM |
20943 | + au_update_dbrange(dentry, /*do_put_zero*/0); |
20944 | + } | |
1308ab2a | 20945 | + } |
1facf9fc | 20946 | + |
4a4d8108 AM |
20947 | + if (!add_entry) |
20948 | + di_write_unlock(parent); | |
20949 | + if (!err) | |
20950 | + err = bcpup; /* success */ | |
1308ab2a | 20951 | + |
027c5e7a | 20952 | + AuTraceErr(err); |
4a4d8108 AM |
20953 | + return err; |
20954 | +} | |
1facf9fc | 20955 | + |
4a4d8108 AM |
20956 | +/* |
20957 | + * decide the branch and the parent dir where we will create a new entry. | |
20958 | + * returns new bindex or an error. | |
20959 | + * copyup the parent dir if needed. | |
20960 | + */ | |
20961 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
20962 | + struct au_wr_dir_args *args) | |
20963 | +{ | |
20964 | + int err; | |
392086de | 20965 | + unsigned int flags; |
5afbbe0d | 20966 | + aufs_bindex_t bcpup, btop, src_btop; |
86dc4139 AM |
20967 | + const unsigned char add_entry |
20968 | + = au_ftest_wrdir(args->flags, ADD_ENTRY) | |
38d290e6 | 20969 | + | au_ftest_wrdir(args->flags, TMPFILE); |
4a4d8108 AM |
20970 | + struct super_block *sb; |
20971 | + struct dentry *parent; | |
20972 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 20973 | + |
4a4d8108 AM |
20974 | + sb = dentry->d_sb; |
20975 | + sbinfo = au_sbi(sb); | |
20976 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
20977 | + btop = au_dbtop(dentry); |
20978 | + bcpup = btop; | |
4a4d8108 AM |
20979 | + if (args->force_btgt < 0) { |
20980 | + if (src_dentry) { | |
5afbbe0d AM |
20981 | + src_btop = au_dbtop(src_dentry); |
20982 | + if (src_btop < btop) | |
20983 | + bcpup = src_btop; | |
4a4d8108 | 20984 | + } else if (add_entry) { |
392086de AM |
20985 | + flags = 0; |
20986 | + if (au_ftest_wrdir(args->flags, ISDIR)) | |
20987 | + au_fset_wbr(flags, DIR); | |
20988 | + err = AuWbrCreate(sbinfo, dentry, flags); | |
4a4d8108 AM |
20989 | + bcpup = err; |
20990 | + } | |
1facf9fc | 20991 | + |
5527c038 | 20992 | + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) { |
4a4d8108 AM |
20993 | + if (add_entry) |
20994 | + err = AuWbrCopyup(sbinfo, dentry); | |
20995 | + else { | |
20996 | + if (!IS_ROOT(dentry)) { | |
20997 | + di_read_lock_parent(parent, !AuLock_IR); | |
20998 | + err = AuWbrCopyup(sbinfo, dentry); | |
20999 | + di_read_unlock(parent, !AuLock_IR); | |
21000 | + } else | |
21001 | + err = AuWbrCopyup(sbinfo, dentry); | |
21002 | + } | |
21003 | + bcpup = err; | |
21004 | + if (unlikely(err < 0)) | |
21005 | + goto out; | |
21006 | + } | |
21007 | + } else { | |
21008 | + bcpup = args->force_btgt; | |
5527c038 | 21009 | + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry))); |
1308ab2a | 21010 | + } |
027c5e7a | 21011 | + |
5afbbe0d | 21012 | + AuDbg("btop %d, bcpup %d\n", btop, bcpup); |
4a4d8108 | 21013 | + err = bcpup; |
5afbbe0d | 21014 | + if (bcpup == btop) |
4a4d8108 | 21015 | + goto out; /* success */ |
4a4d8108 AM |
21016 | + |
21017 | + /* copyup the new parent into the branch we process */ | |
5afbbe0d | 21018 | + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop); |
027c5e7a | 21019 | + if (err >= 0) { |
5527c038 | 21020 | + if (d_really_is_negative(dentry)) { |
5afbbe0d AM |
21021 | + au_set_h_dptr(dentry, btop, NULL); |
21022 | + au_set_dbtop(dentry, bcpup); | |
21023 | + au_set_dbbot(dentry, bcpup); | |
027c5e7a | 21024 | + } |
38d290e6 JR |
21025 | + AuDebugOn(add_entry |
21026 | + && !au_ftest_wrdir(args->flags, TMPFILE) | |
21027 | + && !au_h_dptr(dentry, bcpup)); | |
027c5e7a | 21028 | + } |
86dc4139 AM |
21029 | + |
21030 | +out: | |
21031 | + dput(parent); | |
21032 | + return err; | |
21033 | +} | |
21034 | + | |
21035 | +/* ---------------------------------------------------------------------- */ | |
21036 | + | |
21037 | +void au_pin_hdir_unlock(struct au_pin *p) | |
21038 | +{ | |
21039 | + if (p->hdir) | |
5afbbe0d | 21040 | + au_hn_inode_unlock(p->hdir); |
86dc4139 AM |
21041 | +} |
21042 | + | |
c1595e42 | 21043 | +int au_pin_hdir_lock(struct au_pin *p) |
86dc4139 AM |
21044 | +{ |
21045 | + int err; | |
21046 | + | |
21047 | + err = 0; | |
21048 | + if (!p->hdir) | |
21049 | + goto out; | |
21050 | + | |
21051 | + /* even if an error happens later, keep this lock */ | |
5afbbe0d | 21052 | + au_hn_inode_lock_nested(p->hdir, p->lsc_hi); |
86dc4139 AM |
21053 | + |
21054 | + err = -EBUSY; | |
5527c038 | 21055 | + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent))) |
86dc4139 AM |
21056 | + goto out; |
21057 | + | |
21058 | + err = 0; | |
21059 | + if (p->h_dentry) | |
21060 | + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode, | |
21061 | + p->h_parent, p->br); | |
21062 | + | |
21063 | +out: | |
21064 | + return err; | |
21065 | +} | |
21066 | + | |
21067 | +int au_pin_hdir_relock(struct au_pin *p) | |
21068 | +{ | |
21069 | + int err, i; | |
21070 | + struct inode *h_i; | |
21071 | + struct dentry *h_d[] = { | |
21072 | + p->h_dentry, | |
21073 | + p->h_parent | |
21074 | + }; | |
21075 | + | |
21076 | + err = au_pin_hdir_lock(p); | |
21077 | + if (unlikely(err)) | |
21078 | + goto out; | |
21079 | + | |
21080 | + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) { | |
21081 | + if (!h_d[i]) | |
21082 | + continue; | |
5527c038 JR |
21083 | + if (d_is_positive(h_d[i])) { |
21084 | + h_i = d_inode(h_d[i]); | |
86dc4139 | 21085 | + err = !h_i->i_nlink; |
5527c038 | 21086 | + } |
86dc4139 AM |
21087 | + } |
21088 | + | |
21089 | +out: | |
21090 | + return err; | |
21091 | +} | |
21092 | + | |
5afbbe0d | 21093 | +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task) |
86dc4139 | 21094 | +{ |
5afbbe0d AM |
21095 | +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER) |
21096 | + p->hdir->hi_inode->i_rwsem.owner = task; | |
86dc4139 AM |
21097 | +#endif |
21098 | +} | |
21099 | + | |
21100 | +void au_pin_hdir_acquire_nest(struct au_pin *p) | |
21101 | +{ | |
21102 | + if (p->hdir) { | |
5afbbe0d | 21103 | + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map, |
86dc4139 AM |
21104 | + p->lsc_hi, 0, NULL, _RET_IP_); |
21105 | + au_pin_hdir_set_owner(p, current); | |
21106 | + } | |
dece6358 | 21107 | +} |
1facf9fc | 21108 | + |
86dc4139 AM |
21109 | +void au_pin_hdir_release(struct au_pin *p) |
21110 | +{ | |
21111 | + if (p->hdir) { | |
21112 | + au_pin_hdir_set_owner(p, p->task); | |
5afbbe0d | 21113 | + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_); |
86dc4139 AM |
21114 | + } |
21115 | +} | |
1308ab2a | 21116 | + |
4a4d8108 | 21117 | +struct dentry *au_pinned_h_parent(struct au_pin *pin) |
1308ab2a | 21118 | +{ |
4a4d8108 AM |
21119 | + if (pin && pin->parent) |
21120 | + return au_h_dptr(pin->parent, pin->bindex); | |
21121 | + return NULL; | |
dece6358 | 21122 | +} |
1facf9fc | 21123 | + |
4a4d8108 | 21124 | +void au_unpin(struct au_pin *p) |
dece6358 | 21125 | +{ |
86dc4139 AM |
21126 | + if (p->hdir) |
21127 | + au_pin_hdir_unlock(p); | |
e49829fe | 21128 | + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE)) |
b4510431 | 21129 | + vfsub_mnt_drop_write(p->h_mnt); |
4a4d8108 AM |
21130 | + if (!p->hdir) |
21131 | + return; | |
1facf9fc | 21132 | + |
4a4d8108 AM |
21133 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
21134 | + di_read_unlock(p->parent, AuLock_IR); | |
21135 | + iput(p->hdir->hi_inode); | |
21136 | + dput(p->parent); | |
21137 | + p->parent = NULL; | |
21138 | + p->hdir = NULL; | |
21139 | + p->h_mnt = NULL; | |
86dc4139 | 21140 | + /* do not clear p->task */ |
4a4d8108 | 21141 | +} |
1308ab2a | 21142 | + |
4a4d8108 AM |
21143 | +int au_do_pin(struct au_pin *p) |
21144 | +{ | |
21145 | + int err; | |
21146 | + struct super_block *sb; | |
4a4d8108 AM |
21147 | + struct inode *h_dir; |
21148 | + | |
21149 | + err = 0; | |
21150 | + sb = p->dentry->d_sb; | |
86dc4139 | 21151 | + p->br = au_sbr(sb, p->bindex); |
4a4d8108 AM |
21152 | + if (IS_ROOT(p->dentry)) { |
21153 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { | |
86dc4139 | 21154 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 21155 | + err = vfsub_mnt_want_write(p->h_mnt); |
4a4d8108 AM |
21156 | + if (unlikely(err)) { |
21157 | + au_fclr_pin(p->flags, MNT_WRITE); | |
21158 | + goto out_err; | |
21159 | + } | |
21160 | + } | |
dece6358 | 21161 | + goto out; |
1facf9fc | 21162 | + } |
21163 | + | |
86dc4139 | 21164 | + p->h_dentry = NULL; |
5afbbe0d | 21165 | + if (p->bindex <= au_dbbot(p->dentry)) |
86dc4139 | 21166 | + p->h_dentry = au_h_dptr(p->dentry, p->bindex); |
dece6358 | 21167 | + |
4a4d8108 AM |
21168 | + p->parent = dget_parent(p->dentry); |
21169 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) | |
21170 | + di_read_lock(p->parent, AuLock_IR, p->lsc_di); | |
dece6358 | 21171 | + |
4a4d8108 | 21172 | + h_dir = NULL; |
86dc4139 | 21173 | + p->h_parent = au_h_dptr(p->parent, p->bindex); |
5527c038 | 21174 | + p->hdir = au_hi(d_inode(p->parent), p->bindex); |
4a4d8108 AM |
21175 | + if (p->hdir) |
21176 | + h_dir = p->hdir->hi_inode; | |
dece6358 | 21177 | + |
b752ccd1 AM |
21178 | + /* |
21179 | + * udba case, or | |
21180 | + * if DI_LOCKED is not set, then p->parent may be different | |
21181 | + * and h_parent can be NULL. | |
21182 | + */ | |
86dc4139 | 21183 | + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) { |
e49829fe | 21184 | + err = -EBUSY; |
4a4d8108 AM |
21185 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
21186 | + di_read_unlock(p->parent, AuLock_IR); | |
21187 | + dput(p->parent); | |
21188 | + p->parent = NULL; | |
21189 | + goto out_err; | |
21190 | + } | |
1308ab2a | 21191 | + |
4a4d8108 | 21192 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { |
86dc4139 | 21193 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 21194 | + err = vfsub_mnt_want_write(p->h_mnt); |
dece6358 | 21195 | + if (unlikely(err)) { |
4a4d8108 | 21196 | + au_fclr_pin(p->flags, MNT_WRITE); |
86dc4139 AM |
21197 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
21198 | + di_read_unlock(p->parent, AuLock_IR); | |
21199 | + dput(p->parent); | |
21200 | + p->parent = NULL; | |
21201 | + goto out_err; | |
dece6358 AM |
21202 | + } |
21203 | + } | |
4a4d8108 | 21204 | + |
86dc4139 AM |
21205 | + au_igrab(h_dir); |
21206 | + err = au_pin_hdir_lock(p); | |
21207 | + if (!err) | |
21208 | + goto out; /* success */ | |
21209 | + | |
076b876e AM |
21210 | + au_unpin(p); |
21211 | + | |
4f0767ce | 21212 | +out_err: |
4a4d8108 AM |
21213 | + pr_err("err %d\n", err); |
21214 | + err = au_busy_or_stale(); | |
4f0767ce | 21215 | +out: |
1facf9fc | 21216 | + return err; |
21217 | +} | |
21218 | + | |
4a4d8108 AM |
21219 | +void au_pin_init(struct au_pin *p, struct dentry *dentry, |
21220 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
21221 | + unsigned int udba, unsigned char flags) | |
21222 | +{ | |
21223 | + p->dentry = dentry; | |
21224 | + p->udba = udba; | |
21225 | + p->lsc_di = lsc_di; | |
21226 | + p->lsc_hi = lsc_hi; | |
21227 | + p->flags = flags; | |
21228 | + p->bindex = bindex; | |
21229 | + | |
21230 | + p->parent = NULL; | |
21231 | + p->hdir = NULL; | |
21232 | + p->h_mnt = NULL; | |
86dc4139 AM |
21233 | + |
21234 | + p->h_dentry = NULL; | |
21235 | + p->h_parent = NULL; | |
21236 | + p->br = NULL; | |
21237 | + p->task = current; | |
4a4d8108 AM |
21238 | +} |
21239 | + | |
21240 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
21241 | + unsigned int udba, unsigned char flags) | |
21242 | +{ | |
21243 | + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2, | |
21244 | + udba, flags); | |
21245 | + return au_do_pin(pin); | |
21246 | +} | |
21247 | + | |
dece6358 AM |
21248 | +/* ---------------------------------------------------------------------- */ |
21249 | + | |
1308ab2a | 21250 | +/* |
4a4d8108 AM |
21251 | + * ->setattr() and ->getattr() are called in various cases. |
21252 | + * chmod, stat: dentry is revalidated. | |
21253 | + * fchmod, fstat: file and dentry are not revalidated, additionally they may be | |
21254 | + * unhashed. | |
21255 | + * for ->setattr(), ia->ia_file is passed from ftruncate only. | |
1308ab2a | 21256 | + */ |
027c5e7a | 21257 | +/* todo: consolidate with do_refresh() and simple_reval_dpath() */ |
c1595e42 | 21258 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen) |
1facf9fc | 21259 | +{ |
4a4d8108 | 21260 | + int err; |
4a4d8108 | 21261 | + struct dentry *parent; |
1facf9fc | 21262 | + |
1308ab2a | 21263 | + err = 0; |
027c5e7a | 21264 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 AM |
21265 | + parent = dget_parent(dentry); |
21266 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 21267 | + err = au_refresh_dentry(dentry, parent); |
4a4d8108 AM |
21268 | + di_read_unlock(parent, AuLock_IR); |
21269 | + dput(parent); | |
dece6358 | 21270 | + } |
1facf9fc | 21271 | + |
4a4d8108 | 21272 | + AuTraceErr(err); |
1308ab2a | 21273 | + return err; |
21274 | +} | |
dece6358 | 21275 | + |
c1595e42 JR |
21276 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, |
21277 | + struct au_icpup_args *a) | |
1308ab2a | 21278 | +{ |
21279 | + int err; | |
4a4d8108 | 21280 | + loff_t sz; |
5afbbe0d | 21281 | + aufs_bindex_t btop, ibtop; |
4a4d8108 AM |
21282 | + struct dentry *hi_wh, *parent; |
21283 | + struct inode *inode; | |
4a4d8108 AM |
21284 | + struct au_wr_dir_args wr_dir_args = { |
21285 | + .force_btgt = -1, | |
21286 | + .flags = 0 | |
21287 | + }; | |
21288 | + | |
2000de60 | 21289 | + if (d_is_dir(dentry)) |
4a4d8108 AM |
21290 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
21291 | + /* plink or hi_wh() case */ | |
5afbbe0d | 21292 | + btop = au_dbtop(dentry); |
5527c038 | 21293 | + inode = d_inode(dentry); |
5afbbe0d AM |
21294 | + ibtop = au_ibtop(inode); |
21295 | + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode)) | |
21296 | + wr_dir_args.force_btgt = ibtop; | |
4a4d8108 AM |
21297 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
21298 | + if (unlikely(err < 0)) | |
21299 | + goto out; | |
21300 | + a->btgt = err; | |
5afbbe0d | 21301 | + if (err != btop) |
4a4d8108 AM |
21302 | + au_fset_icpup(a->flags, DID_CPUP); |
21303 | + | |
21304 | + err = 0; | |
21305 | + a->pin_flags = AuPin_MNT_WRITE; | |
21306 | + parent = NULL; | |
21307 | + if (!IS_ROOT(dentry)) { | |
21308 | + au_fset_pin(a->pin_flags, DI_LOCKED); | |
21309 | + parent = dget_parent(dentry); | |
21310 | + di_write_lock_parent(parent); | |
21311 | + } | |
21312 | + | |
21313 | + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags); | |
21314 | + if (unlikely(err)) | |
21315 | + goto out_parent; | |
21316 | + | |
4a4d8108 | 21317 | + sz = -1; |
5afbbe0d | 21318 | + a->h_path.dentry = au_h_dptr(dentry, btop); |
5527c038 | 21319 | + a->h_inode = d_inode(a->h_path.dentry); |
c1595e42 | 21320 | + if (ia && (ia->ia_valid & ATTR_SIZE)) { |
3c1bdaff | 21321 | + vfsub_inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD); |
c1595e42 JR |
21322 | + if (ia->ia_size < i_size_read(a->h_inode)) |
21323 | + sz = ia->ia_size; | |
3c1bdaff | 21324 | + inode_unlock_shared(a->h_inode); |
c1595e42 | 21325 | + } |
4a4d8108 | 21326 | + |
4a4d8108 | 21327 | + hi_wh = NULL; |
027c5e7a | 21328 | + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) { |
4a4d8108 AM |
21329 | + hi_wh = au_hi_wh(inode, a->btgt); |
21330 | + if (!hi_wh) { | |
c2b27bf2 AM |
21331 | + struct au_cp_generic cpg = { |
21332 | + .dentry = dentry, | |
21333 | + .bdst = a->btgt, | |
21334 | + .bsrc = -1, | |
21335 | + .len = sz, | |
21336 | + .pin = &a->pin | |
21337 | + }; | |
21338 | + err = au_sio_cpup_wh(&cpg, /*file*/NULL); | |
4a4d8108 AM |
21339 | + if (unlikely(err)) |
21340 | + goto out_unlock; | |
21341 | + hi_wh = au_hi_wh(inode, a->btgt); | |
21342 | + /* todo: revalidate hi_wh? */ | |
21343 | + } | |
21344 | + } | |
21345 | + | |
21346 | + if (parent) { | |
21347 | + au_pin_set_parent_lflag(&a->pin, /*lflag*/0); | |
21348 | + di_downgrade_lock(parent, AuLock_IR); | |
21349 | + dput(parent); | |
21350 | + parent = NULL; | |
21351 | + } | |
21352 | + if (!au_ftest_icpup(a->flags, DID_CPUP)) | |
21353 | + goto out; /* success */ | |
21354 | + | |
21355 | + if (!d_unhashed(dentry)) { | |
c2b27bf2 AM |
21356 | + struct au_cp_generic cpg = { |
21357 | + .dentry = dentry, | |
21358 | + .bdst = a->btgt, | |
5afbbe0d | 21359 | + .bsrc = btop, |
c2b27bf2 AM |
21360 | + .len = sz, |
21361 | + .pin = &a->pin, | |
21362 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
21363 | + }; | |
21364 | + err = au_sio_cpup_simple(&cpg); | |
4a4d8108 AM |
21365 | + if (!err) |
21366 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
21367 | + } else if (!hi_wh) | |
21368 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
21369 | + else | |
21370 | + a->h_path.dentry = hi_wh; /* do not dget here */ | |
1308ab2a | 21371 | + |
4f0767ce | 21372 | +out_unlock: |
5527c038 | 21373 | + a->h_inode = d_inode(a->h_path.dentry); |
86dc4139 | 21374 | + if (!err) |
dece6358 | 21375 | + goto out; /* success */ |
4a4d8108 | 21376 | + au_unpin(&a->pin); |
4f0767ce | 21377 | +out_parent: |
4a4d8108 AM |
21378 | + if (parent) { |
21379 | + di_write_unlock(parent); | |
21380 | + dput(parent); | |
21381 | + } | |
4f0767ce | 21382 | +out: |
86dc4139 | 21383 | + if (!err) |
febd17d6 | 21384 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
1facf9fc | 21385 | + return err; |
21386 | +} | |
21387 | + | |
4a4d8108 | 21388 | +static int aufs_setattr(struct dentry *dentry, struct iattr *ia) |
1facf9fc | 21389 | +{ |
4a4d8108 | 21390 | + int err; |
523b37e3 | 21391 | + struct inode *inode, *delegated; |
4a4d8108 AM |
21392 | + struct super_block *sb; |
21393 | + struct file *file; | |
21394 | + struct au_icpup_args *a; | |
1facf9fc | 21395 | + |
5527c038 | 21396 | + inode = d_inode(dentry); |
4a4d8108 | 21397 | + IMustLock(inode); |
dece6358 | 21398 | + |
f2c43d5f AM |
21399 | + err = setattr_prepare(dentry, ia); |
21400 | + if (unlikely(err)) | |
21401 | + goto out; | |
21402 | + | |
4a4d8108 AM |
21403 | + err = -ENOMEM; |
21404 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
21405 | + if (unlikely(!a)) | |
21406 | + goto out; | |
1facf9fc | 21407 | + |
4a4d8108 AM |
21408 | + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
21409 | + ia->ia_valid &= ~ATTR_MODE; | |
dece6358 | 21410 | + |
4a4d8108 AM |
21411 | + file = NULL; |
21412 | + sb = dentry->d_sb; | |
e49829fe JR |
21413 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
21414 | + if (unlikely(err)) | |
21415 | + goto out_kfree; | |
21416 | + | |
4a4d8108 AM |
21417 | + if (ia->ia_valid & ATTR_FILE) { |
21418 | + /* currently ftruncate(2) only */ | |
7e9cd9fe | 21419 | + AuDebugOn(!d_is_reg(dentry)); |
4a4d8108 | 21420 | + file = ia->ia_file; |
521ced18 JR |
21421 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, |
21422 | + /*fi_lsc*/0); | |
4a4d8108 AM |
21423 | + if (unlikely(err)) |
21424 | + goto out_si; | |
21425 | + ia->ia_file = au_hf_top(file); | |
21426 | + a->udba = AuOpt_UDBA_NONE; | |
21427 | + } else { | |
21428 | + /* fchmod() doesn't pass ia_file */ | |
21429 | + a->udba = au_opt_udba(sb); | |
027c5e7a AM |
21430 | + di_write_lock_child(dentry); |
21431 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
4a4d8108 AM |
21432 | + if (d_unhashed(dentry)) |
21433 | + a->udba = AuOpt_UDBA_NONE; | |
4a4d8108 AM |
21434 | + if (a->udba != AuOpt_UDBA_NONE) { |
21435 | + AuDebugOn(IS_ROOT(dentry)); | |
21436 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
21437 | + if (unlikely(err)) | |
21438 | + goto out_dentry; | |
21439 | + } | |
dece6358 | 21440 | + } |
dece6358 | 21441 | + |
4a4d8108 AM |
21442 | + err = au_pin_and_icpup(dentry, ia, a); |
21443 | + if (unlikely(err < 0)) | |
21444 | + goto out_dentry; | |
21445 | + if (au_ftest_icpup(a->flags, DID_CPUP)) { | |
21446 | + ia->ia_file = NULL; | |
21447 | + ia->ia_valid &= ~ATTR_FILE; | |
1308ab2a | 21448 | + } |
dece6358 | 21449 | + |
4a4d8108 AM |
21450 | + a->h_path.mnt = au_sbr_mnt(sb, a->btgt); |
21451 | + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME)) | |
21452 | + == (ATTR_MODE | ATTR_CTIME)) { | |
7eafdf33 | 21453 | + err = security_path_chmod(&a->h_path, ia->ia_mode); |
4a4d8108 AM |
21454 | + if (unlikely(err)) |
21455 | + goto out_unlock; | |
21456 | + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID)) | |
21457 | + && (ia->ia_valid & ATTR_CTIME)) { | |
86dc4139 | 21458 | + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid); |
4a4d8108 AM |
21459 | + if (unlikely(err)) |
21460 | + goto out_unlock; | |
21461 | + } | |
dece6358 | 21462 | + |
4a4d8108 AM |
21463 | + if (ia->ia_valid & ATTR_SIZE) { |
21464 | + struct file *f; | |
1308ab2a | 21465 | + |
953406b4 | 21466 | + if (ia->ia_size < i_size_read(inode)) |
4a4d8108 | 21467 | + /* unmap only */ |
953406b4 | 21468 | + truncate_setsize(inode, ia->ia_size); |
1308ab2a | 21469 | + |
4a4d8108 AM |
21470 | + f = NULL; |
21471 | + if (ia->ia_valid & ATTR_FILE) | |
21472 | + f = ia->ia_file; | |
febd17d6 | 21473 | + inode_unlock(a->h_inode); |
4a4d8108 | 21474 | + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f); |
febd17d6 | 21475 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
523b37e3 AM |
21476 | + } else { |
21477 | + delegated = NULL; | |
21478 | + while (1) { | |
21479 | + err = vfsub_notify_change(&a->h_path, ia, &delegated); | |
21480 | + if (delegated) { | |
21481 | + err = break_deleg_wait(&delegated); | |
21482 | + if (!err) | |
21483 | + continue; | |
21484 | + } | |
21485 | + break; | |
21486 | + } | |
21487 | + } | |
8cdd5066 JR |
21488 | + /* |
21489 | + * regardless aufs 'acl' option setting. | |
21490 | + * why don't all acl-aware fs call this func from their ->setattr()? | |
21491 | + */ | |
21492 | + if (!err && (ia->ia_valid & ATTR_MODE)) | |
21493 | + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode); | |
4a4d8108 AM |
21494 | + if (!err) |
21495 | + au_cpup_attr_changeable(inode); | |
1308ab2a | 21496 | + |
4f0767ce | 21497 | +out_unlock: |
febd17d6 | 21498 | + inode_unlock(a->h_inode); |
4a4d8108 | 21499 | + au_unpin(&a->pin); |
027c5e7a | 21500 | + if (unlikely(err)) |
5afbbe0d | 21501 | + au_update_dbtop(dentry); |
4f0767ce | 21502 | +out_dentry: |
4a4d8108 AM |
21503 | + di_write_unlock(dentry); |
21504 | + if (file) { | |
21505 | + fi_write_unlock(file); | |
21506 | + ia->ia_file = file; | |
21507 | + ia->ia_valid |= ATTR_FILE; | |
21508 | + } | |
4f0767ce | 21509 | +out_si: |
4a4d8108 | 21510 | + si_read_unlock(sb); |
e49829fe | 21511 | +out_kfree: |
1c60b727 | 21512 | + kfree(a); |
4f0767ce | 21513 | +out: |
4a4d8108 AM |
21514 | + AuTraceErr(err); |
21515 | + return err; | |
1facf9fc | 21516 | +} |
21517 | + | |
c1595e42 JR |
21518 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) |
21519 | +static int au_h_path_to_set_attr(struct dentry *dentry, | |
21520 | + struct au_icpup_args *a, struct path *h_path) | |
21521 | +{ | |
21522 | + int err; | |
21523 | + struct super_block *sb; | |
21524 | + | |
21525 | + sb = dentry->d_sb; | |
21526 | + a->udba = au_opt_udba(sb); | |
21527 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
21528 | + if (d_unhashed(dentry)) | |
21529 | + a->udba = AuOpt_UDBA_NONE; | |
21530 | + if (a->udba != AuOpt_UDBA_NONE) { | |
21531 | + AuDebugOn(IS_ROOT(dentry)); | |
21532 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
21533 | + if (unlikely(err)) | |
21534 | + goto out; | |
21535 | + } | |
21536 | + err = au_pin_and_icpup(dentry, /*ia*/NULL, a); | |
21537 | + if (unlikely(err < 0)) | |
21538 | + goto out; | |
21539 | + | |
21540 | + h_path->dentry = a->h_path.dentry; | |
21541 | + h_path->mnt = au_sbr_mnt(sb, a->btgt); | |
21542 | + | |
21543 | +out: | |
21544 | + return err; | |
21545 | +} | |
21546 | + | |
f2c43d5f AM |
21547 | +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode, |
21548 | + struct au_sxattr *arg) | |
c1595e42 JR |
21549 | +{ |
21550 | + int err; | |
21551 | + struct path h_path; | |
21552 | + struct super_block *sb; | |
21553 | + struct au_icpup_args *a; | |
5afbbe0d | 21554 | + struct inode *h_inode; |
c1595e42 | 21555 | + |
c1595e42 JR |
21556 | + IMustLock(inode); |
21557 | + | |
21558 | + err = -ENOMEM; | |
21559 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
21560 | + if (unlikely(!a)) | |
21561 | + goto out; | |
21562 | + | |
21563 | + sb = dentry->d_sb; | |
21564 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
21565 | + if (unlikely(err)) | |
21566 | + goto out_kfree; | |
21567 | + | |
21568 | + h_path.dentry = NULL; /* silence gcc */ | |
21569 | + di_write_lock_child(dentry); | |
21570 | + err = au_h_path_to_set_attr(dentry, a, &h_path); | |
21571 | + if (unlikely(err)) | |
21572 | + goto out_di; | |
21573 | + | |
febd17d6 | 21574 | + inode_unlock(a->h_inode); |
c1595e42 JR |
21575 | + switch (arg->type) { |
21576 | + case AU_XATTR_SET: | |
5afbbe0d | 21577 | + AuDebugOn(d_is_negative(h_path.dentry)); |
c1595e42 JR |
21578 | + err = vfsub_setxattr(h_path.dentry, |
21579 | + arg->u.set.name, arg->u.set.value, | |
21580 | + arg->u.set.size, arg->u.set.flags); | |
21581 | + break; | |
c1595e42 JR |
21582 | + case AU_ACL_SET: |
21583 | + err = -EOPNOTSUPP; | |
5527c038 | 21584 | + h_inode = d_inode(h_path.dentry); |
c1595e42 | 21585 | + if (h_inode->i_op->set_acl) |
f2c43d5f | 21586 | + /* this will call posix_acl_update_mode */ |
c1595e42 JR |
21587 | + err = h_inode->i_op->set_acl(h_inode, |
21588 | + arg->u.acl_set.acl, | |
21589 | + arg->u.acl_set.type); | |
21590 | + break; | |
21591 | + } | |
21592 | + if (!err) | |
21593 | + au_cpup_attr_timesizes(inode); | |
21594 | + | |
21595 | + au_unpin(&a->pin); | |
21596 | + if (unlikely(err)) | |
5afbbe0d | 21597 | + au_update_dbtop(dentry); |
c1595e42 JR |
21598 | + |
21599 | +out_di: | |
21600 | + di_write_unlock(dentry); | |
21601 | + si_read_unlock(sb); | |
21602 | +out_kfree: | |
1c60b727 | 21603 | + kfree(a); |
c1595e42 JR |
21604 | +out: |
21605 | + AuTraceErr(err); | |
21606 | + return err; | |
21607 | +} | |
21608 | +#endif | |
21609 | + | |
4a4d8108 AM |
21610 | +static void au_refresh_iattr(struct inode *inode, struct kstat *st, |
21611 | + unsigned int nlink) | |
1facf9fc | 21612 | +{ |
9dbd164d AM |
21613 | + unsigned int n; |
21614 | + | |
4a4d8108 | 21615 | + inode->i_mode = st->mode; |
86dc4139 AM |
21616 | + /* don't i_[ug]id_write() here */ |
21617 | + inode->i_uid = st->uid; | |
21618 | + inode->i_gid = st->gid; | |
4a4d8108 AM |
21619 | + inode->i_atime = st->atime; |
21620 | + inode->i_mtime = st->mtime; | |
21621 | + inode->i_ctime = st->ctime; | |
1facf9fc | 21622 | + |
4a4d8108 AM |
21623 | + au_cpup_attr_nlink(inode, /*force*/0); |
21624 | + if (S_ISDIR(inode->i_mode)) { | |
9dbd164d AM |
21625 | + n = inode->i_nlink; |
21626 | + n -= nlink; | |
21627 | + n += st->nlink; | |
f6b6e03d | 21628 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 21629 | + /* 0 can happen */ |
92d182d2 | 21630 | + set_nlink(inode, n); |
4a4d8108 | 21631 | + } |
1facf9fc | 21632 | + |
4a4d8108 AM |
21633 | + spin_lock(&inode->i_lock); |
21634 | + inode->i_blocks = st->blocks; | |
21635 | + i_size_write(inode, st->size); | |
21636 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 21637 | +} |
21638 | + | |
c1595e42 | 21639 | +/* |
f2c43d5f | 21640 | + * common routine for aufs_getattr() and au_getxattr(). |
c1595e42 JR |
21641 | + * returns zero or negative (an error). |
21642 | + * @dentry will be read-locked in success. | |
21643 | + */ | |
a2654f78 AM |
21644 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path, |
21645 | + int locked) | |
1facf9fc | 21646 | +{ |
4a4d8108 | 21647 | + int err; |
076b876e | 21648 | + unsigned int mnt_flags, sigen; |
c1595e42 | 21649 | + unsigned char udba_none; |
4a4d8108 | 21650 | + aufs_bindex_t bindex; |
4a4d8108 AM |
21651 | + struct super_block *sb, *h_sb; |
21652 | + struct inode *inode; | |
1facf9fc | 21653 | + |
c1595e42 JR |
21654 | + h_path->mnt = NULL; |
21655 | + h_path->dentry = NULL; | |
21656 | + | |
21657 | + err = 0; | |
4a4d8108 | 21658 | + sb = dentry->d_sb; |
4a4d8108 AM |
21659 | + mnt_flags = au_mntflags(sb); |
21660 | + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE); | |
1facf9fc | 21661 | + |
a2654f78 AM |
21662 | + if (unlikely(locked)) |
21663 | + goto body; /* skip locking dinfo */ | |
21664 | + | |
4a4d8108 | 21665 | + /* support fstat(2) */ |
027c5e7a | 21666 | + if (!d_unlinked(dentry) && !udba_none) { |
076b876e | 21667 | + sigen = au_sigen(sb); |
027c5e7a AM |
21668 | + err = au_digen_test(dentry, sigen); |
21669 | + if (!err) { | |
4a4d8108 | 21670 | + di_read_lock_child(dentry, AuLock_IR); |
027c5e7a | 21671 | + err = au_dbrange_test(dentry); |
c1595e42 JR |
21672 | + if (unlikely(err)) { |
21673 | + di_read_unlock(dentry, AuLock_IR); | |
21674 | + goto out; | |
21675 | + } | |
027c5e7a | 21676 | + } else { |
4a4d8108 AM |
21677 | + AuDebugOn(IS_ROOT(dentry)); |
21678 | + di_write_lock_child(dentry); | |
027c5e7a AM |
21679 | + err = au_dbrange_test(dentry); |
21680 | + if (!err) | |
21681 | + err = au_reval_for_attr(dentry, sigen); | |
c1595e42 JR |
21682 | + if (!err) |
21683 | + di_downgrade_lock(dentry, AuLock_IR); | |
21684 | + else { | |
21685 | + di_write_unlock(dentry); | |
21686 | + goto out; | |
21687 | + } | |
4a4d8108 AM |
21688 | + } |
21689 | + } else | |
21690 | + di_read_lock_child(dentry, AuLock_IR); | |
1facf9fc | 21691 | + |
a2654f78 | 21692 | +body: |
5527c038 | 21693 | + inode = d_inode(dentry); |
5afbbe0d | 21694 | + bindex = au_ibtop(inode); |
c1595e42 JR |
21695 | + h_path->mnt = au_sbr_mnt(sb, bindex); |
21696 | + h_sb = h_path->mnt->mnt_sb; | |
21697 | + if (!force | |
21698 | + && !au_test_fs_bad_iattr(h_sb) | |
21699 | + && udba_none) | |
21700 | + goto out; /* success */ | |
1facf9fc | 21701 | + |
5afbbe0d | 21702 | + if (au_dbtop(dentry) == bindex) |
c1595e42 | 21703 | + h_path->dentry = au_h_dptr(dentry, bindex); |
4a4d8108 | 21704 | + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) { |
c1595e42 JR |
21705 | + h_path->dentry = au_plink_lkup(inode, bindex); |
21706 | + if (IS_ERR(h_path->dentry)) | |
21707 | + /* pretending success */ | |
21708 | + h_path->dentry = NULL; | |
21709 | + else | |
21710 | + dput(h_path->dentry); | |
4a4d8108 | 21711 | + } |
c1595e42 JR |
21712 | + |
21713 | +out: | |
21714 | + return err; | |
21715 | +} | |
21716 | + | |
521ced18 JR |
21717 | +static int aufs_getattr(const struct path *path, struct kstat *st, |
21718 | + u32 request, unsigned int query) | |
c1595e42 JR |
21719 | +{ |
21720 | + int err; | |
21721 | + unsigned char positive; | |
21722 | + struct path h_path; | |
521ced18 | 21723 | + struct dentry *dentry; |
c1595e42 JR |
21724 | + struct inode *inode; |
21725 | + struct super_block *sb; | |
21726 | + | |
521ced18 | 21727 | + dentry = path->dentry; |
5527c038 | 21728 | + inode = d_inode(dentry); |
c1595e42 JR |
21729 | + sb = dentry->d_sb; |
21730 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
21731 | + if (unlikely(err)) | |
21732 | + goto out; | |
a2654f78 | 21733 | + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0); |
c1595e42 JR |
21734 | + if (unlikely(err)) |
21735 | + goto out_si; | |
c06a8ce3 | 21736 | + if (unlikely(!h_path.dentry)) |
c1595e42 | 21737 | + /* illegally overlapped or something */ |
4a4d8108 AM |
21738 | + goto out_fill; /* pretending success */ |
21739 | + | |
5527c038 | 21740 | + positive = d_is_positive(h_path.dentry); |
4a4d8108 | 21741 | + if (positive) |
521ced18 JR |
21742 | + /* no vfsub version */ |
21743 | + err = vfs_getattr(&h_path, st, request, query); | |
4a4d8108 AM |
21744 | + if (!err) { |
21745 | + if (positive) | |
c06a8ce3 | 21746 | + au_refresh_iattr(inode, st, |
5527c038 | 21747 | + d_inode(h_path.dentry)->i_nlink); |
4a4d8108 | 21748 | + goto out_fill; /* success */ |
1facf9fc | 21749 | + } |
7f207e10 | 21750 | + AuTraceErr(err); |
c1595e42 | 21751 | + goto out_di; |
4a4d8108 | 21752 | + |
4f0767ce | 21753 | +out_fill: |
4a4d8108 | 21754 | + generic_fillattr(inode, st); |
c1595e42 | 21755 | +out_di: |
4a4d8108 | 21756 | + di_read_unlock(dentry, AuLock_IR); |
c1595e42 | 21757 | +out_si: |
4a4d8108 | 21758 | + si_read_unlock(sb); |
7f207e10 AM |
21759 | +out: |
21760 | + AuTraceErr(err); | |
4a4d8108 | 21761 | + return err; |
1facf9fc | 21762 | +} |
21763 | + | |
21764 | +/* ---------------------------------------------------------------------- */ | |
21765 | + | |
febd17d6 JR |
21766 | +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode, |
21767 | + struct delayed_call *done) | |
4a4d8108 | 21768 | +{ |
c2c0f25c | 21769 | + const char *ret; |
c2c0f25c | 21770 | + struct dentry *h_dentry; |
febd17d6 | 21771 | + struct inode *h_inode; |
4a4d8108 | 21772 | + int err; |
c2c0f25c | 21773 | + aufs_bindex_t bindex; |
1facf9fc | 21774 | + |
79b8bda9 | 21775 | + ret = NULL; /* suppress a warning */ |
febd17d6 JR |
21776 | + err = -ECHILD; |
21777 | + if (!dentry) | |
21778 | + goto out; | |
21779 | + | |
027c5e7a AM |
21780 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
21781 | + if (unlikely(err)) | |
c2c0f25c | 21782 | + goto out; |
027c5e7a AM |
21783 | + |
21784 | + err = au_d_hashed_positive(dentry); | |
c2c0f25c AM |
21785 | + if (unlikely(err)) |
21786 | + goto out_unlock; | |
21787 | + | |
21788 | + err = -EINVAL; | |
21789 | + inode = d_inode(dentry); | |
5afbbe0d | 21790 | + bindex = au_ibtop(inode); |
c2c0f25c | 21791 | + h_inode = au_h_iptr(inode, bindex); |
febd17d6 | 21792 | + if (unlikely(!h_inode->i_op->get_link)) |
c2c0f25c AM |
21793 | + goto out_unlock; |
21794 | + | |
21795 | + err = -EBUSY; | |
21796 | + h_dentry = NULL; | |
5afbbe0d | 21797 | + if (au_dbtop(dentry) <= bindex) { |
c2c0f25c AM |
21798 | + h_dentry = au_h_dptr(dentry, bindex); |
21799 | + if (h_dentry) | |
21800 | + dget(h_dentry); | |
027c5e7a | 21801 | + } |
c2c0f25c AM |
21802 | + if (!h_dentry) { |
21803 | + h_dentry = d_find_any_alias(h_inode); | |
21804 | + if (IS_ERR(h_dentry)) { | |
21805 | + err = PTR_ERR(h_dentry); | |
febd17d6 | 21806 | + goto out_unlock; |
c2c0f25c AM |
21807 | + } |
21808 | + } | |
21809 | + if (unlikely(!h_dentry)) | |
febd17d6 | 21810 | + goto out_unlock; |
1facf9fc | 21811 | + |
c2c0f25c | 21812 | + err = 0; |
febd17d6 | 21813 | + AuDbg("%pf\n", h_inode->i_op->get_link); |
c2c0f25c | 21814 | + AuDbgDentry(h_dentry); |
f2c43d5f | 21815 | + ret = vfs_get_link(h_dentry, done); |
c2c0f25c | 21816 | + dput(h_dentry); |
febd17d6 JR |
21817 | + if (IS_ERR(ret)) |
21818 | + err = PTR_ERR(ret); | |
c2c0f25c | 21819 | + |
c2c0f25c AM |
21820 | +out_unlock: |
21821 | + aufs_read_unlock(dentry, AuLock_IR); | |
4f0767ce | 21822 | +out: |
c2c0f25c AM |
21823 | + if (unlikely(err)) |
21824 | + ret = ERR_PTR(err); | |
21825 | + AuTraceErrPtr(ret); | |
21826 | + return ret; | |
4a4d8108 | 21827 | +} |
1facf9fc | 21828 | + |
4a4d8108 | 21829 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 21830 | + |
e2f27e51 AM |
21831 | +static int au_is_special(struct inode *inode) |
21832 | +{ | |
21833 | + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK)); | |
21834 | +} | |
21835 | + | |
0c3ec466 | 21836 | +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags) |
4a4d8108 | 21837 | +{ |
0c3ec466 | 21838 | + int err; |
e2f27e51 | 21839 | + aufs_bindex_t bindex; |
0c3ec466 AM |
21840 | + struct super_block *sb; |
21841 | + struct inode *h_inode; | |
e2f27e51 | 21842 | + struct vfsmount *h_mnt; |
0c3ec466 AM |
21843 | + |
21844 | + sb = inode->i_sb; | |
e2f27e51 AM |
21845 | + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode), |
21846 | + "unexpected s_flags 0x%lx", sb->s_flags); | |
21847 | + | |
0c3ec466 AM |
21848 | + /* mmap_sem might be acquired already, cf. aufs_mmap() */ |
21849 | + lockdep_off(); | |
21850 | + si_read_lock(sb, AuLock_FLUSH); | |
21851 | + ii_write_lock_child(inode); | |
e2f27e51 AM |
21852 | + |
21853 | + err = 0; | |
21854 | + bindex = au_ibtop(inode); | |
21855 | + h_inode = au_h_iptr(inode, bindex); | |
21856 | + if (!au_test_ro(sb, bindex, inode)) { | |
21857 | + h_mnt = au_sbr_mnt(sb, bindex); | |
21858 | + err = vfsub_mnt_want_write(h_mnt); | |
21859 | + if (!err) { | |
21860 | + err = vfsub_update_time(h_inode, ts, flags); | |
21861 | + vfsub_mnt_drop_write(h_mnt); | |
21862 | + } | |
21863 | + } else if (au_is_special(h_inode)) { | |
21864 | + /* | |
21865 | + * Never copy-up here. | |
21866 | + * These special files may already be opened and used for | |
21867 | + * communicating. If we copied it up, then the communication | |
21868 | + * would be corrupted. | |
21869 | + */ | |
21870 | + AuWarn1("timestamps for i%lu are ignored " | |
21871 | + "since it is on readonly branch (hi%lu).\n", | |
21872 | + inode->i_ino, h_inode->i_ino); | |
21873 | + } else if (flags & ~S_ATIME) { | |
21874 | + err = -EIO; | |
21875 | + AuIOErr1("unexpected flags 0x%x\n", flags); | |
21876 | + AuDebugOn(1); | |
21877 | + } | |
21878 | + | |
38d290e6 JR |
21879 | + if (!err) |
21880 | + au_cpup_attr_timesizes(inode); | |
0c3ec466 AM |
21881 | + ii_write_unlock(inode); |
21882 | + si_read_unlock(sb); | |
21883 | + lockdep_on(); | |
38d290e6 JR |
21884 | + |
21885 | + if (!err && (flags & S_VERSION)) | |
21886 | + inode_inc_iversion(inode); | |
21887 | + | |
0c3ec466 | 21888 | + return err; |
4a4d8108 | 21889 | +} |
1facf9fc | 21890 | + |
4a4d8108 | 21891 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 21892 | + |
b95c5147 AM |
21893 | +/* no getattr version will be set by module.c:aufs_init() */ |
21894 | +struct inode_operations aufs_iop_nogetattr[AuIop_Last], | |
21895 | + aufs_iop[] = { | |
21896 | + [AuIop_SYMLINK] = { | |
21897 | + .permission = aufs_permission, | |
c1595e42 | 21898 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
21899 | + .get_acl = aufs_get_acl, |
21900 | + .set_acl = aufs_set_acl, /* unsupport for symlink? */ | |
c1595e42 JR |
21901 | +#endif |
21902 | + | |
b95c5147 AM |
21903 | + .setattr = aufs_setattr, |
21904 | + .getattr = aufs_getattr, | |
0c3ec466 | 21905 | + |
c1595e42 | 21906 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 21907 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
21908 | +#endif |
21909 | + | |
febd17d6 | 21910 | + .get_link = aufs_get_link, |
0c3ec466 | 21911 | + |
b95c5147 AM |
21912 | + /* .update_time = aufs_update_time */ |
21913 | + }, | |
21914 | + [AuIop_DIR] = { | |
21915 | + .create = aufs_create, | |
21916 | + .lookup = aufs_lookup, | |
21917 | + .link = aufs_link, | |
21918 | + .unlink = aufs_unlink, | |
21919 | + .symlink = aufs_symlink, | |
21920 | + .mkdir = aufs_mkdir, | |
21921 | + .rmdir = aufs_rmdir, | |
21922 | + .mknod = aufs_mknod, | |
21923 | + .rename = aufs_rename, | |
21924 | + | |
21925 | + .permission = aufs_permission, | |
c1595e42 | 21926 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
21927 | + .get_acl = aufs_get_acl, |
21928 | + .set_acl = aufs_set_acl, | |
c1595e42 JR |
21929 | +#endif |
21930 | + | |
b95c5147 AM |
21931 | + .setattr = aufs_setattr, |
21932 | + .getattr = aufs_getattr, | |
0c3ec466 | 21933 | + |
c1595e42 | 21934 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 21935 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
21936 | +#endif |
21937 | + | |
b95c5147 AM |
21938 | + .update_time = aufs_update_time, |
21939 | + .atomic_open = aufs_atomic_open, | |
21940 | + .tmpfile = aufs_tmpfile | |
21941 | + }, | |
21942 | + [AuIop_OTHER] = { | |
21943 | + .permission = aufs_permission, | |
c1595e42 | 21944 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
21945 | + .get_acl = aufs_get_acl, |
21946 | + .set_acl = aufs_set_acl, | |
c1595e42 JR |
21947 | +#endif |
21948 | + | |
b95c5147 AM |
21949 | + .setattr = aufs_setattr, |
21950 | + .getattr = aufs_getattr, | |
0c3ec466 | 21951 | + |
c1595e42 | 21952 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 21953 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
21954 | +#endif |
21955 | + | |
b95c5147 AM |
21956 | + .update_time = aufs_update_time |
21957 | + } | |
4a4d8108 | 21958 | +}; |
7f207e10 AM |
21959 | diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c |
21960 | --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 21961 | +++ linux/fs/aufs/i_op_del.c 2018-01-29 07:56:20.056658502 +0100 |
5afbbe0d | 21962 | @@ -0,0 +1,511 @@ |
1facf9fc | 21963 | +/* |
a2654f78 | 21964 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 21965 | + * |
21966 | + * This program, aufs is free software; you can redistribute it and/or modify | |
21967 | + * it under the terms of the GNU General Public License as published by | |
21968 | + * the Free Software Foundation; either version 2 of the License, or | |
21969 | + * (at your option) any later version. | |
dece6358 AM |
21970 | + * |
21971 | + * This program is distributed in the hope that it will be useful, | |
21972 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21973 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21974 | + * GNU General Public License for more details. | |
21975 | + * | |
21976 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 21977 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 21978 | + */ |
21979 | + | |
21980 | +/* | |
4a4d8108 | 21981 | + * inode operations (del entry) |
1308ab2a | 21982 | + */ |
dece6358 | 21983 | + |
1308ab2a | 21984 | +#include "aufs.h" |
dece6358 | 21985 | + |
4a4d8108 AM |
21986 | +/* |
21987 | + * decide if a new whiteout for @dentry is necessary or not. | |
21988 | + * when it is necessary, prepare the parent dir for the upper branch whose | |
21989 | + * branch index is @bcpup for creation. the actual creation of the whiteout will | |
21990 | + * be done by caller. | |
21991 | + * return value: | |
21992 | + * 0: wh is unnecessary | |
21993 | + * plus: wh is necessary | |
21994 | + * minus: error | |
21995 | + */ | |
21996 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup) | |
1308ab2a | 21997 | +{ |
4a4d8108 | 21998 | + int need_wh, err; |
5afbbe0d | 21999 | + aufs_bindex_t btop; |
4a4d8108 | 22000 | + struct super_block *sb; |
dece6358 | 22001 | + |
4a4d8108 | 22002 | + sb = dentry->d_sb; |
5afbbe0d | 22003 | + btop = au_dbtop(dentry); |
4a4d8108 | 22004 | + if (*bcpup < 0) { |
5afbbe0d AM |
22005 | + *bcpup = btop; |
22006 | + if (au_test_ro(sb, btop, d_inode(dentry))) { | |
4a4d8108 AM |
22007 | + err = AuWbrCopyup(au_sbi(sb), dentry); |
22008 | + *bcpup = err; | |
22009 | + if (unlikely(err < 0)) | |
22010 | + goto out; | |
22011 | + } | |
22012 | + } else | |
5afbbe0d | 22013 | + AuDebugOn(btop < *bcpup |
5527c038 | 22014 | + || au_test_ro(sb, *bcpup, d_inode(dentry))); |
5afbbe0d | 22015 | + AuDbg("bcpup %d, btop %d\n", *bcpup, btop); |
1308ab2a | 22016 | + |
5afbbe0d | 22017 | + if (*bcpup != btop) { |
4a4d8108 AM |
22018 | + err = au_cpup_dirs(dentry, *bcpup); |
22019 | + if (unlikely(err)) | |
22020 | + goto out; | |
22021 | + need_wh = 1; | |
22022 | + } else { | |
027c5e7a | 22023 | + struct au_dinfo *dinfo, *tmp; |
4a4d8108 | 22024 | + |
027c5e7a AM |
22025 | + need_wh = -ENOMEM; |
22026 | + dinfo = au_di(dentry); | |
22027 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
22028 | + if (tmp) { | |
22029 | + au_di_cp(tmp, dinfo); | |
22030 | + au_di_swap(tmp, dinfo); | |
22031 | + /* returns the number of positive dentries */ | |
5afbbe0d AM |
22032 | + need_wh = au_lkup_dentry(dentry, btop + 1, |
22033 | + /* AuLkup_IGNORE_PERM */ 0); | |
027c5e7a AM |
22034 | + au_di_swap(tmp, dinfo); |
22035 | + au_rw_write_unlock(&tmp->di_rwsem); | |
22036 | + au_di_free(tmp); | |
4a4d8108 AM |
22037 | + } |
22038 | + } | |
22039 | + AuDbg("need_wh %d\n", need_wh); | |
22040 | + err = need_wh; | |
22041 | + | |
4f0767ce | 22042 | +out: |
4a4d8108 | 22043 | + return err; |
1facf9fc | 22044 | +} |
22045 | + | |
4a4d8108 AM |
22046 | +/* |
22047 | + * simple tests for the del-entry operations. | |
22048 | + * following the checks in vfs, plus the parent-child relationship. | |
22049 | + */ | |
22050 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
22051 | + struct dentry *h_parent, int isdir) | |
1facf9fc | 22052 | +{ |
4a4d8108 AM |
22053 | + int err; |
22054 | + umode_t h_mode; | |
22055 | + struct dentry *h_dentry, *h_latest; | |
1308ab2a | 22056 | + struct inode *h_inode; |
1facf9fc | 22057 | + |
4a4d8108 | 22058 | + h_dentry = au_h_dptr(dentry, bindex); |
5527c038 | 22059 | + if (d_really_is_positive(dentry)) { |
4a4d8108 | 22060 | + err = -ENOENT; |
5527c038 JR |
22061 | + if (unlikely(d_is_negative(h_dentry))) |
22062 | + goto out; | |
22063 | + h_inode = d_inode(h_dentry); | |
22064 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 | 22065 | + goto out; |
1facf9fc | 22066 | + |
4a4d8108 AM |
22067 | + h_mode = h_inode->i_mode; |
22068 | + if (!isdir) { | |
22069 | + err = -EISDIR; | |
22070 | + if (unlikely(S_ISDIR(h_mode))) | |
22071 | + goto out; | |
22072 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
22073 | + err = -ENOTDIR; | |
22074 | + goto out; | |
22075 | + } | |
22076 | + } else { | |
22077 | + /* rename(2) case */ | |
22078 | + err = -EIO; | |
5527c038 | 22079 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
22080 | + goto out; |
22081 | + } | |
1facf9fc | 22082 | + |
4a4d8108 AM |
22083 | + err = -ENOENT; |
22084 | + /* expected parent dir is locked */ | |
22085 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
22086 | + goto out; | |
22087 | + err = 0; | |
22088 | + | |
22089 | + /* | |
22090 | + * rmdir a dir may break the consistency on some filesystem. | |
22091 | + * let's try heavy test. | |
22092 | + */ | |
22093 | + err = -EACCES; | |
076b876e | 22094 | + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1) |
5527c038 | 22095 | + && au_test_h_perm(d_inode(h_parent), |
076b876e | 22096 | + MAY_EXEC | MAY_WRITE))) |
4a4d8108 AM |
22097 | + goto out; |
22098 | + | |
076b876e | 22099 | + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent); |
4a4d8108 AM |
22100 | + err = -EIO; |
22101 | + if (IS_ERR(h_latest)) | |
22102 | + goto out; | |
22103 | + if (h_latest == h_dentry) | |
22104 | + err = 0; | |
22105 | + dput(h_latest); | |
22106 | + | |
4f0767ce | 22107 | +out: |
4a4d8108 | 22108 | + return err; |
1308ab2a | 22109 | +} |
1facf9fc | 22110 | + |
4a4d8108 AM |
22111 | +/* |
22112 | + * decide the branch where we operate for @dentry. the branch index will be set | |
22113 | + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent | |
22114 | + * dir for reverting. | |
22115 | + * when a new whiteout is necessary, create it. | |
22116 | + */ | |
22117 | +static struct dentry* | |
22118 | +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup, | |
22119 | + struct au_dtime *dt, struct au_pin *pin) | |
1308ab2a | 22120 | +{ |
4a4d8108 AM |
22121 | + struct dentry *wh_dentry; |
22122 | + struct super_block *sb; | |
22123 | + struct path h_path; | |
22124 | + int err, need_wh; | |
22125 | + unsigned int udba; | |
22126 | + aufs_bindex_t bcpup; | |
dece6358 | 22127 | + |
4a4d8108 AM |
22128 | + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup); |
22129 | + wh_dentry = ERR_PTR(need_wh); | |
22130 | + if (unlikely(need_wh < 0)) | |
22131 | + goto out; | |
22132 | + | |
22133 | + sb = dentry->d_sb; | |
22134 | + udba = au_opt_udba(sb); | |
22135 | + bcpup = *rbcpup; | |
22136 | + err = au_pin(pin, dentry, bcpup, udba, | |
22137 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
22138 | + wh_dentry = ERR_PTR(err); | |
22139 | + if (unlikely(err)) | |
22140 | + goto out; | |
22141 | + | |
22142 | + h_path.dentry = au_pinned_h_parent(pin); | |
22143 | + if (udba != AuOpt_UDBA_NONE | |
5afbbe0d | 22144 | + && au_dbtop(dentry) == bcpup) { |
4a4d8108 AM |
22145 | + err = au_may_del(dentry, bcpup, h_path.dentry, isdir); |
22146 | + wh_dentry = ERR_PTR(err); | |
22147 | + if (unlikely(err)) | |
22148 | + goto out_unpin; | |
22149 | + } | |
22150 | + | |
22151 | + h_path.mnt = au_sbr_mnt(sb, bcpup); | |
22152 | + au_dtime_store(dt, au_pinned_parent(pin), &h_path); | |
22153 | + wh_dentry = NULL; | |
22154 | + if (!need_wh) | |
22155 | + goto out; /* success, no need to create whiteout */ | |
22156 | + | |
22157 | + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry); | |
22158 | + if (IS_ERR(wh_dentry)) | |
22159 | + goto out_unpin; | |
22160 | + | |
22161 | + /* returns with the parent is locked and wh_dentry is dget-ed */ | |
22162 | + goto out; /* success */ | |
22163 | + | |
4f0767ce | 22164 | +out_unpin: |
4a4d8108 | 22165 | + au_unpin(pin); |
4f0767ce | 22166 | +out: |
4a4d8108 | 22167 | + return wh_dentry; |
1facf9fc | 22168 | +} |
22169 | + | |
4a4d8108 AM |
22170 | +/* |
22171 | + * when removing a dir, rename it to a unique temporary whiteout-ed name first | |
22172 | + * in order to be revertible and save time for removing many child whiteouts | |
22173 | + * under the dir. | |
22174 | + * returns 1 when there are too many child whiteout and caller should remove | |
22175 | + * them asynchronously. returns 0 when the number of children is enough small to | |
22176 | + * remove now or the branch fs is a remote fs. | |
22177 | + * otherwise return an error. | |
22178 | + */ | |
22179 | +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex, | |
22180 | + struct au_nhash *whlist, struct inode *dir) | |
1facf9fc | 22181 | +{ |
4a4d8108 AM |
22182 | + int rmdir_later, err, dirwh; |
22183 | + struct dentry *h_dentry; | |
22184 | + struct super_block *sb; | |
5527c038 | 22185 | + struct inode *inode; |
4a4d8108 AM |
22186 | + |
22187 | + sb = dentry->d_sb; | |
22188 | + SiMustAnyLock(sb); | |
22189 | + h_dentry = au_h_dptr(dentry, bindex); | |
22190 | + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex)); | |
22191 | + if (unlikely(err)) | |
22192 | + goto out; | |
22193 | + | |
22194 | + /* stop monitoring */ | |
5527c038 JR |
22195 | + inode = d_inode(dentry); |
22196 | + au_hn_free(au_hi(inode, bindex)); | |
4a4d8108 AM |
22197 | + |
22198 | + if (!au_test_fs_remote(h_dentry->d_sb)) { | |
22199 | + dirwh = au_sbi(sb)->si_dirwh; | |
22200 | + rmdir_later = (dirwh <= 1); | |
22201 | + if (!rmdir_later) | |
22202 | + rmdir_later = au_nhash_test_longer_wh(whlist, bindex, | |
22203 | + dirwh); | |
22204 | + if (rmdir_later) | |
22205 | + return rmdir_later; | |
22206 | + } | |
1facf9fc | 22207 | + |
4a4d8108 AM |
22208 | + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist); |
22209 | + if (unlikely(err)) { | |
523b37e3 AM |
22210 | + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n", |
22211 | + h_dentry, bindex, err); | |
4a4d8108 AM |
22212 | + err = 0; |
22213 | + } | |
dece6358 | 22214 | + |
4f0767ce | 22215 | +out: |
4a4d8108 AM |
22216 | + AuTraceErr(err); |
22217 | + return err; | |
22218 | +} | |
1308ab2a | 22219 | + |
4a4d8108 AM |
22220 | +/* |
22221 | + * final procedure for deleting a entry. | |
22222 | + * maintain dentry and iattr. | |
22223 | + */ | |
22224 | +static void epilog(struct inode *dir, struct dentry *dentry, | |
22225 | + aufs_bindex_t bindex) | |
22226 | +{ | |
22227 | + struct inode *inode; | |
1308ab2a | 22228 | + |
5527c038 | 22229 | + inode = d_inode(dentry); |
4a4d8108 AM |
22230 | + d_drop(dentry); |
22231 | + inode->i_ctime = dir->i_ctime; | |
1308ab2a | 22232 | + |
b912730e | 22233 | + au_dir_ts(dir, bindex); |
4a4d8108 | 22234 | + dir->i_version++; |
1facf9fc | 22235 | +} |
22236 | + | |
4a4d8108 AM |
22237 | +/* |
22238 | + * when an error happened, remove the created whiteout and revert everything. | |
22239 | + */ | |
7f207e10 AM |
22240 | +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex, |
22241 | + aufs_bindex_t bwh, struct dentry *wh_dentry, | |
22242 | + struct dentry *dentry, struct au_dtime *dt) | |
1facf9fc | 22243 | +{ |
4a4d8108 AM |
22244 | + int rerr; |
22245 | + struct path h_path = { | |
22246 | + .dentry = wh_dentry, | |
7f207e10 | 22247 | + .mnt = au_sbr_mnt(dir->i_sb, bindex) |
4a4d8108 | 22248 | + }; |
dece6358 | 22249 | + |
7f207e10 | 22250 | + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry); |
4a4d8108 AM |
22251 | + if (!rerr) { |
22252 | + au_set_dbwh(dentry, bwh); | |
22253 | + au_dtime_revert(dt); | |
22254 | + return 0; | |
22255 | + } | |
dece6358 | 22256 | + |
523b37e3 | 22257 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr); |
4a4d8108 | 22258 | + return -EIO; |
1facf9fc | 22259 | +} |
22260 | + | |
4a4d8108 | 22261 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 22262 | + |
4a4d8108 | 22263 | +int aufs_unlink(struct inode *dir, struct dentry *dentry) |
1308ab2a | 22264 | +{ |
4a4d8108 | 22265 | + int err; |
5afbbe0d | 22266 | + aufs_bindex_t bwh, bindex, btop; |
523b37e3 | 22267 | + struct inode *inode, *h_dir, *delegated; |
4a4d8108 | 22268 | + struct dentry *parent, *wh_dentry; |
c2b27bf2 AM |
22269 | + /* to reuduce stack size */ |
22270 | + struct { | |
22271 | + struct au_dtime dt; | |
22272 | + struct au_pin pin; | |
22273 | + struct path h_path; | |
22274 | + } *a; | |
1facf9fc | 22275 | + |
4a4d8108 | 22276 | + IMustLock(dir); |
027c5e7a | 22277 | + |
c2b27bf2 AM |
22278 | + err = -ENOMEM; |
22279 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
22280 | + if (unlikely(!a)) | |
22281 | + goto out; | |
22282 | + | |
027c5e7a AM |
22283 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
22284 | + if (unlikely(err)) | |
c2b27bf2 | 22285 | + goto out_free; |
027c5e7a AM |
22286 | + err = au_d_hashed_positive(dentry); |
22287 | + if (unlikely(err)) | |
22288 | + goto out_unlock; | |
5527c038 | 22289 | + inode = d_inode(dentry); |
4a4d8108 | 22290 | + IMustLock(inode); |
027c5e7a | 22291 | + err = -EISDIR; |
2000de60 | 22292 | + if (unlikely(d_is_dir(dentry))) |
027c5e7a | 22293 | + goto out_unlock; /* possible? */ |
1facf9fc | 22294 | + |
5afbbe0d | 22295 | + btop = au_dbtop(dentry); |
4a4d8108 AM |
22296 | + bwh = au_dbwh(dentry); |
22297 | + bindex = -1; | |
027c5e7a AM |
22298 | + parent = dentry->d_parent; /* dir inode is locked */ |
22299 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
22300 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt, |
22301 | + &a->pin); | |
4a4d8108 AM |
22302 | + err = PTR_ERR(wh_dentry); |
22303 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 22304 | + goto out_parent; |
1facf9fc | 22305 | + |
5afbbe0d AM |
22306 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop); |
22307 | + a->h_path.dentry = au_h_dptr(dentry, btop); | |
c2b27bf2 | 22308 | + dget(a->h_path.dentry); |
5afbbe0d | 22309 | + if (bindex == btop) { |
c2b27bf2 | 22310 | + h_dir = au_pinned_h_dir(&a->pin); |
523b37e3 AM |
22311 | + delegated = NULL; |
22312 | + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0); | |
22313 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22314 | + pr_warn("cannot retry for NFSv4 delegation" | |
22315 | + " for an internal unlink\n"); | |
22316 | + iput(delegated); | |
22317 | + } | |
4a4d8108 AM |
22318 | + } else { |
22319 | + /* dir inode is locked */ | |
5527c038 | 22320 | + h_dir = d_inode(wh_dentry->d_parent); |
4a4d8108 AM |
22321 | + IMustLock(h_dir); |
22322 | + err = 0; | |
22323 | + } | |
dece6358 | 22324 | + |
4a4d8108 | 22325 | + if (!err) { |
7f207e10 | 22326 | + vfsub_drop_nlink(inode); |
4a4d8108 AM |
22327 | + epilog(dir, dentry, bindex); |
22328 | + | |
22329 | + /* update target timestamps */ | |
5afbbe0d | 22330 | + if (bindex == btop) { |
c2b27bf2 AM |
22331 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); |
22332 | + /*ignore*/ | |
5527c038 | 22333 | + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
4a4d8108 AM |
22334 | + } else |
22335 | + /* todo: this timestamp may be reverted later */ | |
22336 | + inode->i_ctime = h_dir->i_ctime; | |
027c5e7a | 22337 | + goto out_unpin; /* success */ |
1facf9fc | 22338 | + } |
22339 | + | |
4a4d8108 AM |
22340 | + /* revert */ |
22341 | + if (wh_dentry) { | |
22342 | + int rerr; | |
22343 | + | |
c2b27bf2 AM |
22344 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
22345 | + &a->dt); | |
4a4d8108 AM |
22346 | + if (rerr) |
22347 | + err = rerr; | |
dece6358 | 22348 | + } |
1facf9fc | 22349 | + |
027c5e7a | 22350 | +out_unpin: |
c2b27bf2 | 22351 | + au_unpin(&a->pin); |
4a4d8108 | 22352 | + dput(wh_dentry); |
c2b27bf2 | 22353 | + dput(a->h_path.dentry); |
027c5e7a | 22354 | +out_parent: |
4a4d8108 | 22355 | + di_write_unlock(parent); |
027c5e7a | 22356 | +out_unlock: |
4a4d8108 | 22357 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 | 22358 | +out_free: |
1c60b727 | 22359 | + kfree(a); |
027c5e7a | 22360 | +out: |
4a4d8108 | 22361 | + return err; |
dece6358 AM |
22362 | +} |
22363 | + | |
4a4d8108 | 22364 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry) |
1308ab2a | 22365 | +{ |
4a4d8108 | 22366 | + int err, rmdir_later; |
5afbbe0d | 22367 | + aufs_bindex_t bwh, bindex, btop; |
4a4d8108 AM |
22368 | + struct inode *inode; |
22369 | + struct dentry *parent, *wh_dentry, *h_dentry; | |
22370 | + struct au_whtmp_rmdir *args; | |
c2b27bf2 AM |
22371 | + /* to reuduce stack size */ |
22372 | + struct { | |
22373 | + struct au_dtime dt; | |
22374 | + struct au_pin pin; | |
22375 | + } *a; | |
1facf9fc | 22376 | + |
4a4d8108 | 22377 | + IMustLock(dir); |
027c5e7a | 22378 | + |
c2b27bf2 AM |
22379 | + err = -ENOMEM; |
22380 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
22381 | + if (unlikely(!a)) | |
22382 | + goto out; | |
22383 | + | |
027c5e7a AM |
22384 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
22385 | + if (unlikely(err)) | |
c2b27bf2 | 22386 | + goto out_free; |
53392da6 AM |
22387 | + err = au_alive_dir(dentry); |
22388 | + if (unlikely(err)) | |
027c5e7a | 22389 | + goto out_unlock; |
5527c038 | 22390 | + inode = d_inode(dentry); |
4a4d8108 | 22391 | + IMustLock(inode); |
027c5e7a | 22392 | + err = -ENOTDIR; |
2000de60 | 22393 | + if (unlikely(!d_is_dir(dentry))) |
027c5e7a | 22394 | + goto out_unlock; /* possible? */ |
dece6358 | 22395 | + |
4a4d8108 AM |
22396 | + err = -ENOMEM; |
22397 | + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS); | |
22398 | + if (unlikely(!args)) | |
22399 | + goto out_unlock; | |
dece6358 | 22400 | + |
4a4d8108 AM |
22401 | + parent = dentry->d_parent; /* dir inode is locked */ |
22402 | + di_write_lock_parent(parent); | |
22403 | + err = au_test_empty(dentry, &args->whlist); | |
22404 | + if (unlikely(err)) | |
027c5e7a | 22405 | + goto out_parent; |
1facf9fc | 22406 | + |
5afbbe0d | 22407 | + btop = au_dbtop(dentry); |
4a4d8108 AM |
22408 | + bwh = au_dbwh(dentry); |
22409 | + bindex = -1; | |
c2b27bf2 AM |
22410 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt, |
22411 | + &a->pin); | |
4a4d8108 AM |
22412 | + err = PTR_ERR(wh_dentry); |
22413 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 22414 | + goto out_parent; |
1facf9fc | 22415 | + |
5afbbe0d | 22416 | + h_dentry = au_h_dptr(dentry, btop); |
4a4d8108 AM |
22417 | + dget(h_dentry); |
22418 | + rmdir_later = 0; | |
5afbbe0d AM |
22419 | + if (bindex == btop) { |
22420 | + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir); | |
4a4d8108 AM |
22421 | + if (err > 0) { |
22422 | + rmdir_later = err; | |
22423 | + err = 0; | |
22424 | + } | |
22425 | + } else { | |
22426 | + /* stop monitoring */ | |
5afbbe0d | 22427 | + au_hn_free(au_hi(inode, btop)); |
4a4d8108 AM |
22428 | + |
22429 | + /* dir inode is locked */ | |
5527c038 | 22430 | + IMustLock(d_inode(wh_dentry->d_parent)); |
1facf9fc | 22431 | + err = 0; |
22432 | + } | |
22433 | + | |
4a4d8108 | 22434 | + if (!err) { |
027c5e7a | 22435 | + vfsub_dead_dir(inode); |
4a4d8108 AM |
22436 | + au_set_dbdiropq(dentry, -1); |
22437 | + epilog(dir, dentry, bindex); | |
1308ab2a | 22438 | + |
4a4d8108 | 22439 | + if (rmdir_later) { |
5afbbe0d | 22440 | + au_whtmp_kick_rmdir(dir, btop, h_dentry, args); |
4a4d8108 AM |
22441 | + args = NULL; |
22442 | + } | |
1308ab2a | 22443 | + |
4a4d8108 | 22444 | + goto out_unpin; /* success */ |
1facf9fc | 22445 | + } |
22446 | + | |
4a4d8108 AM |
22447 | + /* revert */ |
22448 | + AuLabel(revert); | |
22449 | + if (wh_dentry) { | |
22450 | + int rerr; | |
1308ab2a | 22451 | + |
c2b27bf2 AM |
22452 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
22453 | + &a->dt); | |
4a4d8108 AM |
22454 | + if (rerr) |
22455 | + err = rerr; | |
1facf9fc | 22456 | + } |
22457 | + | |
4f0767ce | 22458 | +out_unpin: |
c2b27bf2 | 22459 | + au_unpin(&a->pin); |
4a4d8108 AM |
22460 | + dput(wh_dentry); |
22461 | + dput(h_dentry); | |
027c5e7a | 22462 | +out_parent: |
4a4d8108 AM |
22463 | + di_write_unlock(parent); |
22464 | + if (args) | |
22465 | + au_whtmp_rmdir_free(args); | |
4f0767ce | 22466 | +out_unlock: |
4a4d8108 | 22467 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 | 22468 | +out_free: |
1c60b727 | 22469 | + kfree(a); |
4f0767ce | 22470 | +out: |
4a4d8108 AM |
22471 | + AuTraceErr(err); |
22472 | + return err; | |
dece6358 | 22473 | +} |
7f207e10 AM |
22474 | diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c |
22475 | --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 22476 | +++ linux/fs/aufs/i_op_ren.c 2018-01-29 07:56:20.056658502 +0100 |
8b6a4947 | 22477 | @@ -0,0 +1,1246 @@ |
1facf9fc | 22478 | +/* |
a2654f78 | 22479 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 22480 | + * |
22481 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22482 | + * it under the terms of the GNU General Public License as published by | |
22483 | + * the Free Software Foundation; either version 2 of the License, or | |
22484 | + * (at your option) any later version. | |
dece6358 AM |
22485 | + * |
22486 | + * This program is distributed in the hope that it will be useful, | |
22487 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22488 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22489 | + * GNU General Public License for more details. | |
22490 | + * | |
22491 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22492 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22493 | + */ |
22494 | + | |
22495 | +/* | |
4a4d8108 AM |
22496 | + * inode operation (rename entry) |
22497 | + * todo: this is crazy monster | |
1facf9fc | 22498 | + */ |
22499 | + | |
22500 | +#include "aufs.h" | |
22501 | + | |
4a4d8108 AM |
22502 | +enum { AuSRC, AuDST, AuSrcDst }; |
22503 | +enum { AuPARENT, AuCHILD, AuParentChild }; | |
1facf9fc | 22504 | + |
f2c43d5f AM |
22505 | +#define AuRen_ISDIR_SRC 1 |
22506 | +#define AuRen_ISDIR_DST (1 << 1) | |
22507 | +#define AuRen_ISSAMEDIR (1 << 2) | |
22508 | +#define AuRen_WHSRC (1 << 3) | |
22509 | +#define AuRen_WHDST (1 << 4) | |
22510 | +#define AuRen_MNT_WRITE (1 << 5) | |
22511 | +#define AuRen_DT_DSTDIR (1 << 6) | |
22512 | +#define AuRen_DIROPQ_SRC (1 << 7) | |
22513 | +#define AuRen_DIROPQ_DST (1 << 8) | |
8b6a4947 AM |
22514 | +#define AuRen_DIRREN (1 << 9) |
22515 | +#define AuRen_DROPPED_SRC (1 << 10) | |
22516 | +#define AuRen_DROPPED_DST (1 << 11) | |
4a4d8108 | 22517 | +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) |
7f207e10 AM |
22518 | +#define au_fset_ren(flags, name) \ |
22519 | + do { (flags) |= AuRen_##name; } while (0) | |
22520 | +#define au_fclr_ren(flags, name) \ | |
22521 | + do { (flags) &= ~AuRen_##name; } while (0) | |
1facf9fc | 22522 | + |
8b6a4947 AM |
22523 | +#ifndef CONFIG_AUFS_DIRREN |
22524 | +#undef AuRen_DIRREN | |
22525 | +#define AuRen_DIRREN 0 | |
22526 | +#endif | |
22527 | + | |
4a4d8108 AM |
22528 | +struct au_ren_args { |
22529 | + struct { | |
22530 | + struct dentry *dentry, *h_dentry, *parent, *h_parent, | |
22531 | + *wh_dentry; | |
22532 | + struct inode *dir, *inode; | |
f2c43d5f | 22533 | + struct au_hinode *hdir, *hinode; |
4a4d8108 | 22534 | + struct au_dtime dt[AuParentChild]; |
f2c43d5f | 22535 | + aufs_bindex_t btop, bdiropq; |
4a4d8108 | 22536 | + } sd[AuSrcDst]; |
1facf9fc | 22537 | + |
4a4d8108 AM |
22538 | +#define src_dentry sd[AuSRC].dentry |
22539 | +#define src_dir sd[AuSRC].dir | |
22540 | +#define src_inode sd[AuSRC].inode | |
22541 | +#define src_h_dentry sd[AuSRC].h_dentry | |
22542 | +#define src_parent sd[AuSRC].parent | |
22543 | +#define src_h_parent sd[AuSRC].h_parent | |
22544 | +#define src_wh_dentry sd[AuSRC].wh_dentry | |
22545 | +#define src_hdir sd[AuSRC].hdir | |
f2c43d5f | 22546 | +#define src_hinode sd[AuSRC].hinode |
4a4d8108 AM |
22547 | +#define src_h_dir sd[AuSRC].hdir->hi_inode |
22548 | +#define src_dt sd[AuSRC].dt | |
5afbbe0d | 22549 | +#define src_btop sd[AuSRC].btop |
f2c43d5f | 22550 | +#define src_bdiropq sd[AuSRC].bdiropq |
1facf9fc | 22551 | + |
4a4d8108 AM |
22552 | +#define dst_dentry sd[AuDST].dentry |
22553 | +#define dst_dir sd[AuDST].dir | |
22554 | +#define dst_inode sd[AuDST].inode | |
22555 | +#define dst_h_dentry sd[AuDST].h_dentry | |
22556 | +#define dst_parent sd[AuDST].parent | |
22557 | +#define dst_h_parent sd[AuDST].h_parent | |
22558 | +#define dst_wh_dentry sd[AuDST].wh_dentry | |
22559 | +#define dst_hdir sd[AuDST].hdir | |
f2c43d5f | 22560 | +#define dst_hinode sd[AuDST].hinode |
4a4d8108 AM |
22561 | +#define dst_h_dir sd[AuDST].hdir->hi_inode |
22562 | +#define dst_dt sd[AuDST].dt | |
5afbbe0d | 22563 | +#define dst_btop sd[AuDST].btop |
f2c43d5f | 22564 | +#define dst_bdiropq sd[AuDST].bdiropq |
4a4d8108 AM |
22565 | + |
22566 | + struct dentry *h_trap; | |
22567 | + struct au_branch *br; | |
4a4d8108 AM |
22568 | + struct path h_path; |
22569 | + struct au_nhash whlist; | |
f2c43d5f | 22570 | + aufs_bindex_t btgt, src_bwh; |
1facf9fc | 22571 | + |
f2c43d5f AM |
22572 | + struct { |
22573 | + unsigned short auren_flags; | |
22574 | + unsigned char flags; /* syscall parameter */ | |
22575 | + unsigned char exchange; | |
22576 | + } __packed; | |
1facf9fc | 22577 | + |
4a4d8108 AM |
22578 | + struct au_whtmp_rmdir *thargs; |
22579 | + struct dentry *h_dst; | |
8b6a4947 | 22580 | + struct au_hinode *h_root; |
4a4d8108 | 22581 | +}; |
1308ab2a | 22582 | + |
4a4d8108 | 22583 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 22584 | + |
4a4d8108 AM |
22585 | +/* |
22586 | + * functions for reverting. | |
22587 | + * when an error happened in a single rename systemcall, we should revert | |
79b8bda9 | 22588 | + * everything as if nothing happened. |
4a4d8108 AM |
22589 | + * we don't need to revert the copied-up/down the parent dir since they are |
22590 | + * harmless. | |
22591 | + */ | |
1facf9fc | 22592 | + |
4a4d8108 AM |
22593 | +#define RevertFailure(fmt, ...) do { \ |
22594 | + AuIOErr("revert failure: " fmt " (%d, %d)\n", \ | |
22595 | + ##__VA_ARGS__, err, rerr); \ | |
22596 | + err = -EIO; \ | |
22597 | +} while (0) | |
1facf9fc | 22598 | + |
f2c43d5f | 22599 | +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx) |
1facf9fc | 22600 | +{ |
4a4d8108 | 22601 | + int rerr; |
f2c43d5f AM |
22602 | + struct dentry *d; |
22603 | +#define src_or_dst(member) a->sd[idx].member | |
1facf9fc | 22604 | + |
f2c43d5f AM |
22605 | + d = src_or_dst(dentry); /* {src,dst}_dentry */ |
22606 | + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD); | |
22607 | + rerr = au_diropq_remove(d, a->btgt); | |
22608 | + au_hn_inode_unlock(src_or_dst(hinode)); | |
22609 | + au_set_dbdiropq(d, src_or_dst(bdiropq)); | |
4a4d8108 | 22610 | + if (rerr) |
f2c43d5f AM |
22611 | + RevertFailure("remove diropq %pd", d); |
22612 | + | |
22613 | +#undef src_or_dst_ | |
22614 | +} | |
22615 | + | |
22616 | +static void au_ren_rev_diropq(int err, struct au_ren_args *a) | |
22617 | +{ | |
22618 | + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC)) | |
22619 | + au_ren_do_rev_diropq(err, a, AuSRC); | |
22620 | + if (au_ftest_ren(a->auren_flags, DIROPQ_DST)) | |
22621 | + au_ren_do_rev_diropq(err, a, AuDST); | |
4a4d8108 | 22622 | +} |
1facf9fc | 22623 | + |
4a4d8108 AM |
22624 | +static void au_ren_rev_rename(int err, struct au_ren_args *a) |
22625 | +{ | |
22626 | + int rerr; | |
523b37e3 | 22627 | + struct inode *delegated; |
1facf9fc | 22628 | + |
b4510431 AM |
22629 | + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, |
22630 | + a->src_h_parent); | |
4a4d8108 AM |
22631 | + rerr = PTR_ERR(a->h_path.dentry); |
22632 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 22633 | + RevertFailure("lkup one %pd", a->src_dentry); |
4a4d8108 | 22634 | + return; |
1facf9fc | 22635 | + } |
22636 | + | |
523b37e3 | 22637 | + delegated = NULL; |
4a4d8108 AM |
22638 | + rerr = vfsub_rename(a->dst_h_dir, |
22639 | + au_h_dptr(a->src_dentry, a->btgt), | |
f2c43d5f | 22640 | + a->src_h_dir, &a->h_path, &delegated, a->flags); |
523b37e3 AM |
22641 | + if (unlikely(rerr == -EWOULDBLOCK)) { |
22642 | + pr_warn("cannot retry for NFSv4 delegation" | |
22643 | + " for an internal rename\n"); | |
22644 | + iput(delegated); | |
22645 | + } | |
4a4d8108 AM |
22646 | + d_drop(a->h_path.dentry); |
22647 | + dput(a->h_path.dentry); | |
22648 | + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */ | |
22649 | + if (rerr) | |
523b37e3 | 22650 | + RevertFailure("rename %pd", a->src_dentry); |
1facf9fc | 22651 | +} |
22652 | + | |
4a4d8108 | 22653 | +static void au_ren_rev_whtmp(int err, struct au_ren_args *a) |
1facf9fc | 22654 | +{ |
4a4d8108 | 22655 | + int rerr; |
523b37e3 | 22656 | + struct inode *delegated; |
dece6358 | 22657 | + |
b4510431 AM |
22658 | + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, |
22659 | + a->dst_h_parent); | |
4a4d8108 AM |
22660 | + rerr = PTR_ERR(a->h_path.dentry); |
22661 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 22662 | + RevertFailure("lkup one %pd", a->dst_dentry); |
4a4d8108 AM |
22663 | + return; |
22664 | + } | |
5527c038 | 22665 | + if (d_is_positive(a->h_path.dentry)) { |
4a4d8108 AM |
22666 | + d_drop(a->h_path.dentry); |
22667 | + dput(a->h_path.dentry); | |
22668 | + return; | |
dece6358 AM |
22669 | + } |
22670 | + | |
523b37e3 AM |
22671 | + delegated = NULL; |
22672 | + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path, | |
f2c43d5f | 22673 | + &delegated, a->flags); |
523b37e3 AM |
22674 | + if (unlikely(rerr == -EWOULDBLOCK)) { |
22675 | + pr_warn("cannot retry for NFSv4 delegation" | |
22676 | + " for an internal rename\n"); | |
22677 | + iput(delegated); | |
22678 | + } | |
4a4d8108 AM |
22679 | + d_drop(a->h_path.dentry); |
22680 | + dput(a->h_path.dentry); | |
22681 | + if (!rerr) | |
22682 | + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst)); | |
22683 | + else | |
523b37e3 | 22684 | + RevertFailure("rename %pd", a->h_dst); |
4a4d8108 | 22685 | +} |
1308ab2a | 22686 | + |
4a4d8108 AM |
22687 | +static void au_ren_rev_whsrc(int err, struct au_ren_args *a) |
22688 | +{ | |
22689 | + int rerr; | |
1308ab2a | 22690 | + |
4a4d8108 AM |
22691 | + a->h_path.dentry = a->src_wh_dentry; |
22692 | + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry); | |
027c5e7a | 22693 | + au_set_dbwh(a->src_dentry, a->src_bwh); |
4a4d8108 | 22694 | + if (rerr) |
523b37e3 | 22695 | + RevertFailure("unlink %pd", a->src_wh_dentry); |
4a4d8108 | 22696 | +} |
4a4d8108 | 22697 | +#undef RevertFailure |
1facf9fc | 22698 | + |
1308ab2a | 22699 | +/* ---------------------------------------------------------------------- */ |
22700 | + | |
4a4d8108 AM |
22701 | +/* |
22702 | + * when we have to copyup the renaming entry, do it with the rename-target name | |
22703 | + * in order to minimize the cost (the later actual rename is unnecessary). | |
22704 | + * otherwise rename it on the target branch. | |
22705 | + */ | |
22706 | +static int au_ren_or_cpup(struct au_ren_args *a) | |
1facf9fc | 22707 | +{ |
dece6358 | 22708 | + int err; |
4a4d8108 | 22709 | + struct dentry *d; |
523b37e3 | 22710 | + struct inode *delegated; |
1facf9fc | 22711 | + |
4a4d8108 | 22712 | + d = a->src_dentry; |
5afbbe0d | 22713 | + if (au_dbtop(d) == a->btgt) { |
4a4d8108 | 22714 | + a->h_path.dentry = a->dst_h_dentry; |
5afbbe0d | 22715 | + AuDebugOn(au_dbtop(d) != a->btgt); |
523b37e3 | 22716 | + delegated = NULL; |
4a4d8108 | 22717 | + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt), |
f2c43d5f AM |
22718 | + a->dst_h_dir, &a->h_path, &delegated, |
22719 | + a->flags); | |
523b37e3 AM |
22720 | + if (unlikely(err == -EWOULDBLOCK)) { |
22721 | + pr_warn("cannot retry for NFSv4 delegation" | |
22722 | + " for an internal rename\n"); | |
22723 | + iput(delegated); | |
22724 | + } | |
c2b27bf2 | 22725 | + } else |
86dc4139 | 22726 | + BUG(); |
1308ab2a | 22727 | + |
027c5e7a AM |
22728 | + if (!err && a->h_dst) |
22729 | + /* it will be set to dinfo later */ | |
22730 | + dget(a->h_dst); | |
1facf9fc | 22731 | + |
dece6358 AM |
22732 | + return err; |
22733 | +} | |
1facf9fc | 22734 | + |
4a4d8108 AM |
22735 | +/* cf. aufs_rmdir() */ |
22736 | +static int au_ren_del_whtmp(struct au_ren_args *a) | |
dece6358 | 22737 | +{ |
4a4d8108 AM |
22738 | + int err; |
22739 | + struct inode *dir; | |
1facf9fc | 22740 | + |
4a4d8108 AM |
22741 | + dir = a->dst_dir; |
22742 | + SiMustAnyLock(dir->i_sb); | |
22743 | + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt, | |
22744 | + au_sbi(dir->i_sb)->si_dirwh) | |
22745 | + || au_test_fs_remote(a->h_dst->d_sb)) { | |
22746 | + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist); | |
22747 | + if (unlikely(err)) | |
523b37e3 AM |
22748 | + pr_warn("failed removing whtmp dir %pd (%d), " |
22749 | + "ignored.\n", a->h_dst, err); | |
4a4d8108 AM |
22750 | + } else { |
22751 | + au_nhash_wh_free(&a->thargs->whlist); | |
22752 | + a->thargs->whlist = a->whlist; | |
22753 | + a->whlist.nh_num = 0; | |
22754 | + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs); | |
22755 | + dput(a->h_dst); | |
22756 | + a->thargs = NULL; | |
22757 | + } | |
22758 | + | |
22759 | + return 0; | |
1308ab2a | 22760 | +} |
1facf9fc | 22761 | + |
4a4d8108 | 22762 | +/* make it 'opaque' dir. */ |
f2c43d5f | 22763 | +static int au_ren_do_diropq(struct au_ren_args *a, int idx) |
4a4d8108 AM |
22764 | +{ |
22765 | + int err; | |
f2c43d5f AM |
22766 | + struct dentry *d, *diropq; |
22767 | +#define src_or_dst(member) a->sd[idx].member | |
1facf9fc | 22768 | + |
4a4d8108 | 22769 | + err = 0; |
f2c43d5f AM |
22770 | + d = src_or_dst(dentry); /* {src,dst}_dentry */ |
22771 | + src_or_dst(bdiropq) = au_dbdiropq(d); | |
22772 | + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt); | |
22773 | + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD); | |
22774 | + diropq = au_diropq_create(d, a->btgt); | |
22775 | + au_hn_inode_unlock(src_or_dst(hinode)); | |
4a4d8108 AM |
22776 | + if (IS_ERR(diropq)) |
22777 | + err = PTR_ERR(diropq); | |
076b876e AM |
22778 | + else |
22779 | + dput(diropq); | |
1facf9fc | 22780 | + |
f2c43d5f | 22781 | +#undef src_or_dst_ |
4a4d8108 AM |
22782 | + return err; |
22783 | +} | |
1facf9fc | 22784 | + |
f2c43d5f | 22785 | +static int au_ren_diropq(struct au_ren_args *a) |
4a4d8108 AM |
22786 | +{ |
22787 | + int err; | |
f2c43d5f AM |
22788 | + unsigned char always; |
22789 | + struct dentry *d; | |
1facf9fc | 22790 | + |
f2c43d5f AM |
22791 | + err = 0; |
22792 | + d = a->dst_dentry; /* already renamed on the branch */ | |
22793 | + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ); | |
22794 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) | |
8b6a4947 | 22795 | + && !au_ftest_ren(a->auren_flags, DIRREN) |
f2c43d5f AM |
22796 | + && a->btgt != au_dbdiropq(a->src_dentry) |
22797 | + && (a->dst_wh_dentry | |
22798 | + || a->btgt <= au_dbdiropq(d) | |
22799 | + /* hide the lower to keep xino */ | |
22800 | + /* the lowers may not be a dir, but we hide them anyway */ | |
22801 | + || a->btgt < au_dbbot(d) | |
22802 | + || always)) { | |
22803 | + AuDbg("here\n"); | |
22804 | + err = au_ren_do_diropq(a, AuSRC); | |
22805 | + if (unlikely(err)) | |
4a4d8108 | 22806 | + goto out; |
f2c43d5f | 22807 | + au_fset_ren(a->auren_flags, DIROPQ_SRC); |
4a4d8108 | 22808 | + } |
f2c43d5f AM |
22809 | + if (!a->exchange) |
22810 | + goto out; /* success */ | |
1facf9fc | 22811 | + |
f2c43d5f AM |
22812 | + d = a->src_dentry; /* already renamed on the branch */ |
22813 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) | |
22814 | + && a->btgt != au_dbdiropq(a->dst_dentry) | |
22815 | + && (a->btgt < au_dbdiropq(d) | |
22816 | + || a->btgt < au_dbbot(d) | |
22817 | + || always)) { | |
22818 | + AuDbgDentry(a->src_dentry); | |
22819 | + AuDbgDentry(a->dst_dentry); | |
22820 | + err = au_ren_do_diropq(a, AuDST); | |
4a4d8108 | 22821 | + if (unlikely(err)) |
f2c43d5f AM |
22822 | + goto out_rev_src; |
22823 | + au_fset_ren(a->auren_flags, DIROPQ_DST); | |
22824 | + } | |
22825 | + goto out; /* success */ | |
dece6358 | 22826 | + |
f2c43d5f AM |
22827 | +out_rev_src: |
22828 | + AuDbg("err %d, reverting src\n", err); | |
22829 | + au_ren_rev_diropq(err, a); | |
22830 | +out: | |
22831 | + return err; | |
22832 | +} | |
22833 | + | |
22834 | +static int do_rename(struct au_ren_args *a) | |
22835 | +{ | |
22836 | + int err; | |
22837 | + struct dentry *d, *h_d; | |
22838 | + | |
22839 | + if (!a->exchange) { | |
22840 | + /* prepare workqueue args for asynchronous rmdir */ | |
22841 | + h_d = a->dst_h_dentry; | |
22842 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) | |
8b6a4947 | 22843 | + /* && !au_ftest_ren(a->auren_flags, DIRREN) */ |
f2c43d5f AM |
22844 | + && d_is_positive(h_d)) { |
22845 | + err = -ENOMEM; | |
22846 | + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, | |
22847 | + GFP_NOFS); | |
22848 | + if (unlikely(!a->thargs)) | |
22849 | + goto out; | |
22850 | + a->h_dst = dget(h_d); | |
22851 | + } | |
22852 | + | |
22853 | + /* create whiteout for src_dentry */ | |
22854 | + if (au_ftest_ren(a->auren_flags, WHSRC)) { | |
22855 | + a->src_bwh = au_dbwh(a->src_dentry); | |
22856 | + AuDebugOn(a->src_bwh >= 0); | |
22857 | + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt, | |
22858 | + a->src_h_parent); | |
22859 | + err = PTR_ERR(a->src_wh_dentry); | |
22860 | + if (IS_ERR(a->src_wh_dentry)) | |
22861 | + goto out_thargs; | |
22862 | + } | |
22863 | + | |
22864 | + /* lookup whiteout for dentry */ | |
22865 | + if (au_ftest_ren(a->auren_flags, WHDST)) { | |
22866 | + h_d = au_wh_lkup(a->dst_h_parent, | |
22867 | + &a->dst_dentry->d_name, a->br); | |
22868 | + err = PTR_ERR(h_d); | |
22869 | + if (IS_ERR(h_d)) | |
22870 | + goto out_whsrc; | |
22871 | + if (d_is_negative(h_d)) | |
22872 | + dput(h_d); | |
22873 | + else | |
22874 | + a->dst_wh_dentry = h_d; | |
22875 | + } | |
22876 | + | |
22877 | + /* rename dentry to tmpwh */ | |
22878 | + if (a->thargs) { | |
22879 | + err = au_whtmp_ren(a->dst_h_dentry, a->br); | |
22880 | + if (unlikely(err)) | |
22881 | + goto out_whdst; | |
22882 | + | |
22883 | + d = a->dst_dentry; | |
22884 | + au_set_h_dptr(d, a->btgt, NULL); | |
22885 | + err = au_lkup_neg(d, a->btgt, /*wh*/0); | |
22886 | + if (unlikely(err)) | |
22887 | + goto out_whtmp; | |
22888 | + a->dst_h_dentry = au_h_dptr(d, a->btgt); | |
22889 | + } | |
4a4d8108 | 22890 | + } |
1facf9fc | 22891 | + |
5afbbe0d | 22892 | + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt); |
8b6a4947 AM |
22893 | +#if 0 |
22894 | + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN) | |
22895 | + && d_is_positive(a->dst_h_dentry) | |
22896 | + && a->src_btop != a->btgt); | |
22897 | +#endif | |
1facf9fc | 22898 | + |
4a4d8108 | 22899 | + /* rename by vfs_rename or cpup */ |
4a4d8108 AM |
22900 | + err = au_ren_or_cpup(a); |
22901 | + if (unlikely(err)) | |
22902 | + /* leave the copied-up one */ | |
22903 | + goto out_whtmp; | |
1308ab2a | 22904 | + |
4a4d8108 | 22905 | + /* make dir opaque */ |
f2c43d5f AM |
22906 | + err = au_ren_diropq(a); |
22907 | + if (unlikely(err)) | |
22908 | + goto out_rename; | |
1308ab2a | 22909 | + |
4a4d8108 | 22910 | + /* update target timestamps */ |
f2c43d5f AM |
22911 | + if (a->exchange) { |
22912 | + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt); | |
22913 | + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt); | |
22914 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
22915 | + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; | |
22916 | + } | |
5afbbe0d | 22917 | + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt); |
4a4d8108 AM |
22918 | + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt); |
22919 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
5527c038 | 22920 | + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
1facf9fc | 22921 | + |
f2c43d5f AM |
22922 | + if (!a->exchange) { |
22923 | + /* remove whiteout for dentry */ | |
22924 | + if (a->dst_wh_dentry) { | |
22925 | + a->h_path.dentry = a->dst_wh_dentry; | |
22926 | + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path, | |
22927 | + a->dst_dentry); | |
22928 | + if (unlikely(err)) | |
22929 | + goto out_diropq; | |
22930 | + } | |
1facf9fc | 22931 | + |
f2c43d5f AM |
22932 | + /* remove whtmp */ |
22933 | + if (a->thargs) | |
22934 | + au_ren_del_whtmp(a); /* ignore this error */ | |
1308ab2a | 22935 | + |
f2c43d5f AM |
22936 | + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0); |
22937 | + } | |
4a4d8108 AM |
22938 | + err = 0; |
22939 | + goto out_success; | |
22940 | + | |
4f0767ce | 22941 | +out_diropq: |
f2c43d5f | 22942 | + au_ren_rev_diropq(err, a); |
4f0767ce | 22943 | +out_rename: |
7e9cd9fe | 22944 | + au_ren_rev_rename(err, a); |
027c5e7a | 22945 | + dput(a->h_dst); |
4f0767ce | 22946 | +out_whtmp: |
4a4d8108 AM |
22947 | + if (a->thargs) |
22948 | + au_ren_rev_whtmp(err, a); | |
4f0767ce | 22949 | +out_whdst: |
4a4d8108 AM |
22950 | + dput(a->dst_wh_dentry); |
22951 | + a->dst_wh_dentry = NULL; | |
4f0767ce | 22952 | +out_whsrc: |
4a4d8108 AM |
22953 | + if (a->src_wh_dentry) |
22954 | + au_ren_rev_whsrc(err, a); | |
4f0767ce | 22955 | +out_success: |
4a4d8108 AM |
22956 | + dput(a->src_wh_dentry); |
22957 | + dput(a->dst_wh_dentry); | |
4f0767ce | 22958 | +out_thargs: |
4a4d8108 AM |
22959 | + if (a->thargs) { |
22960 | + dput(a->h_dst); | |
22961 | + au_whtmp_rmdir_free(a->thargs); | |
22962 | + a->thargs = NULL; | |
22963 | + } | |
4f0767ce | 22964 | +out: |
4a4d8108 | 22965 | + return err; |
dece6358 | 22966 | +} |
1facf9fc | 22967 | + |
1308ab2a | 22968 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 22969 | + |
4a4d8108 AM |
22970 | +/* |
22971 | + * test if @dentry dir can be rename destination or not. | |
22972 | + * success means, it is a logically empty dir. | |
22973 | + */ | |
22974 | +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) | |
1308ab2a | 22975 | +{ |
4a4d8108 | 22976 | + return au_test_empty(dentry, whlist); |
1308ab2a | 22977 | +} |
1facf9fc | 22978 | + |
4a4d8108 | 22979 | +/* |
8b6a4947 AM |
22980 | + * test if @a->src_dentry dir can be rename source or not. |
22981 | + * if it can, return 0. | |
4a4d8108 AM |
22982 | + * success means, |
22983 | + * - it is a logically empty dir. | |
22984 | + * - or, it exists on writable branch and has no children including whiteouts | |
8b6a4947 | 22985 | + * on the lower branch unless DIRREN is on. |
4a4d8108 | 22986 | + */ |
8b6a4947 | 22987 | +static int may_rename_srcdir(struct au_ren_args *a) |
4a4d8108 AM |
22988 | +{ |
22989 | + int err; | |
22990 | + unsigned int rdhash; | |
8b6a4947 AM |
22991 | + aufs_bindex_t btop, btgt; |
22992 | + struct dentry *dentry; | |
22993 | + struct super_block *sb; | |
22994 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 22995 | + |
8b6a4947 AM |
22996 | + dentry = a->src_dentry; |
22997 | + sb = dentry->d_sb; | |
22998 | + sbinfo = au_sbi(sb); | |
22999 | + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) | |
23000 | + au_fset_ren(a->auren_flags, DIRREN); | |
23001 | + | |
23002 | + btgt = a->btgt; | |
5afbbe0d AM |
23003 | + btop = au_dbtop(dentry); |
23004 | + if (btop != btgt) { | |
4a4d8108 | 23005 | + struct au_nhash whlist; |
dece6358 | 23006 | + |
8b6a4947 AM |
23007 | + SiMustAnyLock(sb); |
23008 | + rdhash = sbinfo->si_rdhash; | |
4a4d8108 AM |
23009 | + if (!rdhash) |
23010 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, | |
23011 | + dentry)); | |
23012 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
23013 | + if (unlikely(err)) | |
23014 | + goto out; | |
23015 | + err = au_test_empty(dentry, &whlist); | |
23016 | + au_nhash_wh_free(&whlist); | |
23017 | + goto out; | |
23018 | + } | |
dece6358 | 23019 | + |
5afbbe0d | 23020 | + if (btop == au_dbtaildir(dentry)) |
4a4d8108 | 23021 | + return 0; /* success */ |
dece6358 | 23022 | + |
4a4d8108 | 23023 | + err = au_test_empty_lower(dentry); |
1facf9fc | 23024 | + |
4f0767ce | 23025 | +out: |
4a4d8108 | 23026 | + if (err == -ENOTEMPTY) { |
8b6a4947 AM |
23027 | + if (au_ftest_ren(a->auren_flags, DIRREN)) { |
23028 | + err = 0; | |
23029 | + } else { | |
23030 | + AuWarn1("renaming dir who has child(ren) on multiple " | |
23031 | + "branches, is not supported\n"); | |
23032 | + err = -EXDEV; | |
23033 | + } | |
4a4d8108 AM |
23034 | + } |
23035 | + return err; | |
23036 | +} | |
1308ab2a | 23037 | + |
4a4d8108 AM |
23038 | +/* side effect: sets whlist and h_dentry */ |
23039 | +static int au_ren_may_dir(struct au_ren_args *a) | |
1308ab2a | 23040 | +{ |
4a4d8108 AM |
23041 | + int err; |
23042 | + unsigned int rdhash; | |
23043 | + struct dentry *d; | |
1facf9fc | 23044 | + |
4a4d8108 AM |
23045 | + d = a->dst_dentry; |
23046 | + SiMustAnyLock(d->d_sb); | |
1facf9fc | 23047 | + |
4a4d8108 | 23048 | + err = 0; |
f2c43d5f | 23049 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) { |
4a4d8108 AM |
23050 | + rdhash = au_sbi(d->d_sb)->si_rdhash; |
23051 | + if (!rdhash) | |
23052 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d)); | |
23053 | + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS); | |
23054 | + if (unlikely(err)) | |
23055 | + goto out; | |
1308ab2a | 23056 | + |
f2c43d5f AM |
23057 | + if (!a->exchange) { |
23058 | + au_set_dbtop(d, a->dst_btop); | |
23059 | + err = may_rename_dstdir(d, &a->whlist); | |
23060 | + au_set_dbtop(d, a->btgt); | |
23061 | + } else | |
8b6a4947 | 23062 | + err = may_rename_srcdir(a); |
4a4d8108 | 23063 | + } |
5afbbe0d | 23064 | + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d)); |
4a4d8108 AM |
23065 | + if (unlikely(err)) |
23066 | + goto out; | |
23067 | + | |
23068 | + d = a->src_dentry; | |
5afbbe0d | 23069 | + a->src_h_dentry = au_h_dptr(d, au_dbtop(d)); |
f2c43d5f | 23070 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { |
8b6a4947 | 23071 | + err = may_rename_srcdir(a); |
4a4d8108 AM |
23072 | + if (unlikely(err)) { |
23073 | + au_nhash_wh_free(&a->whlist); | |
23074 | + a->whlist.nh_num = 0; | |
23075 | + } | |
23076 | + } | |
4f0767ce | 23077 | +out: |
4a4d8108 | 23078 | + return err; |
1facf9fc | 23079 | +} |
23080 | + | |
4a4d8108 | 23081 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 23082 | + |
4a4d8108 AM |
23083 | +/* |
23084 | + * simple tests for rename. | |
23085 | + * following the checks in vfs, plus the parent-child relationship. | |
23086 | + */ | |
23087 | +static int au_may_ren(struct au_ren_args *a) | |
23088 | +{ | |
23089 | + int err, isdir; | |
23090 | + struct inode *h_inode; | |
1facf9fc | 23091 | + |
5afbbe0d | 23092 | + if (a->src_btop == a->btgt) { |
4a4d8108 | 23093 | + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent, |
f2c43d5f | 23094 | + au_ftest_ren(a->auren_flags, ISDIR_SRC)); |
4a4d8108 AM |
23095 | + if (unlikely(err)) |
23096 | + goto out; | |
23097 | + err = -EINVAL; | |
23098 | + if (unlikely(a->src_h_dentry == a->h_trap)) | |
23099 | + goto out; | |
23100 | + } | |
1facf9fc | 23101 | + |
4a4d8108 | 23102 | + err = 0; |
5afbbe0d | 23103 | + if (a->dst_btop != a->btgt) |
4a4d8108 | 23104 | + goto out; |
1facf9fc | 23105 | + |
027c5e7a AM |
23106 | + err = -ENOTEMPTY; |
23107 | + if (unlikely(a->dst_h_dentry == a->h_trap)) | |
23108 | + goto out; | |
23109 | + | |
4a4d8108 | 23110 | + err = -EIO; |
f2c43d5f | 23111 | + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST); |
5527c038 JR |
23112 | + if (d_really_is_negative(a->dst_dentry)) { |
23113 | + if (d_is_negative(a->dst_h_dentry)) | |
23114 | + err = au_may_add(a->dst_dentry, a->btgt, | |
23115 | + a->dst_h_parent, isdir); | |
4a4d8108 | 23116 | + } else { |
5527c038 | 23117 | + if (unlikely(d_is_negative(a->dst_h_dentry))) |
4a4d8108 | 23118 | + goto out; |
5527c038 JR |
23119 | + h_inode = d_inode(a->dst_h_dentry); |
23120 | + if (h_inode->i_nlink) | |
23121 | + err = au_may_del(a->dst_dentry, a->btgt, | |
23122 | + a->dst_h_parent, isdir); | |
4a4d8108 | 23123 | + } |
1facf9fc | 23124 | + |
4f0767ce | 23125 | +out: |
4a4d8108 AM |
23126 | + if (unlikely(err == -ENOENT || err == -EEXIST)) |
23127 | + err = -EIO; | |
23128 | + AuTraceErr(err); | |
23129 | + return err; | |
23130 | +} | |
1facf9fc | 23131 | + |
1308ab2a | 23132 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 23133 | + |
4a4d8108 AM |
23134 | +/* |
23135 | + * locking order | |
23136 | + * (VFS) | |
23137 | + * - src_dir and dir by lock_rename() | |
23138 | + * - inode if exitsts | |
23139 | + * (aufs) | |
23140 | + * - lock all | |
23141 | + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls, | |
23142 | + * + si_read_lock | |
23143 | + * + di_write_lock2_child() | |
23144 | + * + di_write_lock_child() | |
23145 | + * + ii_write_lock_child() | |
23146 | + * + di_write_lock_child2() | |
23147 | + * + ii_write_lock_child2() | |
23148 | + * + src_parent and parent | |
23149 | + * + di_write_lock_parent() | |
23150 | + * + ii_write_lock_parent() | |
23151 | + * + di_write_lock_parent2() | |
23152 | + * + ii_write_lock_parent2() | |
23153 | + * + lower src_dir and dir by vfsub_lock_rename() | |
23154 | + * + verify the every relationships between child and parent. if any | |
23155 | + * of them failed, unlock all and return -EBUSY. | |
23156 | + */ | |
23157 | +static void au_ren_unlock(struct au_ren_args *a) | |
1308ab2a | 23158 | +{ |
4a4d8108 AM |
23159 | + vfsub_unlock_rename(a->src_h_parent, a->src_hdir, |
23160 | + a->dst_h_parent, a->dst_hdir); | |
8b6a4947 AM |
23161 | + if (au_ftest_ren(a->auren_flags, DIRREN) |
23162 | + && a->h_root) | |
23163 | + au_hn_inode_unlock(a->h_root); | |
f2c43d5f | 23164 | + if (au_ftest_ren(a->auren_flags, MNT_WRITE)) |
86dc4139 | 23165 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
1308ab2a | 23166 | +} |
23167 | + | |
4a4d8108 | 23168 | +static int au_ren_lock(struct au_ren_args *a) |
1308ab2a | 23169 | +{ |
4a4d8108 AM |
23170 | + int err; |
23171 | + unsigned int udba; | |
1308ab2a | 23172 | + |
4a4d8108 AM |
23173 | + err = 0; |
23174 | + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt); | |
23175 | + a->src_hdir = au_hi(a->src_dir, a->btgt); | |
23176 | + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt); | |
23177 | + a->dst_hdir = au_hi(a->dst_dir, a->btgt); | |
86dc4139 AM |
23178 | + |
23179 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); | |
23180 | + if (unlikely(err)) | |
23181 | + goto out; | |
f2c43d5f | 23182 | + au_fset_ren(a->auren_flags, MNT_WRITE); |
8b6a4947 AM |
23183 | + if (au_ftest_ren(a->auren_flags, DIRREN)) { |
23184 | + struct dentry *root; | |
23185 | + struct inode *dir; | |
23186 | + | |
23187 | + /* | |
23188 | + * sbinfo is already locked, so this ii_read_lock is | |
23189 | + * unnecessary. but our debugging feature checks it. | |
23190 | + */ | |
23191 | + root = a->src_inode->i_sb->s_root; | |
23192 | + if (root != a->src_parent && root != a->dst_parent) { | |
23193 | + dir = d_inode(root); | |
23194 | + ii_read_lock_parent3(dir); | |
23195 | + a->h_root = au_hi(dir, a->btgt); | |
23196 | + ii_read_unlock(dir); | |
23197 | + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3); | |
23198 | + } | |
23199 | + } | |
4a4d8108 AM |
23200 | + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, |
23201 | + a->dst_h_parent, a->dst_hdir); | |
23202 | + udba = au_opt_udba(a->src_dentry->d_sb); | |
5527c038 JR |
23203 | + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent) |
23204 | + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent))) | |
4a4d8108 | 23205 | + err = au_busy_or_stale(); |
5afbbe0d | 23206 | + if (!err && au_dbtop(a->src_dentry) == a->btgt) |
4a4d8108 | 23207 | + err = au_h_verify(a->src_h_dentry, udba, |
5527c038 | 23208 | + d_inode(a->src_h_parent), a->src_h_parent, |
4a4d8108 | 23209 | + a->br); |
5afbbe0d | 23210 | + if (!err && au_dbtop(a->dst_dentry) == a->btgt) |
4a4d8108 | 23211 | + err = au_h_verify(a->dst_h_dentry, udba, |
5527c038 | 23212 | + d_inode(a->dst_h_parent), a->dst_h_parent, |
4a4d8108 | 23213 | + a->br); |
86dc4139 | 23214 | + if (!err) |
4a4d8108 | 23215 | + goto out; /* success */ |
4a4d8108 AM |
23216 | + |
23217 | + err = au_busy_or_stale(); | |
4a4d8108 | 23218 | + au_ren_unlock(a); |
86dc4139 | 23219 | + |
4f0767ce | 23220 | +out: |
4a4d8108 | 23221 | + return err; |
1facf9fc | 23222 | +} |
23223 | + | |
23224 | +/* ---------------------------------------------------------------------- */ | |
23225 | + | |
4a4d8108 | 23226 | +static void au_ren_refresh_dir(struct au_ren_args *a) |
1facf9fc | 23227 | +{ |
4a4d8108 | 23228 | + struct inode *dir; |
dece6358 | 23229 | + |
4a4d8108 AM |
23230 | + dir = a->dst_dir; |
23231 | + dir->i_version++; | |
f2c43d5f | 23232 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { |
4a4d8108 AM |
23233 | + /* is this updating defined in POSIX? */ |
23234 | + au_cpup_attr_timesizes(a->src_inode); | |
23235 | + au_cpup_attr_nlink(dir, /*force*/1); | |
4a4d8108 | 23236 | + } |
b912730e | 23237 | + au_dir_ts(dir, a->btgt); |
dece6358 | 23238 | + |
f2c43d5f AM |
23239 | + if (a->exchange) { |
23240 | + dir = a->src_dir; | |
23241 | + dir->i_version++; | |
23242 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) { | |
23243 | + /* is this updating defined in POSIX? */ | |
23244 | + au_cpup_attr_timesizes(a->dst_inode); | |
23245 | + au_cpup_attr_nlink(dir, /*force*/1); | |
23246 | + } | |
23247 | + au_dir_ts(dir, a->btgt); | |
23248 | + } | |
23249 | + | |
23250 | + if (au_ftest_ren(a->auren_flags, ISSAMEDIR)) | |
4a4d8108 | 23251 | + return; |
dece6358 | 23252 | + |
4a4d8108 AM |
23253 | + dir = a->src_dir; |
23254 | + dir->i_version++; | |
f2c43d5f | 23255 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) |
4a4d8108 | 23256 | + au_cpup_attr_nlink(dir, /*force*/1); |
b912730e | 23257 | + au_dir_ts(dir, a->btgt); |
1facf9fc | 23258 | +} |
23259 | + | |
4a4d8108 | 23260 | +static void au_ren_refresh(struct au_ren_args *a) |
1facf9fc | 23261 | +{ |
5afbbe0d | 23262 | + aufs_bindex_t bbot, bindex; |
4a4d8108 AM |
23263 | + struct dentry *d, *h_d; |
23264 | + struct inode *i, *h_i; | |
23265 | + struct super_block *sb; | |
dece6358 | 23266 | + |
027c5e7a AM |
23267 | + d = a->dst_dentry; |
23268 | + d_drop(d); | |
23269 | + if (a->h_dst) | |
23270 | + /* already dget-ed by au_ren_or_cpup() */ | |
23271 | + au_set_h_dptr(d, a->btgt, a->h_dst); | |
23272 | + | |
23273 | + i = a->dst_inode; | |
23274 | + if (i) { | |
f2c43d5f AM |
23275 | + if (!a->exchange) { |
23276 | + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) | |
23277 | + vfsub_drop_nlink(i); | |
23278 | + else { | |
23279 | + vfsub_dead_dir(i); | |
23280 | + au_cpup_attr_timesizes(i); | |
23281 | + } | |
23282 | + au_update_dbrange(d, /*do_put_zero*/1); | |
23283 | + } else | |
23284 | + au_cpup_attr_nlink(i, /*force*/1); | |
027c5e7a | 23285 | + } else { |
5afbbe0d AM |
23286 | + bbot = a->btgt; |
23287 | + for (bindex = au_dbtop(d); bindex < bbot; bindex++) | |
027c5e7a | 23288 | + au_set_h_dptr(d, bindex, NULL); |
5afbbe0d AM |
23289 | + bbot = au_dbbot(d); |
23290 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) | |
027c5e7a AM |
23291 | + au_set_h_dptr(d, bindex, NULL); |
23292 | + au_update_dbrange(d, /*do_put_zero*/0); | |
23293 | + } | |
23294 | + | |
8b6a4947 AM |
23295 | + if (a->exchange |
23296 | + || au_ftest_ren(a->auren_flags, DIRREN)) { | |
23297 | + d_drop(a->src_dentry); | |
23298 | + if (au_ftest_ren(a->auren_flags, DIRREN)) | |
23299 | + au_set_dbwh(a->src_dentry, -1); | |
23300 | + return; | |
23301 | + } | |
23302 | + | |
4a4d8108 | 23303 | + d = a->src_dentry; |
8b6a4947 AM |
23304 | + au_set_dbwh(d, -1); |
23305 | + bbot = au_dbbot(d); | |
23306 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { | |
23307 | + h_d = au_h_dptr(d, bindex); | |
23308 | + if (h_d) | |
23309 | + au_set_h_dptr(d, bindex, NULL); | |
23310 | + } | |
23311 | + au_set_dbbot(d, a->btgt); | |
4a4d8108 | 23312 | + |
8b6a4947 AM |
23313 | + sb = d->d_sb; |
23314 | + i = a->src_inode; | |
23315 | + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i)) | |
23316 | + return; /* success */ | |
4a4d8108 | 23317 | + |
8b6a4947 AM |
23318 | + bbot = au_ibbot(i); |
23319 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { | |
23320 | + h_i = au_h_iptr(i, bindex); | |
23321 | + if (h_i) { | |
23322 | + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0); | |
23323 | + /* ignore this error */ | |
23324 | + au_set_h_iptr(i, bindex, NULL, 0); | |
4a4d8108 AM |
23325 | + } |
23326 | + } | |
8b6a4947 | 23327 | + au_set_ibbot(i, a->btgt); |
1308ab2a | 23328 | +} |
dece6358 | 23329 | + |
4a4d8108 AM |
23330 | +/* ---------------------------------------------------------------------- */ |
23331 | + | |
23332 | +/* mainly for link(2) and rename(2) */ | |
23333 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt) | |
1308ab2a | 23334 | +{ |
4a4d8108 AM |
23335 | + aufs_bindex_t bdiropq, bwh; |
23336 | + struct dentry *parent; | |
23337 | + struct au_branch *br; | |
23338 | + | |
23339 | + parent = dentry->d_parent; | |
5527c038 | 23340 | + IMustLock(d_inode(parent)); /* dir is locked */ |
4a4d8108 AM |
23341 | + |
23342 | + bdiropq = au_dbdiropq(parent); | |
23343 | + bwh = au_dbwh(dentry); | |
23344 | + br = au_sbr(dentry->d_sb, btgt); | |
23345 | + if (au_br_rdonly(br) | |
23346 | + || (0 <= bdiropq && bdiropq < btgt) | |
23347 | + || (0 <= bwh && bwh < btgt)) | |
23348 | + btgt = -1; | |
23349 | + | |
23350 | + AuDbg("btgt %d\n", btgt); | |
23351 | + return btgt; | |
1facf9fc | 23352 | +} |
23353 | + | |
5afbbe0d | 23354 | +/* sets src_btop, dst_btop and btgt */ |
4a4d8108 | 23355 | +static int au_ren_wbr(struct au_ren_args *a) |
1facf9fc | 23356 | +{ |
4a4d8108 AM |
23357 | + int err; |
23358 | + struct au_wr_dir_args wr_dir_args = { | |
23359 | + /* .force_btgt = -1, */ | |
23360 | + .flags = AuWrDir_ADD_ENTRY | |
23361 | + }; | |
dece6358 | 23362 | + |
5afbbe0d AM |
23363 | + a->src_btop = au_dbtop(a->src_dentry); |
23364 | + a->dst_btop = au_dbtop(a->dst_dentry); | |
f2c43d5f AM |
23365 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) |
23366 | + || au_ftest_ren(a->auren_flags, ISDIR_DST)) | |
4a4d8108 | 23367 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
5afbbe0d AM |
23368 | + wr_dir_args.force_btgt = a->src_btop; |
23369 | + if (a->dst_inode && a->dst_btop < a->src_btop) | |
23370 | + wr_dir_args.force_btgt = a->dst_btop; | |
4a4d8108 AM |
23371 | + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt); |
23372 | + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args); | |
23373 | + a->btgt = err; | |
f2c43d5f AM |
23374 | + if (a->exchange) |
23375 | + au_update_dbtop(a->dst_dentry); | |
dece6358 | 23376 | + |
4a4d8108 | 23377 | + return err; |
1facf9fc | 23378 | +} |
23379 | + | |
4a4d8108 | 23380 | +static void au_ren_dt(struct au_ren_args *a) |
1facf9fc | 23381 | +{ |
4a4d8108 AM |
23382 | + a->h_path.dentry = a->src_h_parent; |
23383 | + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path); | |
f2c43d5f | 23384 | + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) { |
4a4d8108 AM |
23385 | + a->h_path.dentry = a->dst_h_parent; |
23386 | + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path); | |
23387 | + } | |
1facf9fc | 23388 | + |
f2c43d5f AM |
23389 | + au_fclr_ren(a->auren_flags, DT_DSTDIR); |
23390 | + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC) | |
23391 | + && !a->exchange) | |
4a4d8108 | 23392 | + return; |
dece6358 | 23393 | + |
4a4d8108 AM |
23394 | + a->h_path.dentry = a->src_h_dentry; |
23395 | + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path); | |
5527c038 | 23396 | + if (d_is_positive(a->dst_h_dentry)) { |
f2c43d5f | 23397 | + au_fset_ren(a->auren_flags, DT_DSTDIR); |
4a4d8108 AM |
23398 | + a->h_path.dentry = a->dst_h_dentry; |
23399 | + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path); | |
23400 | + } | |
1308ab2a | 23401 | +} |
dece6358 | 23402 | + |
4a4d8108 | 23403 | +static void au_ren_rev_dt(int err, struct au_ren_args *a) |
1308ab2a | 23404 | +{ |
4a4d8108 | 23405 | + struct dentry *h_d; |
febd17d6 | 23406 | + struct inode *h_inode; |
4a4d8108 AM |
23407 | + |
23408 | + au_dtime_revert(a->src_dt + AuPARENT); | |
f2c43d5f | 23409 | + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) |
4a4d8108 AM |
23410 | + au_dtime_revert(a->dst_dt + AuPARENT); |
23411 | + | |
f2c43d5f | 23412 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) { |
4a4d8108 | 23413 | + h_d = a->src_dt[AuCHILD].dt_h_path.dentry; |
febd17d6 JR |
23414 | + h_inode = d_inode(h_d); |
23415 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); | |
4a4d8108 | 23416 | + au_dtime_revert(a->src_dt + AuCHILD); |
febd17d6 | 23417 | + inode_unlock(h_inode); |
4a4d8108 | 23418 | + |
f2c43d5f | 23419 | + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) { |
4a4d8108 | 23420 | + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry; |
febd17d6 JR |
23421 | + h_inode = d_inode(h_d); |
23422 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); | |
4a4d8108 | 23423 | + au_dtime_revert(a->dst_dt + AuCHILD); |
febd17d6 | 23424 | + inode_unlock(h_inode); |
1facf9fc | 23425 | + } |
23426 | + } | |
23427 | +} | |
23428 | + | |
4a4d8108 AM |
23429 | +/* ---------------------------------------------------------------------- */ |
23430 | + | |
23431 | +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, | |
f2c43d5f AM |
23432 | + struct inode *_dst_dir, struct dentry *_dst_dentry, |
23433 | + unsigned int _flags) | |
1facf9fc | 23434 | +{ |
f2c43d5f | 23435 | + int err, lock_flags; |
8b6a4947 | 23436 | + void *rev; |
4a4d8108 AM |
23437 | + /* reduce stack space */ |
23438 | + struct au_ren_args *a; | |
f2c43d5f | 23439 | + struct au_pin pin; |
4a4d8108 | 23440 | + |
f2c43d5f | 23441 | + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags); |
4a4d8108 AM |
23442 | + IMustLock(_src_dir); |
23443 | + IMustLock(_dst_dir); | |
23444 | + | |
f2c43d5f AM |
23445 | + err = -EINVAL; |
23446 | + if (unlikely(_flags & RENAME_WHITEOUT)) | |
23447 | + goto out; | |
23448 | + | |
4a4d8108 AM |
23449 | + err = -ENOMEM; |
23450 | + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE); | |
23451 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
23452 | + if (unlikely(!a)) | |
23453 | + goto out; | |
23454 | + | |
f2c43d5f AM |
23455 | + a->flags = _flags; |
23456 | + a->exchange = _flags & RENAME_EXCHANGE; | |
4a4d8108 AM |
23457 | + a->src_dir = _src_dir; |
23458 | + a->src_dentry = _src_dentry; | |
5527c038 JR |
23459 | + a->src_inode = NULL; |
23460 | + if (d_really_is_positive(a->src_dentry)) | |
23461 | + a->src_inode = d_inode(a->src_dentry); | |
4a4d8108 AM |
23462 | + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */ |
23463 | + a->dst_dir = _dst_dir; | |
23464 | + a->dst_dentry = _dst_dentry; | |
5527c038 JR |
23465 | + a->dst_inode = NULL; |
23466 | + if (d_really_is_positive(a->dst_dentry)) | |
23467 | + a->dst_inode = d_inode(a->dst_dentry); | |
4a4d8108 AM |
23468 | + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */ |
23469 | + if (a->dst_inode) { | |
f2c43d5f AM |
23470 | + /* |
23471 | + * if EXCHANGE && src is non-dir && dst is dir, | |
23472 | + * dst is not locked. | |
23473 | + */ | |
23474 | + /* IMustLock(a->dst_inode); */ | |
4a4d8108 | 23475 | + au_igrab(a->dst_inode); |
1facf9fc | 23476 | + } |
1facf9fc | 23477 | + |
4a4d8108 | 23478 | + err = -ENOTDIR; |
f2c43d5f | 23479 | + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN; |
2000de60 | 23480 | + if (d_is_dir(a->src_dentry)) { |
f2c43d5f AM |
23481 | + au_fset_ren(a->auren_flags, ISDIR_SRC); |
23482 | + if (unlikely(!a->exchange | |
23483 | + && d_really_is_positive(a->dst_dentry) | |
2000de60 | 23484 | + && !d_is_dir(a->dst_dentry))) |
4a4d8108 | 23485 | + goto out_free; |
f2c43d5f AM |
23486 | + lock_flags |= AuLock_DIRS; |
23487 | + } | |
23488 | + if (a->dst_inode && d_is_dir(a->dst_dentry)) { | |
23489 | + au_fset_ren(a->auren_flags, ISDIR_DST); | |
23490 | + if (unlikely(!a->exchange | |
23491 | + && d_really_is_positive(a->src_dentry) | |
23492 | + && !d_is_dir(a->src_dentry))) | |
23493 | + goto out_free; | |
23494 | + lock_flags |= AuLock_DIRS; | |
b95c5147 | 23495 | + } |
8b6a4947 AM |
23496 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
23497 | + lock_flags); | |
e49829fe JR |
23498 | + if (unlikely(err)) |
23499 | + goto out_free; | |
1facf9fc | 23500 | + |
027c5e7a AM |
23501 | + err = au_d_hashed_positive(a->src_dentry); |
23502 | + if (unlikely(err)) | |
23503 | + goto out_unlock; | |
23504 | + err = -ENOENT; | |
23505 | + if (a->dst_inode) { | |
23506 | + /* | |
f2c43d5f | 23507 | + * If it is a dir, VFS unhash it before this |
027c5e7a AM |
23508 | + * function. It means we cannot rely upon d_unhashed(). |
23509 | + */ | |
23510 | + if (unlikely(!a->dst_inode->i_nlink)) | |
23511 | + goto out_unlock; | |
f2c43d5f | 23512 | + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) { |
027c5e7a | 23513 | + err = au_d_hashed_positive(a->dst_dentry); |
f2c43d5f | 23514 | + if (unlikely(err && !a->exchange)) |
027c5e7a AM |
23515 | + goto out_unlock; |
23516 | + } else if (unlikely(IS_DEADDIR(a->dst_inode))) | |
23517 | + goto out_unlock; | |
23518 | + } else if (unlikely(d_unhashed(a->dst_dentry))) | |
23519 | + goto out_unlock; | |
23520 | + | |
7eafdf33 AM |
23521 | + /* |
23522 | + * is it possible? | |
79b8bda9 | 23523 | + * yes, it happened (in linux-3.3-rcN) but I don't know why. |
7eafdf33 AM |
23524 | + * there may exist a problem somewhere else. |
23525 | + */ | |
23526 | + err = -EINVAL; | |
5527c038 | 23527 | + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry))) |
7eafdf33 AM |
23528 | + goto out_unlock; |
23529 | + | |
f2c43d5f | 23530 | + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */ |
4a4d8108 | 23531 | + di_write_lock_parent(a->dst_parent); |
1facf9fc | 23532 | + |
4a4d8108 AM |
23533 | + /* which branch we process */ |
23534 | + err = au_ren_wbr(a); | |
23535 | + if (unlikely(err < 0)) | |
027c5e7a | 23536 | + goto out_parent; |
4a4d8108 | 23537 | + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt); |
86dc4139 | 23538 | + a->h_path.mnt = au_br_mnt(a->br); |
1facf9fc | 23539 | + |
4a4d8108 AM |
23540 | + /* are they available to be renamed */ |
23541 | + err = au_ren_may_dir(a); | |
23542 | + if (unlikely(err)) | |
23543 | + goto out_children; | |
1facf9fc | 23544 | + |
4a4d8108 | 23545 | + /* prepare the writable parent dir on the same branch */ |
5afbbe0d | 23546 | + if (a->dst_btop == a->btgt) { |
f2c43d5f | 23547 | + au_fset_ren(a->auren_flags, WHDST); |
4a4d8108 AM |
23548 | + } else { |
23549 | + err = au_cpup_dirs(a->dst_dentry, a->btgt); | |
23550 | + if (unlikely(err)) | |
23551 | + goto out_children; | |
23552 | + } | |
1facf9fc | 23553 | + |
f2c43d5f AM |
23554 | + err = 0; |
23555 | + if (!a->exchange) { | |
23556 | + if (a->src_dir != a->dst_dir) { | |
23557 | + /* | |
23558 | + * this temporary unlock is safe, | |
23559 | + * because both dir->i_mutex are locked. | |
23560 | + */ | |
23561 | + di_write_unlock(a->dst_parent); | |
23562 | + di_write_lock_parent(a->src_parent); | |
23563 | + err = au_wr_dir_need_wh(a->src_dentry, | |
23564 | + au_ftest_ren(a->auren_flags, | |
23565 | + ISDIR_SRC), | |
23566 | + &a->btgt); | |
23567 | + di_write_unlock(a->src_parent); | |
23568 | + di_write_lock2_parent(a->src_parent, a->dst_parent, | |
23569 | + /*isdir*/1); | |
23570 | + au_fclr_ren(a->auren_flags, ISSAMEDIR); | |
23571 | + } else | |
23572 | + err = au_wr_dir_need_wh(a->src_dentry, | |
23573 | + au_ftest_ren(a->auren_flags, | |
23574 | + ISDIR_SRC), | |
23575 | + &a->btgt); | |
23576 | + } | |
4a4d8108 AM |
23577 | + if (unlikely(err < 0)) |
23578 | + goto out_children; | |
23579 | + if (err) | |
f2c43d5f | 23580 | + au_fset_ren(a->auren_flags, WHSRC); |
1facf9fc | 23581 | + |
86dc4139 | 23582 | + /* cpup src */ |
5afbbe0d | 23583 | + if (a->src_btop != a->btgt) { |
86dc4139 AM |
23584 | + err = au_pin(&pin, a->src_dentry, a->btgt, |
23585 | + au_opt_udba(a->src_dentry->d_sb), | |
23586 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
367653fa | 23587 | + if (!err) { |
c2b27bf2 AM |
23588 | + struct au_cp_generic cpg = { |
23589 | + .dentry = a->src_dentry, | |
23590 | + .bdst = a->btgt, | |
5afbbe0d | 23591 | + .bsrc = a->src_btop, |
c2b27bf2 AM |
23592 | + .len = -1, |
23593 | + .pin = &pin, | |
23594 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
23595 | + }; | |
5afbbe0d | 23596 | + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop); |
c2b27bf2 | 23597 | + err = au_sio_cpup_simple(&cpg); |
367653fa | 23598 | + au_unpin(&pin); |
86dc4139 | 23599 | + } |
86dc4139 AM |
23600 | + if (unlikely(err)) |
23601 | + goto out_children; | |
5afbbe0d | 23602 | + a->src_btop = a->btgt; |
86dc4139 | 23603 | + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt); |
f2c43d5f AM |
23604 | + if (!a->exchange) |
23605 | + au_fset_ren(a->auren_flags, WHSRC); | |
23606 | + } | |
23607 | + | |
23608 | + /* cpup dst */ | |
23609 | + if (a->exchange && a->dst_inode | |
23610 | + && a->dst_btop != a->btgt) { | |
23611 | + err = au_pin(&pin, a->dst_dentry, a->btgt, | |
23612 | + au_opt_udba(a->dst_dentry->d_sb), | |
23613 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
23614 | + if (!err) { | |
23615 | + struct au_cp_generic cpg = { | |
23616 | + .dentry = a->dst_dentry, | |
23617 | + .bdst = a->btgt, | |
23618 | + .bsrc = a->dst_btop, | |
23619 | + .len = -1, | |
23620 | + .pin = &pin, | |
23621 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
23622 | + }; | |
23623 | + err = au_sio_cpup_simple(&cpg); | |
23624 | + au_unpin(&pin); | |
23625 | + } | |
23626 | + if (unlikely(err)) | |
23627 | + goto out_children; | |
23628 | + a->dst_btop = a->btgt; | |
23629 | + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt); | |
86dc4139 AM |
23630 | + } |
23631 | + | |
4a4d8108 AM |
23632 | + /* lock them all */ |
23633 | + err = au_ren_lock(a); | |
23634 | + if (unlikely(err)) | |
86dc4139 | 23635 | + /* leave the copied-up one */ |
4a4d8108 | 23636 | + goto out_children; |
1facf9fc | 23637 | + |
f2c43d5f AM |
23638 | + if (!a->exchange) { |
23639 | + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) | |
23640 | + err = au_may_ren(a); | |
23641 | + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
23642 | + err = -ENAMETOOLONG; | |
23643 | + if (unlikely(err)) | |
23644 | + goto out_hdir; | |
23645 | + } | |
1facf9fc | 23646 | + |
4a4d8108 AM |
23647 | + /* store timestamps to be revertible */ |
23648 | + au_ren_dt(a); | |
1facf9fc | 23649 | + |
8b6a4947 AM |
23650 | + /* store dirren info */ |
23651 | + if (au_ftest_ren(a->auren_flags, DIRREN)) { | |
23652 | + err = au_dr_rename(a->src_dentry, a->btgt, | |
23653 | + &a->dst_dentry->d_name, &rev); | |
23654 | + AuTraceErr(err); | |
23655 | + if (unlikely(err)) | |
23656 | + goto out_dt; | |
23657 | + } | |
23658 | + | |
4a4d8108 AM |
23659 | + /* here we go */ |
23660 | + err = do_rename(a); | |
23661 | + if (unlikely(err)) | |
8b6a4947 AM |
23662 | + goto out_dirren; |
23663 | + | |
23664 | + if (au_ftest_ren(a->auren_flags, DIRREN)) | |
23665 | + au_dr_rename_fin(a->src_dentry, a->btgt, rev); | |
4a4d8108 AM |
23666 | + |
23667 | + /* update dir attributes */ | |
23668 | + au_ren_refresh_dir(a); | |
23669 | + | |
23670 | + /* dput/iput all lower dentries */ | |
23671 | + au_ren_refresh(a); | |
23672 | + | |
23673 | + goto out_hdir; /* success */ | |
23674 | + | |
8b6a4947 AM |
23675 | +out_dirren: |
23676 | + if (au_ftest_ren(a->auren_flags, DIRREN)) | |
23677 | + au_dr_rename_rev(a->src_dentry, a->btgt, rev); | |
4f0767ce | 23678 | +out_dt: |
4a4d8108 | 23679 | + au_ren_rev_dt(err, a); |
4f0767ce | 23680 | +out_hdir: |
4a4d8108 | 23681 | + au_ren_unlock(a); |
4f0767ce | 23682 | +out_children: |
4a4d8108 | 23683 | + au_nhash_wh_free(&a->whlist); |
5afbbe0d AM |
23684 | + if (err && a->dst_inode && a->dst_btop != a->btgt) { |
23685 | + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt); | |
027c5e7a | 23686 | + au_set_h_dptr(a->dst_dentry, a->btgt, NULL); |
5afbbe0d | 23687 | + au_set_dbtop(a->dst_dentry, a->dst_btop); |
4a4d8108 | 23688 | + } |
027c5e7a | 23689 | +out_parent: |
f2c43d5f | 23690 | + if (!err) { |
8b6a4947 AM |
23691 | + if (d_unhashed(a->src_dentry)) |
23692 | + au_fset_ren(a->auren_flags, DROPPED_SRC); | |
23693 | + if (d_unhashed(a->dst_dentry)) | |
23694 | + au_fset_ren(a->auren_flags, DROPPED_DST); | |
f2c43d5f AM |
23695 | + if (!a->exchange) |
23696 | + d_move(a->src_dentry, a->dst_dentry); | |
8b6a4947 | 23697 | + else { |
f2c43d5f | 23698 | + d_exchange(a->src_dentry, a->dst_dentry); |
8b6a4947 AM |
23699 | + if (au_ftest_ren(a->auren_flags, DROPPED_DST)) |
23700 | + d_drop(a->dst_dentry); | |
23701 | + } | |
23702 | + if (au_ftest_ren(a->auren_flags, DROPPED_SRC)) | |
23703 | + d_drop(a->src_dentry); | |
f2c43d5f | 23704 | + } else { |
5afbbe0d | 23705 | + au_update_dbtop(a->dst_dentry); |
027c5e7a AM |
23706 | + if (!a->dst_inode) |
23707 | + d_drop(a->dst_dentry); | |
23708 | + } | |
f2c43d5f | 23709 | + if (au_ftest_ren(a->auren_flags, ISSAMEDIR)) |
4a4d8108 AM |
23710 | + di_write_unlock(a->dst_parent); |
23711 | + else | |
23712 | + di_write_unlock2(a->src_parent, a->dst_parent); | |
027c5e7a | 23713 | +out_unlock: |
4a4d8108 | 23714 | + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry); |
4f0767ce | 23715 | +out_free: |
4a4d8108 AM |
23716 | + iput(a->dst_inode); |
23717 | + if (a->thargs) | |
23718 | + au_whtmp_rmdir_free(a->thargs); | |
1c60b727 | 23719 | + kfree(a); |
4f0767ce | 23720 | +out: |
4a4d8108 AM |
23721 | + AuTraceErr(err); |
23722 | + return err; | |
1308ab2a | 23723 | +} |
7f207e10 AM |
23724 | diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig |
23725 | --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 AM |
23726 | +++ linux/fs/aufs/Kconfig 2018-01-29 07:56:20.049991637 +0100 |
23727 | @@ -0,0 +1,199 @@ | |
23728 | +# SPDX-License-Identifier: GPL-2.0 | |
4a4d8108 AM |
23729 | +config AUFS_FS |
23730 | + tristate "Aufs (Advanced multi layered unification filesystem) support" | |
4a4d8108 AM |
23731 | + help |
23732 | + Aufs is a stackable unification filesystem such as Unionfs, | |
23733 | + which unifies several directories and provides a merged single | |
23734 | + directory. | |
23735 | + In the early days, aufs was entirely re-designed and | |
23736 | + re-implemented Unionfs Version 1.x series. Introducing many | |
23737 | + original ideas, approaches and improvements, it becomes totally | |
23738 | + different from Unionfs while keeping the basic features. | |
1facf9fc | 23739 | + |
4a4d8108 AM |
23740 | +if AUFS_FS |
23741 | +choice | |
23742 | + prompt "Maximum number of branches" | |
23743 | + default AUFS_BRANCH_MAX_127 | |
23744 | + help | |
23745 | + Specifies the maximum number of branches (or member directories) | |
23746 | + in a single aufs. The larger value consumes more system | |
23747 | + resources and has a minor impact to performance. | |
23748 | +config AUFS_BRANCH_MAX_127 | |
23749 | + bool "127" | |
23750 | + help | |
23751 | + Specifies the maximum number of branches (or member directories) | |
23752 | + in a single aufs. The larger value consumes more system | |
23753 | + resources and has a minor impact to performance. | |
23754 | +config AUFS_BRANCH_MAX_511 | |
23755 | + bool "511" | |
23756 | + help | |
23757 | + Specifies the maximum number of branches (or member directories) | |
23758 | + in a single aufs. The larger value consumes more system | |
23759 | + resources and has a minor impact to performance. | |
23760 | +config AUFS_BRANCH_MAX_1023 | |
23761 | + bool "1023" | |
23762 | + help | |
23763 | + Specifies the maximum number of branches (or member directories) | |
23764 | + in a single aufs. The larger value consumes more system | |
23765 | + resources and has a minor impact to performance. | |
23766 | +config AUFS_BRANCH_MAX_32767 | |
23767 | + bool "32767" | |
23768 | + help | |
23769 | + Specifies the maximum number of branches (or member directories) | |
23770 | + in a single aufs. The larger value consumes more system | |
23771 | + resources and has a minor impact to performance. | |
23772 | +endchoice | |
1facf9fc | 23773 | + |
e49829fe JR |
23774 | +config AUFS_SBILIST |
23775 | + bool | |
23776 | + depends on AUFS_MAGIC_SYSRQ || PROC_FS | |
23777 | + default y | |
23778 | + help | |
23779 | + Automatic configuration for internal use. | |
23780 | + When aufs supports Magic SysRq or /proc, enabled automatically. | |
23781 | + | |
4a4d8108 AM |
23782 | +config AUFS_HNOTIFY |
23783 | + bool "Detect direct branch access (bypassing aufs)" | |
23784 | + help | |
23785 | + If you want to modify files on branches directly, eg. bypassing aufs, | |
23786 | + and want aufs to detect the changes of them fully, then enable this | |
23787 | + option and use 'udba=notify' mount option. | |
7f207e10 | 23788 | + Currently there is only one available configuration, "fsnotify". |
4a4d8108 AM |
23789 | + It will have a negative impact to the performance. |
23790 | + See detail in aufs.5. | |
dece6358 | 23791 | + |
4a4d8108 AM |
23792 | +choice |
23793 | + prompt "method" if AUFS_HNOTIFY | |
23794 | + default AUFS_HFSNOTIFY | |
23795 | +config AUFS_HFSNOTIFY | |
23796 | + bool "fsnotify" | |
23797 | + select FSNOTIFY | |
4a4d8108 | 23798 | +endchoice |
1facf9fc | 23799 | + |
4a4d8108 AM |
23800 | +config AUFS_EXPORT |
23801 | + bool "NFS-exportable aufs" | |
2cbb1c4b | 23802 | + depends on EXPORTFS |
4a4d8108 AM |
23803 | + help |
23804 | + If you want to export your mounted aufs via NFS, then enable this | |
23805 | + option. There are several requirements for this configuration. | |
23806 | + See detail in aufs.5. | |
1facf9fc | 23807 | + |
4a4d8108 AM |
23808 | +config AUFS_INO_T_64 |
23809 | + bool | |
23810 | + depends on AUFS_EXPORT | |
23811 | + depends on 64BIT && !(ALPHA || S390) | |
23812 | + default y | |
23813 | + help | |
23814 | + Automatic configuration for internal use. | |
23815 | + /* typedef unsigned long/int __kernel_ino_t */ | |
23816 | + /* alpha and s390x are int */ | |
1facf9fc | 23817 | + |
c1595e42 JR |
23818 | +config AUFS_XATTR |
23819 | + bool "support for XATTR/EA (including Security Labels)" | |
23820 | + help | |
23821 | + If your branch fs supports XATTR/EA and you want to make them | |
23822 | + available in aufs too, then enable this opsion and specify the | |
23823 | + branch attributes for EA. | |
23824 | + See detail in aufs.5. | |
23825 | + | |
076b876e AM |
23826 | +config AUFS_FHSM |
23827 | + bool "File-based Hierarchical Storage Management" | |
23828 | + help | |
23829 | + Hierarchical Storage Management (or HSM) is a well-known feature | |
23830 | + in the storage world. Aufs provides this feature as file-based. | |
23831 | + with multiple branches. | |
23832 | + These multiple branches are prioritized, ie. the topmost one | |
23833 | + should be the fastest drive and be used heavily. | |
23834 | + | |
4a4d8108 AM |
23835 | +config AUFS_RDU |
23836 | + bool "Readdir in userspace" | |
23837 | + help | |
23838 | + Aufs has two methods to provide a merged view for a directory, | |
23839 | + by a user-space library and by kernel-space natively. The latter | |
23840 | + is always enabled but sometimes large and slow. | |
23841 | + If you enable this option, install the library in aufs2-util | |
23842 | + package, and set some environment variables for your readdir(3), | |
23843 | + then the work will be handled in user-space which generally | |
23844 | + shows better performance in most cases. | |
23845 | + See detail in aufs.5. | |
1facf9fc | 23846 | + |
8b6a4947 AM |
23847 | +config AUFS_DIRREN |
23848 | + bool "Workaround for rename(2)-ing a directory" | |
23849 | + help | |
23850 | + By default, aufs returns EXDEV error in renameing a dir who has | |
23851 | + his child on the lower branch, since it is a bad idea to issue | |
23852 | + rename(2) internally for every lower branch. But user may not | |
23853 | + accept this behaviour. So here is a workaround to allow such | |
23854 | + rename(2) and store some extra infromation on the writable | |
23855 | + branch. Obviously this costs high (and I don't like it). | |
23856 | + To use this feature, you need to enable this configuration AND | |
23857 | + to specify the mount option `dirren.' | |
23858 | + See details in aufs.5 and the design documents. | |
23859 | + | |
4a4d8108 AM |
23860 | +config AUFS_SHWH |
23861 | + bool "Show whiteouts" | |
23862 | + help | |
23863 | + If you want to make the whiteouts in aufs visible, then enable | |
23864 | + this option and specify 'shwh' mount option. Although it may | |
23865 | + sounds like philosophy or something, but in technically it | |
23866 | + simply shows the name of whiteout with keeping its behaviour. | |
1facf9fc | 23867 | + |
4a4d8108 AM |
23868 | +config AUFS_BR_RAMFS |
23869 | + bool "Ramfs (initramfs/rootfs) as an aufs branch" | |
23870 | + help | |
23871 | + If you want to use ramfs as an aufs branch fs, then enable this | |
23872 | + option. Generally tmpfs is recommended. | |
23873 | + Aufs prohibited them to be a branch fs by default, because | |
23874 | + initramfs becomes unusable after switch_root or something | |
23875 | + generally. If you sets initramfs as an aufs branch and boot your | |
23876 | + system by switch_root, you will meet a problem easily since the | |
23877 | + files in initramfs may be inaccessible. | |
23878 | + Unless you are going to use ramfs as an aufs branch fs without | |
23879 | + switch_root or something, leave it N. | |
1facf9fc | 23880 | + |
4a4d8108 AM |
23881 | +config AUFS_BR_FUSE |
23882 | + bool "Fuse fs as an aufs branch" | |
23883 | + depends on FUSE_FS | |
23884 | + select AUFS_POLL | |
23885 | + help | |
23886 | + If you want to use fuse-based userspace filesystem as an aufs | |
23887 | + branch fs, then enable this option. | |
23888 | + It implements the internal poll(2) operation which is | |
23889 | + implemented by fuse only (curretnly). | |
1facf9fc | 23890 | + |
4a4d8108 AM |
23891 | +config AUFS_POLL |
23892 | + bool | |
23893 | + help | |
23894 | + Automatic configuration for internal use. | |
1facf9fc | 23895 | + |
4a4d8108 AM |
23896 | +config AUFS_BR_HFSPLUS |
23897 | + bool "Hfsplus as an aufs branch" | |
23898 | + depends on HFSPLUS_FS | |
23899 | + default y | |
23900 | + help | |
23901 | + If you want to use hfsplus fs as an aufs branch fs, then enable | |
23902 | + this option. This option introduces a small overhead at | |
23903 | + copying-up a file on hfsplus. | |
1facf9fc | 23904 | + |
4a4d8108 AM |
23905 | +config AUFS_BDEV_LOOP |
23906 | + bool | |
23907 | + depends on BLK_DEV_LOOP | |
23908 | + default y | |
23909 | + help | |
23910 | + Automatic configuration for internal use. | |
23911 | + Convert =[ym] into =y. | |
1308ab2a | 23912 | + |
4a4d8108 AM |
23913 | +config AUFS_DEBUG |
23914 | + bool "Debug aufs" | |
23915 | + help | |
23916 | + Enable this to compile aufs internal debug code. | |
23917 | + It will have a negative impact to the performance. | |
23918 | + | |
23919 | +config AUFS_MAGIC_SYSRQ | |
23920 | + bool | |
23921 | + depends on AUFS_DEBUG && MAGIC_SYSRQ | |
23922 | + default y | |
23923 | + help | |
23924 | + Automatic configuration for internal use. | |
23925 | + When aufs supports Magic SysRq, enabled automatically. | |
23926 | +endif | |
7f207e10 AM |
23927 | diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c |
23928 | --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 23929 | +++ linux/fs/aufs/loop.c 2018-01-29 07:56:20.056658502 +0100 |
e2f27e51 | 23930 | @@ -0,0 +1,147 @@ |
1facf9fc | 23931 | +/* |
a2654f78 | 23932 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 23933 | + * |
23934 | + * This program, aufs is free software; you can redistribute it and/or modify | |
23935 | + * it under the terms of the GNU General Public License as published by | |
23936 | + * the Free Software Foundation; either version 2 of the License, or | |
23937 | + * (at your option) any later version. | |
dece6358 AM |
23938 | + * |
23939 | + * This program is distributed in the hope that it will be useful, | |
23940 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23941 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23942 | + * GNU General Public License for more details. | |
23943 | + * | |
23944 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 23945 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 23946 | + */ |
23947 | + | |
23948 | +/* | |
23949 | + * support for loopback block device as a branch | |
23950 | + */ | |
23951 | + | |
1facf9fc | 23952 | +#include "aufs.h" |
23953 | + | |
392086de AM |
23954 | +/* added into drivers/block/loop.c */ |
23955 | +static struct file *(*backing_file_func)(struct super_block *sb); | |
23956 | + | |
1facf9fc | 23957 | +/* |
23958 | + * test if two lower dentries have overlapping branches. | |
23959 | + */ | |
b752ccd1 | 23960 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding) |
1facf9fc | 23961 | +{ |
b752ccd1 | 23962 | + struct super_block *h_sb; |
392086de AM |
23963 | + struct file *backing_file; |
23964 | + | |
23965 | + if (unlikely(!backing_file_func)) { | |
23966 | + /* don't load "loop" module here */ | |
23967 | + backing_file_func = symbol_get(loop_backing_file); | |
23968 | + if (unlikely(!backing_file_func)) | |
23969 | + /* "loop" module is not loaded */ | |
23970 | + return 0; | |
23971 | + } | |
1facf9fc | 23972 | + |
b752ccd1 | 23973 | + h_sb = h_adding->d_sb; |
392086de AM |
23974 | + backing_file = backing_file_func(h_sb); |
23975 | + if (!backing_file) | |
1facf9fc | 23976 | + return 0; |
23977 | + | |
2000de60 | 23978 | + h_adding = backing_file->f_path.dentry; |
b752ccd1 AM |
23979 | + /* |
23980 | + * h_adding can be local NFS. | |
23981 | + * in this case aufs cannot detect the loop. | |
23982 | + */ | |
23983 | + if (unlikely(h_adding->d_sb == sb)) | |
1facf9fc | 23984 | + return 1; |
b752ccd1 | 23985 | + return !!au_test_subdir(h_adding, sb->s_root); |
1facf9fc | 23986 | +} |
23987 | + | |
23988 | +/* true if a kernel thread named 'loop[0-9].*' accesses a file */ | |
23989 | +int au_test_loopback_kthread(void) | |
23990 | +{ | |
b752ccd1 AM |
23991 | + int ret; |
23992 | + struct task_struct *tsk = current; | |
a2a7ad62 | 23993 | + char c, comm[sizeof(tsk->comm)]; |
b752ccd1 AM |
23994 | + |
23995 | + ret = 0; | |
23996 | + if (tsk->flags & PF_KTHREAD) { | |
a2a7ad62 AM |
23997 | + get_task_comm(comm, tsk); |
23998 | + c = comm[4]; | |
b752ccd1 | 23999 | + ret = ('0' <= c && c <= '9' |
a2a7ad62 | 24000 | + && !strncmp(comm, "loop", 4)); |
b752ccd1 | 24001 | + } |
1facf9fc | 24002 | + |
b752ccd1 | 24003 | + return ret; |
1facf9fc | 24004 | +} |
87a755f4 AM |
24005 | + |
24006 | +/* ---------------------------------------------------------------------- */ | |
24007 | + | |
24008 | +#define au_warn_loopback_step 16 | |
24009 | +static int au_warn_loopback_nelem = au_warn_loopback_step; | |
24010 | +static unsigned long *au_warn_loopback_array; | |
24011 | + | |
24012 | +void au_warn_loopback(struct super_block *h_sb) | |
24013 | +{ | |
24014 | + int i, new_nelem; | |
24015 | + unsigned long *a, magic; | |
24016 | + static DEFINE_SPINLOCK(spin); | |
24017 | + | |
24018 | + magic = h_sb->s_magic; | |
24019 | + spin_lock(&spin); | |
24020 | + a = au_warn_loopback_array; | |
24021 | + for (i = 0; i < au_warn_loopback_nelem && *a; i++) | |
24022 | + if (a[i] == magic) { | |
24023 | + spin_unlock(&spin); | |
24024 | + return; | |
24025 | + } | |
24026 | + | |
24027 | + /* h_sb is new to us, print it */ | |
24028 | + if (i < au_warn_loopback_nelem) { | |
24029 | + a[i] = magic; | |
24030 | + goto pr; | |
24031 | + } | |
24032 | + | |
24033 | + /* expand the array */ | |
24034 | + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step; | |
24035 | + a = au_kzrealloc(au_warn_loopback_array, | |
24036 | + au_warn_loopback_nelem * sizeof(unsigned long), | |
e2f27e51 AM |
24037 | + new_nelem * sizeof(unsigned long), GFP_ATOMIC, |
24038 | + /*may_shrink*/0); | |
87a755f4 AM |
24039 | + if (a) { |
24040 | + au_warn_loopback_nelem = new_nelem; | |
24041 | + au_warn_loopback_array = a; | |
24042 | + a[i] = magic; | |
24043 | + goto pr; | |
24044 | + } | |
24045 | + | |
24046 | + spin_unlock(&spin); | |
24047 | + AuWarn1("realloc failed, ignored\n"); | |
24048 | + return; | |
24049 | + | |
24050 | +pr: | |
24051 | + spin_unlock(&spin); | |
0c3ec466 AM |
24052 | + pr_warn("you may want to try another patch for loopback file " |
24053 | + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic); | |
87a755f4 AM |
24054 | +} |
24055 | + | |
24056 | +int au_loopback_init(void) | |
24057 | +{ | |
24058 | + int err; | |
24059 | + struct super_block *sb __maybe_unused; | |
24060 | + | |
79b8bda9 | 24061 | + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long)); |
87a755f4 AM |
24062 | + |
24063 | + err = 0; | |
24064 | + au_warn_loopback_array = kcalloc(au_warn_loopback_step, | |
24065 | + sizeof(unsigned long), GFP_NOFS); | |
24066 | + if (unlikely(!au_warn_loopback_array)) | |
24067 | + err = -ENOMEM; | |
24068 | + | |
24069 | + return err; | |
24070 | +} | |
24071 | + | |
24072 | +void au_loopback_fin(void) | |
24073 | +{ | |
79b8bda9 AM |
24074 | + if (backing_file_func) |
24075 | + symbol_put(loop_backing_file); | |
1c60b727 | 24076 | + kfree(au_warn_loopback_array); |
87a755f4 | 24077 | +} |
7f207e10 AM |
24078 | diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h |
24079 | --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 24080 | +++ linux/fs/aufs/loop.h 2018-01-29 07:56:20.059991935 +0100 |
523b37e3 | 24081 | @@ -0,0 +1,52 @@ |
1facf9fc | 24082 | +/* |
a2654f78 | 24083 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 24084 | + * |
24085 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24086 | + * it under the terms of the GNU General Public License as published by | |
24087 | + * the Free Software Foundation; either version 2 of the License, or | |
24088 | + * (at your option) any later version. | |
dece6358 AM |
24089 | + * |
24090 | + * This program is distributed in the hope that it will be useful, | |
24091 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24092 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24093 | + * GNU General Public License for more details. | |
24094 | + * | |
24095 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24096 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24097 | + */ |
24098 | + | |
24099 | +/* | |
24100 | + * support for loopback mount as a branch | |
24101 | + */ | |
24102 | + | |
24103 | +#ifndef __AUFS_LOOP_H__ | |
24104 | +#define __AUFS_LOOP_H__ | |
24105 | + | |
24106 | +#ifdef __KERNEL__ | |
24107 | + | |
dece6358 AM |
24108 | +struct dentry; |
24109 | +struct super_block; | |
1facf9fc | 24110 | + |
24111 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
392086de AM |
24112 | +/* drivers/block/loop.c */ |
24113 | +struct file *loop_backing_file(struct super_block *sb); | |
24114 | + | |
1facf9fc | 24115 | +/* loop.c */ |
b752ccd1 | 24116 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding); |
1facf9fc | 24117 | +int au_test_loopback_kthread(void); |
87a755f4 AM |
24118 | +void au_warn_loopback(struct super_block *h_sb); |
24119 | + | |
24120 | +int au_loopback_init(void); | |
24121 | +void au_loopback_fin(void); | |
1facf9fc | 24122 | +#else |
4a4d8108 | 24123 | +AuStubInt0(au_test_loopback_overlap, struct super_block *sb, |
b752ccd1 | 24124 | + struct dentry *h_adding) |
4a4d8108 | 24125 | +AuStubInt0(au_test_loopback_kthread, void) |
87a755f4 AM |
24126 | +AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
24127 | + | |
24128 | +AuStubInt0(au_loopback_init, void) | |
24129 | +AuStubVoid(au_loopback_fin, void) | |
1facf9fc | 24130 | +#endif /* BLK_DEV_LOOP */ |
24131 | + | |
24132 | +#endif /* __KERNEL__ */ | |
24133 | +#endif /* __AUFS_LOOP_H__ */ | |
7f207e10 AM |
24134 | diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk |
24135 | --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 AM |
24136 | +++ linux/fs/aufs/magic.mk 2018-01-29 07:56:20.059991935 +0100 |
24137 | @@ -0,0 +1,31 @@ | |
24138 | +# SPDX-License-Identifier: GPL-2.0 | |
1facf9fc | 24139 | + |
24140 | +# defined in ${srctree}/fs/fuse/inode.c | |
24141 | +# tristate | |
24142 | +ifdef CONFIG_FUSE_FS | |
24143 | +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546 | |
24144 | +endif | |
24145 | + | |
1facf9fc | 24146 | +# defined in ${srctree}/fs/xfs/xfs_sb.h |
24147 | +# tristate | |
24148 | +ifdef CONFIG_XFS_FS | |
24149 | +ccflags-y += -DXFS_SB_MAGIC=0x58465342 | |
24150 | +endif | |
24151 | + | |
24152 | +# defined in ${srctree}/fs/configfs/mount.c | |
24153 | +# tristate | |
24154 | +ifdef CONFIG_CONFIGFS_FS | |
24155 | +ccflags-y += -DCONFIGFS_MAGIC=0x62656570 | |
24156 | +endif | |
24157 | + | |
1facf9fc | 24158 | +# defined in ${srctree}/fs/ubifs/ubifs.h |
24159 | +# tristate | |
24160 | +ifdef CONFIG_UBIFS_FS | |
24161 | +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905 | |
24162 | +endif | |
4a4d8108 AM |
24163 | + |
24164 | +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h | |
24165 | +# tristate | |
24166 | +ifdef CONFIG_HFSPLUS_FS | |
24167 | +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b | |
24168 | +endif | |
7f207e10 AM |
24169 | diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile |
24170 | --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 AM |
24171 | +++ linux/fs/aufs/Makefile 2018-01-29 07:56:20.049991637 +0100 |
24172 | @@ -0,0 +1,46 @@ | |
24173 | +# SPDX-License-Identifier: GPL-2.0 | |
4a4d8108 AM |
24174 | + |
24175 | +include ${src}/magic.mk | |
24176 | +ifeq (${CONFIG_AUFS_FS},m) | |
24177 | +include ${src}/conf.mk | |
24178 | +endif | |
24179 | +-include ${src}/priv_def.mk | |
24180 | + | |
24181 | +# cf. include/linux/kernel.h | |
24182 | +# enable pr_debug | |
24183 | +ccflags-y += -DDEBUG | |
f6c5ef8b AM |
24184 | +# sparse requires the full pathname |
24185 | +ifdef M | |
523b37e3 | 24186 | +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h |
f6c5ef8b | 24187 | +else |
523b37e3 | 24188 | +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h |
f6c5ef8b | 24189 | +endif |
4a4d8108 AM |
24190 | + |
24191 | +obj-$(CONFIG_AUFS_FS) += aufs.o | |
24192 | +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ | |
24193 | + wkq.o vfsub.o dcsub.o \ | |
e49829fe | 24194 | + cpup.o whout.o wbr_policy.o \ |
4a4d8108 AM |
24195 | + dinfo.o dentry.o \ |
24196 | + dynop.o \ | |
24197 | + finfo.o file.o f_op.o \ | |
24198 | + dir.o vdir.o \ | |
24199 | + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \ | |
c2b27bf2 | 24200 | + mvdown.o ioctl.o |
4a4d8108 AM |
24201 | + |
24202 | +# all are boolean | |
e49829fe | 24203 | +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o |
4a4d8108 AM |
24204 | +aufs-$(CONFIG_SYSFS) += sysfs.o |
24205 | +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o | |
24206 | +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o | |
24207 | +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o | |
24208 | +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o | |
4a4d8108 | 24209 | +aufs-$(CONFIG_AUFS_EXPORT) += export.o |
c1595e42 JR |
24210 | +aufs-$(CONFIG_AUFS_XATTR) += xattr.o |
24211 | +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o | |
8b6a4947 | 24212 | +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o |
076b876e | 24213 | +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o |
4a4d8108 AM |
24214 | +aufs-$(CONFIG_AUFS_POLL) += poll.o |
24215 | +aufs-$(CONFIG_AUFS_RDU) += rdu.o | |
4a4d8108 AM |
24216 | +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o |
24217 | +aufs-$(CONFIG_AUFS_DEBUG) += debug.o | |
24218 | +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o | |
7f207e10 AM |
24219 | diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c |
24220 | --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 24221 | +++ linux/fs/aufs/module.c 2018-01-29 07:56:20.059991935 +0100 |
1c60b727 | 24222 | @@ -0,0 +1,266 @@ |
1facf9fc | 24223 | +/* |
a2654f78 | 24224 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 24225 | + * |
24226 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24227 | + * it under the terms of the GNU General Public License as published by | |
24228 | + * the Free Software Foundation; either version 2 of the License, or | |
24229 | + * (at your option) any later version. | |
dece6358 AM |
24230 | + * |
24231 | + * This program is distributed in the hope that it will be useful, | |
24232 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24233 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24234 | + * GNU General Public License for more details. | |
24235 | + * | |
24236 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24237 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24238 | + */ |
24239 | + | |
24240 | +/* | |
24241 | + * module global variables and operations | |
24242 | + */ | |
24243 | + | |
24244 | +#include <linux/module.h> | |
24245 | +#include <linux/seq_file.h> | |
24246 | +#include "aufs.h" | |
24247 | + | |
e2f27e51 AM |
24248 | +/* shrinkable realloc */ |
24249 | +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink) | |
1facf9fc | 24250 | +{ |
e2f27e51 AM |
24251 | + size_t sz; |
24252 | + int diff; | |
1facf9fc | 24253 | + |
e2f27e51 AM |
24254 | + sz = 0; |
24255 | + diff = -1; | |
24256 | + if (p) { | |
24257 | +#if 0 /* unused */ | |
24258 | + if (!new_sz) { | |
1c60b727 | 24259 | + kfree(p); |
e2f27e51 AM |
24260 | + p = NULL; |
24261 | + goto out; | |
24262 | + } | |
24263 | +#else | |
24264 | + AuDebugOn(!new_sz); | |
24265 | +#endif | |
24266 | + sz = ksize(p); | |
24267 | + diff = au_kmidx_sub(sz, new_sz); | |
24268 | + } | |
24269 | + if (sz && !diff) | |
24270 | + goto out; | |
24271 | + | |
24272 | + if (sz < new_sz) | |
24273 | + /* expand or SLOB */ | |
24274 | + p = krealloc(p, new_sz, gfp); | |
24275 | + else if (new_sz < sz && may_shrink) { | |
24276 | + /* shrink */ | |
24277 | + void *q; | |
24278 | + | |
24279 | + q = kmalloc(new_sz, gfp); | |
24280 | + if (q) { | |
24281 | + if (p) { | |
24282 | + memcpy(q, p, new_sz); | |
1c60b727 | 24283 | + kfree(p); |
e2f27e51 AM |
24284 | + } |
24285 | + p = q; | |
24286 | + } else | |
24287 | + p = NULL; | |
24288 | + } | |
24289 | + | |
24290 | +out: | |
24291 | + return p; | |
24292 | +} | |
24293 | + | |
24294 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp, | |
24295 | + int may_shrink) | |
24296 | +{ | |
24297 | + p = au_krealloc(p, new_sz, gfp, may_shrink); | |
24298 | + if (p && new_sz > nused) | |
1facf9fc | 24299 | + memset(p + nused, 0, new_sz - nused); |
24300 | + return p; | |
24301 | +} | |
24302 | + | |
24303 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 24304 | +/* |
24305 | + * aufs caches | |
24306 | + */ | |
1c60b727 | 24307 | +struct kmem_cache *au_cache[AuCache_Last]; |
5afbbe0d AM |
24308 | + |
24309 | +static void au_cache_fin(void) | |
24310 | +{ | |
24311 | + int i; | |
24312 | + | |
24313 | + /* | |
24314 | + * Make sure all delayed rcu free inodes are flushed before we | |
24315 | + * destroy cache. | |
24316 | + */ | |
24317 | + rcu_barrier(); | |
24318 | + | |
24319 | + /* excluding AuCache_HNOTIFY */ | |
24320 | + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last); | |
24321 | + for (i = 0; i < AuCache_HNOTIFY; i++) { | |
1c60b727 AM |
24322 | + kmem_cache_destroy(au_cache[i]); |
24323 | + au_cache[i] = NULL; | |
5afbbe0d AM |
24324 | + } |
24325 | +} | |
24326 | + | |
1facf9fc | 24327 | +static int __init au_cache_init(void) |
24328 | +{ | |
1c60b727 AM |
24329 | + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once); |
24330 | + if (au_cache[AuCache_DINFO]) | |
027c5e7a | 24331 | + /* SLAB_DESTROY_BY_RCU */ |
1c60b727 | 24332 | + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr, |
f0c0a007 | 24333 | + au_icntnr_init_once); |
1c60b727 AM |
24334 | + if (au_cache[AuCache_ICNTNR]) |
24335 | + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo, | |
f0c0a007 | 24336 | + au_fi_init_once); |
1c60b727 AM |
24337 | + if (au_cache[AuCache_FINFO]) |
24338 | + au_cache[AuCache_VDIR] = AuCache(au_vdir); | |
24339 | + if (au_cache[AuCache_VDIR]) | |
24340 | + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr); | |
24341 | + if (au_cache[AuCache_DEHSTR]) | |
1facf9fc | 24342 | + return 0; |
24343 | + | |
5afbbe0d | 24344 | + au_cache_fin(); |
1facf9fc | 24345 | + return -ENOMEM; |
24346 | +} | |
24347 | + | |
1facf9fc | 24348 | +/* ---------------------------------------------------------------------- */ |
24349 | + | |
24350 | +int au_dir_roflags; | |
24351 | + | |
e49829fe | 24352 | +#ifdef CONFIG_AUFS_SBILIST |
1e00d052 AM |
24353 | +/* |
24354 | + * iterate_supers_type() doesn't protect us from | |
24355 | + * remounting (branch management) | |
24356 | + */ | |
8b6a4947 | 24357 | +struct hlist_bl_head au_sbilist; |
e49829fe JR |
24358 | +#endif |
24359 | + | |
1facf9fc | 24360 | +/* |
24361 | + * functions for module interface. | |
24362 | + */ | |
24363 | +MODULE_LICENSE("GPL"); | |
24364 | +/* MODULE_LICENSE("GPL v2"); */ | |
dece6358 | 24365 | +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>"); |
1facf9fc | 24366 | +MODULE_DESCRIPTION(AUFS_NAME |
24367 | + " -- Advanced multi layered unification filesystem"); | |
24368 | +MODULE_VERSION(AUFS_VERSION); | |
c06a8ce3 | 24369 | +MODULE_ALIAS_FS(AUFS_NAME); |
1facf9fc | 24370 | + |
1facf9fc | 24371 | +/* this module parameter has no meaning when SYSFS is disabled */ |
24372 | +int sysaufs_brs = 1; | |
24373 | +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN"); | |
24374 | +module_param_named(brs, sysaufs_brs, int, S_IRUGO); | |
24375 | + | |
076b876e | 24376 | +/* this module parameter has no meaning when USER_NS is disabled */ |
8cdd5066 | 24377 | +bool au_userns; |
076b876e AM |
24378 | +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns"); |
24379 | +module_param_named(allow_userns, au_userns, bool, S_IRUGO); | |
24380 | + | |
1facf9fc | 24381 | +/* ---------------------------------------------------------------------- */ |
24382 | + | |
24383 | +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */ | |
24384 | + | |
24385 | +int au_seq_path(struct seq_file *seq, struct path *path) | |
24386 | +{ | |
79b8bda9 AM |
24387 | + int err; |
24388 | + | |
24389 | + err = seq_path(seq, path, au_esc_chars); | |
1c60b727 | 24390 | + if (err >= 0) |
79b8bda9 | 24391 | + err = 0; |
1c60b727 | 24392 | + else |
79b8bda9 AM |
24393 | + err = -ENOMEM; |
24394 | + | |
24395 | + return err; | |
1facf9fc | 24396 | +} |
24397 | + | |
24398 | +/* ---------------------------------------------------------------------- */ | |
24399 | + | |
24400 | +static int __init aufs_init(void) | |
24401 | +{ | |
24402 | + int err, i; | |
24403 | + char *p; | |
24404 | + | |
24405 | + p = au_esc_chars; | |
24406 | + for (i = 1; i <= ' '; i++) | |
24407 | + *p++ = i; | |
24408 | + *p++ = '\\'; | |
24409 | + *p++ = '\x7f'; | |
24410 | + *p = 0; | |
24411 | + | |
24412 | + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE); | |
24413 | + | |
b95c5147 AM |
24414 | + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop)); |
24415 | + for (i = 0; i < AuIop_Last; i++) | |
24416 | + aufs_iop_nogetattr[i].getattr = NULL; | |
24417 | + | |
1c60b727 | 24418 | + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */ |
f0c0a007 | 24419 | + |
e49829fe | 24420 | + au_sbilist_init(); |
1facf9fc | 24421 | + sysaufs_brs_init(); |
24422 | + au_debug_init(); | |
4a4d8108 | 24423 | + au_dy_init(); |
1facf9fc | 24424 | + err = sysaufs_init(); |
24425 | + if (unlikely(err)) | |
24426 | + goto out; | |
e49829fe | 24427 | + err = au_procfs_init(); |
4f0767ce | 24428 | + if (unlikely(err)) |
953406b4 | 24429 | + goto out_sysaufs; |
e49829fe JR |
24430 | + err = au_wkq_init(); |
24431 | + if (unlikely(err)) | |
24432 | + goto out_procfs; | |
87a755f4 | 24433 | + err = au_loopback_init(); |
1facf9fc | 24434 | + if (unlikely(err)) |
24435 | + goto out_wkq; | |
87a755f4 AM |
24436 | + err = au_hnotify_init(); |
24437 | + if (unlikely(err)) | |
24438 | + goto out_loopback; | |
1facf9fc | 24439 | + err = au_sysrq_init(); |
24440 | + if (unlikely(err)) | |
24441 | + goto out_hin; | |
24442 | + err = au_cache_init(); | |
24443 | + if (unlikely(err)) | |
24444 | + goto out_sysrq; | |
076b876e AM |
24445 | + |
24446 | + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0; | |
1facf9fc | 24447 | + err = register_filesystem(&aufs_fs_type); |
24448 | + if (unlikely(err)) | |
24449 | + goto out_cache; | |
076b876e | 24450 | + |
4a4d8108 AM |
24451 | + /* since we define pr_fmt, call printk directly */ |
24452 | + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n"); | |
1facf9fc | 24453 | + goto out; /* success */ |
24454 | + | |
4f0767ce | 24455 | +out_cache: |
1facf9fc | 24456 | + au_cache_fin(); |
4f0767ce | 24457 | +out_sysrq: |
1facf9fc | 24458 | + au_sysrq_fin(); |
4f0767ce | 24459 | +out_hin: |
4a4d8108 | 24460 | + au_hnotify_fin(); |
87a755f4 AM |
24461 | +out_loopback: |
24462 | + au_loopback_fin(); | |
4f0767ce | 24463 | +out_wkq: |
1facf9fc | 24464 | + au_wkq_fin(); |
e49829fe JR |
24465 | +out_procfs: |
24466 | + au_procfs_fin(); | |
4f0767ce | 24467 | +out_sysaufs: |
1facf9fc | 24468 | + sysaufs_fin(); |
4a4d8108 | 24469 | + au_dy_fin(); |
4f0767ce | 24470 | +out: |
1facf9fc | 24471 | + return err; |
24472 | +} | |
24473 | + | |
24474 | +static void __exit aufs_exit(void) | |
24475 | +{ | |
24476 | + unregister_filesystem(&aufs_fs_type); | |
24477 | + au_cache_fin(); | |
24478 | + au_sysrq_fin(); | |
4a4d8108 | 24479 | + au_hnotify_fin(); |
87a755f4 | 24480 | + au_loopback_fin(); |
1facf9fc | 24481 | + au_wkq_fin(); |
e49829fe | 24482 | + au_procfs_fin(); |
1facf9fc | 24483 | + sysaufs_fin(); |
4a4d8108 | 24484 | + au_dy_fin(); |
1facf9fc | 24485 | +} |
24486 | + | |
24487 | +module_init(aufs_init); | |
24488 | +module_exit(aufs_exit); | |
7f207e10 AM |
24489 | diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h |
24490 | --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 24491 | +++ linux/fs/aufs/module.h 2018-01-29 07:56:20.059991935 +0100 |
1c60b727 | 24492 | @@ -0,0 +1,101 @@ |
1facf9fc | 24493 | +/* |
a2654f78 | 24494 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 24495 | + * |
24496 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24497 | + * it under the terms of the GNU General Public License as published by | |
24498 | + * the Free Software Foundation; either version 2 of the License, or | |
24499 | + * (at your option) any later version. | |
dece6358 AM |
24500 | + * |
24501 | + * This program is distributed in the hope that it will be useful, | |
24502 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24503 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24504 | + * GNU General Public License for more details. | |
24505 | + * | |
24506 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24507 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24508 | + */ |
24509 | + | |
24510 | +/* | |
24511 | + * module initialization and module-global | |
24512 | + */ | |
24513 | + | |
24514 | +#ifndef __AUFS_MODULE_H__ | |
24515 | +#define __AUFS_MODULE_H__ | |
24516 | + | |
24517 | +#ifdef __KERNEL__ | |
24518 | + | |
24519 | +#include <linux/slab.h> | |
24520 | + | |
dece6358 AM |
24521 | +struct path; |
24522 | +struct seq_file; | |
24523 | + | |
1facf9fc | 24524 | +/* module parameters */ |
1facf9fc | 24525 | +extern int sysaufs_brs; |
8cdd5066 | 24526 | +extern bool au_userns; |
1facf9fc | 24527 | + |
24528 | +/* ---------------------------------------------------------------------- */ | |
24529 | + | |
24530 | +extern int au_dir_roflags; | |
24531 | + | |
e2f27e51 AM |
24532 | +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink); |
24533 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp, | |
24534 | + int may_shrink); | |
24535 | + | |
24536 | +static inline int au_kmidx_sub(size_t sz, size_t new_sz) | |
24537 | +{ | |
24538 | +#ifndef CONFIG_SLOB | |
24539 | + return kmalloc_index(sz) - kmalloc_index(new_sz); | |
24540 | +#else | |
24541 | + return -1; /* SLOB is untested */ | |
24542 | +#endif | |
24543 | +} | |
24544 | + | |
1facf9fc | 24545 | +int au_seq_path(struct seq_file *seq, struct path *path); |
24546 | + | |
e49829fe JR |
24547 | +#ifdef CONFIG_PROC_FS |
24548 | +/* procfs.c */ | |
24549 | +int __init au_procfs_init(void); | |
24550 | +void au_procfs_fin(void); | |
24551 | +#else | |
24552 | +AuStubInt0(au_procfs_init, void); | |
24553 | +AuStubVoid(au_procfs_fin, void); | |
24554 | +#endif | |
24555 | + | |
4f0767ce JR |
24556 | +/* ---------------------------------------------------------------------- */ |
24557 | + | |
1c60b727 | 24558 | +/* kmem cache */ |
1facf9fc | 24559 | +enum { |
24560 | + AuCache_DINFO, | |
24561 | + AuCache_ICNTNR, | |
24562 | + AuCache_FINFO, | |
24563 | + AuCache_VDIR, | |
24564 | + AuCache_DEHSTR, | |
7eafdf33 | 24565 | + AuCache_HNOTIFY, /* must be last */ |
1facf9fc | 24566 | + AuCache_Last |
24567 | +}; | |
24568 | + | |
1c60b727 | 24569 | +extern struct kmem_cache *au_cache[AuCache_Last]; |
f0c0a007 | 24570 | + |
4a4d8108 AM |
24571 | +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD) |
24572 | +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags) | |
24573 | +#define AuCacheCtor(type, ctor) \ | |
24574 | + kmem_cache_create(#type, sizeof(struct type), \ | |
24575 | + __alignof__(struct type), AuCacheFlags, ctor) | |
1facf9fc | 24576 | + |
1facf9fc | 24577 | +#define AuCacheFuncs(name, index) \ |
4a4d8108 | 24578 | +static inline struct au_##name *au_cache_alloc_##name(void) \ |
1c60b727 | 24579 | +{ return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \ |
4a4d8108 | 24580 | +static inline void au_cache_free_##name(struct au_##name *p) \ |
1c60b727 | 24581 | +{ kmem_cache_free(au_cache[AuCache_##index], p); } |
1facf9fc | 24582 | + |
24583 | +AuCacheFuncs(dinfo, DINFO); | |
24584 | +AuCacheFuncs(icntnr, ICNTNR); | |
24585 | +AuCacheFuncs(finfo, FINFO); | |
24586 | +AuCacheFuncs(vdir, VDIR); | |
4a4d8108 AM |
24587 | +AuCacheFuncs(vdir_dehstr, DEHSTR); |
24588 | +#ifdef CONFIG_AUFS_HNOTIFY | |
24589 | +AuCacheFuncs(hnotify, HNOTIFY); | |
24590 | +#endif | |
1facf9fc | 24591 | + |
4a4d8108 AM |
24592 | +#endif /* __KERNEL__ */ |
24593 | +#endif /* __AUFS_MODULE_H__ */ | |
c2b27bf2 AM |
24594 | diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c |
24595 | --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 24596 | +++ linux/fs/aufs/mvdown.c 2018-01-29 07:56:20.059991935 +0100 |
5afbbe0d | 24597 | @@ -0,0 +1,704 @@ |
c2b27bf2 | 24598 | +/* |
a2654f78 | 24599 | + * Copyright (C) 2011-2017 Junjiro R. Okajima |
c2b27bf2 AM |
24600 | + * |
24601 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24602 | + * it under the terms of the GNU General Public License as published by | |
24603 | + * the Free Software Foundation; either version 2 of the License, or | |
24604 | + * (at your option) any later version. | |
24605 | + * | |
24606 | + * This program is distributed in the hope that it will be useful, | |
24607 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24608 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24609 | + * GNU General Public License for more details. | |
24610 | + * | |
24611 | + * You should have received a copy of the GNU General Public License | |
523b37e3 AM |
24612 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
24613 | + */ | |
24614 | + | |
24615 | +/* | |
24616 | + * move-down, opposite of copy-up | |
c2b27bf2 AM |
24617 | + */ |
24618 | + | |
24619 | +#include "aufs.h" | |
24620 | + | |
c2b27bf2 AM |
24621 | +struct au_mvd_args { |
24622 | + struct { | |
c2b27bf2 AM |
24623 | + struct super_block *h_sb; |
24624 | + struct dentry *h_parent; | |
24625 | + struct au_hinode *hdir; | |
392086de | 24626 | + struct inode *h_dir, *h_inode; |
c1595e42 | 24627 | + struct au_pin pin; |
c2b27bf2 AM |
24628 | + } info[AUFS_MVDOWN_NARRAY]; |
24629 | + | |
24630 | + struct aufs_mvdown mvdown; | |
24631 | + struct dentry *dentry, *parent; | |
24632 | + struct inode *inode, *dir; | |
24633 | + struct super_block *sb; | |
24634 | + aufs_bindex_t bopq, bwh, bfound; | |
24635 | + unsigned char rename_lock; | |
c2b27bf2 AM |
24636 | +}; |
24637 | + | |
392086de | 24638 | +#define mvd_errno mvdown.au_errno |
076b876e AM |
24639 | +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex |
24640 | +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid | |
24641 | +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex | |
24642 | +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid | |
c2b27bf2 | 24643 | + |
392086de AM |
24644 | +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb |
24645 | +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent | |
24646 | +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir | |
24647 | +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir | |
24648 | +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode | |
c1595e42 | 24649 | +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin |
392086de AM |
24650 | + |
24651 | +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb | |
24652 | +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent | |
24653 | +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir | |
24654 | +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir | |
24655 | +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode | |
c1595e42 | 24656 | +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin |
c2b27bf2 AM |
24657 | + |
24658 | +#define AU_MVD_PR(flag, ...) do { \ | |
24659 | + if (flag) \ | |
24660 | + pr_err(__VA_ARGS__); \ | |
24661 | + } while (0) | |
24662 | + | |
076b876e AM |
24663 | +static int find_lower_writable(struct au_mvd_args *a) |
24664 | +{ | |
24665 | + struct super_block *sb; | |
5afbbe0d | 24666 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
24667 | + struct au_branch *br; |
24668 | + | |
24669 | + sb = a->sb; | |
24670 | + bindex = a->mvd_bsrc; | |
5afbbe0d | 24671 | + bbot = au_sbbot(sb); |
076b876e | 24672 | + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER) |
5afbbe0d | 24673 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
24674 | + br = au_sbr(sb, bindex); |
24675 | + if (au_br_fhsm(br->br_perm) | |
8b6a4947 | 24676 | + && !sb_rdonly(au_br_sb(br))) |
076b876e AM |
24677 | + return bindex; |
24678 | + } | |
24679 | + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) | |
5afbbe0d | 24680 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
24681 | + br = au_sbr(sb, bindex); |
24682 | + if (!au_br_rdonly(br)) | |
24683 | + return bindex; | |
24684 | + } | |
24685 | + else | |
5afbbe0d | 24686 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e | 24687 | + br = au_sbr(sb, bindex); |
8b6a4947 | 24688 | + if (!sb_rdonly(au_br_sb(br))) { |
076b876e AM |
24689 | + if (au_br_rdonly(br)) |
24690 | + a->mvdown.flags | |
24691 | + |= AUFS_MVDOWN_ROLOWER_R; | |
24692 | + return bindex; | |
24693 | + } | |
24694 | + } | |
24695 | + | |
24696 | + return -1; | |
24697 | +} | |
24698 | + | |
c2b27bf2 | 24699 | +/* make the parent dir on bdst */ |
392086de | 24700 | +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24701 | +{ |
24702 | + int err; | |
24703 | + | |
24704 | + err = 0; | |
24705 | + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc); | |
24706 | + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst); | |
24707 | + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc); | |
24708 | + a->mvd_h_dst_parent = NULL; | |
5afbbe0d | 24709 | + if (au_dbbot(a->parent) >= a->mvd_bdst) |
c2b27bf2 AM |
24710 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); |
24711 | + if (!a->mvd_h_dst_parent) { | |
24712 | + err = au_cpdown_dirs(a->dentry, a->mvd_bdst); | |
24713 | + if (unlikely(err)) { | |
392086de | 24714 | + AU_MVD_PR(dmsg, "cpdown_dirs failed\n"); |
c2b27bf2 AM |
24715 | + goto out; |
24716 | + } | |
24717 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
24718 | + } | |
24719 | + | |
24720 | +out: | |
24721 | + AuTraceErr(err); | |
24722 | + return err; | |
24723 | +} | |
24724 | + | |
24725 | +/* lock them all */ | |
392086de | 24726 | +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24727 | +{ |
24728 | + int err; | |
24729 | + struct dentry *h_trap; | |
24730 | + | |
24731 | + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc); | |
24732 | + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst); | |
c1595e42 JR |
24733 | + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst, |
24734 | + au_opt_udba(a->sb), | |
24735 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
24736 | + AuTraceErr(err); | |
24737 | + if (unlikely(err)) { | |
24738 | + AU_MVD_PR(dmsg, "pin_dst failed\n"); | |
24739 | + goto out; | |
24740 | + } | |
24741 | + | |
c2b27bf2 AM |
24742 | + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) { |
24743 | + a->rename_lock = 0; | |
c1595e42 JR |
24744 | + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, |
24745 | + AuLsc_DI_PARENT, AuLsc_I_PARENT3, | |
24746 | + au_opt_udba(a->sb), | |
24747 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
24748 | + err = au_do_pin(&a->mvd_pin_src); | |
24749 | + AuTraceErr(err); | |
5527c038 | 24750 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
24751 | + if (unlikely(err)) { |
24752 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
24753 | + goto out_dst; | |
24754 | + } | |
24755 | + goto out; /* success */ | |
c2b27bf2 AM |
24756 | + } |
24757 | + | |
c2b27bf2 | 24758 | + a->rename_lock = 1; |
c1595e42 JR |
24759 | + au_pin_hdir_unlock(&a->mvd_pin_dst); |
24760 | + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, | |
24761 | + au_opt_udba(a->sb), | |
24762 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
24763 | + AuTraceErr(err); | |
5527c038 | 24764 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
24765 | + if (unlikely(err)) { |
24766 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
24767 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
24768 | + goto out_dst; | |
24769 | + } | |
24770 | + au_pin_hdir_unlock(&a->mvd_pin_src); | |
c2b27bf2 AM |
24771 | + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
24772 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
24773 | + if (h_trap) { | |
24774 | + err = (h_trap != a->mvd_h_src_parent); | |
24775 | + if (err) | |
24776 | + err = (h_trap != a->mvd_h_dst_parent); | |
24777 | + } | |
24778 | + BUG_ON(err); /* it should never happen */ | |
c1595e42 JR |
24779 | + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) { |
24780 | + err = -EBUSY; | |
24781 | + AuTraceErr(err); | |
24782 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, | |
24783 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
24784 | + au_pin_hdir_lock(&a->mvd_pin_src); | |
24785 | + au_unpin(&a->mvd_pin_src); | |
24786 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
24787 | + goto out_dst; | |
24788 | + } | |
24789 | + goto out; /* success */ | |
c2b27bf2 | 24790 | + |
c1595e42 JR |
24791 | +out_dst: |
24792 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
24793 | +out: |
24794 | + AuTraceErr(err); | |
24795 | + return err; | |
24796 | +} | |
24797 | + | |
392086de | 24798 | +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 | 24799 | +{ |
c1595e42 JR |
24800 | + if (!a->rename_lock) |
24801 | + au_unpin(&a->mvd_pin_src); | |
24802 | + else { | |
c2b27bf2 AM |
24803 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
24804 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
c1595e42 JR |
24805 | + au_pin_hdir_lock(&a->mvd_pin_src); |
24806 | + au_unpin(&a->mvd_pin_src); | |
24807 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
24808 | + } | |
24809 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
24810 | +} |
24811 | + | |
24812 | +/* copy-down the file */ | |
392086de | 24813 | +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24814 | +{ |
24815 | + int err; | |
24816 | + struct au_cp_generic cpg = { | |
24817 | + .dentry = a->dentry, | |
24818 | + .bdst = a->mvd_bdst, | |
24819 | + .bsrc = a->mvd_bsrc, | |
24820 | + .len = -1, | |
c1595e42 | 24821 | + .pin = &a->mvd_pin_dst, |
c2b27bf2 AM |
24822 | + .flags = AuCpup_DTIME | AuCpup_HOPEN |
24823 | + }; | |
24824 | + | |
24825 | + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst); | |
392086de AM |
24826 | + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER) |
24827 | + au_fset_cpup(cpg.flags, OVERWRITE); | |
24828 | + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER) | |
24829 | + au_fset_cpup(cpg.flags, RWDST); | |
c2b27bf2 AM |
24830 | + err = au_sio_cpdown_simple(&cpg); |
24831 | + if (unlikely(err)) | |
392086de | 24832 | + AU_MVD_PR(dmsg, "cpdown failed\n"); |
c2b27bf2 AM |
24833 | + |
24834 | + AuTraceErr(err); | |
24835 | + return err; | |
24836 | +} | |
24837 | + | |
24838 | +/* | |
24839 | + * unlink the whiteout on bdst if exist which may be created by UDBA while we | |
24840 | + * were sleeping | |
24841 | + */ | |
392086de | 24842 | +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24843 | +{ |
24844 | + int err; | |
24845 | + struct path h_path; | |
24846 | + struct au_branch *br; | |
523b37e3 | 24847 | + struct inode *delegated; |
c2b27bf2 AM |
24848 | + |
24849 | + br = au_sbr(a->sb, a->mvd_bdst); | |
24850 | + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br); | |
24851 | + err = PTR_ERR(h_path.dentry); | |
24852 | + if (IS_ERR(h_path.dentry)) { | |
392086de | 24853 | + AU_MVD_PR(dmsg, "wh_lkup failed\n"); |
c2b27bf2 AM |
24854 | + goto out; |
24855 | + } | |
24856 | + | |
24857 | + err = 0; | |
5527c038 | 24858 | + if (d_is_positive(h_path.dentry)) { |
c2b27bf2 | 24859 | + h_path.mnt = au_br_mnt(br); |
523b37e3 | 24860 | + delegated = NULL; |
5527c038 | 24861 | + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path, |
523b37e3 AM |
24862 | + &delegated, /*force*/0); |
24863 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24864 | + pr_warn("cannot retry for NFSv4 delegation" | |
24865 | + " for an internal unlink\n"); | |
24866 | + iput(delegated); | |
24867 | + } | |
c2b27bf2 | 24868 | + if (unlikely(err)) |
392086de | 24869 | + AU_MVD_PR(dmsg, "wh_unlink failed\n"); |
c2b27bf2 AM |
24870 | + } |
24871 | + dput(h_path.dentry); | |
24872 | + | |
24873 | +out: | |
24874 | + AuTraceErr(err); | |
24875 | + return err; | |
24876 | +} | |
24877 | + | |
24878 | +/* | |
24879 | + * unlink the topmost h_dentry | |
c2b27bf2 | 24880 | + */ |
392086de | 24881 | +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24882 | +{ |
24883 | + int err; | |
24884 | + struct path h_path; | |
523b37e3 | 24885 | + struct inode *delegated; |
c2b27bf2 AM |
24886 | + |
24887 | + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc); | |
24888 | + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc); | |
523b37e3 AM |
24889 | + delegated = NULL; |
24890 | + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0); | |
24891 | + if (unlikely(err == -EWOULDBLOCK)) { | |
24892 | + pr_warn("cannot retry for NFSv4 delegation" | |
24893 | + " for an internal unlink\n"); | |
24894 | + iput(delegated); | |
24895 | + } | |
c2b27bf2 | 24896 | + if (unlikely(err)) |
392086de | 24897 | + AU_MVD_PR(dmsg, "unlink failed\n"); |
c2b27bf2 AM |
24898 | + |
24899 | + AuTraceErr(err); | |
24900 | + return err; | |
24901 | +} | |
24902 | + | |
076b876e AM |
24903 | +/* Since mvdown succeeded, we ignore an error of this function */ |
24904 | +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a) | |
24905 | +{ | |
24906 | + int err; | |
24907 | + struct au_branch *br; | |
24908 | + | |
24909 | + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED; | |
24910 | + br = au_sbr(a->sb, a->mvd_bsrc); | |
24911 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs); | |
24912 | + if (!err) { | |
24913 | + br = au_sbr(a->sb, a->mvd_bdst); | |
24914 | + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id; | |
24915 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs); | |
24916 | + } | |
24917 | + if (!err) | |
24918 | + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED; | |
24919 | + else | |
24920 | + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err); | |
24921 | +} | |
24922 | + | |
c2b27bf2 AM |
24923 | +/* |
24924 | + * copy-down the file and unlink the bsrc file. | |
24925 | + * - unlink the bdst whout if exist | |
24926 | + * - copy-down the file (with whtmp name and rename) | |
24927 | + * - unlink the bsrc file | |
24928 | + */ | |
392086de | 24929 | +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24930 | +{ |
24931 | + int err; | |
24932 | + | |
392086de | 24933 | + err = au_do_mkdir(dmsg, a); |
c2b27bf2 | 24934 | + if (!err) |
392086de | 24935 | + err = au_do_lock(dmsg, a); |
c2b27bf2 AM |
24936 | + if (unlikely(err)) |
24937 | + goto out; | |
24938 | + | |
24939 | + /* | |
24940 | + * do not revert the activities we made on bdst since they should be | |
24941 | + * harmless in aufs. | |
24942 | + */ | |
24943 | + | |
392086de | 24944 | + err = au_do_cpdown(dmsg, a); |
c2b27bf2 | 24945 | + if (!err) |
392086de AM |
24946 | + err = au_do_unlink_wh(dmsg, a); |
24947 | + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
24948 | + err = au_do_unlink(dmsg, a); | |
c2b27bf2 AM |
24949 | + if (unlikely(err)) |
24950 | + goto out_unlock; | |
24951 | + | |
c1595e42 JR |
24952 | + AuDbg("%pd2, 0x%x, %d --> %d\n", |
24953 | + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst); | |
076b876e AM |
24954 | + if (find_lower_writable(a) < 0) |
24955 | + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM; | |
24956 | + | |
24957 | + if (a->mvdown.flags & AUFS_MVDOWN_STFS) | |
24958 | + au_do_stfs(dmsg, a); | |
24959 | + | |
c2b27bf2 | 24960 | + /* maintain internal array */ |
392086de AM |
24961 | + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) { |
24962 | + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL); | |
5afbbe0d | 24963 | + au_set_dbtop(a->dentry, a->mvd_bdst); |
392086de | 24964 | + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0); |
5afbbe0d | 24965 | + au_set_ibtop(a->inode, a->mvd_bdst); |
79b8bda9 AM |
24966 | + } else { |
24967 | + /* hide the lower */ | |
24968 | + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL); | |
5afbbe0d | 24969 | + au_set_dbbot(a->dentry, a->mvd_bsrc); |
79b8bda9 | 24970 | + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0); |
5afbbe0d | 24971 | + au_set_ibbot(a->inode, a->mvd_bsrc); |
392086de | 24972 | + } |
5afbbe0d AM |
24973 | + if (au_dbbot(a->dentry) < a->mvd_bdst) |
24974 | + au_set_dbbot(a->dentry, a->mvd_bdst); | |
24975 | + if (au_ibbot(a->inode) < a->mvd_bdst) | |
24976 | + au_set_ibbot(a->inode, a->mvd_bdst); | |
c2b27bf2 AM |
24977 | + |
24978 | +out_unlock: | |
392086de | 24979 | + au_do_unlock(dmsg, a); |
c2b27bf2 AM |
24980 | +out: |
24981 | + AuTraceErr(err); | |
24982 | + return err; | |
24983 | +} | |
24984 | + | |
24985 | +/* ---------------------------------------------------------------------- */ | |
24986 | + | |
c2b27bf2 | 24987 | +/* make sure the file is idle */ |
392086de | 24988 | +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
24989 | +{ |
24990 | + int err, plinked; | |
c2b27bf2 AM |
24991 | + |
24992 | + err = 0; | |
c2b27bf2 | 24993 | + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK); |
5afbbe0d | 24994 | + if (au_dbtop(a->dentry) == a->mvd_bsrc |
c1595e42 | 24995 | + && au_dcount(a->dentry) == 1 |
c2b27bf2 | 24996 | + && atomic_read(&a->inode->i_count) == 1 |
392086de | 24997 | + /* && a->mvd_h_src_inode->i_nlink == 1 */ |
c2b27bf2 AM |
24998 | + && (!plinked || !au_plink_test(a->inode)) |
24999 | + && a->inode->i_nlink == 1) | |
25000 | + goto out; | |
25001 | + | |
25002 | + err = -EBUSY; | |
392086de | 25003 | + AU_MVD_PR(dmsg, |
c1595e42 | 25004 | + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n", |
5afbbe0d | 25005 | + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry), |
c2b27bf2 | 25006 | + atomic_read(&a->inode->i_count), a->inode->i_nlink, |
392086de | 25007 | + a->mvd_h_src_inode->i_nlink, |
c2b27bf2 AM |
25008 | + plinked, plinked ? au_plink_test(a->inode) : 0); |
25009 | + | |
25010 | +out: | |
25011 | + AuTraceErr(err); | |
25012 | + return err; | |
25013 | +} | |
25014 | + | |
25015 | +/* make sure the parent dir is fine */ | |
392086de | 25016 | +static int au_mvd_args_parent(const unsigned char dmsg, |
c2b27bf2 AM |
25017 | + struct au_mvd_args *a) |
25018 | +{ | |
25019 | + int err; | |
25020 | + aufs_bindex_t bindex; | |
25021 | + | |
25022 | + err = 0; | |
25023 | + if (unlikely(au_alive_dir(a->parent))) { | |
25024 | + err = -ENOENT; | |
392086de | 25025 | + AU_MVD_PR(dmsg, "parent dir is dead\n"); |
c2b27bf2 AM |
25026 | + goto out; |
25027 | + } | |
25028 | + | |
25029 | + a->bopq = au_dbdiropq(a->parent); | |
25030 | + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst); | |
25031 | + AuDbg("b%d\n", bindex); | |
25032 | + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst) | |
25033 | + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) { | |
25034 | + err = -EINVAL; | |
392086de AM |
25035 | + a->mvd_errno = EAU_MVDOWN_OPAQUE; |
25036 | + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n", | |
c2b27bf2 AM |
25037 | + a->bopq, a->mvd_bdst); |
25038 | + } | |
25039 | + | |
25040 | +out: | |
25041 | + AuTraceErr(err); | |
25042 | + return err; | |
25043 | +} | |
25044 | + | |
392086de | 25045 | +static int au_mvd_args_intermediate(const unsigned char dmsg, |
c2b27bf2 AM |
25046 | + struct au_mvd_args *a) |
25047 | +{ | |
25048 | + int err; | |
25049 | + struct au_dinfo *dinfo, *tmp; | |
25050 | + | |
25051 | + /* lookup the next lower positive entry */ | |
25052 | + err = -ENOMEM; | |
25053 | + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP); | |
25054 | + if (unlikely(!tmp)) | |
25055 | + goto out; | |
25056 | + | |
25057 | + a->bfound = -1; | |
25058 | + a->bwh = -1; | |
25059 | + dinfo = au_di(a->dentry); | |
25060 | + au_di_cp(tmp, dinfo); | |
25061 | + au_di_swap(tmp, dinfo); | |
25062 | + | |
25063 | + /* returns the number of positive dentries */ | |
5afbbe0d AM |
25064 | + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, |
25065 | + /* AuLkup_IGNORE_PERM */ 0); | |
c2b27bf2 AM |
25066 | + if (!err) |
25067 | + a->bwh = au_dbwh(a->dentry); | |
25068 | + else if (err > 0) | |
5afbbe0d | 25069 | + a->bfound = au_dbtop(a->dentry); |
c2b27bf2 AM |
25070 | + |
25071 | + au_di_swap(tmp, dinfo); | |
25072 | + au_rw_write_unlock(&tmp->di_rwsem); | |
25073 | + au_di_free(tmp); | |
25074 | + if (unlikely(err < 0)) | |
392086de | 25075 | + AU_MVD_PR(dmsg, "failed look-up lower\n"); |
c2b27bf2 AM |
25076 | + |
25077 | + /* | |
25078 | + * here, we have these cases. | |
25079 | + * bfound == -1 | |
25080 | + * no positive dentry under bsrc. there are more sub-cases. | |
25081 | + * bwh < 0 | |
25082 | + * there no whiteout, we can safely move-down. | |
25083 | + * bwh <= bsrc | |
25084 | + * impossible | |
25085 | + * bsrc < bwh && bwh < bdst | |
25086 | + * there is a whiteout on RO branch. cannot proceed. | |
25087 | + * bwh == bdst | |
25088 | + * there is a whiteout on the RW target branch. it should | |
25089 | + * be removed. | |
25090 | + * bdst < bwh | |
25091 | + * there is a whiteout somewhere unrelated branch. | |
25092 | + * -1 < bfound && bfound <= bsrc | |
25093 | + * impossible. | |
25094 | + * bfound < bdst | |
25095 | + * found, but it is on RO branch between bsrc and bdst. cannot | |
25096 | + * proceed. | |
25097 | + * bfound == bdst | |
25098 | + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return | |
25099 | + * error. | |
25100 | + * bdst < bfound | |
25101 | + * found, after we create the file on bdst, it will be hidden. | |
25102 | + */ | |
25103 | + | |
25104 | + AuDebugOn(a->bfound == -1 | |
25105 | + && a->bwh != -1 | |
25106 | + && a->bwh <= a->mvd_bsrc); | |
25107 | + AuDebugOn(-1 < a->bfound | |
25108 | + && a->bfound <= a->mvd_bsrc); | |
25109 | + | |
25110 | + err = -EINVAL; | |
25111 | + if (a->bfound == -1 | |
25112 | + && a->mvd_bsrc < a->bwh | |
25113 | + && a->bwh != -1 | |
25114 | + && a->bwh < a->mvd_bdst) { | |
392086de AM |
25115 | + a->mvd_errno = EAU_MVDOWN_WHITEOUT; |
25116 | + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n", | |
c2b27bf2 AM |
25117 | + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh); |
25118 | + goto out; | |
25119 | + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) { | |
392086de AM |
25120 | + a->mvd_errno = EAU_MVDOWN_UPPER; |
25121 | + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n", | |
c2b27bf2 AM |
25122 | + a->mvd_bdst, a->bfound); |
25123 | + goto out; | |
25124 | + } | |
25125 | + | |
25126 | + err = 0; /* success */ | |
25127 | + | |
25128 | +out: | |
25129 | + AuTraceErr(err); | |
25130 | + return err; | |
25131 | +} | |
25132 | + | |
392086de | 25133 | +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25134 | +{ |
25135 | + int err; | |
25136 | + | |
392086de AM |
25137 | + err = 0; |
25138 | + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER) | |
25139 | + && a->bfound == a->mvd_bdst) | |
25140 | + err = -EEXIST; | |
c2b27bf2 AM |
25141 | + AuTraceErr(err); |
25142 | + return err; | |
25143 | +} | |
25144 | + | |
392086de | 25145 | +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25146 | +{ |
25147 | + int err; | |
25148 | + struct au_branch *br; | |
25149 | + | |
25150 | + err = -EISDIR; | |
25151 | + if (unlikely(S_ISDIR(a->inode->i_mode))) | |
25152 | + goto out; | |
25153 | + | |
25154 | + err = -EINVAL; | |
392086de | 25155 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER)) |
5afbbe0d | 25156 | + a->mvd_bsrc = au_ibtop(a->inode); |
392086de AM |
25157 | + else { |
25158 | + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid); | |
25159 | + if (unlikely(a->mvd_bsrc < 0 | |
5afbbe0d AM |
25160 | + || (a->mvd_bsrc < au_dbtop(a->dentry) |
25161 | + || au_dbbot(a->dentry) < a->mvd_bsrc | |
392086de | 25162 | + || !au_h_dptr(a->dentry, a->mvd_bsrc)) |
5afbbe0d AM |
25163 | + || (a->mvd_bsrc < au_ibtop(a->inode) |
25164 | + || au_ibbot(a->inode) < a->mvd_bsrc | |
392086de AM |
25165 | + || !au_h_iptr(a->inode, a->mvd_bsrc)))) { |
25166 | + a->mvd_errno = EAU_MVDOWN_NOUPPER; | |
25167 | + AU_MVD_PR(dmsg, "no upper\n"); | |
25168 | + goto out; | |
25169 | + } | |
25170 | + } | |
5afbbe0d | 25171 | + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) { |
392086de AM |
25172 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; |
25173 | + AU_MVD_PR(dmsg, "on the bottom\n"); | |
c2b27bf2 AM |
25174 | + goto out; |
25175 | + } | |
392086de | 25176 | + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc); |
c2b27bf2 AM |
25177 | + br = au_sbr(a->sb, a->mvd_bsrc); |
25178 | + err = au_br_rdonly(br); | |
392086de AM |
25179 | + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) { |
25180 | + if (unlikely(err)) | |
25181 | + goto out; | |
25182 | + } else if (!(vfsub_native_ro(a->mvd_h_src_inode) | |
25183 | + || IS_APPEND(a->mvd_h_src_inode))) { | |
25184 | + if (err) | |
25185 | + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R; | |
25186 | + /* go on */ | |
25187 | + } else | |
c2b27bf2 AM |
25188 | + goto out; |
25189 | + | |
25190 | + err = -EINVAL; | |
392086de AM |
25191 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) { |
25192 | + a->mvd_bdst = find_lower_writable(a); | |
25193 | + if (unlikely(a->mvd_bdst < 0)) { | |
25194 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; | |
25195 | + AU_MVD_PR(dmsg, "no writable lower branch\n"); | |
25196 | + goto out; | |
25197 | + } | |
25198 | + } else { | |
25199 | + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid); | |
25200 | + if (unlikely(a->mvd_bdst < 0 | |
5afbbe0d | 25201 | + || au_sbbot(a->sb) < a->mvd_bdst)) { |
392086de AM |
25202 | + a->mvd_errno = EAU_MVDOWN_NOLOWERBR; |
25203 | + AU_MVD_PR(dmsg, "no lower brid\n"); | |
25204 | + goto out; | |
25205 | + } | |
c2b27bf2 AM |
25206 | + } |
25207 | + | |
392086de | 25208 | + err = au_mvd_args_busy(dmsg, a); |
c2b27bf2 | 25209 | + if (!err) |
392086de | 25210 | + err = au_mvd_args_parent(dmsg, a); |
c2b27bf2 | 25211 | + if (!err) |
392086de | 25212 | + err = au_mvd_args_intermediate(dmsg, a); |
c2b27bf2 | 25213 | + if (!err) |
392086de | 25214 | + err = au_mvd_args_exist(dmsg, a); |
c2b27bf2 AM |
25215 | + if (!err) |
25216 | + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst); | |
25217 | + | |
25218 | +out: | |
25219 | + AuTraceErr(err); | |
25220 | + return err; | |
25221 | +} | |
25222 | + | |
25223 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg) | |
25224 | +{ | |
392086de AM |
25225 | + int err, e; |
25226 | + unsigned char dmsg; | |
25227 | + struct au_mvd_args *args; | |
79b8bda9 | 25228 | + struct inode *inode; |
c2b27bf2 | 25229 | + |
79b8bda9 | 25230 | + inode = d_inode(dentry); |
c2b27bf2 AM |
25231 | + err = -EPERM; |
25232 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
25233 | + goto out; | |
25234 | + | |
392086de AM |
25235 | + err = -ENOMEM; |
25236 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
25237 | + if (unlikely(!args)) | |
25238 | + goto out; | |
25239 | + | |
25240 | + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown)); | |
25241 | + if (!err) | |
25242 | + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg)); | |
c2b27bf2 AM |
25243 | + if (unlikely(err)) { |
25244 | + err = -EFAULT; | |
392086de AM |
25245 | + AuTraceErr(err); |
25246 | + goto out_free; | |
c2b27bf2 | 25247 | + } |
392086de AM |
25248 | + AuDbg("flags 0x%x\n", args->mvdown.flags); |
25249 | + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R); | |
25250 | + args->mvdown.au_errno = 0; | |
25251 | + args->dentry = dentry; | |
79b8bda9 | 25252 | + args->inode = inode; |
392086de | 25253 | + args->sb = dentry->d_sb; |
c2b27bf2 | 25254 | + |
392086de AM |
25255 | + err = -ENOENT; |
25256 | + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG); | |
25257 | + args->parent = dget_parent(dentry); | |
5527c038 | 25258 | + args->dir = d_inode(args->parent); |
febd17d6 | 25259 | + inode_lock_nested(args->dir, I_MUTEX_PARENT); |
392086de AM |
25260 | + dput(args->parent); |
25261 | + if (unlikely(args->parent != dentry->d_parent)) { | |
25262 | + AU_MVD_PR(dmsg, "parent dir is moved\n"); | |
c2b27bf2 AM |
25263 | + goto out_dir; |
25264 | + } | |
25265 | + | |
febd17d6 | 25266 | + inode_lock_nested(inode, I_MUTEX_CHILD); |
b95c5147 | 25267 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW); |
c2b27bf2 AM |
25268 | + if (unlikely(err)) |
25269 | + goto out_inode; | |
25270 | + | |
392086de AM |
25271 | + di_write_lock_parent(args->parent); |
25272 | + err = au_mvd_args(dmsg, args); | |
c2b27bf2 AM |
25273 | + if (unlikely(err)) |
25274 | + goto out_parent; | |
25275 | + | |
392086de | 25276 | + err = au_do_mvdown(dmsg, args); |
c2b27bf2 AM |
25277 | + if (unlikely(err)) |
25278 | + goto out_parent; | |
c2b27bf2 | 25279 | + |
392086de | 25280 | + au_cpup_attr_timesizes(args->dir); |
79b8bda9 AM |
25281 | + au_cpup_attr_timesizes(inode); |
25282 | + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
25283 | + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst)); | |
c2b27bf2 AM |
25284 | + /* au_digen_dec(dentry); */ |
25285 | + | |
25286 | +out_parent: | |
392086de | 25287 | + di_write_unlock(args->parent); |
c2b27bf2 AM |
25288 | + aufs_read_unlock(dentry, AuLock_DW); |
25289 | +out_inode: | |
febd17d6 | 25290 | + inode_unlock(inode); |
c2b27bf2 | 25291 | +out_dir: |
febd17d6 | 25292 | + inode_unlock(args->dir); |
392086de AM |
25293 | +out_free: |
25294 | + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown)); | |
25295 | + if (unlikely(e)) | |
25296 | + err = -EFAULT; | |
1c60b727 | 25297 | + kfree(args); |
c2b27bf2 AM |
25298 | +out: |
25299 | + AuTraceErr(err); | |
25300 | + return err; | |
25301 | +} | |
25302 | diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c | |
25303 | --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 25304 | +++ linux/fs/aufs/opts.c 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 25305 | @@ -0,0 +1,1891 @@ |
1facf9fc | 25306 | +/* |
a2654f78 | 25307 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 25308 | + * |
25309 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25310 | + * it under the terms of the GNU General Public License as published by | |
25311 | + * the Free Software Foundation; either version 2 of the License, or | |
25312 | + * (at your option) any later version. | |
dece6358 AM |
25313 | + * |
25314 | + * This program is distributed in the hope that it will be useful, | |
25315 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25316 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25317 | + * GNU General Public License for more details. | |
25318 | + * | |
25319 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25320 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25321 | + */ |
25322 | + | |
25323 | +/* | |
25324 | + * mount options/flags | |
25325 | + */ | |
25326 | + | |
dece6358 | 25327 | +#include <linux/namei.h> |
1facf9fc | 25328 | +#include <linux/types.h> /* a distribution requires */ |
25329 | +#include <linux/parser.h> | |
25330 | +#include "aufs.h" | |
25331 | + | |
25332 | +/* ---------------------------------------------------------------------- */ | |
25333 | + | |
25334 | +enum { | |
25335 | + Opt_br, | |
7e9cd9fe AM |
25336 | + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend, |
25337 | + Opt_idel, Opt_imod, | |
25338 | + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, | |
dece6358 | 25339 | + Opt_rdblk_def, Opt_rdhash_def, |
7e9cd9fe | 25340 | + Opt_xino, Opt_noxino, |
1facf9fc | 25341 | + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino, |
25342 | + Opt_trunc_xino_path, Opt_itrunc_xino, | |
25343 | + Opt_trunc_xib, Opt_notrunc_xib, | |
dece6358 | 25344 | + Opt_shwh, Opt_noshwh, |
1facf9fc | 25345 | + Opt_plink, Opt_noplink, Opt_list_plink, |
25346 | + Opt_udba, | |
4a4d8108 | 25347 | + Opt_dio, Opt_nodio, |
1facf9fc | 25348 | + Opt_diropq_a, Opt_diropq_w, |
25349 | + Opt_warn_perm, Opt_nowarn_perm, | |
25350 | + Opt_wbr_copyup, Opt_wbr_create, | |
076b876e | 25351 | + Opt_fhsm_sec, |
1facf9fc | 25352 | + Opt_verbose, Opt_noverbose, |
25353 | + Opt_sum, Opt_nosum, Opt_wsum, | |
076b876e | 25354 | + Opt_dirperm1, Opt_nodirperm1, |
8b6a4947 | 25355 | + Opt_dirren, Opt_nodirren, |
c1595e42 | 25356 | + Opt_acl, Opt_noacl, |
1facf9fc | 25357 | + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err |
25358 | +}; | |
25359 | + | |
25360 | +static match_table_t options = { | |
25361 | + {Opt_br, "br=%s"}, | |
25362 | + {Opt_br, "br:%s"}, | |
25363 | + | |
25364 | + {Opt_add, "add=%d:%s"}, | |
25365 | + {Opt_add, "add:%d:%s"}, | |
25366 | + {Opt_add, "ins=%d:%s"}, | |
25367 | + {Opt_add, "ins:%d:%s"}, | |
25368 | + {Opt_append, "append=%s"}, | |
25369 | + {Opt_append, "append:%s"}, | |
25370 | + {Opt_prepend, "prepend=%s"}, | |
25371 | + {Opt_prepend, "prepend:%s"}, | |
25372 | + | |
25373 | + {Opt_del, "del=%s"}, | |
25374 | + {Opt_del, "del:%s"}, | |
25375 | + /* {Opt_idel, "idel:%d"}, */ | |
25376 | + {Opt_mod, "mod=%s"}, | |
25377 | + {Opt_mod, "mod:%s"}, | |
25378 | + /* {Opt_imod, "imod:%d:%s"}, */ | |
25379 | + | |
25380 | + {Opt_dirwh, "dirwh=%d"}, | |
25381 | + | |
25382 | + {Opt_xino, "xino=%s"}, | |
25383 | + {Opt_noxino, "noxino"}, | |
25384 | + {Opt_trunc_xino, "trunc_xino"}, | |
25385 | + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"}, | |
25386 | + {Opt_notrunc_xino, "notrunc_xino"}, | |
25387 | + {Opt_trunc_xino_path, "trunc_xino=%s"}, | |
25388 | + {Opt_itrunc_xino, "itrunc_xino=%d"}, | |
25389 | + /* {Opt_zxino, "zxino=%s"}, */ | |
25390 | + {Opt_trunc_xib, "trunc_xib"}, | |
25391 | + {Opt_notrunc_xib, "notrunc_xib"}, | |
25392 | + | |
e49829fe | 25393 | +#ifdef CONFIG_PROC_FS |
1facf9fc | 25394 | + {Opt_plink, "plink"}, |
e49829fe JR |
25395 | +#else |
25396 | + {Opt_ignore_silent, "plink"}, | |
25397 | +#endif | |
25398 | + | |
1facf9fc | 25399 | + {Opt_noplink, "noplink"}, |
e49829fe | 25400 | + |
1facf9fc | 25401 | +#ifdef CONFIG_AUFS_DEBUG |
25402 | + {Opt_list_plink, "list_plink"}, | |
25403 | +#endif | |
25404 | + | |
25405 | + {Opt_udba, "udba=%s"}, | |
25406 | + | |
4a4d8108 AM |
25407 | + {Opt_dio, "dio"}, |
25408 | + {Opt_nodio, "nodio"}, | |
25409 | + | |
8b6a4947 AM |
25410 | +#ifdef CONFIG_AUFS_DIRREN |
25411 | + {Opt_dirren, "dirren"}, | |
25412 | + {Opt_nodirren, "nodirren"}, | |
25413 | +#else | |
25414 | + {Opt_ignore, "dirren"}, | |
25415 | + {Opt_ignore_silent, "nodirren"}, | |
25416 | +#endif | |
25417 | + | |
076b876e AM |
25418 | +#ifdef CONFIG_AUFS_FHSM |
25419 | + {Opt_fhsm_sec, "fhsm_sec=%d"}, | |
25420 | +#else | |
8b6a4947 | 25421 | + {Opt_ignore, "fhsm_sec=%d"}, |
076b876e AM |
25422 | +#endif |
25423 | + | |
1facf9fc | 25424 | + {Opt_diropq_a, "diropq=always"}, |
25425 | + {Opt_diropq_a, "diropq=a"}, | |
25426 | + {Opt_diropq_w, "diropq=whiteouted"}, | |
25427 | + {Opt_diropq_w, "diropq=w"}, | |
25428 | + | |
25429 | + {Opt_warn_perm, "warn_perm"}, | |
25430 | + {Opt_nowarn_perm, "nowarn_perm"}, | |
25431 | + | |
25432 | + /* keep them temporary */ | |
1facf9fc | 25433 | + {Opt_ignore_silent, "nodlgt"}, |
8b6a4947 | 25434 | + {Opt_ignore, "clean_plink"}, |
1facf9fc | 25435 | + |
dece6358 AM |
25436 | +#ifdef CONFIG_AUFS_SHWH |
25437 | + {Opt_shwh, "shwh"}, | |
25438 | +#endif | |
25439 | + {Opt_noshwh, "noshwh"}, | |
25440 | + | |
076b876e AM |
25441 | + {Opt_dirperm1, "dirperm1"}, |
25442 | + {Opt_nodirperm1, "nodirperm1"}, | |
25443 | + | |
1facf9fc | 25444 | + {Opt_verbose, "verbose"}, |
25445 | + {Opt_verbose, "v"}, | |
25446 | + {Opt_noverbose, "noverbose"}, | |
25447 | + {Opt_noverbose, "quiet"}, | |
25448 | + {Opt_noverbose, "q"}, | |
25449 | + {Opt_noverbose, "silent"}, | |
25450 | + | |
25451 | + {Opt_sum, "sum"}, | |
25452 | + {Opt_nosum, "nosum"}, | |
25453 | + {Opt_wsum, "wsum"}, | |
25454 | + | |
25455 | + {Opt_rdcache, "rdcache=%d"}, | |
25456 | + {Opt_rdblk, "rdblk=%d"}, | |
dece6358 | 25457 | + {Opt_rdblk_def, "rdblk=def"}, |
1facf9fc | 25458 | + {Opt_rdhash, "rdhash=%d"}, |
dece6358 | 25459 | + {Opt_rdhash_def, "rdhash=def"}, |
1facf9fc | 25460 | + |
25461 | + {Opt_wbr_create, "create=%s"}, | |
25462 | + {Opt_wbr_create, "create_policy=%s"}, | |
25463 | + {Opt_wbr_copyup, "cpup=%s"}, | |
25464 | + {Opt_wbr_copyup, "copyup=%s"}, | |
25465 | + {Opt_wbr_copyup, "copyup_policy=%s"}, | |
25466 | + | |
c1595e42 JR |
25467 | + /* generic VFS flag */ |
25468 | +#ifdef CONFIG_FS_POSIX_ACL | |
25469 | + {Opt_acl, "acl"}, | |
25470 | + {Opt_noacl, "noacl"}, | |
25471 | +#else | |
8b6a4947 | 25472 | + {Opt_ignore, "acl"}, |
c1595e42 JR |
25473 | + {Opt_ignore_silent, "noacl"}, |
25474 | +#endif | |
25475 | + | |
1facf9fc | 25476 | + /* internal use for the scripts */ |
25477 | + {Opt_ignore_silent, "si=%s"}, | |
25478 | + | |
25479 | + {Opt_br, "dirs=%s"}, | |
25480 | + {Opt_ignore, "debug=%d"}, | |
25481 | + {Opt_ignore, "delete=whiteout"}, | |
25482 | + {Opt_ignore, "delete=all"}, | |
25483 | + {Opt_ignore, "imap=%s"}, | |
25484 | + | |
1308ab2a | 25485 | + /* temporary workaround, due to old mount(8)? */ |
25486 | + {Opt_ignore_silent, "relatime"}, | |
25487 | + | |
1facf9fc | 25488 | + {Opt_err, NULL} |
25489 | +}; | |
25490 | + | |
25491 | +/* ---------------------------------------------------------------------- */ | |
25492 | + | |
076b876e | 25493 | +static const char *au_parser_pattern(int val, match_table_t tbl) |
1facf9fc | 25494 | +{ |
076b876e AM |
25495 | + struct match_token *p; |
25496 | + | |
25497 | + p = tbl; | |
25498 | + while (p->pattern) { | |
25499 | + if (p->token == val) | |
25500 | + return p->pattern; | |
25501 | + p++; | |
1facf9fc | 25502 | + } |
25503 | + BUG(); | |
25504 | + return "??"; | |
25505 | +} | |
25506 | + | |
076b876e AM |
25507 | +static const char *au_optstr(int *val, match_table_t tbl) |
25508 | +{ | |
25509 | + struct match_token *p; | |
25510 | + int v; | |
25511 | + | |
25512 | + v = *val; | |
2000de60 JR |
25513 | + if (!v) |
25514 | + goto out; | |
076b876e | 25515 | + p = tbl; |
2000de60 JR |
25516 | + while (p->pattern) { |
25517 | + if (p->token | |
25518 | + && (v & p->token) == p->token) { | |
076b876e AM |
25519 | + *val &= ~p->token; |
25520 | + return p->pattern; | |
25521 | + } | |
25522 | + p++; | |
25523 | + } | |
2000de60 JR |
25524 | + |
25525 | +out: | |
076b876e AM |
25526 | + return NULL; |
25527 | +} | |
25528 | + | |
1facf9fc | 25529 | +/* ---------------------------------------------------------------------- */ |
25530 | + | |
1e00d052 | 25531 | +static match_table_t brperm = { |
1facf9fc | 25532 | + {AuBrPerm_RO, AUFS_BRPERM_RO}, |
25533 | + {AuBrPerm_RR, AUFS_BRPERM_RR}, | |
25534 | + {AuBrPerm_RW, AUFS_BRPERM_RW}, | |
1e00d052 AM |
25535 | + {0, NULL} |
25536 | +}; | |
1facf9fc | 25537 | + |
86dc4139 | 25538 | +static match_table_t brattr = { |
076b876e AM |
25539 | + /* general */ |
25540 | + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG}, | |
25541 | + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL}, | |
c1595e42 | 25542 | + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */ |
86dc4139 | 25543 | + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN}, |
2000de60 | 25544 | +#ifdef CONFIG_AUFS_FHSM |
076b876e | 25545 | + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM}, |
2000de60 JR |
25546 | +#endif |
25547 | +#ifdef CONFIG_AUFS_XATTR | |
c1595e42 JR |
25548 | + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX}, |
25549 | + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC}, | |
25550 | + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS}, | |
25551 | + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR}, | |
25552 | + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR}, | |
25553 | + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH}, | |
2000de60 | 25554 | +#endif |
076b876e AM |
25555 | + |
25556 | + /* ro/rr branch */ | |
1e00d052 | 25557 | + {AuBrRAttr_WH, AUFS_BRRATTR_WH}, |
076b876e AM |
25558 | + |
25559 | + /* rw branch */ | |
25560 | + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO}, | |
1e00d052 | 25561 | + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH}, |
076b876e | 25562 | + |
1e00d052 | 25563 | + {0, NULL} |
1facf9fc | 25564 | +}; |
25565 | + | |
1e00d052 AM |
25566 | +static int br_attr_val(char *str, match_table_t table, substring_t args[]) |
25567 | +{ | |
25568 | + int attr, v; | |
25569 | + char *p; | |
25570 | + | |
25571 | + attr = 0; | |
25572 | + do { | |
25573 | + p = strchr(str, '+'); | |
25574 | + if (p) | |
25575 | + *p = 0; | |
25576 | + v = match_token(str, table, args); | |
076b876e AM |
25577 | + if (v) { |
25578 | + if (v & AuBrAttr_CMOO_Mask) | |
25579 | + attr &= ~AuBrAttr_CMOO_Mask; | |
1e00d052 | 25580 | + attr |= v; |
076b876e | 25581 | + } else { |
1e00d052 AM |
25582 | + if (p) |
25583 | + *p = '+'; | |
0c3ec466 | 25584 | + pr_warn("ignored branch attribute %s\n", str); |
1e00d052 AM |
25585 | + break; |
25586 | + } | |
25587 | + if (p) | |
25588 | + str = p + 1; | |
25589 | + } while (p); | |
25590 | + | |
25591 | + return attr; | |
25592 | +} | |
25593 | + | |
076b876e AM |
25594 | +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm) |
25595 | +{ | |
25596 | + int sz; | |
25597 | + const char *p; | |
25598 | + char *q; | |
25599 | + | |
076b876e AM |
25600 | + q = str->a; |
25601 | + *q = 0; | |
25602 | + p = au_optstr(&perm, brattr); | |
25603 | + if (p) { | |
25604 | + sz = strlen(p); | |
25605 | + memcpy(q, p, sz + 1); | |
25606 | + q += sz; | |
25607 | + } else | |
25608 | + goto out; | |
25609 | + | |
25610 | + do { | |
25611 | + p = au_optstr(&perm, brattr); | |
25612 | + if (p) { | |
25613 | + *q++ = '+'; | |
25614 | + sz = strlen(p); | |
25615 | + memcpy(q, p, sz + 1); | |
25616 | + q += sz; | |
25617 | + } | |
25618 | + } while (p); | |
25619 | + | |
25620 | +out: | |
c1595e42 | 25621 | + return q - str->a; |
076b876e AM |
25622 | +} |
25623 | + | |
4a4d8108 | 25624 | +static int noinline_for_stack br_perm_val(char *perm) |
1facf9fc | 25625 | +{ |
076b876e AM |
25626 | + int val, bad, sz; |
25627 | + char *p; | |
1facf9fc | 25628 | + substring_t args[MAX_OPT_ARGS]; |
076b876e | 25629 | + au_br_perm_str_t attr; |
1facf9fc | 25630 | + |
1e00d052 AM |
25631 | + p = strchr(perm, '+'); |
25632 | + if (p) | |
25633 | + *p = 0; | |
25634 | + val = match_token(perm, brperm, args); | |
25635 | + if (!val) { | |
25636 | + if (p) | |
25637 | + *p = '+'; | |
0c3ec466 | 25638 | + pr_warn("ignored branch permission %s\n", perm); |
1e00d052 AM |
25639 | + val = AuBrPerm_RO; |
25640 | + goto out; | |
25641 | + } | |
25642 | + if (!p) | |
25643 | + goto out; | |
25644 | + | |
076b876e AM |
25645 | + val |= br_attr_val(p + 1, brattr, args); |
25646 | + | |
25647 | + bad = 0; | |
86dc4139 | 25648 | + switch (val & AuBrPerm_Mask) { |
1e00d052 AM |
25649 | + case AuBrPerm_RO: |
25650 | + case AuBrPerm_RR: | |
076b876e AM |
25651 | + bad = val & AuBrWAttr_Mask; |
25652 | + val &= ~AuBrWAttr_Mask; | |
1e00d052 AM |
25653 | + break; |
25654 | + case AuBrPerm_RW: | |
076b876e AM |
25655 | + bad = val & AuBrRAttr_Mask; |
25656 | + val &= ~AuBrRAttr_Mask; | |
1e00d052 AM |
25657 | + break; |
25658 | + } | |
c1595e42 JR |
25659 | + |
25660 | + /* | |
25661 | + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs | |
25662 | + * does not treat it as an error, just warning. | |
25663 | + * this is a tiny guard for the user operation. | |
25664 | + */ | |
25665 | + if (val & AuBrAttr_UNPIN) { | |
25666 | + bad |= AuBrAttr_UNPIN; | |
25667 | + val &= ~AuBrAttr_UNPIN; | |
25668 | + } | |
25669 | + | |
076b876e AM |
25670 | + if (unlikely(bad)) { |
25671 | + sz = au_do_optstr_br_attr(&attr, bad); | |
25672 | + AuDebugOn(!sz); | |
25673 | + pr_warn("ignored branch attribute %s\n", attr.a); | |
25674 | + } | |
1e00d052 AM |
25675 | + |
25676 | +out: | |
1facf9fc | 25677 | + return val; |
25678 | +} | |
25679 | + | |
076b876e | 25680 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm) |
1facf9fc | 25681 | +{ |
076b876e AM |
25682 | + au_br_perm_str_t attr; |
25683 | + const char *p; | |
25684 | + char *q; | |
1e00d052 AM |
25685 | + int sz; |
25686 | + | |
076b876e AM |
25687 | + q = str->a; |
25688 | + p = au_optstr(&perm, brperm); | |
25689 | + AuDebugOn(!p || !*p); | |
25690 | + sz = strlen(p); | |
25691 | + memcpy(q, p, sz + 1); | |
25692 | + q += sz; | |
1e00d052 | 25693 | + |
076b876e AM |
25694 | + sz = au_do_optstr_br_attr(&attr, perm); |
25695 | + if (sz) { | |
25696 | + *q++ = '+'; | |
25697 | + memcpy(q, attr.a, sz + 1); | |
1e00d052 AM |
25698 | + } |
25699 | + | |
076b876e | 25700 | + AuDebugOn(strlen(str->a) >= sizeof(str->a)); |
1facf9fc | 25701 | +} |
25702 | + | |
25703 | +/* ---------------------------------------------------------------------- */ | |
25704 | + | |
25705 | +static match_table_t udbalevel = { | |
25706 | + {AuOpt_UDBA_REVAL, "reval"}, | |
25707 | + {AuOpt_UDBA_NONE, "none"}, | |
4a4d8108 AM |
25708 | +#ifdef CONFIG_AUFS_HNOTIFY |
25709 | + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */ | |
25710 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
25711 | + {AuOpt_UDBA_HNOTIFY, "fsnotify"}, | |
4a4d8108 | 25712 | +#endif |
1facf9fc | 25713 | +#endif |
25714 | + {-1, NULL} | |
25715 | +}; | |
25716 | + | |
4a4d8108 | 25717 | +static int noinline_for_stack udba_val(char *str) |
1facf9fc | 25718 | +{ |
25719 | + substring_t args[MAX_OPT_ARGS]; | |
25720 | + | |
7f207e10 | 25721 | + return match_token(str, udbalevel, args); |
1facf9fc | 25722 | +} |
25723 | + | |
25724 | +const char *au_optstr_udba(int udba) | |
25725 | +{ | |
076b876e | 25726 | + return au_parser_pattern(udba, udbalevel); |
1facf9fc | 25727 | +} |
25728 | + | |
25729 | +/* ---------------------------------------------------------------------- */ | |
25730 | + | |
25731 | +static match_table_t au_wbr_create_policy = { | |
25732 | + {AuWbrCreate_TDP, "tdp"}, | |
25733 | + {AuWbrCreate_TDP, "top-down-parent"}, | |
25734 | + {AuWbrCreate_RR, "rr"}, | |
25735 | + {AuWbrCreate_RR, "round-robin"}, | |
25736 | + {AuWbrCreate_MFS, "mfs"}, | |
25737 | + {AuWbrCreate_MFS, "most-free-space"}, | |
25738 | + {AuWbrCreate_MFSV, "mfs:%d"}, | |
25739 | + {AuWbrCreate_MFSV, "most-free-space:%d"}, | |
25740 | + | |
f2c43d5f AM |
25741 | + /* top-down regardless the parent, and then mfs */ |
25742 | + {AuWbrCreate_TDMFS, "tdmfs:%d"}, | |
25743 | + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"}, | |
25744 | + | |
1facf9fc | 25745 | + {AuWbrCreate_MFSRR, "mfsrr:%d"}, |
25746 | + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"}, | |
25747 | + {AuWbrCreate_PMFS, "pmfs"}, | |
25748 | + {AuWbrCreate_PMFSV, "pmfs:%d"}, | |
392086de AM |
25749 | + {AuWbrCreate_PMFSRR, "pmfsrr:%d"}, |
25750 | + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"}, | |
1facf9fc | 25751 | + |
25752 | + {-1, NULL} | |
25753 | +}; | |
25754 | + | |
1facf9fc | 25755 | +static int au_wbr_mfs_wmark(substring_t *arg, char *str, |
25756 | + struct au_opt_wbr_create *create) | |
25757 | +{ | |
25758 | + int err; | |
25759 | + unsigned long long ull; | |
25760 | + | |
25761 | + err = 0; | |
a2654f78 | 25762 | + if (!match_u64(arg, &ull)) |
1facf9fc | 25763 | + create->mfsrr_watermark = ull; |
25764 | + else { | |
4a4d8108 | 25765 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 25766 | + err = -EINVAL; |
25767 | + } | |
25768 | + | |
25769 | + return err; | |
25770 | +} | |
25771 | + | |
25772 | +static int au_wbr_mfs_sec(substring_t *arg, char *str, | |
25773 | + struct au_opt_wbr_create *create) | |
25774 | +{ | |
25775 | + int n, err; | |
25776 | + | |
25777 | + err = 0; | |
027c5e7a | 25778 | + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC) |
1facf9fc | 25779 | + create->mfs_second = n; |
25780 | + else { | |
4a4d8108 | 25781 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 25782 | + err = -EINVAL; |
25783 | + } | |
25784 | + | |
25785 | + return err; | |
25786 | +} | |
25787 | + | |
4a4d8108 AM |
25788 | +static int noinline_for_stack |
25789 | +au_wbr_create_val(char *str, struct au_opt_wbr_create *create) | |
1facf9fc | 25790 | +{ |
25791 | + int err, e; | |
25792 | + substring_t args[MAX_OPT_ARGS]; | |
25793 | + | |
25794 | + err = match_token(str, au_wbr_create_policy, args); | |
25795 | + create->wbr_create = err; | |
25796 | + switch (err) { | |
25797 | + case AuWbrCreate_MFSRRV: | |
f2c43d5f | 25798 | + case AuWbrCreate_TDMFSV: |
392086de | 25799 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 25800 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
25801 | + if (!e) | |
25802 | + e = au_wbr_mfs_sec(&args[1], str, create); | |
25803 | + if (unlikely(e)) | |
25804 | + err = e; | |
25805 | + break; | |
25806 | + case AuWbrCreate_MFSRR: | |
f2c43d5f | 25807 | + case AuWbrCreate_TDMFS: |
392086de | 25808 | + case AuWbrCreate_PMFSRR: |
1facf9fc | 25809 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
25810 | + if (unlikely(e)) { | |
25811 | + err = e; | |
25812 | + break; | |
25813 | + } | |
25814 | + /*FALLTHROUGH*/ | |
25815 | + case AuWbrCreate_MFS: | |
25816 | + case AuWbrCreate_PMFS: | |
027c5e7a | 25817 | + create->mfs_second = AUFS_MFS_DEF_SEC; |
1facf9fc | 25818 | + break; |
25819 | + case AuWbrCreate_MFSV: | |
25820 | + case AuWbrCreate_PMFSV: | |
25821 | + e = au_wbr_mfs_sec(&args[0], str, create); | |
25822 | + if (unlikely(e)) | |
25823 | + err = e; | |
25824 | + break; | |
25825 | + } | |
25826 | + | |
25827 | + return err; | |
25828 | +} | |
25829 | + | |
25830 | +const char *au_optstr_wbr_create(int wbr_create) | |
25831 | +{ | |
076b876e | 25832 | + return au_parser_pattern(wbr_create, au_wbr_create_policy); |
1facf9fc | 25833 | +} |
25834 | + | |
25835 | +static match_table_t au_wbr_copyup_policy = { | |
25836 | + {AuWbrCopyup_TDP, "tdp"}, | |
25837 | + {AuWbrCopyup_TDP, "top-down-parent"}, | |
25838 | + {AuWbrCopyup_BUP, "bup"}, | |
25839 | + {AuWbrCopyup_BUP, "bottom-up-parent"}, | |
25840 | + {AuWbrCopyup_BU, "bu"}, | |
25841 | + {AuWbrCopyup_BU, "bottom-up"}, | |
25842 | + {-1, NULL} | |
25843 | +}; | |
25844 | + | |
4a4d8108 | 25845 | +static int noinline_for_stack au_wbr_copyup_val(char *str) |
1facf9fc | 25846 | +{ |
25847 | + substring_t args[MAX_OPT_ARGS]; | |
25848 | + | |
25849 | + return match_token(str, au_wbr_copyup_policy, args); | |
25850 | +} | |
25851 | + | |
25852 | +const char *au_optstr_wbr_copyup(int wbr_copyup) | |
25853 | +{ | |
076b876e | 25854 | + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy); |
1facf9fc | 25855 | +} |
25856 | + | |
25857 | +/* ---------------------------------------------------------------------- */ | |
25858 | + | |
25859 | +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; | |
25860 | + | |
25861 | +static void dump_opts(struct au_opts *opts) | |
25862 | +{ | |
25863 | +#ifdef CONFIG_AUFS_DEBUG | |
25864 | + /* reduce stack space */ | |
25865 | + union { | |
25866 | + struct au_opt_add *add; | |
25867 | + struct au_opt_del *del; | |
25868 | + struct au_opt_mod *mod; | |
25869 | + struct au_opt_xino *xino; | |
25870 | + struct au_opt_xino_itrunc *xino_itrunc; | |
25871 | + struct au_opt_wbr_create *create; | |
25872 | + } u; | |
25873 | + struct au_opt *opt; | |
25874 | + | |
25875 | + opt = opts->opt; | |
25876 | + while (opt->type != Opt_tail) { | |
25877 | + switch (opt->type) { | |
25878 | + case Opt_add: | |
25879 | + u.add = &opt->add; | |
25880 | + AuDbg("add {b%d, %s, 0x%x, %p}\n", | |
25881 | + u.add->bindex, u.add->pathname, u.add->perm, | |
25882 | + u.add->path.dentry); | |
25883 | + break; | |
25884 | + case Opt_del: | |
25885 | + case Opt_idel: | |
25886 | + u.del = &opt->del; | |
25887 | + AuDbg("del {%s, %p}\n", | |
25888 | + u.del->pathname, u.del->h_path.dentry); | |
25889 | + break; | |
25890 | + case Opt_mod: | |
25891 | + case Opt_imod: | |
25892 | + u.mod = &opt->mod; | |
25893 | + AuDbg("mod {%s, 0x%x, %p}\n", | |
25894 | + u.mod->path, u.mod->perm, u.mod->h_root); | |
25895 | + break; | |
25896 | + case Opt_append: | |
25897 | + u.add = &opt->add; | |
25898 | + AuDbg("append {b%d, %s, 0x%x, %p}\n", | |
25899 | + u.add->bindex, u.add->pathname, u.add->perm, | |
25900 | + u.add->path.dentry); | |
25901 | + break; | |
25902 | + case Opt_prepend: | |
25903 | + u.add = &opt->add; | |
25904 | + AuDbg("prepend {b%d, %s, 0x%x, %p}\n", | |
25905 | + u.add->bindex, u.add->pathname, u.add->perm, | |
25906 | + u.add->path.dentry); | |
25907 | + break; | |
25908 | + case Opt_dirwh: | |
25909 | + AuDbg("dirwh %d\n", opt->dirwh); | |
25910 | + break; | |
25911 | + case Opt_rdcache: | |
25912 | + AuDbg("rdcache %d\n", opt->rdcache); | |
25913 | + break; | |
25914 | + case Opt_rdblk: | |
25915 | + AuDbg("rdblk %u\n", opt->rdblk); | |
25916 | + break; | |
dece6358 AM |
25917 | + case Opt_rdblk_def: |
25918 | + AuDbg("rdblk_def\n"); | |
25919 | + break; | |
1facf9fc | 25920 | + case Opt_rdhash: |
25921 | + AuDbg("rdhash %u\n", opt->rdhash); | |
25922 | + break; | |
dece6358 AM |
25923 | + case Opt_rdhash_def: |
25924 | + AuDbg("rdhash_def\n"); | |
25925 | + break; | |
1facf9fc | 25926 | + case Opt_xino: |
25927 | + u.xino = &opt->xino; | |
523b37e3 | 25928 | + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file); |
1facf9fc | 25929 | + break; |
25930 | + case Opt_trunc_xino: | |
25931 | + AuLabel(trunc_xino); | |
25932 | + break; | |
25933 | + case Opt_notrunc_xino: | |
25934 | + AuLabel(notrunc_xino); | |
25935 | + break; | |
25936 | + case Opt_trunc_xino_path: | |
25937 | + case Opt_itrunc_xino: | |
25938 | + u.xino_itrunc = &opt->xino_itrunc; | |
25939 | + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex); | |
25940 | + break; | |
1facf9fc | 25941 | + case Opt_noxino: |
25942 | + AuLabel(noxino); | |
25943 | + break; | |
25944 | + case Opt_trunc_xib: | |
25945 | + AuLabel(trunc_xib); | |
25946 | + break; | |
25947 | + case Opt_notrunc_xib: | |
25948 | + AuLabel(notrunc_xib); | |
25949 | + break; | |
dece6358 AM |
25950 | + case Opt_shwh: |
25951 | + AuLabel(shwh); | |
25952 | + break; | |
25953 | + case Opt_noshwh: | |
25954 | + AuLabel(noshwh); | |
25955 | + break; | |
076b876e AM |
25956 | + case Opt_dirperm1: |
25957 | + AuLabel(dirperm1); | |
25958 | + break; | |
25959 | + case Opt_nodirperm1: | |
25960 | + AuLabel(nodirperm1); | |
25961 | + break; | |
1facf9fc | 25962 | + case Opt_plink: |
25963 | + AuLabel(plink); | |
25964 | + break; | |
25965 | + case Opt_noplink: | |
25966 | + AuLabel(noplink); | |
25967 | + break; | |
25968 | + case Opt_list_plink: | |
25969 | + AuLabel(list_plink); | |
25970 | + break; | |
25971 | + case Opt_udba: | |
25972 | + AuDbg("udba %d, %s\n", | |
25973 | + opt->udba, au_optstr_udba(opt->udba)); | |
25974 | + break; | |
4a4d8108 AM |
25975 | + case Opt_dio: |
25976 | + AuLabel(dio); | |
25977 | + break; | |
25978 | + case Opt_nodio: | |
25979 | + AuLabel(nodio); | |
25980 | + break; | |
1facf9fc | 25981 | + case Opt_diropq_a: |
25982 | + AuLabel(diropq_a); | |
25983 | + break; | |
25984 | + case Opt_diropq_w: | |
25985 | + AuLabel(diropq_w); | |
25986 | + break; | |
25987 | + case Opt_warn_perm: | |
25988 | + AuLabel(warn_perm); | |
25989 | + break; | |
25990 | + case Opt_nowarn_perm: | |
25991 | + AuLabel(nowarn_perm); | |
25992 | + break; | |
1facf9fc | 25993 | + case Opt_verbose: |
25994 | + AuLabel(verbose); | |
25995 | + break; | |
25996 | + case Opt_noverbose: | |
25997 | + AuLabel(noverbose); | |
25998 | + break; | |
25999 | + case Opt_sum: | |
26000 | + AuLabel(sum); | |
26001 | + break; | |
26002 | + case Opt_nosum: | |
26003 | + AuLabel(nosum); | |
26004 | + break; | |
26005 | + case Opt_wsum: | |
26006 | + AuLabel(wsum); | |
26007 | + break; | |
26008 | + case Opt_wbr_create: | |
26009 | + u.create = &opt->wbr_create; | |
26010 | + AuDbg("create %d, %s\n", u.create->wbr_create, | |
26011 | + au_optstr_wbr_create(u.create->wbr_create)); | |
26012 | + switch (u.create->wbr_create) { | |
26013 | + case AuWbrCreate_MFSV: | |
26014 | + case AuWbrCreate_PMFSV: | |
26015 | + AuDbg("%d sec\n", u.create->mfs_second); | |
26016 | + break; | |
26017 | + case AuWbrCreate_MFSRR: | |
f2c43d5f | 26018 | + case AuWbrCreate_TDMFS: |
1facf9fc | 26019 | + AuDbg("%llu watermark\n", |
26020 | + u.create->mfsrr_watermark); | |
26021 | + break; | |
26022 | + case AuWbrCreate_MFSRRV: | |
f2c43d5f | 26023 | + case AuWbrCreate_TDMFSV: |
392086de | 26024 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 26025 | + AuDbg("%llu watermark, %d sec\n", |
26026 | + u.create->mfsrr_watermark, | |
26027 | + u.create->mfs_second); | |
26028 | + break; | |
26029 | + } | |
26030 | + break; | |
26031 | + case Opt_wbr_copyup: | |
26032 | + AuDbg("copyup %d, %s\n", opt->wbr_copyup, | |
26033 | + au_optstr_wbr_copyup(opt->wbr_copyup)); | |
26034 | + break; | |
076b876e AM |
26035 | + case Opt_fhsm_sec: |
26036 | + AuDbg("fhsm_sec %u\n", opt->fhsm_second); | |
26037 | + break; | |
8b6a4947 AM |
26038 | + case Opt_dirren: |
26039 | + AuLabel(dirren); | |
26040 | + break; | |
26041 | + case Opt_nodirren: | |
26042 | + AuLabel(nodirren); | |
26043 | + break; | |
c1595e42 JR |
26044 | + case Opt_acl: |
26045 | + AuLabel(acl); | |
26046 | + break; | |
26047 | + case Opt_noacl: | |
26048 | + AuLabel(noacl); | |
26049 | + break; | |
1facf9fc | 26050 | + default: |
26051 | + BUG(); | |
26052 | + } | |
26053 | + opt++; | |
26054 | + } | |
26055 | +#endif | |
26056 | +} | |
26057 | + | |
26058 | +void au_opts_free(struct au_opts *opts) | |
26059 | +{ | |
26060 | + struct au_opt *opt; | |
26061 | + | |
26062 | + opt = opts->opt; | |
26063 | + while (opt->type != Opt_tail) { | |
26064 | + switch (opt->type) { | |
26065 | + case Opt_add: | |
26066 | + case Opt_append: | |
26067 | + case Opt_prepend: | |
26068 | + path_put(&opt->add.path); | |
26069 | + break; | |
26070 | + case Opt_del: | |
26071 | + case Opt_idel: | |
26072 | + path_put(&opt->del.h_path); | |
26073 | + break; | |
26074 | + case Opt_mod: | |
26075 | + case Opt_imod: | |
26076 | + dput(opt->mod.h_root); | |
26077 | + break; | |
26078 | + case Opt_xino: | |
26079 | + fput(opt->xino.file); | |
26080 | + break; | |
26081 | + } | |
26082 | + opt++; | |
26083 | + } | |
26084 | +} | |
26085 | + | |
26086 | +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags, | |
26087 | + aufs_bindex_t bindex) | |
26088 | +{ | |
26089 | + int err; | |
26090 | + struct au_opt_add *add = &opt->add; | |
26091 | + char *p; | |
26092 | + | |
26093 | + add->bindex = bindex; | |
1e00d052 | 26094 | + add->perm = AuBrPerm_RO; |
1facf9fc | 26095 | + add->pathname = opt_str; |
26096 | + p = strchr(opt_str, '='); | |
26097 | + if (p) { | |
26098 | + *p++ = 0; | |
26099 | + if (*p) | |
26100 | + add->perm = br_perm_val(p); | |
26101 | + } | |
26102 | + | |
26103 | + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path); | |
26104 | + if (!err) { | |
26105 | + if (!p) { | |
26106 | + add->perm = AuBrPerm_RO; | |
26107 | + if (au_test_fs_rr(add->path.dentry->d_sb)) | |
26108 | + add->perm = AuBrPerm_RR; | |
2121bcd9 | 26109 | + else if (!bindex && !(sb_flags & SB_RDONLY)) |
1facf9fc | 26110 | + add->perm = AuBrPerm_RW; |
26111 | + } | |
26112 | + opt->type = Opt_add; | |
26113 | + goto out; | |
26114 | + } | |
4a4d8108 | 26115 | + pr_err("lookup failed %s (%d)\n", add->pathname, err); |
1facf9fc | 26116 | + err = -EINVAL; |
26117 | + | |
4f0767ce | 26118 | +out: |
1facf9fc | 26119 | + return err; |
26120 | +} | |
26121 | + | |
26122 | +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[]) | |
26123 | +{ | |
26124 | + int err; | |
26125 | + | |
26126 | + del->pathname = args[0].from; | |
26127 | + AuDbg("del path %s\n", del->pathname); | |
26128 | + | |
26129 | + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path); | |
26130 | + if (unlikely(err)) | |
4a4d8108 | 26131 | + pr_err("lookup failed %s (%d)\n", del->pathname, err); |
1facf9fc | 26132 | + |
26133 | + return err; | |
26134 | +} | |
26135 | + | |
26136 | +#if 0 /* reserved for future use */ | |
26137 | +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex, | |
26138 | + struct au_opt_del *del, substring_t args[]) | |
26139 | +{ | |
26140 | + int err; | |
26141 | + struct dentry *root; | |
26142 | + | |
26143 | + err = -EINVAL; | |
26144 | + root = sb->s_root; | |
26145 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 26146 | + if (bindex < 0 || au_sbbot(sb) < bindex) { |
4a4d8108 | 26147 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 26148 | + goto out; |
26149 | + } | |
26150 | + | |
26151 | + err = 0; | |
26152 | + del->h_path.dentry = dget(au_h_dptr(root, bindex)); | |
26153 | + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex)); | |
26154 | + | |
4f0767ce | 26155 | +out: |
1facf9fc | 26156 | + aufs_read_unlock(root, !AuLock_IR); |
26157 | + return err; | |
26158 | +} | |
26159 | +#endif | |
26160 | + | |
4a4d8108 AM |
26161 | +static int noinline_for_stack |
26162 | +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[]) | |
1facf9fc | 26163 | +{ |
26164 | + int err; | |
26165 | + struct path path; | |
26166 | + char *p; | |
26167 | + | |
26168 | + err = -EINVAL; | |
26169 | + mod->path = args[0].from; | |
26170 | + p = strchr(mod->path, '='); | |
26171 | + if (unlikely(!p)) { | |
4a4d8108 | 26172 | + pr_err("no permssion %s\n", args[0].from); |
1facf9fc | 26173 | + goto out; |
26174 | + } | |
26175 | + | |
26176 | + *p++ = 0; | |
26177 | + err = vfsub_kern_path(mod->path, lkup_dirflags, &path); | |
26178 | + if (unlikely(err)) { | |
4a4d8108 | 26179 | + pr_err("lookup failed %s (%d)\n", mod->path, err); |
1facf9fc | 26180 | + goto out; |
26181 | + } | |
26182 | + | |
26183 | + mod->perm = br_perm_val(p); | |
26184 | + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p); | |
26185 | + mod->h_root = dget(path.dentry); | |
26186 | + path_put(&path); | |
26187 | + | |
4f0767ce | 26188 | +out: |
1facf9fc | 26189 | + return err; |
26190 | +} | |
26191 | + | |
26192 | +#if 0 /* reserved for future use */ | |
26193 | +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex, | |
26194 | + struct au_opt_mod *mod, substring_t args[]) | |
26195 | +{ | |
26196 | + int err; | |
26197 | + struct dentry *root; | |
26198 | + | |
26199 | + err = -EINVAL; | |
26200 | + root = sb->s_root; | |
26201 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 26202 | + if (bindex < 0 || au_sbbot(sb) < bindex) { |
4a4d8108 | 26203 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 26204 | + goto out; |
26205 | + } | |
26206 | + | |
26207 | + err = 0; | |
26208 | + mod->perm = br_perm_val(args[1].from); | |
26209 | + AuDbg("mod path %s, perm 0x%x, %s\n", | |
26210 | + mod->path, mod->perm, args[1].from); | |
26211 | + mod->h_root = dget(au_h_dptr(root, bindex)); | |
26212 | + | |
4f0767ce | 26213 | +out: |
1facf9fc | 26214 | + aufs_read_unlock(root, !AuLock_IR); |
26215 | + return err; | |
26216 | +} | |
26217 | +#endif | |
26218 | + | |
26219 | +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino, | |
26220 | + substring_t args[]) | |
26221 | +{ | |
26222 | + int err; | |
26223 | + struct file *file; | |
26224 | + | |
26225 | + file = au_xino_create(sb, args[0].from, /*silent*/0); | |
26226 | + err = PTR_ERR(file); | |
26227 | + if (IS_ERR(file)) | |
26228 | + goto out; | |
26229 | + | |
26230 | + err = -EINVAL; | |
2000de60 | 26231 | + if (unlikely(file->f_path.dentry->d_sb == sb)) { |
1facf9fc | 26232 | + fput(file); |
4a4d8108 | 26233 | + pr_err("%s must be outside\n", args[0].from); |
1facf9fc | 26234 | + goto out; |
26235 | + } | |
26236 | + | |
26237 | + err = 0; | |
26238 | + xino->file = file; | |
26239 | + xino->path = args[0].from; | |
26240 | + | |
4f0767ce | 26241 | +out: |
1facf9fc | 26242 | + return err; |
26243 | +} | |
26244 | + | |
4a4d8108 AM |
26245 | +static int noinline_for_stack |
26246 | +au_opts_parse_xino_itrunc_path(struct super_block *sb, | |
26247 | + struct au_opt_xino_itrunc *xino_itrunc, | |
26248 | + substring_t args[]) | |
1facf9fc | 26249 | +{ |
26250 | + int err; | |
5afbbe0d | 26251 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 26252 | + struct path path; |
26253 | + struct dentry *root; | |
26254 | + | |
26255 | + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path); | |
26256 | + if (unlikely(err)) { | |
4a4d8108 | 26257 | + pr_err("lookup failed %s (%d)\n", args[0].from, err); |
1facf9fc | 26258 | + goto out; |
26259 | + } | |
26260 | + | |
26261 | + xino_itrunc->bindex = -1; | |
26262 | + root = sb->s_root; | |
26263 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d AM |
26264 | + bbot = au_sbbot(sb); |
26265 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
1facf9fc | 26266 | + if (au_h_dptr(root, bindex) == path.dentry) { |
26267 | + xino_itrunc->bindex = bindex; | |
26268 | + break; | |
26269 | + } | |
26270 | + } | |
26271 | + aufs_read_unlock(root, !AuLock_IR); | |
26272 | + path_put(&path); | |
26273 | + | |
26274 | + if (unlikely(xino_itrunc->bindex < 0)) { | |
4a4d8108 | 26275 | + pr_err("no such branch %s\n", args[0].from); |
1facf9fc | 26276 | + err = -EINVAL; |
26277 | + } | |
26278 | + | |
4f0767ce | 26279 | +out: |
1facf9fc | 26280 | + return err; |
26281 | +} | |
26282 | + | |
26283 | +/* called without aufs lock */ | |
26284 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) | |
26285 | +{ | |
26286 | + int err, n, token; | |
26287 | + aufs_bindex_t bindex; | |
26288 | + unsigned char skipped; | |
26289 | + struct dentry *root; | |
26290 | + struct au_opt *opt, *opt_tail; | |
26291 | + char *opt_str; | |
26292 | + /* reduce the stack space */ | |
26293 | + union { | |
26294 | + struct au_opt_xino_itrunc *xino_itrunc; | |
26295 | + struct au_opt_wbr_create *create; | |
26296 | + } u; | |
26297 | + struct { | |
26298 | + substring_t args[MAX_OPT_ARGS]; | |
26299 | + } *a; | |
26300 | + | |
26301 | + err = -ENOMEM; | |
26302 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
26303 | + if (unlikely(!a)) | |
26304 | + goto out; | |
26305 | + | |
26306 | + root = sb->s_root; | |
26307 | + err = 0; | |
26308 | + bindex = 0; | |
26309 | + opt = opts->opt; | |
26310 | + opt_tail = opt + opts->max_opt - 1; | |
26311 | + opt->type = Opt_tail; | |
26312 | + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { | |
26313 | + err = -EINVAL; | |
26314 | + skipped = 0; | |
26315 | + token = match_token(opt_str, options, a->args); | |
26316 | + switch (token) { | |
26317 | + case Opt_br: | |
26318 | + err = 0; | |
26319 | + while (!err && (opt_str = strsep(&a->args[0].from, ":")) | |
26320 | + && *opt_str) { | |
26321 | + err = opt_add(opt, opt_str, opts->sb_flags, | |
26322 | + bindex++); | |
26323 | + if (unlikely(!err && ++opt > opt_tail)) { | |
26324 | + err = -E2BIG; | |
26325 | + break; | |
26326 | + } | |
26327 | + opt->type = Opt_tail; | |
26328 | + skipped = 1; | |
26329 | + } | |
26330 | + break; | |
26331 | + case Opt_add: | |
26332 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 26333 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26334 | + break; |
26335 | + } | |
26336 | + bindex = n; | |
26337 | + err = opt_add(opt, a->args[1].from, opts->sb_flags, | |
26338 | + bindex); | |
26339 | + if (!err) | |
26340 | + opt->type = token; | |
26341 | + break; | |
26342 | + case Opt_append: | |
26343 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
26344 | + /*dummy bindex*/1); | |
26345 | + if (!err) | |
26346 | + opt->type = token; | |
26347 | + break; | |
26348 | + case Opt_prepend: | |
26349 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
26350 | + /*bindex*/0); | |
26351 | + if (!err) | |
26352 | + opt->type = token; | |
26353 | + break; | |
26354 | + case Opt_del: | |
26355 | + err = au_opts_parse_del(&opt->del, a->args); | |
26356 | + if (!err) | |
26357 | + opt->type = token; | |
26358 | + break; | |
26359 | +#if 0 /* reserved for future use */ | |
26360 | + case Opt_idel: | |
26361 | + del->pathname = "(indexed)"; | |
26362 | + if (unlikely(match_int(&args[0], &n))) { | |
4a4d8108 | 26363 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26364 | + break; |
26365 | + } | |
26366 | + err = au_opts_parse_idel(sb, n, &opt->del, a->args); | |
26367 | + if (!err) | |
26368 | + opt->type = token; | |
26369 | + break; | |
26370 | +#endif | |
26371 | + case Opt_mod: | |
26372 | + err = au_opts_parse_mod(&opt->mod, a->args); | |
26373 | + if (!err) | |
26374 | + opt->type = token; | |
26375 | + break; | |
26376 | +#ifdef IMOD /* reserved for future use */ | |
26377 | + case Opt_imod: | |
26378 | + u.mod->path = "(indexed)"; | |
26379 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 26380 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26381 | + break; |
26382 | + } | |
26383 | + err = au_opts_parse_imod(sb, n, &opt->mod, a->args); | |
26384 | + if (!err) | |
26385 | + opt->type = token; | |
26386 | + break; | |
26387 | +#endif | |
26388 | + case Opt_xino: | |
26389 | + err = au_opts_parse_xino(sb, &opt->xino, a->args); | |
26390 | + if (!err) | |
26391 | + opt->type = token; | |
26392 | + break; | |
26393 | + | |
26394 | + case Opt_trunc_xino_path: | |
26395 | + err = au_opts_parse_xino_itrunc_path | |
26396 | + (sb, &opt->xino_itrunc, a->args); | |
26397 | + if (!err) | |
26398 | + opt->type = token; | |
26399 | + break; | |
26400 | + | |
26401 | + case Opt_itrunc_xino: | |
26402 | + u.xino_itrunc = &opt->xino_itrunc; | |
26403 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 26404 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26405 | + break; |
26406 | + } | |
26407 | + u.xino_itrunc->bindex = n; | |
26408 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 26409 | + if (n < 0 || au_sbbot(sb) < n) { |
4a4d8108 | 26410 | + pr_err("out of bounds, %d\n", n); |
1facf9fc | 26411 | + aufs_read_unlock(root, !AuLock_IR); |
26412 | + break; | |
26413 | + } | |
26414 | + aufs_read_unlock(root, !AuLock_IR); | |
26415 | + err = 0; | |
26416 | + opt->type = token; | |
26417 | + break; | |
26418 | + | |
26419 | + case Opt_dirwh: | |
26420 | + if (unlikely(match_int(&a->args[0], &opt->dirwh))) | |
26421 | + break; | |
26422 | + err = 0; | |
26423 | + opt->type = token; | |
26424 | + break; | |
26425 | + | |
26426 | + case Opt_rdcache: | |
027c5e7a AM |
26427 | + if (unlikely(match_int(&a->args[0], &n))) { |
26428 | + pr_err("bad integer in %s\n", opt_str); | |
1facf9fc | 26429 | + break; |
027c5e7a AM |
26430 | + } |
26431 | + if (unlikely(n > AUFS_RDCACHE_MAX)) { | |
26432 | + pr_err("rdcache must be smaller than %d\n", | |
26433 | + AUFS_RDCACHE_MAX); | |
26434 | + break; | |
26435 | + } | |
26436 | + opt->rdcache = n; | |
1facf9fc | 26437 | + err = 0; |
26438 | + opt->type = token; | |
26439 | + break; | |
26440 | + case Opt_rdblk: | |
26441 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 26442 | + || n < 0 |
1facf9fc | 26443 | + || n > KMALLOC_MAX_SIZE)) { |
4a4d8108 | 26444 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26445 | + break; |
26446 | + } | |
1308ab2a | 26447 | + if (unlikely(n && n < NAME_MAX)) { |
4a4d8108 AM |
26448 | + pr_err("rdblk must be larger than %d\n", |
26449 | + NAME_MAX); | |
1facf9fc | 26450 | + break; |
26451 | + } | |
26452 | + opt->rdblk = n; | |
26453 | + err = 0; | |
26454 | + opt->type = token; | |
26455 | + break; | |
26456 | + case Opt_rdhash: | |
26457 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 26458 | + || n < 0 |
1facf9fc | 26459 | + || n * sizeof(struct hlist_head) |
26460 | + > KMALLOC_MAX_SIZE)) { | |
4a4d8108 | 26461 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26462 | + break; |
26463 | + } | |
26464 | + opt->rdhash = n; | |
26465 | + err = 0; | |
26466 | + opt->type = token; | |
26467 | + break; | |
26468 | + | |
26469 | + case Opt_trunc_xino: | |
26470 | + case Opt_notrunc_xino: | |
26471 | + case Opt_noxino: | |
26472 | + case Opt_trunc_xib: | |
26473 | + case Opt_notrunc_xib: | |
dece6358 AM |
26474 | + case Opt_shwh: |
26475 | + case Opt_noshwh: | |
076b876e AM |
26476 | + case Opt_dirperm1: |
26477 | + case Opt_nodirperm1: | |
1facf9fc | 26478 | + case Opt_plink: |
26479 | + case Opt_noplink: | |
26480 | + case Opt_list_plink: | |
4a4d8108 AM |
26481 | + case Opt_dio: |
26482 | + case Opt_nodio: | |
1facf9fc | 26483 | + case Opt_diropq_a: |
26484 | + case Opt_diropq_w: | |
26485 | + case Opt_warn_perm: | |
26486 | + case Opt_nowarn_perm: | |
1facf9fc | 26487 | + case Opt_verbose: |
26488 | + case Opt_noverbose: | |
26489 | + case Opt_sum: | |
26490 | + case Opt_nosum: | |
26491 | + case Opt_wsum: | |
dece6358 AM |
26492 | + case Opt_rdblk_def: |
26493 | + case Opt_rdhash_def: | |
8b6a4947 AM |
26494 | + case Opt_dirren: |
26495 | + case Opt_nodirren: | |
c1595e42 JR |
26496 | + case Opt_acl: |
26497 | + case Opt_noacl: | |
1facf9fc | 26498 | + err = 0; |
26499 | + opt->type = token; | |
26500 | + break; | |
26501 | + | |
26502 | + case Opt_udba: | |
26503 | + opt->udba = udba_val(a->args[0].from); | |
26504 | + if (opt->udba >= 0) { | |
26505 | + err = 0; | |
26506 | + opt->type = token; | |
26507 | + } else | |
4a4d8108 | 26508 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 26509 | + break; |
26510 | + | |
26511 | + case Opt_wbr_create: | |
26512 | + u.create = &opt->wbr_create; | |
26513 | + u.create->wbr_create | |
26514 | + = au_wbr_create_val(a->args[0].from, u.create); | |
26515 | + if (u.create->wbr_create >= 0) { | |
26516 | + err = 0; | |
26517 | + opt->type = token; | |
26518 | + } else | |
4a4d8108 | 26519 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 26520 | + break; |
26521 | + case Opt_wbr_copyup: | |
26522 | + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); | |
26523 | + if (opt->wbr_copyup >= 0) { | |
26524 | + err = 0; | |
26525 | + opt->type = token; | |
26526 | + } else | |
4a4d8108 | 26527 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 26528 | + break; |
26529 | + | |
076b876e AM |
26530 | + case Opt_fhsm_sec: |
26531 | + if (unlikely(match_int(&a->args[0], &n) | |
26532 | + || n < 0)) { | |
26533 | + pr_err("bad integer in %s\n", opt_str); | |
26534 | + break; | |
26535 | + } | |
26536 | + if (sysaufs_brs) { | |
26537 | + opt->fhsm_second = n; | |
26538 | + opt->type = token; | |
26539 | + } else | |
26540 | + pr_warn("ignored %s\n", opt_str); | |
26541 | + err = 0; | |
26542 | + break; | |
26543 | + | |
1facf9fc | 26544 | + case Opt_ignore: |
0c3ec466 | 26545 | + pr_warn("ignored %s\n", opt_str); |
1facf9fc | 26546 | + /*FALLTHROUGH*/ |
26547 | + case Opt_ignore_silent: | |
26548 | + skipped = 1; | |
26549 | + err = 0; | |
26550 | + break; | |
26551 | + case Opt_err: | |
4a4d8108 | 26552 | + pr_err("unknown option %s\n", opt_str); |
1facf9fc | 26553 | + break; |
26554 | + } | |
26555 | + | |
26556 | + if (!err && !skipped) { | |
26557 | + if (unlikely(++opt > opt_tail)) { | |
26558 | + err = -E2BIG; | |
26559 | + opt--; | |
26560 | + opt->type = Opt_tail; | |
26561 | + break; | |
26562 | + } | |
26563 | + opt->type = Opt_tail; | |
26564 | + } | |
26565 | + } | |
26566 | + | |
1c60b727 | 26567 | + kfree(a); |
1facf9fc | 26568 | + dump_opts(opts); |
26569 | + if (unlikely(err)) | |
26570 | + au_opts_free(opts); | |
26571 | + | |
4f0767ce | 26572 | +out: |
1facf9fc | 26573 | + return err; |
26574 | +} | |
26575 | + | |
26576 | +static int au_opt_wbr_create(struct super_block *sb, | |
26577 | + struct au_opt_wbr_create *create) | |
26578 | +{ | |
26579 | + int err; | |
26580 | + struct au_sbinfo *sbinfo; | |
26581 | + | |
dece6358 AM |
26582 | + SiMustWriteLock(sb); |
26583 | + | |
1facf9fc | 26584 | + err = 1; /* handled */ |
26585 | + sbinfo = au_sbi(sb); | |
26586 | + if (sbinfo->si_wbr_create_ops->fin) { | |
26587 | + err = sbinfo->si_wbr_create_ops->fin(sb); | |
26588 | + if (!err) | |
26589 | + err = 1; | |
26590 | + } | |
26591 | + | |
26592 | + sbinfo->si_wbr_create = create->wbr_create; | |
26593 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create; | |
26594 | + switch (create->wbr_create) { | |
26595 | + case AuWbrCreate_MFSRRV: | |
26596 | + case AuWbrCreate_MFSRR: | |
f2c43d5f AM |
26597 | + case AuWbrCreate_TDMFS: |
26598 | + case AuWbrCreate_TDMFSV: | |
392086de AM |
26599 | + case AuWbrCreate_PMFSRR: |
26600 | + case AuWbrCreate_PMFSRRV: | |
1facf9fc | 26601 | + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark; |
26602 | + /*FALLTHROUGH*/ | |
26603 | + case AuWbrCreate_MFS: | |
26604 | + case AuWbrCreate_MFSV: | |
26605 | + case AuWbrCreate_PMFS: | |
26606 | + case AuWbrCreate_PMFSV: | |
e49829fe JR |
26607 | + sbinfo->si_wbr_mfs.mfs_expire |
26608 | + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC); | |
1facf9fc | 26609 | + break; |
26610 | + } | |
26611 | + | |
26612 | + if (sbinfo->si_wbr_create_ops->init) | |
26613 | + sbinfo->si_wbr_create_ops->init(sb); /* ignore */ | |
26614 | + | |
26615 | + return err; | |
26616 | +} | |
26617 | + | |
26618 | +/* | |
26619 | + * returns, | |
26620 | + * plus: processed without an error | |
26621 | + * zero: unprocessed | |
26622 | + */ | |
26623 | +static int au_opt_simple(struct super_block *sb, struct au_opt *opt, | |
26624 | + struct au_opts *opts) | |
26625 | +{ | |
26626 | + int err; | |
26627 | + struct au_sbinfo *sbinfo; | |
26628 | + | |
dece6358 AM |
26629 | + SiMustWriteLock(sb); |
26630 | + | |
1facf9fc | 26631 | + err = 1; /* handled */ |
26632 | + sbinfo = au_sbi(sb); | |
26633 | + switch (opt->type) { | |
26634 | + case Opt_udba: | |
26635 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; | |
26636 | + sbinfo->si_mntflags |= opt->udba; | |
26637 | + opts->given_udba |= opt->udba; | |
26638 | + break; | |
26639 | + | |
26640 | + case Opt_plink: | |
26641 | + au_opt_set(sbinfo->si_mntflags, PLINK); | |
26642 | + break; | |
26643 | + case Opt_noplink: | |
26644 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
e49829fe | 26645 | + au_plink_put(sb, /*verbose*/1); |
1facf9fc | 26646 | + au_opt_clr(sbinfo->si_mntflags, PLINK); |
26647 | + break; | |
26648 | + case Opt_list_plink: | |
26649 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
26650 | + au_plink_list(sb); | |
26651 | + break; | |
26652 | + | |
4a4d8108 AM |
26653 | + case Opt_dio: |
26654 | + au_opt_set(sbinfo->si_mntflags, DIO); | |
26655 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
26656 | + break; | |
26657 | + case Opt_nodio: | |
26658 | + au_opt_clr(sbinfo->si_mntflags, DIO); | |
26659 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
26660 | + break; | |
26661 | + | |
076b876e AM |
26662 | + case Opt_fhsm_sec: |
26663 | + au_fhsm_set(sbinfo, opt->fhsm_second); | |
26664 | + break; | |
26665 | + | |
1facf9fc | 26666 | + case Opt_diropq_a: |
26667 | + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
26668 | + break; | |
26669 | + case Opt_diropq_w: | |
26670 | + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
26671 | + break; | |
26672 | + | |
26673 | + case Opt_warn_perm: | |
26674 | + au_opt_set(sbinfo->si_mntflags, WARN_PERM); | |
26675 | + break; | |
26676 | + case Opt_nowarn_perm: | |
26677 | + au_opt_clr(sbinfo->si_mntflags, WARN_PERM); | |
26678 | + break; | |
26679 | + | |
1facf9fc | 26680 | + case Opt_verbose: |
26681 | + au_opt_set(sbinfo->si_mntflags, VERBOSE); | |
26682 | + break; | |
26683 | + case Opt_noverbose: | |
26684 | + au_opt_clr(sbinfo->si_mntflags, VERBOSE); | |
26685 | + break; | |
26686 | + | |
26687 | + case Opt_sum: | |
26688 | + au_opt_set(sbinfo->si_mntflags, SUM); | |
26689 | + break; | |
26690 | + case Opt_wsum: | |
26691 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
26692 | + au_opt_set(sbinfo->si_mntflags, SUM_W); | |
26693 | + case Opt_nosum: | |
26694 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
26695 | + au_opt_clr(sbinfo->si_mntflags, SUM_W); | |
26696 | + break; | |
26697 | + | |
26698 | + case Opt_wbr_create: | |
26699 | + err = au_opt_wbr_create(sb, &opt->wbr_create); | |
26700 | + break; | |
26701 | + case Opt_wbr_copyup: | |
26702 | + sbinfo->si_wbr_copyup = opt->wbr_copyup; | |
26703 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup; | |
26704 | + break; | |
26705 | + | |
26706 | + case Opt_dirwh: | |
26707 | + sbinfo->si_dirwh = opt->dirwh; | |
26708 | + break; | |
26709 | + | |
26710 | + case Opt_rdcache: | |
e49829fe JR |
26711 | + sbinfo->si_rdcache |
26712 | + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC); | |
1facf9fc | 26713 | + break; |
26714 | + case Opt_rdblk: | |
26715 | + sbinfo->si_rdblk = opt->rdblk; | |
26716 | + break; | |
dece6358 AM |
26717 | + case Opt_rdblk_def: |
26718 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; | |
26719 | + break; | |
1facf9fc | 26720 | + case Opt_rdhash: |
26721 | + sbinfo->si_rdhash = opt->rdhash; | |
26722 | + break; | |
dece6358 AM |
26723 | + case Opt_rdhash_def: |
26724 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
26725 | + break; | |
26726 | + | |
26727 | + case Opt_shwh: | |
26728 | + au_opt_set(sbinfo->si_mntflags, SHWH); | |
26729 | + break; | |
26730 | + case Opt_noshwh: | |
26731 | + au_opt_clr(sbinfo->si_mntflags, SHWH); | |
26732 | + break; | |
1facf9fc | 26733 | + |
076b876e AM |
26734 | + case Opt_dirperm1: |
26735 | + au_opt_set(sbinfo->si_mntflags, DIRPERM1); | |
26736 | + break; | |
26737 | + case Opt_nodirperm1: | |
26738 | + au_opt_clr(sbinfo->si_mntflags, DIRPERM1); | |
26739 | + break; | |
26740 | + | |
1facf9fc | 26741 | + case Opt_trunc_xino: |
26742 | + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO); | |
26743 | + break; | |
26744 | + case Opt_notrunc_xino: | |
26745 | + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO); | |
26746 | + break; | |
26747 | + | |
26748 | + case Opt_trunc_xino_path: | |
26749 | + case Opt_itrunc_xino: | |
26750 | + err = au_xino_trunc(sb, opt->xino_itrunc.bindex); | |
26751 | + if (!err) | |
26752 | + err = 1; | |
26753 | + break; | |
26754 | + | |
26755 | + case Opt_trunc_xib: | |
26756 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
26757 | + break; | |
26758 | + case Opt_notrunc_xib: | |
26759 | + au_fclr_opts(opts->flags, TRUNC_XIB); | |
26760 | + break; | |
26761 | + | |
8b6a4947 AM |
26762 | + case Opt_dirren: |
26763 | + err = 1; | |
26764 | + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) { | |
26765 | + err = au_dr_opt_set(sb); | |
26766 | + if (!err) | |
26767 | + err = 1; | |
26768 | + } | |
26769 | + if (err == 1) | |
26770 | + au_opt_set(sbinfo->si_mntflags, DIRREN); | |
26771 | + break; | |
26772 | + case Opt_nodirren: | |
26773 | + err = 1; | |
26774 | + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) { | |
26775 | + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags, | |
26776 | + DR_FLUSHED)); | |
26777 | + if (!err) | |
26778 | + err = 1; | |
26779 | + } | |
26780 | + if (err == 1) | |
26781 | + au_opt_clr(sbinfo->si_mntflags, DIRREN); | |
26782 | + break; | |
26783 | + | |
c1595e42 | 26784 | + case Opt_acl: |
2121bcd9 | 26785 | + sb->s_flags |= SB_POSIXACL; |
c1595e42 JR |
26786 | + break; |
26787 | + case Opt_noacl: | |
2121bcd9 | 26788 | + sb->s_flags &= ~SB_POSIXACL; |
c1595e42 JR |
26789 | + break; |
26790 | + | |
1facf9fc | 26791 | + default: |
26792 | + err = 0; | |
26793 | + break; | |
26794 | + } | |
26795 | + | |
26796 | + return err; | |
26797 | +} | |
26798 | + | |
26799 | +/* | |
26800 | + * returns tri-state. | |
26801 | + * plus: processed without an error | |
26802 | + * zero: unprocessed | |
26803 | + * minus: error | |
26804 | + */ | |
26805 | +static int au_opt_br(struct super_block *sb, struct au_opt *opt, | |
26806 | + struct au_opts *opts) | |
26807 | +{ | |
26808 | + int err, do_refresh; | |
26809 | + | |
26810 | + err = 0; | |
26811 | + switch (opt->type) { | |
26812 | + case Opt_append: | |
5afbbe0d | 26813 | + opt->add.bindex = au_sbbot(sb) + 1; |
1facf9fc | 26814 | + if (opt->add.bindex < 0) |
26815 | + opt->add.bindex = 0; | |
26816 | + goto add; | |
26817 | + case Opt_prepend: | |
26818 | + opt->add.bindex = 0; | |
f6b6e03d | 26819 | + add: /* indented label */ |
1facf9fc | 26820 | + case Opt_add: |
26821 | + err = au_br_add(sb, &opt->add, | |
26822 | + au_ftest_opts(opts->flags, REMOUNT)); | |
26823 | + if (!err) { | |
26824 | + err = 1; | |
027c5e7a | 26825 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 26826 | + } |
26827 | + break; | |
26828 | + | |
26829 | + case Opt_del: | |
26830 | + case Opt_idel: | |
26831 | + err = au_br_del(sb, &opt->del, | |
26832 | + au_ftest_opts(opts->flags, REMOUNT)); | |
26833 | + if (!err) { | |
26834 | + err = 1; | |
26835 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
027c5e7a | 26836 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 26837 | + } |
26838 | + break; | |
26839 | + | |
26840 | + case Opt_mod: | |
26841 | + case Opt_imod: | |
26842 | + err = au_br_mod(sb, &opt->mod, | |
26843 | + au_ftest_opts(opts->flags, REMOUNT), | |
26844 | + &do_refresh); | |
26845 | + if (!err) { | |
26846 | + err = 1; | |
027c5e7a AM |
26847 | + if (do_refresh) |
26848 | + au_fset_opts(opts->flags, REFRESH); | |
1facf9fc | 26849 | + } |
26850 | + break; | |
26851 | + } | |
1facf9fc | 26852 | + return err; |
26853 | +} | |
26854 | + | |
26855 | +static int au_opt_xino(struct super_block *sb, struct au_opt *opt, | |
26856 | + struct au_opt_xino **opt_xino, | |
26857 | + struct au_opts *opts) | |
26858 | +{ | |
26859 | + int err; | |
5afbbe0d | 26860 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 26861 | + struct dentry *root, *parent, *h_root; |
26862 | + | |
26863 | + err = 0; | |
26864 | + switch (opt->type) { | |
26865 | + case Opt_xino: | |
26866 | + err = au_xino_set(sb, &opt->xino, | |
26867 | + !!au_ftest_opts(opts->flags, REMOUNT)); | |
26868 | + if (unlikely(err)) | |
26869 | + break; | |
26870 | + | |
26871 | + *opt_xino = &opt->xino; | |
26872 | + au_xino_brid_set(sb, -1); | |
26873 | + | |
26874 | + /* safe d_parent access */ | |
2000de60 | 26875 | + parent = opt->xino.file->f_path.dentry->d_parent; |
1facf9fc | 26876 | + root = sb->s_root; |
5afbbe0d AM |
26877 | + bbot = au_sbbot(sb); |
26878 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
1facf9fc | 26879 | + h_root = au_h_dptr(root, bindex); |
26880 | + if (h_root == parent) { | |
26881 | + au_xino_brid_set(sb, au_sbr_id(sb, bindex)); | |
26882 | + break; | |
26883 | + } | |
26884 | + } | |
26885 | + break; | |
26886 | + | |
26887 | + case Opt_noxino: | |
26888 | + au_xino_clr(sb); | |
26889 | + au_xino_brid_set(sb, -1); | |
26890 | + *opt_xino = (void *)-1; | |
26891 | + break; | |
26892 | + } | |
26893 | + | |
26894 | + return err; | |
26895 | +} | |
26896 | + | |
26897 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
26898 | + unsigned int pending) | |
26899 | +{ | |
076b876e | 26900 | + int err, fhsm; |
5afbbe0d | 26901 | + aufs_bindex_t bindex, bbot; |
79b8bda9 | 26902 | + unsigned char do_plink, skip, do_free, can_no_dreval; |
1facf9fc | 26903 | + struct au_branch *br; |
26904 | + struct au_wbr *wbr; | |
79b8bda9 | 26905 | + struct dentry *root, *dentry; |
1facf9fc | 26906 | + struct inode *dir, *h_dir; |
26907 | + struct au_sbinfo *sbinfo; | |
26908 | + struct au_hinode *hdir; | |
26909 | + | |
dece6358 AM |
26910 | + SiMustAnyLock(sb); |
26911 | + | |
1facf9fc | 26912 | + sbinfo = au_sbi(sb); |
26913 | + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA)); | |
26914 | + | |
2121bcd9 | 26915 | + if (!(sb_flags & SB_RDONLY)) { |
dece6358 | 26916 | + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0)))) |
0c3ec466 | 26917 | + pr_warn("first branch should be rw\n"); |
dece6358 | 26918 | + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH))) |
febd17d6 | 26919 | + pr_warn_once("shwh should be used with ro\n"); |
dece6358 | 26920 | + } |
1facf9fc | 26921 | + |
4a4d8108 | 26922 | + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY) |
1facf9fc | 26923 | + && !au_opt_test(sbinfo->si_mntflags, XINO)) |
febd17d6 | 26924 | + pr_warn_once("udba=*notify requires xino\n"); |
1facf9fc | 26925 | + |
076b876e | 26926 | + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1)) |
febd17d6 JR |
26927 | + pr_warn_once("dirperm1 breaks the protection" |
26928 | + " by the permission bits on the lower branch\n"); | |
076b876e | 26929 | + |
1facf9fc | 26930 | + err = 0; |
076b876e | 26931 | + fhsm = 0; |
1facf9fc | 26932 | + root = sb->s_root; |
5527c038 | 26933 | + dir = d_inode(root); |
1facf9fc | 26934 | + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK); |
79b8bda9 AM |
26935 | + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending), |
26936 | + UDBA_NONE); | |
5afbbe0d AM |
26937 | + bbot = au_sbbot(sb); |
26938 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
1facf9fc | 26939 | + skip = 0; |
26940 | + h_dir = au_h_iptr(dir, bindex); | |
26941 | + br = au_sbr(sb, bindex); | |
1facf9fc | 26942 | + |
c1595e42 JR |
26943 | + if ((br->br_perm & AuBrAttr_ICEX) |
26944 | + && !h_dir->i_op->listxattr) | |
26945 | + br->br_perm &= ~AuBrAttr_ICEX; | |
26946 | +#if 0 | |
26947 | + if ((br->br_perm & AuBrAttr_ICEX_SEC) | |
2121bcd9 | 26948 | + && (au_br_sb(br)->s_flags & SB_NOSEC)) |
c1595e42 JR |
26949 | + br->br_perm &= ~AuBrAttr_ICEX_SEC; |
26950 | +#endif | |
26951 | + | |
26952 | + do_free = 0; | |
1facf9fc | 26953 | + wbr = br->br_wbr; |
26954 | + if (wbr) | |
26955 | + wbr_wh_read_lock(wbr); | |
26956 | + | |
1e00d052 | 26957 | + if (!au_br_writable(br->br_perm)) { |
1facf9fc | 26958 | + do_free = !!wbr; |
26959 | + skip = (!wbr | |
26960 | + || (!wbr->wbr_whbase | |
26961 | + && !wbr->wbr_plink | |
26962 | + && !wbr->wbr_orph)); | |
1e00d052 | 26963 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 26964 | + /* skip = (!br->br_whbase && !br->br_orph); */ |
26965 | + skip = (!wbr || !wbr->wbr_whbase); | |
26966 | + if (skip && wbr) { | |
26967 | + if (do_plink) | |
26968 | + skip = !!wbr->wbr_plink; | |
26969 | + else | |
26970 | + skip = !wbr->wbr_plink; | |
26971 | + } | |
1e00d052 | 26972 | + } else { |
1facf9fc | 26973 | + /* skip = (br->br_whbase && br->br_ohph); */ |
26974 | + skip = (wbr && wbr->wbr_whbase); | |
26975 | + if (skip) { | |
26976 | + if (do_plink) | |
26977 | + skip = !!wbr->wbr_plink; | |
26978 | + else | |
26979 | + skip = !wbr->wbr_plink; | |
26980 | + } | |
1facf9fc | 26981 | + } |
26982 | + if (wbr) | |
26983 | + wbr_wh_read_unlock(wbr); | |
26984 | + | |
79b8bda9 AM |
26985 | + if (can_no_dreval) { |
26986 | + dentry = br->br_path.dentry; | |
26987 | + spin_lock(&dentry->d_lock); | |
26988 | + if (dentry->d_flags & | |
26989 | + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE)) | |
26990 | + can_no_dreval = 0; | |
26991 | + spin_unlock(&dentry->d_lock); | |
26992 | + } | |
26993 | + | |
076b876e AM |
26994 | + if (au_br_fhsm(br->br_perm)) { |
26995 | + fhsm++; | |
26996 | + AuDebugOn(!br->br_fhsm); | |
26997 | + } | |
26998 | + | |
1facf9fc | 26999 | + if (skip) |
27000 | + continue; | |
27001 | + | |
27002 | + hdir = au_hi(dir, bindex); | |
5afbbe0d | 27003 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 27004 | + if (wbr) |
27005 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 27006 | + err = au_wh_init(br, sb); |
1facf9fc | 27007 | + if (wbr) |
27008 | + wbr_wh_write_unlock(wbr); | |
5afbbe0d | 27009 | + au_hn_inode_unlock(hdir); |
1facf9fc | 27010 | + |
27011 | + if (!err && do_free) { | |
1c60b727 | 27012 | + kfree(wbr); |
1facf9fc | 27013 | + br->br_wbr = NULL; |
27014 | + } | |
27015 | + } | |
27016 | + | |
79b8bda9 AM |
27017 | + if (can_no_dreval) |
27018 | + au_fset_si(sbinfo, NO_DREVAL); | |
27019 | + else | |
27020 | + au_fclr_si(sbinfo, NO_DREVAL); | |
27021 | + | |
c1595e42 | 27022 | + if (fhsm >= 2) { |
076b876e | 27023 | + au_fset_si(sbinfo, FHSM); |
5afbbe0d | 27024 | + for (bindex = bbot; bindex >= 0; bindex--) { |
c1595e42 JR |
27025 | + br = au_sbr(sb, bindex); |
27026 | + if (au_br_fhsm(br->br_perm)) { | |
27027 | + au_fhsm_set_bottom(sb, bindex); | |
27028 | + break; | |
27029 | + } | |
27030 | + } | |
27031 | + } else { | |
076b876e | 27032 | + au_fclr_si(sbinfo, FHSM); |
c1595e42 JR |
27033 | + au_fhsm_set_bottom(sb, -1); |
27034 | + } | |
076b876e | 27035 | + |
1facf9fc | 27036 | + return err; |
27037 | +} | |
27038 | + | |
27039 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts) | |
27040 | +{ | |
27041 | + int err; | |
27042 | + unsigned int tmp; | |
5afbbe0d | 27043 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 27044 | + struct au_opt *opt; |
27045 | + struct au_opt_xino *opt_xino, xino; | |
27046 | + struct au_sbinfo *sbinfo; | |
027c5e7a | 27047 | + struct au_branch *br; |
076b876e | 27048 | + struct inode *dir; |
1facf9fc | 27049 | + |
dece6358 AM |
27050 | + SiMustWriteLock(sb); |
27051 | + | |
1facf9fc | 27052 | + err = 0; |
27053 | + opt_xino = NULL; | |
27054 | + opt = opts->opt; | |
27055 | + while (err >= 0 && opt->type != Opt_tail) | |
27056 | + err = au_opt_simple(sb, opt++, opts); | |
27057 | + if (err > 0) | |
27058 | + err = 0; | |
27059 | + else if (unlikely(err < 0)) | |
27060 | + goto out; | |
27061 | + | |
27062 | + /* disable xino and udba temporary */ | |
27063 | + sbinfo = au_sbi(sb); | |
27064 | + tmp = sbinfo->si_mntflags; | |
27065 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
27066 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL); | |
27067 | + | |
27068 | + opt = opts->opt; | |
27069 | + while (err >= 0 && opt->type != Opt_tail) | |
27070 | + err = au_opt_br(sb, opt++, opts); | |
27071 | + if (err > 0) | |
27072 | + err = 0; | |
27073 | + else if (unlikely(err < 0)) | |
27074 | + goto out; | |
27075 | + | |
5afbbe0d AM |
27076 | + bbot = au_sbbot(sb); |
27077 | + if (unlikely(bbot < 0)) { | |
1facf9fc | 27078 | + err = -EINVAL; |
4a4d8108 | 27079 | + pr_err("no branches\n"); |
1facf9fc | 27080 | + goto out; |
27081 | + } | |
27082 | + | |
27083 | + if (au_opt_test(tmp, XINO)) | |
27084 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
27085 | + opt = opts->opt; | |
27086 | + while (!err && opt->type != Opt_tail) | |
27087 | + err = au_opt_xino(sb, opt++, &opt_xino, opts); | |
27088 | + if (unlikely(err)) | |
27089 | + goto out; | |
27090 | + | |
27091 | + err = au_opts_verify(sb, sb->s_flags, tmp); | |
27092 | + if (unlikely(err)) | |
27093 | + goto out; | |
27094 | + | |
27095 | + /* restore xino */ | |
27096 | + if (au_opt_test(tmp, XINO) && !opt_xino) { | |
27097 | + xino.file = au_xino_def(sb); | |
27098 | + err = PTR_ERR(xino.file); | |
27099 | + if (IS_ERR(xino.file)) | |
27100 | + goto out; | |
27101 | + | |
27102 | + err = au_xino_set(sb, &xino, /*remount*/0); | |
27103 | + fput(xino.file); | |
27104 | + if (unlikely(err)) | |
27105 | + goto out; | |
27106 | + } | |
27107 | + | |
27108 | + /* restore udba */ | |
027c5e7a | 27109 | + tmp &= AuOptMask_UDBA; |
1facf9fc | 27110 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; |
027c5e7a | 27111 | + sbinfo->si_mntflags |= tmp; |
5afbbe0d AM |
27112 | + bbot = au_sbbot(sb); |
27113 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
027c5e7a AM |
27114 | + br = au_sbr(sb, bindex); |
27115 | + err = au_hnotify_reset_br(tmp, br, br->br_perm); | |
27116 | + if (unlikely(err)) | |
27117 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", | |
27118 | + bindex, err); | |
27119 | + /* go on even if err */ | |
27120 | + } | |
4a4d8108 | 27121 | + if (au_opt_test(tmp, UDBA_HNOTIFY)) { |
5527c038 | 27122 | + dir = d_inode(sb->s_root); |
4a4d8108 | 27123 | + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO); |
1facf9fc | 27124 | + } |
27125 | + | |
4f0767ce | 27126 | +out: |
1facf9fc | 27127 | + return err; |
27128 | +} | |
27129 | + | |
27130 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts) | |
27131 | +{ | |
27132 | + int err, rerr; | |
79b8bda9 | 27133 | + unsigned char no_dreval; |
1facf9fc | 27134 | + struct inode *dir; |
27135 | + struct au_opt_xino *opt_xino; | |
27136 | + struct au_opt *opt; | |
27137 | + struct au_sbinfo *sbinfo; | |
27138 | + | |
dece6358 AM |
27139 | + SiMustWriteLock(sb); |
27140 | + | |
8b6a4947 AM |
27141 | + err = au_dr_opt_flush(sb); |
27142 | + if (unlikely(err)) | |
27143 | + goto out; | |
27144 | + au_fset_opts(opts->flags, DR_FLUSHED); | |
27145 | + | |
5527c038 | 27146 | + dir = d_inode(sb->s_root); |
1facf9fc | 27147 | + sbinfo = au_sbi(sb); |
1facf9fc | 27148 | + opt_xino = NULL; |
27149 | + opt = opts->opt; | |
27150 | + while (err >= 0 && opt->type != Opt_tail) { | |
27151 | + err = au_opt_simple(sb, opt, opts); | |
27152 | + if (!err) | |
27153 | + err = au_opt_br(sb, opt, opts); | |
27154 | + if (!err) | |
27155 | + err = au_opt_xino(sb, opt, &opt_xino, opts); | |
27156 | + opt++; | |
27157 | + } | |
27158 | + if (err > 0) | |
27159 | + err = 0; | |
27160 | + AuTraceErr(err); | |
27161 | + /* go on even err */ | |
27162 | + | |
79b8bda9 | 27163 | + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL); |
1facf9fc | 27164 | + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0); |
27165 | + if (unlikely(rerr && !err)) | |
27166 | + err = rerr; | |
27167 | + | |
79b8bda9 | 27168 | + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL)) |
b95c5147 | 27169 | + au_fset_opts(opts->flags, REFRESH_IDOP); |
79b8bda9 | 27170 | + |
1facf9fc | 27171 | + if (au_ftest_opts(opts->flags, TRUNC_XIB)) { |
27172 | + rerr = au_xib_trunc(sb); | |
27173 | + if (unlikely(rerr && !err)) | |
27174 | + err = rerr; | |
27175 | + } | |
27176 | + | |
27177 | + /* will be handled by the caller */ | |
027c5e7a | 27178 | + if (!au_ftest_opts(opts->flags, REFRESH) |
79b8bda9 AM |
27179 | + && (opts->given_udba |
27180 | + || au_opt_test(sbinfo->si_mntflags, XINO) | |
b95c5147 | 27181 | + || au_ftest_opts(opts->flags, REFRESH_IDOP) |
79b8bda9 | 27182 | + )) |
027c5e7a | 27183 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 27184 | + |
27185 | + AuDbg("status 0x%x\n", opts->flags); | |
8b6a4947 AM |
27186 | + |
27187 | +out: | |
1facf9fc | 27188 | + return err; |
27189 | +} | |
27190 | + | |
27191 | +/* ---------------------------------------------------------------------- */ | |
27192 | + | |
27193 | +unsigned int au_opt_udba(struct super_block *sb) | |
27194 | +{ | |
27195 | + return au_mntflags(sb) & AuOptMask_UDBA; | |
27196 | +} | |
7f207e10 AM |
27197 | diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h |
27198 | --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 27199 | +++ linux/fs/aufs/opts.h 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 27200 | @@ -0,0 +1,224 @@ |
1facf9fc | 27201 | +/* |
a2654f78 | 27202 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 27203 | + * |
27204 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27205 | + * it under the terms of the GNU General Public License as published by | |
27206 | + * the Free Software Foundation; either version 2 of the License, or | |
27207 | + * (at your option) any later version. | |
dece6358 AM |
27208 | + * |
27209 | + * This program is distributed in the hope that it will be useful, | |
27210 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27211 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27212 | + * GNU General Public License for more details. | |
27213 | + * | |
27214 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27215 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27216 | + */ |
27217 | + | |
27218 | +/* | |
27219 | + * mount options/flags | |
27220 | + */ | |
27221 | + | |
27222 | +#ifndef __AUFS_OPTS_H__ | |
27223 | +#define __AUFS_OPTS_H__ | |
27224 | + | |
27225 | +#ifdef __KERNEL__ | |
27226 | + | |
dece6358 | 27227 | +#include <linux/path.h> |
1facf9fc | 27228 | + |
dece6358 | 27229 | +struct file; |
dece6358 | 27230 | + |
1facf9fc | 27231 | +/* ---------------------------------------------------------------------- */ |
27232 | + | |
27233 | +/* mount flags */ | |
27234 | +#define AuOpt_XINO 1 /* external inode number bitmap | |
27235 | + and translation table */ | |
27236 | +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */ | |
27237 | +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */ | |
27238 | +#define AuOpt_UDBA_REVAL (1 << 3) | |
4a4d8108 | 27239 | +#define AuOpt_UDBA_HNOTIFY (1 << 4) |
dece6358 AM |
27240 | +#define AuOpt_SHWH (1 << 5) /* show whiteout */ |
27241 | +#define AuOpt_PLINK (1 << 6) /* pseudo-link */ | |
076b876e AM |
27242 | +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm |
27243 | + bits */ | |
dece6358 AM |
27244 | +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */ |
27245 | +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */ | |
27246 | +#define AuOpt_SUM_W (1 << 11) /* unimplemented */ | |
27247 | +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */ | |
27248 | +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */ | |
4a4d8108 | 27249 | +#define AuOpt_DIO (1 << 14) /* direct io */ |
8b6a4947 | 27250 | +#define AuOpt_DIRREN (1 << 15) /* directory rename */ |
1facf9fc | 27251 | + |
4a4d8108 AM |
27252 | +#ifndef CONFIG_AUFS_HNOTIFY |
27253 | +#undef AuOpt_UDBA_HNOTIFY | |
27254 | +#define AuOpt_UDBA_HNOTIFY 0 | |
1facf9fc | 27255 | +#endif |
8b6a4947 AM |
27256 | +#ifndef CONFIG_AUFS_DIRREN |
27257 | +#undef AuOpt_DIRREN | |
27258 | +#define AuOpt_DIRREN 0 | |
27259 | +#endif | |
dece6358 AM |
27260 | +#ifndef CONFIG_AUFS_SHWH |
27261 | +#undef AuOpt_SHWH | |
27262 | +#define AuOpt_SHWH 0 | |
27263 | +#endif | |
1facf9fc | 27264 | + |
27265 | +#define AuOpt_Def (AuOpt_XINO \ | |
27266 | + | AuOpt_UDBA_REVAL \ | |
27267 | + | AuOpt_PLINK \ | |
27268 | + /* | AuOpt_DIRPERM1 */ \ | |
27269 | + | AuOpt_WARN_PERM) | |
27270 | +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \ | |
27271 | + | AuOpt_UDBA_REVAL \ | |
4a4d8108 | 27272 | + | AuOpt_UDBA_HNOTIFY) |
1facf9fc | 27273 | + |
27274 | +#define au_opt_test(flags, name) (flags & AuOpt_##name) | |
27275 | +#define au_opt_set(flags, name) do { \ | |
27276 | + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \ | |
27277 | + ((flags) |= AuOpt_##name); \ | |
27278 | +} while (0) | |
27279 | +#define au_opt_set_udba(flags, name) do { \ | |
27280 | + (flags) &= ~AuOptMask_UDBA; \ | |
27281 | + ((flags) |= AuOpt_##name); \ | |
27282 | +} while (0) | |
7f207e10 AM |
27283 | +#define au_opt_clr(flags, name) do { \ |
27284 | + ((flags) &= ~AuOpt_##name); \ | |
27285 | +} while (0) | |
1facf9fc | 27286 | + |
e49829fe JR |
27287 | +static inline unsigned int au_opts_plink(unsigned int mntflags) |
27288 | +{ | |
27289 | +#ifdef CONFIG_PROC_FS | |
27290 | + return mntflags; | |
27291 | +#else | |
27292 | + return mntflags & ~AuOpt_PLINK; | |
27293 | +#endif | |
27294 | +} | |
27295 | + | |
1facf9fc | 27296 | +/* ---------------------------------------------------------------------- */ |
27297 | + | |
27298 | +/* policies to select one among multiple writable branches */ | |
27299 | +enum { | |
27300 | + AuWbrCreate_TDP, /* top down parent */ | |
27301 | + AuWbrCreate_RR, /* round robin */ | |
27302 | + AuWbrCreate_MFS, /* most free space */ | |
27303 | + AuWbrCreate_MFSV, /* mfs with seconds */ | |
27304 | + AuWbrCreate_MFSRR, /* mfs then rr */ | |
27305 | + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */ | |
f2c43d5f AM |
27306 | + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */ |
27307 | + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */ | |
1facf9fc | 27308 | + AuWbrCreate_PMFS, /* parent and mfs */ |
27309 | + AuWbrCreate_PMFSV, /* parent and mfs with seconds */ | |
392086de AM |
27310 | + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */ |
27311 | + AuWbrCreate_PMFSRRV, /* plus seconds */ | |
1facf9fc | 27312 | + |
27313 | + AuWbrCreate_Def = AuWbrCreate_TDP | |
27314 | +}; | |
27315 | + | |
27316 | +enum { | |
27317 | + AuWbrCopyup_TDP, /* top down parent */ | |
27318 | + AuWbrCopyup_BUP, /* bottom up parent */ | |
27319 | + AuWbrCopyup_BU, /* bottom up */ | |
27320 | + | |
27321 | + AuWbrCopyup_Def = AuWbrCopyup_TDP | |
27322 | +}; | |
27323 | + | |
27324 | +/* ---------------------------------------------------------------------- */ | |
27325 | + | |
27326 | +struct au_opt_add { | |
27327 | + aufs_bindex_t bindex; | |
27328 | + char *pathname; | |
27329 | + int perm; | |
27330 | + struct path path; | |
27331 | +}; | |
27332 | + | |
27333 | +struct au_opt_del { | |
27334 | + char *pathname; | |
27335 | + struct path h_path; | |
27336 | +}; | |
27337 | + | |
27338 | +struct au_opt_mod { | |
27339 | + char *path; | |
27340 | + int perm; | |
27341 | + struct dentry *h_root; | |
27342 | +}; | |
27343 | + | |
27344 | +struct au_opt_xino { | |
27345 | + char *path; | |
27346 | + struct file *file; | |
27347 | +}; | |
27348 | + | |
27349 | +struct au_opt_xino_itrunc { | |
27350 | + aufs_bindex_t bindex; | |
27351 | +}; | |
27352 | + | |
27353 | +struct au_opt_wbr_create { | |
27354 | + int wbr_create; | |
27355 | + int mfs_second; | |
27356 | + unsigned long long mfsrr_watermark; | |
27357 | +}; | |
27358 | + | |
27359 | +struct au_opt { | |
27360 | + int type; | |
27361 | + union { | |
27362 | + struct au_opt_xino xino; | |
27363 | + struct au_opt_xino_itrunc xino_itrunc; | |
27364 | + struct au_opt_add add; | |
27365 | + struct au_opt_del del; | |
27366 | + struct au_opt_mod mod; | |
27367 | + int dirwh; | |
27368 | + int rdcache; | |
27369 | + unsigned int rdblk; | |
27370 | + unsigned int rdhash; | |
27371 | + int udba; | |
27372 | + struct au_opt_wbr_create wbr_create; | |
27373 | + int wbr_copyup; | |
076b876e | 27374 | + unsigned int fhsm_second; |
1facf9fc | 27375 | + }; |
27376 | +}; | |
27377 | + | |
27378 | +/* opts flags */ | |
27379 | +#define AuOpts_REMOUNT 1 | |
027c5e7a AM |
27380 | +#define AuOpts_REFRESH (1 << 1) |
27381 | +#define AuOpts_TRUNC_XIB (1 << 2) | |
27382 | +#define AuOpts_REFRESH_DYAOP (1 << 3) | |
b95c5147 | 27383 | +#define AuOpts_REFRESH_IDOP (1 << 4) |
8b6a4947 | 27384 | +#define AuOpts_DR_FLUSHED (1 << 5) |
1facf9fc | 27385 | +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name) |
7f207e10 AM |
27386 | +#define au_fset_opts(flags, name) \ |
27387 | + do { (flags) |= AuOpts_##name; } while (0) | |
27388 | +#define au_fclr_opts(flags, name) \ | |
27389 | + do { (flags) &= ~AuOpts_##name; } while (0) | |
1facf9fc | 27390 | + |
8b6a4947 AM |
27391 | +#ifndef CONFIG_AUFS_DIRREN |
27392 | +#undef AuOpts_DR_FLUSHED | |
27393 | +#define AuOpts_DR_FLUSHED 0 | |
27394 | +#endif | |
27395 | + | |
1facf9fc | 27396 | +struct au_opts { |
27397 | + struct au_opt *opt; | |
27398 | + int max_opt; | |
27399 | + | |
27400 | + unsigned int given_udba; | |
27401 | + unsigned int flags; | |
27402 | + unsigned long sb_flags; | |
27403 | +}; | |
27404 | + | |
27405 | +/* ---------------------------------------------------------------------- */ | |
27406 | + | |
7e9cd9fe | 27407 | +/* opts.c */ |
076b876e | 27408 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm); |
1facf9fc | 27409 | +const char *au_optstr_udba(int udba); |
27410 | +const char *au_optstr_wbr_copyup(int wbr_copyup); | |
27411 | +const char *au_optstr_wbr_create(int wbr_create); | |
27412 | + | |
27413 | +void au_opts_free(struct au_opts *opts); | |
3c1bdaff | 27414 | +struct super_block; |
1facf9fc | 27415 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts); |
27416 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
27417 | + unsigned int pending); | |
27418 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts); | |
27419 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts); | |
27420 | + | |
27421 | +unsigned int au_opt_udba(struct super_block *sb); | |
27422 | + | |
1facf9fc | 27423 | +#endif /* __KERNEL__ */ |
27424 | +#endif /* __AUFS_OPTS_H__ */ | |
7f207e10 AM |
27425 | diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c |
27426 | --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 27427 | +++ linux/fs/aufs/plink.c 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 27428 | @@ -0,0 +1,515 @@ |
1facf9fc | 27429 | +/* |
a2654f78 | 27430 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 27431 | + * |
27432 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27433 | + * it under the terms of the GNU General Public License as published by | |
27434 | + * the Free Software Foundation; either version 2 of the License, or | |
27435 | + * (at your option) any later version. | |
dece6358 AM |
27436 | + * |
27437 | + * This program is distributed in the hope that it will be useful, | |
27438 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27439 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27440 | + * GNU General Public License for more details. | |
27441 | + * | |
27442 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27443 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27444 | + */ |
27445 | + | |
27446 | +/* | |
27447 | + * pseudo-link | |
27448 | + */ | |
27449 | + | |
27450 | +#include "aufs.h" | |
27451 | + | |
27452 | +/* | |
e49829fe | 27453 | + * the pseudo-link maintenance mode. |
1facf9fc | 27454 | + * during a user process maintains the pseudo-links, |
27455 | + * prohibit adding a new plink and branch manipulation. | |
e49829fe JR |
27456 | + * |
27457 | + * Flags | |
27458 | + * NOPLM: | |
27459 | + * For entry functions which will handle plink, and i_mutex is already held | |
27460 | + * in VFS. | |
27461 | + * They cannot wait and should return an error at once. | |
27462 | + * Callers has to check the error. | |
27463 | + * NOPLMW: | |
27464 | + * For entry functions which will handle plink, but i_mutex is not held | |
27465 | + * in VFS. | |
27466 | + * They can wait the plink maintenance mode to finish. | |
27467 | + * | |
27468 | + * They behave like F_SETLK and F_SETLKW. | |
27469 | + * If the caller never handle plink, then both flags are unnecessary. | |
1facf9fc | 27470 | + */ |
e49829fe JR |
27471 | + |
27472 | +int au_plink_maint(struct super_block *sb, int flags) | |
1facf9fc | 27473 | +{ |
e49829fe JR |
27474 | + int err; |
27475 | + pid_t pid, ppid; | |
f0c0a007 | 27476 | + struct task_struct *parent, *prev; |
e49829fe | 27477 | + struct au_sbinfo *sbi; |
dece6358 AM |
27478 | + |
27479 | + SiMustAnyLock(sb); | |
27480 | + | |
e49829fe JR |
27481 | + err = 0; |
27482 | + if (!au_opt_test(au_mntflags(sb), PLINK)) | |
27483 | + goto out; | |
27484 | + | |
27485 | + sbi = au_sbi(sb); | |
27486 | + pid = sbi->si_plink_maint_pid; | |
27487 | + if (!pid || pid == current->pid) | |
27488 | + goto out; | |
27489 | + | |
27490 | + /* todo: it highly depends upon /sbin/mount.aufs */ | |
f0c0a007 AM |
27491 | + prev = NULL; |
27492 | + parent = current; | |
27493 | + ppid = 0; | |
e49829fe | 27494 | + rcu_read_lock(); |
f0c0a007 AM |
27495 | + while (1) { |
27496 | + parent = rcu_dereference(parent->real_parent); | |
27497 | + if (parent == prev) | |
27498 | + break; | |
27499 | + ppid = task_pid_vnr(parent); | |
27500 | + if (pid == ppid) { | |
27501 | + rcu_read_unlock(); | |
27502 | + goto out; | |
27503 | + } | |
27504 | + prev = parent; | |
27505 | + } | |
e49829fe | 27506 | + rcu_read_unlock(); |
e49829fe JR |
27507 | + |
27508 | + if (au_ftest_lock(flags, NOPLMW)) { | |
027c5e7a AM |
27509 | + /* if there is no i_mutex lock in VFS, we don't need to wait */ |
27510 | + /* AuDebugOn(!lockdep_depth(current)); */ | |
e49829fe JR |
27511 | + while (sbi->si_plink_maint_pid) { |
27512 | + si_read_unlock(sb); | |
27513 | + /* gave up wake_up_bit() */ | |
27514 | + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid); | |
27515 | + | |
27516 | + if (au_ftest_lock(flags, FLUSH)) | |
27517 | + au_nwt_flush(&sbi->si_nowait); | |
27518 | + si_noflush_read_lock(sb); | |
27519 | + } | |
27520 | + } else if (au_ftest_lock(flags, NOPLM)) { | |
27521 | + AuDbg("ppid %d, pid %d\n", ppid, pid); | |
27522 | + err = -EAGAIN; | |
27523 | + } | |
27524 | + | |
27525 | +out: | |
27526 | + return err; | |
4a4d8108 AM |
27527 | +} |
27528 | + | |
e49829fe | 27529 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo) |
4a4d8108 | 27530 | +{ |
4a4d8108 | 27531 | + spin_lock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 27532 | + sbinfo->si_plink_maint_pid = 0; |
4a4d8108 | 27533 | + spin_unlock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 27534 | + wake_up_all(&sbinfo->si_plink_wq); |
4a4d8108 AM |
27535 | +} |
27536 | + | |
e49829fe | 27537 | +int au_plink_maint_enter(struct super_block *sb) |
4a4d8108 AM |
27538 | +{ |
27539 | + int err; | |
4a4d8108 AM |
27540 | + struct au_sbinfo *sbinfo; |
27541 | + | |
27542 | + err = 0; | |
4a4d8108 AM |
27543 | + sbinfo = au_sbi(sb); |
27544 | + /* make sure i am the only one in this fs */ | |
e49829fe JR |
27545 | + si_write_lock(sb, AuLock_FLUSH); |
27546 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
27547 | + spin_lock(&sbinfo->si_plink_maint_lock); | |
27548 | + if (!sbinfo->si_plink_maint_pid) | |
27549 | + sbinfo->si_plink_maint_pid = current->pid; | |
27550 | + else | |
27551 | + err = -EBUSY; | |
27552 | + spin_unlock(&sbinfo->si_plink_maint_lock); | |
27553 | + } | |
4a4d8108 AM |
27554 | + si_write_unlock(sb); |
27555 | + | |
27556 | + return err; | |
1facf9fc | 27557 | +} |
27558 | + | |
27559 | +/* ---------------------------------------------------------------------- */ | |
27560 | + | |
1facf9fc | 27561 | +#ifdef CONFIG_AUFS_DEBUG |
27562 | +void au_plink_list(struct super_block *sb) | |
27563 | +{ | |
86dc4139 | 27564 | + int i; |
1facf9fc | 27565 | + struct au_sbinfo *sbinfo; |
8b6a4947 AM |
27566 | + struct hlist_bl_head *hbl; |
27567 | + struct hlist_bl_node *pos; | |
5afbbe0d | 27568 | + struct au_icntnr *icntnr; |
1facf9fc | 27569 | + |
dece6358 AM |
27570 | + SiMustAnyLock(sb); |
27571 | + | |
1facf9fc | 27572 | + sbinfo = au_sbi(sb); |
27573 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 27574 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 27575 | + |
86dc4139 | 27576 | + for (i = 0; i < AuPlink_NHASH; i++) { |
8b6a4947 AM |
27577 | + hbl = sbinfo->si_plink + i; |
27578 | + hlist_bl_lock(hbl); | |
27579 | + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) | |
5afbbe0d | 27580 | + AuDbg("%lu\n", icntnr->vfs_inode.i_ino); |
8b6a4947 | 27581 | + hlist_bl_unlock(hbl); |
86dc4139 | 27582 | + } |
1facf9fc | 27583 | +} |
27584 | +#endif | |
27585 | + | |
27586 | +/* is the inode pseudo-linked? */ | |
27587 | +int au_plink_test(struct inode *inode) | |
27588 | +{ | |
86dc4139 | 27589 | + int found, i; |
1facf9fc | 27590 | + struct au_sbinfo *sbinfo; |
8b6a4947 AM |
27591 | + struct hlist_bl_head *hbl; |
27592 | + struct hlist_bl_node *pos; | |
5afbbe0d | 27593 | + struct au_icntnr *icntnr; |
1facf9fc | 27594 | + |
27595 | + sbinfo = au_sbi(inode->i_sb); | |
dece6358 | 27596 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
1facf9fc | 27597 | + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK)); |
e49829fe | 27598 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
1facf9fc | 27599 | + |
27600 | + found = 0; | |
86dc4139 | 27601 | + i = au_plink_hash(inode->i_ino); |
8b6a4947 AM |
27602 | + hbl = sbinfo->si_plink + i; |
27603 | + hlist_bl_lock(hbl); | |
27604 | + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) | |
5afbbe0d | 27605 | + if (&icntnr->vfs_inode == inode) { |
1facf9fc | 27606 | + found = 1; |
27607 | + break; | |
27608 | + } | |
8b6a4947 | 27609 | + hlist_bl_unlock(hbl); |
1facf9fc | 27610 | + return found; |
27611 | +} | |
27612 | + | |
27613 | +/* ---------------------------------------------------------------------- */ | |
27614 | + | |
27615 | +/* | |
27616 | + * generate a name for plink. | |
27617 | + * the file will be stored under AUFS_WH_PLINKDIR. | |
27618 | + */ | |
27619 | +/* 20 is max digits length of ulong 64 */ | |
27620 | +#define PLINK_NAME_LEN ((20 + 1) * 2) | |
27621 | + | |
27622 | +static int plink_name(char *name, int len, struct inode *inode, | |
27623 | + aufs_bindex_t bindex) | |
27624 | +{ | |
27625 | + int rlen; | |
27626 | + struct inode *h_inode; | |
27627 | + | |
27628 | + h_inode = au_h_iptr(inode, bindex); | |
27629 | + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino); | |
27630 | + return rlen; | |
27631 | +} | |
27632 | + | |
7f207e10 AM |
27633 | +struct au_do_plink_lkup_args { |
27634 | + struct dentry **errp; | |
27635 | + struct qstr *tgtname; | |
27636 | + struct dentry *h_parent; | |
27637 | + struct au_branch *br; | |
27638 | +}; | |
27639 | + | |
27640 | +static struct dentry *au_do_plink_lkup(struct qstr *tgtname, | |
27641 | + struct dentry *h_parent, | |
27642 | + struct au_branch *br) | |
27643 | +{ | |
27644 | + struct dentry *h_dentry; | |
febd17d6 | 27645 | + struct inode *h_inode; |
7f207e10 | 27646 | + |
febd17d6 | 27647 | + h_inode = d_inode(h_parent); |
3c1bdaff | 27648 | + vfsub_inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2); |
b4510431 | 27649 | + h_dentry = vfsub_lkup_one(tgtname, h_parent); |
3c1bdaff | 27650 | + inode_unlock_shared(h_inode); |
7f207e10 AM |
27651 | + return h_dentry; |
27652 | +} | |
27653 | + | |
27654 | +static void au_call_do_plink_lkup(void *args) | |
27655 | +{ | |
27656 | + struct au_do_plink_lkup_args *a = args; | |
27657 | + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br); | |
27658 | +} | |
27659 | + | |
1facf9fc | 27660 | +/* lookup the plink-ed @inode under the branch at @bindex */ |
27661 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex) | |
27662 | +{ | |
27663 | + struct dentry *h_dentry, *h_parent; | |
27664 | + struct au_branch *br; | |
7f207e10 | 27665 | + int wkq_err; |
1facf9fc | 27666 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 27667 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 27668 | + |
e49829fe JR |
27669 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
27670 | + | |
1facf9fc | 27671 | + br = au_sbr(inode->i_sb, bindex); |
27672 | + h_parent = br->br_wbr->wbr_plink; | |
1facf9fc | 27673 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
27674 | + | |
2dfbb274 | 27675 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
7f207e10 AM |
27676 | + struct au_do_plink_lkup_args args = { |
27677 | + .errp = &h_dentry, | |
27678 | + .tgtname = &tgtname, | |
27679 | + .h_parent = h_parent, | |
27680 | + .br = br | |
27681 | + }; | |
27682 | + | |
27683 | + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args); | |
27684 | + if (unlikely(wkq_err)) | |
27685 | + h_dentry = ERR_PTR(wkq_err); | |
27686 | + } else | |
27687 | + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br); | |
27688 | + | |
1facf9fc | 27689 | + return h_dentry; |
27690 | +} | |
27691 | + | |
27692 | +/* create a pseudo-link */ | |
27693 | +static int do_whplink(struct qstr *tgt, struct dentry *h_parent, | |
27694 | + struct dentry *h_dentry, struct au_branch *br) | |
27695 | +{ | |
27696 | + int err; | |
27697 | + struct path h_path = { | |
86dc4139 | 27698 | + .mnt = au_br_mnt(br) |
1facf9fc | 27699 | + }; |
523b37e3 | 27700 | + struct inode *h_dir, *delegated; |
1facf9fc | 27701 | + |
5527c038 | 27702 | + h_dir = d_inode(h_parent); |
febd17d6 | 27703 | + inode_lock_nested(h_dir, AuLsc_I_CHILD2); |
4f0767ce | 27704 | +again: |
b4510431 | 27705 | + h_path.dentry = vfsub_lkup_one(tgt, h_parent); |
1facf9fc | 27706 | + err = PTR_ERR(h_path.dentry); |
27707 | + if (IS_ERR(h_path.dentry)) | |
27708 | + goto out; | |
27709 | + | |
27710 | + err = 0; | |
27711 | + /* wh.plink dir is not monitored */ | |
7f207e10 | 27712 | + /* todo: is it really safe? */ |
5527c038 JR |
27713 | + if (d_is_positive(h_path.dentry) |
27714 | + && d_inode(h_path.dentry) != d_inode(h_dentry)) { | |
523b37e3 AM |
27715 | + delegated = NULL; |
27716 | + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0); | |
27717 | + if (unlikely(err == -EWOULDBLOCK)) { | |
27718 | + pr_warn("cannot retry for NFSv4 delegation" | |
27719 | + " for an internal unlink\n"); | |
27720 | + iput(delegated); | |
27721 | + } | |
1facf9fc | 27722 | + dput(h_path.dentry); |
27723 | + h_path.dentry = NULL; | |
27724 | + if (!err) | |
27725 | + goto again; | |
27726 | + } | |
5527c038 | 27727 | + if (!err && d_is_negative(h_path.dentry)) { |
523b37e3 AM |
27728 | + delegated = NULL; |
27729 | + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated); | |
27730 | + if (unlikely(err == -EWOULDBLOCK)) { | |
27731 | + pr_warn("cannot retry for NFSv4 delegation" | |
27732 | + " for an internal link\n"); | |
27733 | + iput(delegated); | |
27734 | + } | |
27735 | + } | |
1facf9fc | 27736 | + dput(h_path.dentry); |
27737 | + | |
4f0767ce | 27738 | +out: |
febd17d6 | 27739 | + inode_unlock(h_dir); |
1facf9fc | 27740 | + return err; |
27741 | +} | |
27742 | + | |
27743 | +struct do_whplink_args { | |
27744 | + int *errp; | |
27745 | + struct qstr *tgt; | |
27746 | + struct dentry *h_parent; | |
27747 | + struct dentry *h_dentry; | |
27748 | + struct au_branch *br; | |
27749 | +}; | |
27750 | + | |
27751 | +static void call_do_whplink(void *args) | |
27752 | +{ | |
27753 | + struct do_whplink_args *a = args; | |
27754 | + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br); | |
27755 | +} | |
27756 | + | |
27757 | +static int whplink(struct dentry *h_dentry, struct inode *inode, | |
27758 | + aufs_bindex_t bindex, struct au_branch *br) | |
27759 | +{ | |
27760 | + int err, wkq_err; | |
27761 | + struct au_wbr *wbr; | |
27762 | + struct dentry *h_parent; | |
1facf9fc | 27763 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 27764 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 27765 | + |
27766 | + wbr = au_sbr(inode->i_sb, bindex)->br_wbr; | |
27767 | + h_parent = wbr->wbr_plink; | |
1facf9fc | 27768 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
27769 | + | |
27770 | + /* always superio. */ | |
2dfbb274 | 27771 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
1facf9fc | 27772 | + struct do_whplink_args args = { |
27773 | + .errp = &err, | |
27774 | + .tgt = &tgtname, | |
27775 | + .h_parent = h_parent, | |
27776 | + .h_dentry = h_dentry, | |
27777 | + .br = br | |
27778 | + }; | |
27779 | + wkq_err = au_wkq_wait(call_do_whplink, &args); | |
27780 | + if (unlikely(wkq_err)) | |
27781 | + err = wkq_err; | |
27782 | + } else | |
27783 | + err = do_whplink(&tgtname, h_parent, h_dentry, br); | |
1facf9fc | 27784 | + |
27785 | + return err; | |
27786 | +} | |
27787 | + | |
1facf9fc | 27788 | +/* |
27789 | + * create a new pseudo-link for @h_dentry on @bindex. | |
27790 | + * the linked inode is held in aufs @inode. | |
27791 | + */ | |
27792 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
27793 | + struct dentry *h_dentry) | |
27794 | +{ | |
27795 | + struct super_block *sb; | |
27796 | + struct au_sbinfo *sbinfo; | |
8b6a4947 AM |
27797 | + struct hlist_bl_head *hbl; |
27798 | + struct hlist_bl_node *pos; | |
5afbbe0d | 27799 | + struct au_icntnr *icntnr; |
86dc4139 | 27800 | + int found, err, cnt, i; |
1facf9fc | 27801 | + |
27802 | + sb = inode->i_sb; | |
27803 | + sbinfo = au_sbi(sb); | |
27804 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 27805 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 27806 | + |
86dc4139 | 27807 | + found = au_plink_test(inode); |
4a4d8108 | 27808 | + if (found) |
1facf9fc | 27809 | + return; |
4a4d8108 | 27810 | + |
86dc4139 | 27811 | + i = au_plink_hash(inode->i_ino); |
8b6a4947 | 27812 | + hbl = sbinfo->si_plink + i; |
5afbbe0d | 27813 | + au_igrab(inode); |
1facf9fc | 27814 | + |
8b6a4947 AM |
27815 | + hlist_bl_lock(hbl); |
27816 | + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) { | |
5afbbe0d | 27817 | + if (&icntnr->vfs_inode == inode) { |
4a4d8108 AM |
27818 | + found = 1; |
27819 | + break; | |
27820 | + } | |
1facf9fc | 27821 | + } |
5afbbe0d AM |
27822 | + if (!found) { |
27823 | + icntnr = container_of(inode, struct au_icntnr, vfs_inode); | |
8b6a4947 | 27824 | + hlist_bl_add_head(&icntnr->plink, hbl); |
5afbbe0d | 27825 | + } |
8b6a4947 | 27826 | + hlist_bl_unlock(hbl); |
4a4d8108 | 27827 | + if (!found) { |
8b6a4947 | 27828 | + cnt = au_hbl_count(hbl); |
86dc4139 AM |
27829 | +#define msg "unexpectedly unblanced or too many pseudo-links" |
27830 | + if (cnt > AUFS_PLINK_WARN) | |
27831 | + AuWarn1(msg ", %d\n", cnt); | |
27832 | +#undef msg | |
1facf9fc | 27833 | + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex)); |
5afbbe0d AM |
27834 | + if (unlikely(err)) { |
27835 | + pr_warn("err %d, damaged pseudo link.\n", err); | |
8b6a4947 | 27836 | + au_hbl_del(&icntnr->plink, hbl); |
5afbbe0d | 27837 | + iput(&icntnr->vfs_inode); |
4a4d8108 | 27838 | + } |
5afbbe0d AM |
27839 | + } else |
27840 | + iput(&icntnr->vfs_inode); | |
1facf9fc | 27841 | +} |
27842 | + | |
27843 | +/* free all plinks */ | |
e49829fe | 27844 | +void au_plink_put(struct super_block *sb, int verbose) |
1facf9fc | 27845 | +{ |
86dc4139 | 27846 | + int i, warned; |
1facf9fc | 27847 | + struct au_sbinfo *sbinfo; |
8b6a4947 AM |
27848 | + struct hlist_bl_head *hbl; |
27849 | + struct hlist_bl_node *pos, *tmp; | |
5afbbe0d | 27850 | + struct au_icntnr *icntnr; |
1facf9fc | 27851 | + |
dece6358 AM |
27852 | + SiMustWriteLock(sb); |
27853 | + | |
1facf9fc | 27854 | + sbinfo = au_sbi(sb); |
27855 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 27856 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 27857 | + |
1facf9fc | 27858 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
27859 | + warned = 0; |
27860 | + for (i = 0; i < AuPlink_NHASH; i++) { | |
8b6a4947 AM |
27861 | + hbl = sbinfo->si_plink + i; |
27862 | + if (!warned && verbose && !hlist_bl_empty(hbl)) { | |
86dc4139 AM |
27863 | + pr_warn("pseudo-link is not flushed"); |
27864 | + warned = 1; | |
27865 | + } | |
8b6a4947 | 27866 | + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) |
5afbbe0d | 27867 | + iput(&icntnr->vfs_inode); |
8b6a4947 | 27868 | + INIT_HLIST_BL_HEAD(hbl); |
86dc4139 | 27869 | + } |
1facf9fc | 27870 | +} |
27871 | + | |
e49829fe JR |
27872 | +void au_plink_clean(struct super_block *sb, int verbose) |
27873 | +{ | |
27874 | + struct dentry *root; | |
27875 | + | |
27876 | + root = sb->s_root; | |
27877 | + aufs_write_lock(root); | |
27878 | + if (au_opt_test(au_mntflags(sb), PLINK)) | |
27879 | + au_plink_put(sb, verbose); | |
27880 | + aufs_write_unlock(root); | |
27881 | +} | |
27882 | + | |
86dc4139 AM |
27883 | +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id) |
27884 | +{ | |
27885 | + int do_put; | |
5afbbe0d | 27886 | + aufs_bindex_t btop, bbot, bindex; |
86dc4139 AM |
27887 | + |
27888 | + do_put = 0; | |
5afbbe0d AM |
27889 | + btop = au_ibtop(inode); |
27890 | + bbot = au_ibbot(inode); | |
27891 | + if (btop >= 0) { | |
27892 | + for (bindex = btop; bindex <= bbot; bindex++) { | |
86dc4139 AM |
27893 | + if (!au_h_iptr(inode, bindex) |
27894 | + || au_ii_br_id(inode, bindex) != br_id) | |
27895 | + continue; | |
27896 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
27897 | + do_put = 1; | |
27898 | + break; | |
27899 | + } | |
27900 | + if (do_put) | |
5afbbe0d | 27901 | + for (bindex = btop; bindex <= bbot; bindex++) |
86dc4139 AM |
27902 | + if (au_h_iptr(inode, bindex)) { |
27903 | + do_put = 0; | |
27904 | + break; | |
27905 | + } | |
27906 | + } else | |
27907 | + do_put = 1; | |
27908 | + | |
27909 | + return do_put; | |
27910 | +} | |
27911 | + | |
1facf9fc | 27912 | +/* free the plinks on a branch specified by @br_id */ |
27913 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id) | |
27914 | +{ | |
27915 | + struct au_sbinfo *sbinfo; | |
8b6a4947 AM |
27916 | + struct hlist_bl_head *hbl; |
27917 | + struct hlist_bl_node *pos, *tmp; | |
5afbbe0d | 27918 | + struct au_icntnr *icntnr; |
1facf9fc | 27919 | + struct inode *inode; |
86dc4139 | 27920 | + int i, do_put; |
1facf9fc | 27921 | + |
dece6358 AM |
27922 | + SiMustWriteLock(sb); |
27923 | + | |
1facf9fc | 27924 | + sbinfo = au_sbi(sb); |
27925 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 27926 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 27927 | + |
8b6a4947 | 27928 | + /* no bit_lock since sbinfo is write-locked */ |
86dc4139 | 27929 | + for (i = 0; i < AuPlink_NHASH; i++) { |
8b6a4947 AM |
27930 | + hbl = sbinfo->si_plink + i; |
27931 | + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) { | |
5afbbe0d | 27932 | + inode = au_igrab(&icntnr->vfs_inode); |
86dc4139 AM |
27933 | + ii_write_lock_child(inode); |
27934 | + do_put = au_plink_do_half_refresh(inode, br_id); | |
5afbbe0d | 27935 | + if (do_put) { |
8b6a4947 | 27936 | + hlist_bl_del(&icntnr->plink); |
5afbbe0d AM |
27937 | + iput(inode); |
27938 | + } | |
86dc4139 AM |
27939 | + ii_write_unlock(inode); |
27940 | + iput(inode); | |
dece6358 | 27941 | + } |
dece6358 AM |
27942 | + } |
27943 | +} | |
7f207e10 AM |
27944 | diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c |
27945 | --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 27946 | +++ linux/fs/aufs/poll.c 2018-01-29 07:56:20.059991935 +0100 |
b912730e | 27947 | @@ -0,0 +1,52 @@ |
dece6358 | 27948 | +/* |
a2654f78 | 27949 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
dece6358 AM |
27950 | + * |
27951 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27952 | + * it under the terms of the GNU General Public License as published by | |
27953 | + * the Free Software Foundation; either version 2 of the License, or | |
27954 | + * (at your option) any later version. | |
27955 | + * | |
27956 | + * This program is distributed in the hope that it will be useful, | |
27957 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27958 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27959 | + * GNU General Public License for more details. | |
27960 | + * | |
27961 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27962 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 AM |
27963 | + */ |
27964 | + | |
1308ab2a | 27965 | +/* |
27966 | + * poll operation | |
27967 | + * There is only one filesystem which implements ->poll operation, currently. | |
27968 | + */ | |
27969 | + | |
27970 | +#include "aufs.h" | |
27971 | + | |
27972 | +unsigned int aufs_poll(struct file *file, poll_table *wait) | |
27973 | +{ | |
27974 | + unsigned int mask; | |
27975 | + int err; | |
27976 | + struct file *h_file; | |
1308ab2a | 27977 | + struct super_block *sb; |
27978 | + | |
27979 | + /* We should pretend an error happened. */ | |
27980 | + mask = POLLERR /* | POLLIN | POLLOUT */; | |
b912730e | 27981 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 27982 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 27983 | + |
521ced18 | 27984 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
27985 | + err = PTR_ERR(h_file); |
27986 | + if (IS_ERR(h_file)) | |
1308ab2a | 27987 | + goto out; |
27988 | + | |
27989 | + /* it is not an error if h_file has no operation */ | |
27990 | + mask = DEFAULT_POLLMASK; | |
523b37e3 | 27991 | + if (h_file->f_op->poll) |
1308ab2a | 27992 | + mask = h_file->f_op->poll(h_file, wait); |
b912730e | 27993 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 27994 | + |
4f0767ce | 27995 | +out: |
1308ab2a | 27996 | + si_read_unlock(sb); |
27997 | + AuTraceErr((int)mask); | |
27998 | + return mask; | |
27999 | +} | |
c1595e42 JR |
28000 | diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c |
28001 | --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 28002 | +++ linux/fs/aufs/posix_acl.c 2018-01-29 07:56:20.059991935 +0100 |
a2654f78 | 28003 | @@ -0,0 +1,102 @@ |
c1595e42 | 28004 | +/* |
a2654f78 | 28005 | + * Copyright (C) 2014-2017 Junjiro R. Okajima |
c1595e42 JR |
28006 | + * |
28007 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28008 | + * it under the terms of the GNU General Public License as published by | |
28009 | + * the Free Software Foundation; either version 2 of the License, or | |
28010 | + * (at your option) any later version. | |
28011 | + * | |
28012 | + * This program is distributed in the hope that it will be useful, | |
28013 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28014 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28015 | + * GNU General Public License for more details. | |
28016 | + * | |
28017 | + * You should have received a copy of the GNU General Public License | |
28018 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28019 | + */ | |
28020 | + | |
28021 | +/* | |
28022 | + * posix acl operations | |
28023 | + */ | |
28024 | + | |
28025 | +#include <linux/fs.h> | |
c1595e42 JR |
28026 | +#include "aufs.h" |
28027 | + | |
28028 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
28029 | +{ | |
28030 | + struct posix_acl *acl; | |
28031 | + int err; | |
28032 | + aufs_bindex_t bindex; | |
28033 | + struct inode *h_inode; | |
28034 | + struct super_block *sb; | |
28035 | + | |
28036 | + acl = NULL; | |
28037 | + sb = inode->i_sb; | |
28038 | + si_read_lock(sb, AuLock_FLUSH); | |
28039 | + ii_read_lock_child(inode); | |
2121bcd9 | 28040 | + if (!(sb->s_flags & SB_POSIXACL)) |
c1595e42 JR |
28041 | + goto out; |
28042 | + | |
5afbbe0d | 28043 | + bindex = au_ibtop(inode); |
c1595e42 JR |
28044 | + h_inode = au_h_iptr(inode, bindex); |
28045 | + if (unlikely(!h_inode | |
28046 | + || ((h_inode->i_mode & S_IFMT) | |
28047 | + != (inode->i_mode & S_IFMT)))) { | |
28048 | + err = au_busy_or_stale(); | |
28049 | + acl = ERR_PTR(err); | |
28050 | + goto out; | |
28051 | + } | |
28052 | + | |
28053 | + /* always topmost only */ | |
28054 | + acl = get_acl(h_inode, type); | |
a2654f78 AM |
28055 | + if (!IS_ERR_OR_NULL(acl)) |
28056 | + set_cached_acl(inode, type, acl); | |
c1595e42 JR |
28057 | + |
28058 | +out: | |
28059 | + ii_read_unlock(inode); | |
28060 | + si_read_unlock(sb); | |
28061 | + | |
28062 | + AuTraceErrPtr(acl); | |
28063 | + return acl; | |
28064 | +} | |
28065 | + | |
28066 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
28067 | +{ | |
28068 | + int err; | |
28069 | + ssize_t ssz; | |
28070 | + struct dentry *dentry; | |
f2c43d5f | 28071 | + struct au_sxattr arg = { |
c1595e42 JR |
28072 | + .type = AU_ACL_SET, |
28073 | + .u.acl_set = { | |
28074 | + .acl = acl, | |
28075 | + .type = type | |
28076 | + }, | |
28077 | + }; | |
28078 | + | |
5afbbe0d AM |
28079 | + IMustLock(inode); |
28080 | + | |
c1595e42 JR |
28081 | + if (inode->i_ino == AUFS_ROOT_INO) |
28082 | + dentry = dget(inode->i_sb->s_root); | |
28083 | + else { | |
28084 | + dentry = d_find_alias(inode); | |
28085 | + if (!dentry) | |
28086 | + dentry = d_find_any_alias(inode); | |
28087 | + if (!dentry) { | |
28088 | + pr_warn("cannot handle this inode, " | |
28089 | + "please report to aufs-users ML\n"); | |
28090 | + err = -ENOENT; | |
28091 | + goto out; | |
28092 | + } | |
28093 | + } | |
28094 | + | |
f2c43d5f | 28095 | + ssz = au_sxattr(dentry, inode, &arg); |
c1595e42 JR |
28096 | + dput(dentry); |
28097 | + err = ssz; | |
a2654f78 | 28098 | + if (ssz >= 0) { |
c1595e42 | 28099 | + err = 0; |
a2654f78 AM |
28100 | + set_cached_acl(inode, type, acl); |
28101 | + } | |
c1595e42 JR |
28102 | + |
28103 | +out: | |
c1595e42 JR |
28104 | + return err; |
28105 | +} | |
7f207e10 AM |
28106 | diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c |
28107 | --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 28108 | +++ linux/fs/aufs/procfs.c 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 28109 | @@ -0,0 +1,170 @@ |
e49829fe | 28110 | +/* |
a2654f78 | 28111 | + * Copyright (C) 2010-2017 Junjiro R. Okajima |
e49829fe JR |
28112 | + * |
28113 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28114 | + * it under the terms of the GNU General Public License as published by | |
28115 | + * the Free Software Foundation; either version 2 of the License, or | |
28116 | + * (at your option) any later version. | |
28117 | + * | |
28118 | + * This program is distributed in the hope that it will be useful, | |
28119 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28120 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28121 | + * GNU General Public License for more details. | |
28122 | + * | |
28123 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28124 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
28125 | + */ |
28126 | + | |
28127 | +/* | |
28128 | + * procfs interfaces | |
28129 | + */ | |
28130 | + | |
28131 | +#include <linux/proc_fs.h> | |
28132 | +#include "aufs.h" | |
28133 | + | |
28134 | +static int au_procfs_plm_release(struct inode *inode, struct file *file) | |
28135 | +{ | |
28136 | + struct au_sbinfo *sbinfo; | |
28137 | + | |
28138 | + sbinfo = file->private_data; | |
28139 | + if (sbinfo) { | |
28140 | + au_plink_maint_leave(sbinfo); | |
28141 | + kobject_put(&sbinfo->si_kobj); | |
28142 | + } | |
28143 | + | |
28144 | + return 0; | |
28145 | +} | |
28146 | + | |
28147 | +static void au_procfs_plm_write_clean(struct file *file) | |
28148 | +{ | |
28149 | + struct au_sbinfo *sbinfo; | |
28150 | + | |
28151 | + sbinfo = file->private_data; | |
28152 | + if (sbinfo) | |
28153 | + au_plink_clean(sbinfo->si_sb, /*verbose*/0); | |
28154 | +} | |
28155 | + | |
28156 | +static int au_procfs_plm_write_si(struct file *file, unsigned long id) | |
28157 | +{ | |
28158 | + int err; | |
28159 | + struct super_block *sb; | |
28160 | + struct au_sbinfo *sbinfo; | |
8b6a4947 | 28161 | + struct hlist_bl_node *pos; |
e49829fe JR |
28162 | + |
28163 | + err = -EBUSY; | |
28164 | + if (unlikely(file->private_data)) | |
28165 | + goto out; | |
28166 | + | |
28167 | + sb = NULL; | |
53392da6 | 28168 | + /* don't use au_sbilist_lock() here */ |
8b6a4947 AM |
28169 | + hlist_bl_lock(&au_sbilist); |
28170 | + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list) | |
e49829fe JR |
28171 | + if (id == sysaufs_si_id(sbinfo)) { |
28172 | + kobject_get(&sbinfo->si_kobj); | |
28173 | + sb = sbinfo->si_sb; | |
28174 | + break; | |
28175 | + } | |
8b6a4947 | 28176 | + hlist_bl_unlock(&au_sbilist); |
e49829fe JR |
28177 | + |
28178 | + err = -EINVAL; | |
28179 | + if (unlikely(!sb)) | |
28180 | + goto out; | |
28181 | + | |
28182 | + err = au_plink_maint_enter(sb); | |
28183 | + if (!err) | |
28184 | + /* keep kobject_get() */ | |
28185 | + file->private_data = sbinfo; | |
28186 | + else | |
28187 | + kobject_put(&sbinfo->si_kobj); | |
28188 | +out: | |
28189 | + return err; | |
28190 | +} | |
28191 | + | |
28192 | +/* | |
28193 | + * Accept a valid "si=xxxx" only. | |
28194 | + * Once it is accepted successfully, accept "clean" too. | |
28195 | + */ | |
28196 | +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf, | |
28197 | + size_t count, loff_t *ppos) | |
28198 | +{ | |
28199 | + ssize_t err; | |
28200 | + unsigned long id; | |
28201 | + /* last newline is allowed */ | |
28202 | + char buf[3 + sizeof(unsigned long) * 2 + 1]; | |
28203 | + | |
28204 | + err = -EACCES; | |
28205 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
28206 | + goto out; | |
28207 | + | |
28208 | + err = -EINVAL; | |
28209 | + if (unlikely(count > sizeof(buf))) | |
28210 | + goto out; | |
28211 | + | |
28212 | + err = copy_from_user(buf, ubuf, count); | |
28213 | + if (unlikely(err)) { | |
28214 | + err = -EFAULT; | |
28215 | + goto out; | |
28216 | + } | |
28217 | + buf[count] = 0; | |
28218 | + | |
28219 | + err = -EINVAL; | |
28220 | + if (!strcmp("clean", buf)) { | |
28221 | + au_procfs_plm_write_clean(file); | |
28222 | + goto out_success; | |
28223 | + } else if (unlikely(strncmp("si=", buf, 3))) | |
28224 | + goto out; | |
28225 | + | |
9dbd164d | 28226 | + err = kstrtoul(buf + 3, 16, &id); |
e49829fe JR |
28227 | + if (unlikely(err)) |
28228 | + goto out; | |
28229 | + | |
28230 | + err = au_procfs_plm_write_si(file, id); | |
28231 | + if (unlikely(err)) | |
28232 | + goto out; | |
28233 | + | |
28234 | +out_success: | |
28235 | + err = count; /* success */ | |
28236 | +out: | |
28237 | + return err; | |
28238 | +} | |
28239 | + | |
28240 | +static const struct file_operations au_procfs_plm_fop = { | |
28241 | + .write = au_procfs_plm_write, | |
28242 | + .release = au_procfs_plm_release, | |
28243 | + .owner = THIS_MODULE | |
28244 | +}; | |
28245 | + | |
28246 | +/* ---------------------------------------------------------------------- */ | |
28247 | + | |
28248 | +static struct proc_dir_entry *au_procfs_dir; | |
28249 | + | |
28250 | +void au_procfs_fin(void) | |
28251 | +{ | |
28252 | + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir); | |
28253 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
28254 | +} | |
28255 | + | |
28256 | +int __init au_procfs_init(void) | |
28257 | +{ | |
28258 | + int err; | |
28259 | + struct proc_dir_entry *entry; | |
28260 | + | |
28261 | + err = -ENOMEM; | |
28262 | + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); | |
28263 | + if (unlikely(!au_procfs_dir)) | |
28264 | + goto out; | |
28265 | + | |
28266 | + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR, | |
28267 | + au_procfs_dir, &au_procfs_plm_fop); | |
28268 | + if (unlikely(!entry)) | |
28269 | + goto out_dir; | |
28270 | + | |
28271 | + err = 0; | |
28272 | + goto out; /* success */ | |
28273 | + | |
28274 | + | |
28275 | +out_dir: | |
28276 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
28277 | +out: | |
28278 | + return err; | |
28279 | +} | |
7f207e10 AM |
28280 | diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c |
28281 | --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 28282 | +++ linux/fs/aufs/rdu.c 2018-01-29 07:56:20.059991935 +0100 |
5afbbe0d | 28283 | @@ -0,0 +1,381 @@ |
1308ab2a | 28284 | +/* |
a2654f78 | 28285 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1308ab2a | 28286 | + * |
28287 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28288 | + * it under the terms of the GNU General Public License as published by | |
28289 | + * the Free Software Foundation; either version 2 of the License, or | |
28290 | + * (at your option) any later version. | |
28291 | + * | |
28292 | + * This program is distributed in the hope that it will be useful, | |
28293 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28294 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28295 | + * GNU General Public License for more details. | |
28296 | + * | |
28297 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28298 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1308ab2a | 28299 | + */ |
28300 | + | |
28301 | +/* | |
28302 | + * readdir in userspace. | |
28303 | + */ | |
28304 | + | |
b752ccd1 | 28305 | +#include <linux/compat.h> |
4a4d8108 | 28306 | +#include <linux/fs_stack.h> |
1308ab2a | 28307 | +#include <linux/security.h> |
1308ab2a | 28308 | +#include "aufs.h" |
28309 | + | |
28310 | +/* bits for struct aufs_rdu.flags */ | |
28311 | +#define AuRdu_CALLED 1 | |
28312 | +#define AuRdu_CONT (1 << 1) | |
28313 | +#define AuRdu_FULL (1 << 2) | |
28314 | +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name) | |
7f207e10 AM |
28315 | +#define au_fset_rdu(flags, name) \ |
28316 | + do { (flags) |= AuRdu_##name; } while (0) | |
28317 | +#define au_fclr_rdu(flags, name) \ | |
28318 | + do { (flags) &= ~AuRdu_##name; } while (0) | |
1308ab2a | 28319 | + |
28320 | +struct au_rdu_arg { | |
392086de | 28321 | + struct dir_context ctx; |
1308ab2a | 28322 | + struct aufs_rdu *rdu; |
28323 | + union au_rdu_ent_ul ent; | |
28324 | + unsigned long end; | |
28325 | + | |
28326 | + struct super_block *sb; | |
28327 | + int err; | |
28328 | +}; | |
28329 | + | |
392086de | 28330 | +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen, |
1308ab2a | 28331 | + loff_t offset, u64 h_ino, unsigned int d_type) |
28332 | +{ | |
28333 | + int err, len; | |
392086de | 28334 | + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx); |
1308ab2a | 28335 | + struct aufs_rdu *rdu = arg->rdu; |
28336 | + struct au_rdu_ent ent; | |
28337 | + | |
28338 | + err = 0; | |
28339 | + arg->err = 0; | |
28340 | + au_fset_rdu(rdu->cookie.flags, CALLED); | |
28341 | + len = au_rdu_len(nlen); | |
28342 | + if (arg->ent.ul + len < arg->end) { | |
28343 | + ent.ino = h_ino; | |
28344 | + ent.bindex = rdu->cookie.bindex; | |
28345 | + ent.type = d_type; | |
28346 | + ent.nlen = nlen; | |
4a4d8108 AM |
28347 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) |
28348 | + ent.type = DT_UNKNOWN; | |
1308ab2a | 28349 | + |
9dbd164d | 28350 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 28351 | + err = -EFAULT; |
28352 | + if (copy_to_user(arg->ent.e, &ent, sizeof(ent))) | |
28353 | + goto out; | |
28354 | + if (copy_to_user(arg->ent.e->name, name, nlen)) | |
28355 | + goto out; | |
28356 | + /* the terminating NULL */ | |
28357 | + if (__put_user(0, arg->ent.e->name + nlen)) | |
28358 | + goto out; | |
28359 | + err = 0; | |
28360 | + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */ | |
28361 | + arg->ent.ul += len; | |
28362 | + rdu->rent++; | |
28363 | + } else { | |
28364 | + err = -EFAULT; | |
28365 | + au_fset_rdu(rdu->cookie.flags, FULL); | |
28366 | + rdu->full = 1; | |
28367 | + rdu->tail = arg->ent; | |
28368 | + } | |
28369 | + | |
4f0767ce | 28370 | +out: |
1308ab2a | 28371 | + /* AuTraceErr(err); */ |
28372 | + return err; | |
28373 | +} | |
28374 | + | |
28375 | +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg) | |
28376 | +{ | |
28377 | + int err; | |
28378 | + loff_t offset; | |
28379 | + struct au_rdu_cookie *cookie = &arg->rdu->cookie; | |
28380 | + | |
92d182d2 | 28381 | + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */ |
1308ab2a | 28382 | + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET); |
28383 | + err = offset; | |
28384 | + if (unlikely(offset != cookie->h_pos)) | |
28385 | + goto out; | |
28386 | + | |
28387 | + err = 0; | |
28388 | + do { | |
28389 | + arg->err = 0; | |
28390 | + au_fclr_rdu(cookie->flags, CALLED); | |
28391 | + /* smp_mb(); */ | |
392086de | 28392 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1308ab2a | 28393 | + if (err >= 0) |
28394 | + err = arg->err; | |
28395 | + } while (!err | |
28396 | + && au_ftest_rdu(cookie->flags, CALLED) | |
28397 | + && !au_ftest_rdu(cookie->flags, FULL)); | |
28398 | + cookie->h_pos = h_file->f_pos; | |
28399 | + | |
4f0767ce | 28400 | +out: |
1308ab2a | 28401 | + AuTraceErr(err); |
28402 | + return err; | |
28403 | +} | |
28404 | + | |
28405 | +static int au_rdu(struct file *file, struct aufs_rdu *rdu) | |
28406 | +{ | |
28407 | + int err; | |
5afbbe0d | 28408 | + aufs_bindex_t bbot; |
392086de AM |
28409 | + struct au_rdu_arg arg = { |
28410 | + .ctx = { | |
2000de60 | 28411 | + .actor = au_rdu_fill |
392086de AM |
28412 | + } |
28413 | + }; | |
1308ab2a | 28414 | + struct dentry *dentry; |
28415 | + struct inode *inode; | |
28416 | + struct file *h_file; | |
28417 | + struct au_rdu_cookie *cookie = &rdu->cookie; | |
28418 | + | |
28419 | + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz); | |
28420 | + if (unlikely(err)) { | |
28421 | + err = -EFAULT; | |
28422 | + AuTraceErr(err); | |
28423 | + goto out; | |
28424 | + } | |
28425 | + rdu->rent = 0; | |
28426 | + rdu->tail = rdu->ent; | |
28427 | + rdu->full = 0; | |
28428 | + arg.rdu = rdu; | |
28429 | + arg.ent = rdu->ent; | |
28430 | + arg.end = arg.ent.ul; | |
28431 | + arg.end += rdu->sz; | |
28432 | + | |
28433 | + err = -ENOTDIR; | |
5afbbe0d | 28434 | + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared)) |
1308ab2a | 28435 | + goto out; |
28436 | + | |
28437 | + err = security_file_permission(file, MAY_READ); | |
28438 | + AuTraceErr(err); | |
28439 | + if (unlikely(err)) | |
28440 | + goto out; | |
28441 | + | |
2000de60 | 28442 | + dentry = file->f_path.dentry; |
5527c038 | 28443 | + inode = d_inode(dentry); |
5afbbe0d | 28444 | + inode_lock_shared(inode); |
1308ab2a | 28445 | + |
28446 | + arg.sb = inode->i_sb; | |
e49829fe JR |
28447 | + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM); |
28448 | + if (unlikely(err)) | |
28449 | + goto out_mtx; | |
027c5e7a AM |
28450 | + err = au_alive_dir(dentry); |
28451 | + if (unlikely(err)) | |
28452 | + goto out_si; | |
e49829fe | 28453 | + /* todo: reval? */ |
1308ab2a | 28454 | + fi_read_lock(file); |
28455 | + | |
28456 | + err = -EAGAIN; | |
28457 | + if (unlikely(au_ftest_rdu(cookie->flags, CONT) | |
28458 | + && cookie->generation != au_figen(file))) | |
28459 | + goto out_unlock; | |
28460 | + | |
28461 | + err = 0; | |
28462 | + if (!rdu->blk) { | |
28463 | + rdu->blk = au_sbi(arg.sb)->si_rdblk; | |
28464 | + if (!rdu->blk) | |
28465 | + rdu->blk = au_dir_size(file, /*dentry*/NULL); | |
28466 | + } | |
5afbbe0d AM |
28467 | + bbot = au_fbtop(file); |
28468 | + if (cookie->bindex < bbot) | |
28469 | + cookie->bindex = bbot; | |
28470 | + bbot = au_fbbot_dir(file); | |
28471 | + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */ | |
28472 | + for (; !err && cookie->bindex <= bbot; | |
1308ab2a | 28473 | + cookie->bindex++, cookie->h_pos = 0) { |
4a4d8108 | 28474 | + h_file = au_hf_dir(file, cookie->bindex); |
1308ab2a | 28475 | + if (!h_file) |
28476 | + continue; | |
28477 | + | |
28478 | + au_fclr_rdu(cookie->flags, FULL); | |
28479 | + err = au_rdu_do(h_file, &arg); | |
28480 | + AuTraceErr(err); | |
28481 | + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err)) | |
28482 | + break; | |
28483 | + } | |
28484 | + AuDbg("rent %llu\n", rdu->rent); | |
28485 | + | |
28486 | + if (!err && !au_ftest_rdu(cookie->flags, CONT)) { | |
28487 | + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH); | |
28488 | + au_fset_rdu(cookie->flags, CONT); | |
28489 | + cookie->generation = au_figen(file); | |
28490 | + } | |
28491 | + | |
28492 | + ii_read_lock_child(inode); | |
5afbbe0d | 28493 | + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode))); |
1308ab2a | 28494 | + ii_read_unlock(inode); |
28495 | + | |
4f0767ce | 28496 | +out_unlock: |
1308ab2a | 28497 | + fi_read_unlock(file); |
027c5e7a | 28498 | +out_si: |
1308ab2a | 28499 | + si_read_unlock(arg.sb); |
4f0767ce | 28500 | +out_mtx: |
5afbbe0d | 28501 | + inode_unlock_shared(inode); |
4f0767ce | 28502 | +out: |
1308ab2a | 28503 | + AuTraceErr(err); |
28504 | + return err; | |
28505 | +} | |
28506 | + | |
28507 | +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu) | |
28508 | +{ | |
28509 | + int err; | |
28510 | + ino_t ino; | |
28511 | + unsigned long long nent; | |
28512 | + union au_rdu_ent_ul *u; | |
28513 | + struct au_rdu_ent ent; | |
28514 | + struct super_block *sb; | |
28515 | + | |
28516 | + err = 0; | |
28517 | + nent = rdu->nent; | |
28518 | + u = &rdu->ent; | |
2000de60 | 28519 | + sb = file->f_path.dentry->d_sb; |
1308ab2a | 28520 | + si_read_lock(sb, AuLock_FLUSH); |
28521 | + while (nent-- > 0) { | |
9dbd164d | 28522 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 28523 | + err = copy_from_user(&ent, u->e, sizeof(ent)); |
4a4d8108 AM |
28524 | + if (!err) |
28525 | + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino)); | |
1308ab2a | 28526 | + if (unlikely(err)) { |
28527 | + err = -EFAULT; | |
28528 | + AuTraceErr(err); | |
28529 | + break; | |
28530 | + } | |
28531 | + | |
28532 | + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */ | |
28533 | + if (!ent.wh) | |
28534 | + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino); | |
28535 | + else | |
28536 | + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type, | |
28537 | + &ino); | |
28538 | + if (unlikely(err)) { | |
28539 | + AuTraceErr(err); | |
28540 | + break; | |
28541 | + } | |
28542 | + | |
28543 | + err = __put_user(ino, &u->e->ino); | |
28544 | + if (unlikely(err)) { | |
28545 | + err = -EFAULT; | |
28546 | + AuTraceErr(err); | |
28547 | + break; | |
28548 | + } | |
28549 | + u->ul += au_rdu_len(ent.nlen); | |
28550 | + } | |
28551 | + si_read_unlock(sb); | |
28552 | + | |
28553 | + return err; | |
28554 | +} | |
28555 | + | |
28556 | +/* ---------------------------------------------------------------------- */ | |
28557 | + | |
28558 | +static int au_rdu_verify(struct aufs_rdu *rdu) | |
28559 | +{ | |
b752ccd1 | 28560 | + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | " |
1308ab2a | 28561 | + "%llu, b%d, 0x%x, g%u}\n", |
b752ccd1 | 28562 | + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ], |
1308ab2a | 28563 | + rdu->blk, |
28564 | + rdu->rent, rdu->shwh, rdu->full, | |
28565 | + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags, | |
28566 | + rdu->cookie.generation); | |
dece6358 | 28567 | + |
b752ccd1 | 28568 | + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu)) |
1308ab2a | 28569 | + return 0; |
dece6358 | 28570 | + |
b752ccd1 AM |
28571 | + AuDbg("%u:%u\n", |
28572 | + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu)); | |
1308ab2a | 28573 | + return -EINVAL; |
28574 | +} | |
28575 | + | |
28576 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
dece6358 | 28577 | +{ |
1308ab2a | 28578 | + long err, e; |
28579 | + struct aufs_rdu rdu; | |
28580 | + void __user *p = (void __user *)arg; | |
dece6358 | 28581 | + |
1308ab2a | 28582 | + err = copy_from_user(&rdu, p, sizeof(rdu)); |
28583 | + if (unlikely(err)) { | |
28584 | + err = -EFAULT; | |
28585 | + AuTraceErr(err); | |
28586 | + goto out; | |
28587 | + } | |
28588 | + err = au_rdu_verify(&rdu); | |
dece6358 AM |
28589 | + if (unlikely(err)) |
28590 | + goto out; | |
28591 | + | |
1308ab2a | 28592 | + switch (cmd) { |
28593 | + case AUFS_CTL_RDU: | |
28594 | + err = au_rdu(file, &rdu); | |
28595 | + if (unlikely(err)) | |
28596 | + break; | |
dece6358 | 28597 | + |
1308ab2a | 28598 | + e = copy_to_user(p, &rdu, sizeof(rdu)); |
28599 | + if (unlikely(e)) { | |
28600 | + err = -EFAULT; | |
28601 | + AuTraceErr(err); | |
28602 | + } | |
28603 | + break; | |
28604 | + case AUFS_CTL_RDU_INO: | |
28605 | + err = au_rdu_ino(file, &rdu); | |
28606 | + break; | |
28607 | + | |
28608 | + default: | |
4a4d8108 | 28609 | + /* err = -ENOTTY; */ |
1308ab2a | 28610 | + err = -EINVAL; |
28611 | + } | |
dece6358 | 28612 | + |
4f0767ce | 28613 | +out: |
1308ab2a | 28614 | + AuTraceErr(err); |
28615 | + return err; | |
1facf9fc | 28616 | +} |
b752ccd1 AM |
28617 | + |
28618 | +#ifdef CONFIG_COMPAT | |
28619 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
28620 | +{ | |
28621 | + long err, e; | |
28622 | + struct aufs_rdu rdu; | |
28623 | + void __user *p = compat_ptr(arg); | |
28624 | + | |
28625 | + /* todo: get_user()? */ | |
28626 | + err = copy_from_user(&rdu, p, sizeof(rdu)); | |
28627 | + if (unlikely(err)) { | |
28628 | + err = -EFAULT; | |
28629 | + AuTraceErr(err); | |
28630 | + goto out; | |
28631 | + } | |
28632 | + rdu.ent.e = compat_ptr(rdu.ent.ul); | |
28633 | + err = au_rdu_verify(&rdu); | |
28634 | + if (unlikely(err)) | |
28635 | + goto out; | |
28636 | + | |
28637 | + switch (cmd) { | |
28638 | + case AUFS_CTL_RDU: | |
28639 | + err = au_rdu(file, &rdu); | |
28640 | + if (unlikely(err)) | |
28641 | + break; | |
28642 | + | |
28643 | + rdu.ent.ul = ptr_to_compat(rdu.ent.e); | |
28644 | + rdu.tail.ul = ptr_to_compat(rdu.tail.e); | |
28645 | + e = copy_to_user(p, &rdu, sizeof(rdu)); | |
28646 | + if (unlikely(e)) { | |
28647 | + err = -EFAULT; | |
28648 | + AuTraceErr(err); | |
28649 | + } | |
28650 | + break; | |
28651 | + case AUFS_CTL_RDU_INO: | |
28652 | + err = au_rdu_ino(file, &rdu); | |
28653 | + break; | |
28654 | + | |
28655 | + default: | |
28656 | + /* err = -ENOTTY; */ | |
28657 | + err = -EINVAL; | |
28658 | + } | |
28659 | + | |
4f0767ce | 28660 | +out: |
b752ccd1 AM |
28661 | + AuTraceErr(err); |
28662 | + return err; | |
28663 | +} | |
28664 | +#endif | |
7f207e10 AM |
28665 | diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h |
28666 | --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 28667 | +++ linux/fs/aufs/rwsem.h 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 28668 | @@ -0,0 +1,72 @@ |
1facf9fc | 28669 | +/* |
a2654f78 | 28670 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 28671 | + * |
28672 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28673 | + * it under the terms of the GNU General Public License as published by | |
28674 | + * the Free Software Foundation; either version 2 of the License, or | |
28675 | + * (at your option) any later version. | |
dece6358 AM |
28676 | + * |
28677 | + * This program is distributed in the hope that it will be useful, | |
28678 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28679 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28680 | + * GNU General Public License for more details. | |
28681 | + * | |
28682 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28683 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28684 | + */ |
28685 | + | |
28686 | +/* | |
28687 | + * simple read-write semaphore wrappers | |
28688 | + */ | |
28689 | + | |
28690 | +#ifndef __AUFS_RWSEM_H__ | |
28691 | +#define __AUFS_RWSEM_H__ | |
28692 | + | |
28693 | +#ifdef __KERNEL__ | |
28694 | + | |
4a4d8108 | 28695 | +#include "debug.h" |
dece6358 | 28696 | + |
8b6a4947 AM |
28697 | +/* in the futre, the name 'au_rwsem' will be totally gone */ |
28698 | +#define au_rwsem rw_semaphore | |
dece6358 AM |
28699 | + |
28700 | +/* to debug easier, do not make them inlined functions */ | |
8b6a4947 | 28701 | +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw)) |
dece6358 | 28702 | +/* rwsem_is_locked() is unusable */ |
8b6a4947 AM |
28703 | +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \ |
28704 | + && debug_locks \ | |
28705 | + && !lockdep_is_held_type(rw, 1)) | |
28706 | +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
28707 | + && debug_locks \ | |
28708 | + && !lockdep_is_held_type(rw, 0)) | |
28709 | +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
28710 | + && debug_locks \ | |
28711 | + && !lockdep_is_held(rw)) | |
28712 | +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \ | |
28713 | + && debug_locks \ | |
28714 | + && lockdep_is_held(rw)) | |
28715 | + | |
28716 | +#define au_rw_init(rw) init_rwsem(rw) | |
dece6358 | 28717 | + |
5afbbe0d AM |
28718 | +#define au_rw_init_wlock(rw) do { \ |
28719 | + au_rw_init(rw); \ | |
8b6a4947 | 28720 | + down_write(rw); \ |
5afbbe0d | 28721 | + } while (0) |
dece6358 | 28722 | + |
8b6a4947 AM |
28723 | +#define au_rw_init_wlock_nested(rw, lsc) do { \ |
28724 | + au_rw_init(rw); \ | |
28725 | + down_write_nested(rw, lsc); \ | |
5afbbe0d | 28726 | + } while (0) |
dece6358 | 28727 | + |
8b6a4947 AM |
28728 | +#define au_rw_read_lock(rw) down_read(rw) |
28729 | +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc) | |
28730 | +#define au_rw_read_unlock(rw) up_read(rw) | |
28731 | +#define au_rw_dgrade_lock(rw) downgrade_write(rw) | |
28732 | +#define au_rw_write_lock(rw) down_write(rw) | |
28733 | +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc) | |
28734 | +#define au_rw_write_unlock(rw) up_write(rw) | |
28735 | +/* why is not _nested version defined? */ | |
28736 | +#define au_rw_read_trylock(rw) down_read_trylock(rw) | |
28737 | +#define au_rw_write_trylock(rw) down_write_trylock(rw) | |
1facf9fc | 28738 | + |
28739 | +#endif /* __KERNEL__ */ | |
28740 | +#endif /* __AUFS_RWSEM_H__ */ | |
7f207e10 AM |
28741 | diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c |
28742 | --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 28743 | +++ linux/fs/aufs/sbinfo.c 2018-01-29 07:56:20.059991935 +0100 |
a2654f78 | 28744 | @@ -0,0 +1,304 @@ |
1facf9fc | 28745 | +/* |
a2654f78 | 28746 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 28747 | + * |
28748 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28749 | + * it under the terms of the GNU General Public License as published by | |
28750 | + * the Free Software Foundation; either version 2 of the License, or | |
28751 | + * (at your option) any later version. | |
dece6358 AM |
28752 | + * |
28753 | + * This program is distributed in the hope that it will be useful, | |
28754 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28755 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28756 | + * GNU General Public License for more details. | |
28757 | + * | |
28758 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28759 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 28760 | + */ |
28761 | + | |
28762 | +/* | |
28763 | + * superblock private data | |
28764 | + */ | |
28765 | + | |
28766 | +#include "aufs.h" | |
28767 | + | |
28768 | +/* | |
28769 | + * they are necessary regardless sysfs is disabled. | |
28770 | + */ | |
28771 | +void au_si_free(struct kobject *kobj) | |
28772 | +{ | |
86dc4139 | 28773 | + int i; |
1facf9fc | 28774 | + struct au_sbinfo *sbinfo; |
b752ccd1 | 28775 | + char *locked __maybe_unused; /* debug only */ |
1facf9fc | 28776 | + |
28777 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
86dc4139 | 28778 | + for (i = 0; i < AuPlink_NHASH; i++) |
8b6a4947 | 28779 | + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i)); |
f0c0a007 | 28780 | + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len)); |
5afbbe0d AM |
28781 | + |
28782 | + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes)); | |
28783 | + percpu_counter_destroy(&sbinfo->si_ninodes); | |
28784 | + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles)); | |
28785 | + percpu_counter_destroy(&sbinfo->si_nfiles); | |
1facf9fc | 28786 | + |
e49829fe | 28787 | + au_rw_write_lock(&sbinfo->si_rwsem); |
1facf9fc | 28788 | + au_br_free(sbinfo); |
e49829fe | 28789 | + au_rw_write_unlock(&sbinfo->si_rwsem); |
b752ccd1 | 28790 | + |
1c60b727 | 28791 | + kfree(sbinfo->si_branch); |
1facf9fc | 28792 | + mutex_destroy(&sbinfo->si_xib_mtx); |
dece6358 | 28793 | + AuRwDestroy(&sbinfo->si_rwsem); |
1facf9fc | 28794 | + |
1c60b727 | 28795 | + kfree(sbinfo); |
1facf9fc | 28796 | +} |
28797 | + | |
28798 | +int au_si_alloc(struct super_block *sb) | |
28799 | +{ | |
86dc4139 | 28800 | + int err, i; |
1facf9fc | 28801 | + struct au_sbinfo *sbinfo; |
28802 | + | |
28803 | + err = -ENOMEM; | |
4a4d8108 | 28804 | + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS); |
1facf9fc | 28805 | + if (unlikely(!sbinfo)) |
28806 | + goto out; | |
28807 | + | |
28808 | + /* will be reallocated separately */ | |
28809 | + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS); | |
28810 | + if (unlikely(!sbinfo->si_branch)) | |
febd17d6 | 28811 | + goto out_sbinfo; |
1facf9fc | 28812 | + |
1facf9fc | 28813 | + err = sysaufs_si_init(sbinfo); |
28814 | + if (unlikely(err)) | |
28815 | + goto out_br; | |
28816 | + | |
28817 | + au_nwt_init(&sbinfo->si_nowait); | |
dece6358 | 28818 | + au_rw_init_wlock(&sbinfo->si_rwsem); |
b752ccd1 | 28819 | + |
5afbbe0d AM |
28820 | + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS); |
28821 | + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS); | |
7f207e10 | 28822 | + |
5afbbe0d | 28823 | + sbinfo->si_bbot = -1; |
392086de | 28824 | + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2; |
1facf9fc | 28825 | + |
28826 | + sbinfo->si_wbr_copyup = AuWbrCopyup_Def; | |
28827 | + sbinfo->si_wbr_create = AuWbrCreate_Def; | |
4a4d8108 AM |
28828 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup; |
28829 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create; | |
1facf9fc | 28830 | + |
076b876e AM |
28831 | + au_fhsm_init(sbinfo); |
28832 | + | |
e49829fe | 28833 | + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def); |
1facf9fc | 28834 | + |
392086de AM |
28835 | + sbinfo->si_xino_jiffy = jiffies; |
28836 | + sbinfo->si_xino_expire | |
28837 | + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC); | |
1facf9fc | 28838 | + mutex_init(&sbinfo->si_xib_mtx); |
1facf9fc | 28839 | + sbinfo->si_xino_brid = -1; |
28840 | + /* leave si_xib_last_pindex and si_xib_next_bit */ | |
28841 | + | |
8b6a4947 | 28842 | + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen); |
b912730e | 28843 | + |
e49829fe | 28844 | + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC); |
1facf9fc | 28845 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; |
28846 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
28847 | + sbinfo->si_dirwh = AUFS_DIRWH_DEF; | |
28848 | + | |
86dc4139 | 28849 | + for (i = 0; i < AuPlink_NHASH; i++) |
8b6a4947 | 28850 | + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i); |
1facf9fc | 28851 | + init_waitqueue_head(&sbinfo->si_plink_wq); |
4a4d8108 | 28852 | + spin_lock_init(&sbinfo->si_plink_maint_lock); |
1facf9fc | 28853 | + |
8b6a4947 | 28854 | + INIT_HLIST_BL_HEAD(&sbinfo->si_files); |
523b37e3 | 28855 | + |
b95c5147 AM |
28856 | + /* with getattr by default */ |
28857 | + sbinfo->si_iop_array = aufs_iop; | |
28858 | + | |
1facf9fc | 28859 | + /* leave other members for sysaufs and si_mnt. */ |
28860 | + sbinfo->si_sb = sb; | |
28861 | + sb->s_fs_info = sbinfo; | |
b752ccd1 | 28862 | + si_pid_set(sb); |
1facf9fc | 28863 | + return 0; /* success */ |
28864 | + | |
4f0767ce | 28865 | +out_br: |
1c60b727 | 28866 | + kfree(sbinfo->si_branch); |
4f0767ce | 28867 | +out_sbinfo: |
1c60b727 | 28868 | + kfree(sbinfo); |
4f0767ce | 28869 | +out: |
1facf9fc | 28870 | + return err; |
28871 | +} | |
28872 | + | |
e2f27e51 | 28873 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink) |
1facf9fc | 28874 | +{ |
28875 | + int err, sz; | |
28876 | + struct au_branch **brp; | |
28877 | + | |
dece6358 AM |
28878 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
28879 | + | |
1facf9fc | 28880 | + err = -ENOMEM; |
5afbbe0d | 28881 | + sz = sizeof(*brp) * (sbinfo->si_bbot + 1); |
1facf9fc | 28882 | + if (unlikely(!sz)) |
28883 | + sz = sizeof(*brp); | |
e2f27e51 AM |
28884 | + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS, |
28885 | + may_shrink); | |
1facf9fc | 28886 | + if (brp) { |
28887 | + sbinfo->si_branch = brp; | |
28888 | + err = 0; | |
28889 | + } | |
28890 | + | |
28891 | + return err; | |
28892 | +} | |
28893 | + | |
28894 | +/* ---------------------------------------------------------------------- */ | |
28895 | + | |
28896 | +unsigned int au_sigen_inc(struct super_block *sb) | |
28897 | +{ | |
28898 | + unsigned int gen; | |
5527c038 | 28899 | + struct inode *inode; |
1facf9fc | 28900 | + |
dece6358 AM |
28901 | + SiMustWriteLock(sb); |
28902 | + | |
1facf9fc | 28903 | + gen = ++au_sbi(sb)->si_generation; |
28904 | + au_update_digen(sb->s_root); | |
5527c038 JR |
28905 | + inode = d_inode(sb->s_root); |
28906 | + au_update_iigen(inode, /*half*/0); | |
28907 | + inode->i_version++; | |
1facf9fc | 28908 | + return gen; |
28909 | +} | |
28910 | + | |
28911 | +aufs_bindex_t au_new_br_id(struct super_block *sb) | |
28912 | +{ | |
28913 | + aufs_bindex_t br_id; | |
28914 | + int i; | |
28915 | + struct au_sbinfo *sbinfo; | |
28916 | + | |
dece6358 AM |
28917 | + SiMustWriteLock(sb); |
28918 | + | |
1facf9fc | 28919 | + sbinfo = au_sbi(sb); |
28920 | + for (i = 0; i <= AUFS_BRANCH_MAX; i++) { | |
28921 | + br_id = ++sbinfo->si_last_br_id; | |
7f207e10 | 28922 | + AuDebugOn(br_id < 0); |
1facf9fc | 28923 | + if (br_id && au_br_index(sb, br_id) < 0) |
28924 | + return br_id; | |
28925 | + } | |
28926 | + | |
28927 | + return -1; | |
28928 | +} | |
28929 | + | |
28930 | +/* ---------------------------------------------------------------------- */ | |
28931 | + | |
e49829fe JR |
28932 | +/* it is ok that new 'nwt' tasks are appended while we are sleeping */ |
28933 | +int si_read_lock(struct super_block *sb, int flags) | |
28934 | +{ | |
28935 | + int err; | |
28936 | + | |
28937 | + err = 0; | |
28938 | + if (au_ftest_lock(flags, FLUSH)) | |
28939 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28940 | + | |
28941 | + si_noflush_read_lock(sb); | |
28942 | + err = au_plink_maint(sb, flags); | |
28943 | + if (unlikely(err)) | |
28944 | + si_read_unlock(sb); | |
28945 | + | |
28946 | + return err; | |
28947 | +} | |
28948 | + | |
28949 | +int si_write_lock(struct super_block *sb, int flags) | |
28950 | +{ | |
28951 | + int err; | |
28952 | + | |
28953 | + if (au_ftest_lock(flags, FLUSH)) | |
28954 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
28955 | + | |
28956 | + si_noflush_write_lock(sb); | |
28957 | + err = au_plink_maint(sb, flags); | |
28958 | + if (unlikely(err)) | |
28959 | + si_write_unlock(sb); | |
28960 | + | |
28961 | + return err; | |
28962 | +} | |
28963 | + | |
1facf9fc | 28964 | +/* dentry and super_block lock. call at entry point */ |
e49829fe | 28965 | +int aufs_read_lock(struct dentry *dentry, int flags) |
1facf9fc | 28966 | +{ |
e49829fe | 28967 | + int err; |
027c5e7a | 28968 | + struct super_block *sb; |
e49829fe | 28969 | + |
027c5e7a AM |
28970 | + sb = dentry->d_sb; |
28971 | + err = si_read_lock(sb, flags); | |
28972 | + if (unlikely(err)) | |
28973 | + goto out; | |
28974 | + | |
28975 | + if (au_ftest_lock(flags, DW)) | |
28976 | + di_write_lock_child(dentry); | |
28977 | + else | |
28978 | + di_read_lock_child(dentry, flags); | |
28979 | + | |
28980 | + if (au_ftest_lock(flags, GEN)) { | |
28981 | + err = au_digen_test(dentry, au_sigen(sb)); | |
79b8bda9 AM |
28982 | + if (!au_opt_test(au_mntflags(sb), UDBA_NONE)) |
28983 | + AuDebugOn(!err && au_dbrange_test(dentry)); | |
28984 | + else if (!err) | |
28985 | + err = au_dbrange_test(dentry); | |
027c5e7a AM |
28986 | + if (unlikely(err)) |
28987 | + aufs_read_unlock(dentry, flags); | |
e49829fe JR |
28988 | + } |
28989 | + | |
027c5e7a | 28990 | +out: |
e49829fe | 28991 | + return err; |
1facf9fc | 28992 | +} |
28993 | + | |
28994 | +void aufs_read_unlock(struct dentry *dentry, int flags) | |
28995 | +{ | |
28996 | + if (au_ftest_lock(flags, DW)) | |
28997 | + di_write_unlock(dentry); | |
28998 | + else | |
28999 | + di_read_unlock(dentry, flags); | |
29000 | + si_read_unlock(dentry->d_sb); | |
29001 | +} | |
29002 | + | |
29003 | +void aufs_write_lock(struct dentry *dentry) | |
29004 | +{ | |
e49829fe | 29005 | + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW); |
1facf9fc | 29006 | + di_write_lock_child(dentry); |
29007 | +} | |
29008 | + | |
29009 | +void aufs_write_unlock(struct dentry *dentry) | |
29010 | +{ | |
29011 | + di_write_unlock(dentry); | |
29012 | + si_write_unlock(dentry->d_sb); | |
29013 | +} | |
29014 | + | |
e49829fe | 29015 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags) |
1facf9fc | 29016 | +{ |
e49829fe | 29017 | + int err; |
027c5e7a AM |
29018 | + unsigned int sigen; |
29019 | + struct super_block *sb; | |
e49829fe | 29020 | + |
027c5e7a AM |
29021 | + sb = d1->d_sb; |
29022 | + err = si_read_lock(sb, flags); | |
29023 | + if (unlikely(err)) | |
29024 | + goto out; | |
29025 | + | |
b95c5147 | 29026 | + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS)); |
027c5e7a AM |
29027 | + |
29028 | + if (au_ftest_lock(flags, GEN)) { | |
29029 | + sigen = au_sigen(sb); | |
29030 | + err = au_digen_test(d1, sigen); | |
29031 | + AuDebugOn(!err && au_dbrange_test(d1)); | |
29032 | + if (!err) { | |
29033 | + err = au_digen_test(d2, sigen); | |
29034 | + AuDebugOn(!err && au_dbrange_test(d2)); | |
29035 | + } | |
29036 | + if (unlikely(err)) | |
29037 | + aufs_read_and_write_unlock2(d1, d2); | |
29038 | + } | |
29039 | + | |
29040 | +out: | |
e49829fe | 29041 | + return err; |
1facf9fc | 29042 | +} |
29043 | + | |
29044 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2) | |
29045 | +{ | |
29046 | + di_write_unlock2(d1, d2); | |
29047 | + si_read_unlock(d1->d_sb); | |
29048 | +} | |
7f207e10 AM |
29049 | diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c |
29050 | --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 29051 | +++ linux/fs/aufs/super.c 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 29052 | @@ -0,0 +1,1046 @@ |
1facf9fc | 29053 | +/* |
a2654f78 | 29054 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 29055 | + * |
29056 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29057 | + * it under the terms of the GNU General Public License as published by | |
29058 | + * the Free Software Foundation; either version 2 of the License, or | |
29059 | + * (at your option) any later version. | |
dece6358 AM |
29060 | + * |
29061 | + * This program is distributed in the hope that it will be useful, | |
29062 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29063 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29064 | + * GNU General Public License for more details. | |
29065 | + * | |
29066 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29067 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29068 | + */ |
29069 | + | |
29070 | +/* | |
29071 | + * mount and super_block operations | |
29072 | + */ | |
29073 | + | |
f6c5ef8b | 29074 | +#include <linux/mm.h> |
1facf9fc | 29075 | +#include <linux/seq_file.h> |
29076 | +#include <linux/statfs.h> | |
7f207e10 | 29077 | +#include <linux/vmalloc.h> |
1facf9fc | 29078 | +#include "aufs.h" |
29079 | + | |
29080 | +/* | |
29081 | + * super_operations | |
29082 | + */ | |
29083 | +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused) | |
29084 | +{ | |
29085 | + struct au_icntnr *c; | |
29086 | + | |
29087 | + c = au_cache_alloc_icntnr(); | |
29088 | + if (c) { | |
027c5e7a | 29089 | + au_icntnr_init(c); |
1facf9fc | 29090 | + c->vfs_inode.i_version = 1; /* sigen(sb); */ |
29091 | + c->iinfo.ii_hinode = NULL; | |
29092 | + return &c->vfs_inode; | |
29093 | + } | |
29094 | + return NULL; | |
29095 | +} | |
29096 | + | |
027c5e7a AM |
29097 | +static void aufs_destroy_inode_cb(struct rcu_head *head) |
29098 | +{ | |
29099 | + struct inode *inode = container_of(head, struct inode, i_rcu); | |
29100 | + | |
1c60b727 | 29101 | + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode)); |
027c5e7a AM |
29102 | +} |
29103 | + | |
1facf9fc | 29104 | +static void aufs_destroy_inode(struct inode *inode) |
29105 | +{ | |
5afbbe0d AM |
29106 | + if (!au_is_bad_inode(inode)) |
29107 | + au_iinfo_fin(inode); | |
027c5e7a | 29108 | + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb); |
1facf9fc | 29109 | +} |
29110 | + | |
29111 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino) | |
29112 | +{ | |
29113 | + struct inode *inode; | |
29114 | + int err; | |
29115 | + | |
29116 | + inode = iget_locked(sb, ino); | |
29117 | + if (unlikely(!inode)) { | |
29118 | + inode = ERR_PTR(-ENOMEM); | |
29119 | + goto out; | |
29120 | + } | |
29121 | + if (!(inode->i_state & I_NEW)) | |
29122 | + goto out; | |
29123 | + | |
29124 | + err = au_xigen_new(inode); | |
29125 | + if (!err) | |
29126 | + err = au_iinfo_init(inode); | |
29127 | + if (!err) | |
29128 | + inode->i_version++; | |
29129 | + else { | |
29130 | + iget_failed(inode); | |
29131 | + inode = ERR_PTR(err); | |
29132 | + } | |
29133 | + | |
4f0767ce | 29134 | +out: |
1facf9fc | 29135 | + /* never return NULL */ |
29136 | + AuDebugOn(!inode); | |
29137 | + AuTraceErrPtr(inode); | |
29138 | + return inode; | |
29139 | +} | |
29140 | + | |
29141 | +/* lock free root dinfo */ | |
29142 | +static int au_show_brs(struct seq_file *seq, struct super_block *sb) | |
29143 | +{ | |
29144 | + int err; | |
5afbbe0d | 29145 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 29146 | + struct path path; |
4a4d8108 | 29147 | + struct au_hdentry *hdp; |
1facf9fc | 29148 | + struct au_branch *br; |
076b876e | 29149 | + au_br_perm_str_t perm; |
1facf9fc | 29150 | + |
29151 | + err = 0; | |
5afbbe0d AM |
29152 | + bbot = au_sbbot(sb); |
29153 | + bindex = 0; | |
29154 | + hdp = au_hdentry(au_di(sb->s_root), bindex); | |
29155 | + for (; !err && bindex <= bbot; bindex++, hdp++) { | |
1facf9fc | 29156 | + br = au_sbr(sb, bindex); |
86dc4139 | 29157 | + path.mnt = au_br_mnt(br); |
5afbbe0d | 29158 | + path.dentry = hdp->hd_dentry; |
1facf9fc | 29159 | + err = au_seq_path(seq, &path); |
79b8bda9 | 29160 | + if (!err) { |
076b876e | 29161 | + au_optstr_br_perm(&perm, br->br_perm); |
79b8bda9 | 29162 | + seq_printf(seq, "=%s", perm.a); |
5afbbe0d | 29163 | + if (bindex != bbot) |
79b8bda9 | 29164 | + seq_putc(seq, ':'); |
1e00d052 | 29165 | + } |
1facf9fc | 29166 | + } |
79b8bda9 AM |
29167 | + if (unlikely(err || seq_has_overflowed(seq))) |
29168 | + err = -E2BIG; | |
1facf9fc | 29169 | + |
29170 | + return err; | |
29171 | +} | |
29172 | + | |
f2c43d5f AM |
29173 | +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat, |
29174 | + const char *append) | |
29175 | +{ | |
29176 | + char *p; | |
29177 | + | |
29178 | + p = fmt; | |
29179 | + while (*pat != ':') | |
29180 | + *p++ = *pat++; | |
29181 | + *p++ = *pat++; | |
29182 | + strcpy(p, append); | |
29183 | + AuDebugOn(strlen(fmt) >= len); | |
29184 | +} | |
29185 | + | |
1facf9fc | 29186 | +static void au_show_wbr_create(struct seq_file *m, int v, |
29187 | + struct au_sbinfo *sbinfo) | |
29188 | +{ | |
29189 | + const char *pat; | |
f2c43d5f AM |
29190 | + char fmt[32]; |
29191 | + struct au_wbr_mfs *mfs; | |
1facf9fc | 29192 | + |
dece6358 AM |
29193 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
29194 | + | |
c2b27bf2 | 29195 | + seq_puts(m, ",create="); |
1facf9fc | 29196 | + pat = au_optstr_wbr_create(v); |
f2c43d5f | 29197 | + mfs = &sbinfo->si_wbr_mfs; |
1facf9fc | 29198 | + switch (v) { |
29199 | + case AuWbrCreate_TDP: | |
29200 | + case AuWbrCreate_RR: | |
29201 | + case AuWbrCreate_MFS: | |
29202 | + case AuWbrCreate_PMFS: | |
c2b27bf2 | 29203 | + seq_puts(m, pat); |
1facf9fc | 29204 | + break; |
f2c43d5f AM |
29205 | + case AuWbrCreate_MFSRR: |
29206 | + case AuWbrCreate_TDMFS: | |
29207 | + case AuWbrCreate_PMFSRR: | |
29208 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu"); | |
29209 | + seq_printf(m, fmt, mfs->mfsrr_watermark); | |
1facf9fc | 29210 | + break; |
f2c43d5f | 29211 | + case AuWbrCreate_MFSV: |
1facf9fc | 29212 | + case AuWbrCreate_PMFSV: |
f2c43d5f AM |
29213 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu"); |
29214 | + seq_printf(m, fmt, | |
29215 | + jiffies_to_msecs(mfs->mfs_expire) | |
e49829fe | 29216 | + / MSEC_PER_SEC); |
1facf9fc | 29217 | + break; |
1facf9fc | 29218 | + case AuWbrCreate_MFSRRV: |
f2c43d5f | 29219 | + case AuWbrCreate_TDMFSV: |
392086de | 29220 | + case AuWbrCreate_PMFSRRV: |
f2c43d5f AM |
29221 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu"); |
29222 | + seq_printf(m, fmt, mfs->mfsrr_watermark, | |
29223 | + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC); | |
392086de | 29224 | + break; |
f2c43d5f AM |
29225 | + default: |
29226 | + BUG(); | |
1facf9fc | 29227 | + } |
29228 | +} | |
29229 | + | |
7eafdf33 | 29230 | +static int au_show_xino(struct seq_file *seq, struct super_block *sb) |
1facf9fc | 29231 | +{ |
29232 | +#ifdef CONFIG_SYSFS | |
29233 | + return 0; | |
29234 | +#else | |
29235 | + int err; | |
29236 | + const int len = sizeof(AUFS_XINO_FNAME) - 1; | |
29237 | + aufs_bindex_t bindex, brid; | |
1facf9fc | 29238 | + struct qstr *name; |
29239 | + struct file *f; | |
29240 | + struct dentry *d, *h_root; | |
29241 | + | |
dece6358 AM |
29242 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
29243 | + | |
1facf9fc | 29244 | + err = 0; |
1facf9fc | 29245 | + f = au_sbi(sb)->si_xib; |
29246 | + if (!f) | |
29247 | + goto out; | |
29248 | + | |
29249 | + /* stop printing the default xino path on the first writable branch */ | |
29250 | + h_root = NULL; | |
29251 | + brid = au_xino_brid(sb); | |
29252 | + if (brid >= 0) { | |
29253 | + bindex = au_br_index(sb, brid); | |
5afbbe0d | 29254 | + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry; |
1facf9fc | 29255 | + } |
2000de60 | 29256 | + d = f->f_path.dentry; |
1facf9fc | 29257 | + name = &d->d_name; |
29258 | + /* safe ->d_parent because the file is unlinked */ | |
29259 | + if (d->d_parent == h_root | |
29260 | + && name->len == len | |
29261 | + && !memcmp(name->name, AUFS_XINO_FNAME, len)) | |
29262 | + goto out; | |
29263 | + | |
29264 | + seq_puts(seq, ",xino="); | |
29265 | + err = au_xino_path(seq, f); | |
29266 | + | |
4f0767ce | 29267 | +out: |
1facf9fc | 29268 | + return err; |
29269 | +#endif | |
29270 | +} | |
29271 | + | |
29272 | +/* seq_file will re-call me in case of too long string */ | |
7eafdf33 | 29273 | +static int aufs_show_options(struct seq_file *m, struct dentry *dentry) |
1facf9fc | 29274 | +{ |
027c5e7a | 29275 | + int err; |
1facf9fc | 29276 | + unsigned int mnt_flags, v; |
29277 | + struct super_block *sb; | |
29278 | + struct au_sbinfo *sbinfo; | |
29279 | + | |
29280 | +#define AuBool(name, str) do { \ | |
29281 | + v = au_opt_test(mnt_flags, name); \ | |
29282 | + if (v != au_opt_test(AuOpt_Def, name)) \ | |
29283 | + seq_printf(m, ",%s" #str, v ? "" : "no"); \ | |
29284 | +} while (0) | |
29285 | + | |
29286 | +#define AuStr(name, str) do { \ | |
29287 | + v = mnt_flags & AuOptMask_##name; \ | |
29288 | + if (v != (AuOpt_Def & AuOptMask_##name)) \ | |
29289 | + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \ | |
29290 | +} while (0) | |
29291 | + | |
29292 | +#define AuUInt(name, str, val) do { \ | |
29293 | + if (val != AUFS_##name##_DEF) \ | |
29294 | + seq_printf(m, "," #str "=%u", val); \ | |
29295 | +} while (0) | |
29296 | + | |
7eafdf33 | 29297 | + sb = dentry->d_sb; |
2121bcd9 | 29298 | + if (sb->s_flags & SB_POSIXACL) |
c1595e42 JR |
29299 | + seq_puts(m, ",acl"); |
29300 | + | |
29301 | + /* lock free root dinfo */ | |
1facf9fc | 29302 | + si_noflush_read_lock(sb); |
29303 | + sbinfo = au_sbi(sb); | |
29304 | + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo)); | |
29305 | + | |
29306 | + mnt_flags = au_mntflags(sb); | |
29307 | + if (au_opt_test(mnt_flags, XINO)) { | |
7eafdf33 | 29308 | + err = au_show_xino(m, sb); |
1facf9fc | 29309 | + if (unlikely(err)) |
29310 | + goto out; | |
29311 | + } else | |
29312 | + seq_puts(m, ",noxino"); | |
29313 | + | |
29314 | + AuBool(TRUNC_XINO, trunc_xino); | |
29315 | + AuStr(UDBA, udba); | |
dece6358 | 29316 | + AuBool(SHWH, shwh); |
1facf9fc | 29317 | + AuBool(PLINK, plink); |
4a4d8108 | 29318 | + AuBool(DIO, dio); |
076b876e | 29319 | + AuBool(DIRPERM1, dirperm1); |
1facf9fc | 29320 | + |
29321 | + v = sbinfo->si_wbr_create; | |
29322 | + if (v != AuWbrCreate_Def) | |
29323 | + au_show_wbr_create(m, v, sbinfo); | |
29324 | + | |
29325 | + v = sbinfo->si_wbr_copyup; | |
29326 | + if (v != AuWbrCopyup_Def) | |
29327 | + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v)); | |
29328 | + | |
29329 | + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ); | |
29330 | + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ)) | |
29331 | + seq_printf(m, ",diropq=%c", v ? 'a' : 'w'); | |
29332 | + | |
29333 | + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh); | |
29334 | + | |
027c5e7a AM |
29335 | + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC; |
29336 | + AuUInt(RDCACHE, rdcache, v); | |
1facf9fc | 29337 | + |
29338 | + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk); | |
29339 | + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash); | |
29340 | + | |
076b876e AM |
29341 | + au_fhsm_show(m, sbinfo); |
29342 | + | |
8b6a4947 | 29343 | + AuBool(DIRREN, dirren); |
1facf9fc | 29344 | + AuBool(SUM, sum); |
29345 | + /* AuBool(SUM_W, wsum); */ | |
29346 | + AuBool(WARN_PERM, warn_perm); | |
29347 | + AuBool(VERBOSE, verbose); | |
29348 | + | |
4f0767ce | 29349 | +out: |
1facf9fc | 29350 | + /* be sure to print "br:" last */ |
29351 | + if (!sysaufs_brs) { | |
29352 | + seq_puts(m, ",br:"); | |
29353 | + au_show_brs(m, sb); | |
29354 | + } | |
29355 | + si_read_unlock(sb); | |
29356 | + return 0; | |
29357 | + | |
1facf9fc | 29358 | +#undef AuBool |
29359 | +#undef AuStr | |
4a4d8108 | 29360 | +#undef AuUInt |
1facf9fc | 29361 | +} |
29362 | + | |
29363 | +/* ---------------------------------------------------------------------- */ | |
29364 | + | |
29365 | +/* sum mode which returns the summation for statfs(2) */ | |
29366 | + | |
29367 | +static u64 au_add_till_max(u64 a, u64 b) | |
29368 | +{ | |
29369 | + u64 old; | |
29370 | + | |
29371 | + old = a; | |
29372 | + a += b; | |
92d182d2 AM |
29373 | + if (old <= a) |
29374 | + return a; | |
29375 | + return ULLONG_MAX; | |
29376 | +} | |
29377 | + | |
29378 | +static u64 au_mul_till_max(u64 a, long mul) | |
29379 | +{ | |
29380 | + u64 old; | |
29381 | + | |
29382 | + old = a; | |
29383 | + a *= mul; | |
29384 | + if (old <= a) | |
1facf9fc | 29385 | + return a; |
29386 | + return ULLONG_MAX; | |
29387 | +} | |
29388 | + | |
29389 | +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf) | |
29390 | +{ | |
29391 | + int err; | |
92d182d2 | 29392 | + long bsize, factor; |
1facf9fc | 29393 | + u64 blocks, bfree, bavail, files, ffree; |
5afbbe0d | 29394 | + aufs_bindex_t bbot, bindex, i; |
1facf9fc | 29395 | + unsigned char shared; |
7f207e10 | 29396 | + struct path h_path; |
1facf9fc | 29397 | + struct super_block *h_sb; |
29398 | + | |
92d182d2 AM |
29399 | + err = 0; |
29400 | + bsize = LONG_MAX; | |
29401 | + files = 0; | |
29402 | + ffree = 0; | |
1facf9fc | 29403 | + blocks = 0; |
29404 | + bfree = 0; | |
29405 | + bavail = 0; | |
5afbbe0d AM |
29406 | + bbot = au_sbbot(sb); |
29407 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
7f207e10 AM |
29408 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
29409 | + h_sb = h_path.mnt->mnt_sb; | |
1facf9fc | 29410 | + shared = 0; |
92d182d2 | 29411 | + for (i = 0; !shared && i < bindex; i++) |
1facf9fc | 29412 | + shared = (au_sbr_sb(sb, i) == h_sb); |
29413 | + if (shared) | |
29414 | + continue; | |
29415 | + | |
29416 | + /* sb->s_root for NFS is unreliable */ | |
7f207e10 AM |
29417 | + h_path.dentry = h_path.mnt->mnt_root; |
29418 | + err = vfs_statfs(&h_path, buf); | |
1facf9fc | 29419 | + if (unlikely(err)) |
29420 | + goto out; | |
29421 | + | |
92d182d2 AM |
29422 | + if (bsize > buf->f_bsize) { |
29423 | + /* | |
29424 | + * we will reduce bsize, so we have to expand blocks | |
29425 | + * etc. to match them again | |
29426 | + */ | |
29427 | + factor = (bsize / buf->f_bsize); | |
29428 | + blocks = au_mul_till_max(blocks, factor); | |
29429 | + bfree = au_mul_till_max(bfree, factor); | |
29430 | + bavail = au_mul_till_max(bavail, factor); | |
29431 | + bsize = buf->f_bsize; | |
29432 | + } | |
29433 | + | |
29434 | + factor = (buf->f_bsize / bsize); | |
29435 | + blocks = au_add_till_max(blocks, | |
29436 | + au_mul_till_max(buf->f_blocks, factor)); | |
29437 | + bfree = au_add_till_max(bfree, | |
29438 | + au_mul_till_max(buf->f_bfree, factor)); | |
29439 | + bavail = au_add_till_max(bavail, | |
29440 | + au_mul_till_max(buf->f_bavail, factor)); | |
1facf9fc | 29441 | + files = au_add_till_max(files, buf->f_files); |
29442 | + ffree = au_add_till_max(ffree, buf->f_ffree); | |
29443 | + } | |
29444 | + | |
92d182d2 | 29445 | + buf->f_bsize = bsize; |
1facf9fc | 29446 | + buf->f_blocks = blocks; |
29447 | + buf->f_bfree = bfree; | |
29448 | + buf->f_bavail = bavail; | |
29449 | + buf->f_files = files; | |
29450 | + buf->f_ffree = ffree; | |
92d182d2 | 29451 | + buf->f_frsize = 0; |
1facf9fc | 29452 | + |
4f0767ce | 29453 | +out: |
1facf9fc | 29454 | + return err; |
29455 | +} | |
29456 | + | |
29457 | +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
29458 | +{ | |
29459 | + int err; | |
7f207e10 | 29460 | + struct path h_path; |
1facf9fc | 29461 | + struct super_block *sb; |
29462 | + | |
29463 | + /* lock free root dinfo */ | |
29464 | + sb = dentry->d_sb; | |
29465 | + si_noflush_read_lock(sb); | |
7f207e10 | 29466 | + if (!au_opt_test(au_mntflags(sb), SUM)) { |
1facf9fc | 29467 | + /* sb->s_root for NFS is unreliable */ |
7f207e10 AM |
29468 | + h_path.mnt = au_sbr_mnt(sb, 0); |
29469 | + h_path.dentry = h_path.mnt->mnt_root; | |
29470 | + err = vfs_statfs(&h_path, buf); | |
29471 | + } else | |
1facf9fc | 29472 | + err = au_statfs_sum(sb, buf); |
29473 | + si_read_unlock(sb); | |
29474 | + | |
29475 | + if (!err) { | |
29476 | + buf->f_type = AUFS_SUPER_MAGIC; | |
4a4d8108 | 29477 | + buf->f_namelen = AUFS_MAX_NAMELEN; |
1facf9fc | 29478 | + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid)); |
29479 | + } | |
29480 | + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */ | |
29481 | + | |
29482 | + return err; | |
29483 | +} | |
29484 | + | |
29485 | +/* ---------------------------------------------------------------------- */ | |
29486 | + | |
537831f9 AM |
29487 | +static int aufs_sync_fs(struct super_block *sb, int wait) |
29488 | +{ | |
29489 | + int err, e; | |
5afbbe0d | 29490 | + aufs_bindex_t bbot, bindex; |
537831f9 AM |
29491 | + struct au_branch *br; |
29492 | + struct super_block *h_sb; | |
29493 | + | |
29494 | + err = 0; | |
29495 | + si_noflush_read_lock(sb); | |
5afbbe0d AM |
29496 | + bbot = au_sbbot(sb); |
29497 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
537831f9 AM |
29498 | + br = au_sbr(sb, bindex); |
29499 | + if (!au_br_writable(br->br_perm)) | |
29500 | + continue; | |
29501 | + | |
29502 | + h_sb = au_sbr_sb(sb, bindex); | |
a2654f78 AM |
29503 | + e = vfsub_sync_filesystem(h_sb, wait); |
29504 | + if (unlikely(e && !err)) | |
29505 | + err = e; | |
29506 | + /* go on even if an error happens */ | |
537831f9 AM |
29507 | + } |
29508 | + si_read_unlock(sb); | |
29509 | + | |
29510 | + return err; | |
29511 | +} | |
29512 | + | |
29513 | +/* ---------------------------------------------------------------------- */ | |
29514 | + | |
1facf9fc | 29515 | +/* final actions when unmounting a file system */ |
29516 | +static void aufs_put_super(struct super_block *sb) | |
29517 | +{ | |
29518 | + struct au_sbinfo *sbinfo; | |
29519 | + | |
29520 | + sbinfo = au_sbi(sb); | |
29521 | + if (!sbinfo) | |
29522 | + return; | |
29523 | + | |
1facf9fc | 29524 | + dbgaufs_si_fin(sbinfo); |
29525 | + kobject_put(&sbinfo->si_kobj); | |
29526 | +} | |
29527 | + | |
29528 | +/* ---------------------------------------------------------------------- */ | |
29529 | + | |
79b8bda9 AM |
29530 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, |
29531 | + struct super_block *sb, void *arg) | |
7f207e10 AM |
29532 | +{ |
29533 | + void *array; | |
076b876e | 29534 | + unsigned long long n, sz; |
7f207e10 AM |
29535 | + |
29536 | + array = NULL; | |
29537 | + n = 0; | |
29538 | + if (!*hint) | |
29539 | + goto out; | |
29540 | + | |
29541 | + if (*hint > ULLONG_MAX / sizeof(array)) { | |
29542 | + array = ERR_PTR(-EMFILE); | |
29543 | + pr_err("hint %llu\n", *hint); | |
29544 | + goto out; | |
29545 | + } | |
29546 | + | |
076b876e AM |
29547 | + sz = sizeof(array) * *hint; |
29548 | + array = kzalloc(sz, GFP_NOFS); | |
7f207e10 | 29549 | + if (unlikely(!array)) |
076b876e | 29550 | + array = vzalloc(sz); |
7f207e10 AM |
29551 | + if (unlikely(!array)) { |
29552 | + array = ERR_PTR(-ENOMEM); | |
29553 | + goto out; | |
29554 | + } | |
29555 | + | |
79b8bda9 | 29556 | + n = cb(sb, array, *hint, arg); |
7f207e10 AM |
29557 | + AuDebugOn(n > *hint); |
29558 | + | |
29559 | +out: | |
29560 | + *hint = n; | |
29561 | + return array; | |
29562 | +} | |
29563 | + | |
79b8bda9 | 29564 | +static unsigned long long au_iarray_cb(struct super_block *sb, void *a, |
7f207e10 AM |
29565 | + unsigned long long max __maybe_unused, |
29566 | + void *arg) | |
29567 | +{ | |
29568 | + unsigned long long n; | |
29569 | + struct inode **p, *inode; | |
29570 | + struct list_head *head; | |
29571 | + | |
29572 | + n = 0; | |
29573 | + p = a; | |
29574 | + head = arg; | |
79b8bda9 | 29575 | + spin_lock(&sb->s_inode_list_lock); |
7f207e10 | 29576 | + list_for_each_entry(inode, head, i_sb_list) { |
5afbbe0d AM |
29577 | + if (!au_is_bad_inode(inode) |
29578 | + && au_ii(inode)->ii_btop >= 0) { | |
2cbb1c4b JR |
29579 | + spin_lock(&inode->i_lock); |
29580 | + if (atomic_read(&inode->i_count)) { | |
29581 | + au_igrab(inode); | |
29582 | + *p++ = inode; | |
29583 | + n++; | |
29584 | + AuDebugOn(n > max); | |
29585 | + } | |
29586 | + spin_unlock(&inode->i_lock); | |
7f207e10 AM |
29587 | + } |
29588 | + } | |
79b8bda9 | 29589 | + spin_unlock(&sb->s_inode_list_lock); |
7f207e10 AM |
29590 | + |
29591 | + return n; | |
29592 | +} | |
29593 | + | |
29594 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max) | |
29595 | +{ | |
5afbbe0d | 29596 | + *max = au_ninodes(sb); |
79b8bda9 | 29597 | + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes); |
7f207e10 AM |
29598 | +} |
29599 | + | |
29600 | +void au_iarray_free(struct inode **a, unsigned long long max) | |
29601 | +{ | |
29602 | + unsigned long long ull; | |
29603 | + | |
29604 | + for (ull = 0; ull < max; ull++) | |
29605 | + iput(a[ull]); | |
be52b249 | 29606 | + kvfree(a); |
7f207e10 AM |
29607 | +} |
29608 | + | |
29609 | +/* ---------------------------------------------------------------------- */ | |
29610 | + | |
1facf9fc | 29611 | +/* |
29612 | + * refresh dentry and inode at remount time. | |
29613 | + */ | |
027c5e7a AM |
29614 | +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */ |
29615 | +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags, | |
29616 | + struct dentry *parent) | |
1facf9fc | 29617 | +{ |
29618 | + int err; | |
1facf9fc | 29619 | + |
29620 | + di_write_lock_child(dentry); | |
1facf9fc | 29621 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a AM |
29622 | + err = au_refresh_dentry(dentry, parent); |
29623 | + if (!err && dir_flags) | |
5527c038 | 29624 | + au_hn_reset(d_inode(dentry), dir_flags); |
1facf9fc | 29625 | + di_read_unlock(parent, AuLock_IR); |
1facf9fc | 29626 | + di_write_unlock(dentry); |
29627 | + | |
29628 | + return err; | |
29629 | +} | |
29630 | + | |
027c5e7a AM |
29631 | +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen, |
29632 | + struct au_sbinfo *sbinfo, | |
b95c5147 | 29633 | + const unsigned int dir_flags, unsigned int do_idop) |
1facf9fc | 29634 | +{ |
027c5e7a AM |
29635 | + int err; |
29636 | + struct dentry *parent; | |
027c5e7a AM |
29637 | + |
29638 | + err = 0; | |
29639 | + parent = dget_parent(dentry); | |
29640 | + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) { | |
5527c038 JR |
29641 | + if (d_really_is_positive(dentry)) { |
29642 | + if (!d_is_dir(dentry)) | |
027c5e7a AM |
29643 | + err = au_do_refresh(dentry, /*dir_flags*/0, |
29644 | + parent); | |
29645 | + else { | |
29646 | + err = au_do_refresh(dentry, dir_flags, parent); | |
29647 | + if (unlikely(err)) | |
29648 | + au_fset_si(sbinfo, FAILED_REFRESH_DIR); | |
29649 | + } | |
29650 | + } else | |
29651 | + err = au_do_refresh(dentry, /*dir_flags*/0, parent); | |
29652 | + AuDbgDentry(dentry); | |
29653 | + } | |
29654 | + dput(parent); | |
29655 | + | |
79b8bda9 | 29656 | + if (!err) { |
b95c5147 | 29657 | + if (do_idop) |
79b8bda9 AM |
29658 | + au_refresh_dop(dentry, /*force_reval*/0); |
29659 | + } else | |
29660 | + au_refresh_dop(dentry, /*force_reval*/1); | |
29661 | + | |
027c5e7a AM |
29662 | + AuTraceErr(err); |
29663 | + return err; | |
1facf9fc | 29664 | +} |
29665 | + | |
b95c5147 | 29666 | +static int au_refresh_d(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 29667 | +{ |
29668 | + int err, i, j, ndentry, e; | |
027c5e7a | 29669 | + unsigned int sigen; |
1facf9fc | 29670 | + struct au_dcsub_pages dpages; |
29671 | + struct au_dpage *dpage; | |
027c5e7a AM |
29672 | + struct dentry **dentries, *d; |
29673 | + struct au_sbinfo *sbinfo; | |
29674 | + struct dentry *root = sb->s_root; | |
5527c038 | 29675 | + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1); |
1facf9fc | 29676 | + |
b95c5147 | 29677 | + if (do_idop) |
79b8bda9 AM |
29678 | + au_refresh_dop(root, /*force_reval*/0); |
29679 | + | |
027c5e7a AM |
29680 | + err = au_dpages_init(&dpages, GFP_NOFS); |
29681 | + if (unlikely(err)) | |
1facf9fc | 29682 | + goto out; |
027c5e7a AM |
29683 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); |
29684 | + if (unlikely(err)) | |
1facf9fc | 29685 | + goto out_dpages; |
1facf9fc | 29686 | + |
027c5e7a AM |
29687 | + sigen = au_sigen(sb); |
29688 | + sbinfo = au_sbi(sb); | |
29689 | + for (i = 0; i < dpages.ndpage; i++) { | |
1facf9fc | 29690 | + dpage = dpages.dpages + i; |
29691 | + dentries = dpage->dentries; | |
29692 | + ndentry = dpage->ndentry; | |
027c5e7a | 29693 | + for (j = 0; j < ndentry; j++) { |
1facf9fc | 29694 | + d = dentries[j]; |
79b8bda9 | 29695 | + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags, |
b95c5147 | 29696 | + do_idop); |
027c5e7a AM |
29697 | + if (unlikely(e && !err)) |
29698 | + err = e; | |
29699 | + /* go on even err */ | |
1facf9fc | 29700 | + } |
29701 | + } | |
29702 | + | |
4f0767ce | 29703 | +out_dpages: |
1facf9fc | 29704 | + au_dpages_free(&dpages); |
4f0767ce | 29705 | +out: |
1facf9fc | 29706 | + return err; |
29707 | +} | |
29708 | + | |
b95c5147 | 29709 | +static int au_refresh_i(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 29710 | +{ |
027c5e7a AM |
29711 | + int err, e; |
29712 | + unsigned int sigen; | |
29713 | + unsigned long long max, ull; | |
29714 | + struct inode *inode, **array; | |
1facf9fc | 29715 | + |
027c5e7a AM |
29716 | + array = au_iarray_alloc(sb, &max); |
29717 | + err = PTR_ERR(array); | |
29718 | + if (IS_ERR(array)) | |
29719 | + goto out; | |
1facf9fc | 29720 | + |
29721 | + err = 0; | |
027c5e7a AM |
29722 | + sigen = au_sigen(sb); |
29723 | + for (ull = 0; ull < max; ull++) { | |
29724 | + inode = array[ull]; | |
076b876e AM |
29725 | + if (unlikely(!inode)) |
29726 | + break; | |
b95c5147 AM |
29727 | + |
29728 | + e = 0; | |
29729 | + ii_write_lock_child(inode); | |
537831f9 | 29730 | + if (au_iigen(inode, NULL) != sigen) { |
027c5e7a | 29731 | + e = au_refresh_hinode_self(inode); |
1facf9fc | 29732 | + if (unlikely(e)) { |
b95c5147 | 29733 | + au_refresh_iop(inode, /*force_getattr*/1); |
027c5e7a | 29734 | + pr_err("error %d, i%lu\n", e, inode->i_ino); |
1facf9fc | 29735 | + if (!err) |
29736 | + err = e; | |
29737 | + /* go on even if err */ | |
29738 | + } | |
29739 | + } | |
b95c5147 AM |
29740 | + if (!e && do_idop) |
29741 | + au_refresh_iop(inode, /*force_getattr*/0); | |
29742 | + ii_write_unlock(inode); | |
1facf9fc | 29743 | + } |
29744 | + | |
027c5e7a | 29745 | + au_iarray_free(array, max); |
1facf9fc | 29746 | + |
4f0767ce | 29747 | +out: |
1facf9fc | 29748 | + return err; |
29749 | +} | |
29750 | + | |
b95c5147 | 29751 | +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 29752 | +{ |
027c5e7a AM |
29753 | + int err, e; |
29754 | + unsigned int udba; | |
5afbbe0d | 29755 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 29756 | + struct dentry *root; |
29757 | + struct inode *inode; | |
027c5e7a | 29758 | + struct au_branch *br; |
79b8bda9 | 29759 | + struct au_sbinfo *sbi; |
1facf9fc | 29760 | + |
29761 | + au_sigen_inc(sb); | |
79b8bda9 AM |
29762 | + sbi = au_sbi(sb); |
29763 | + au_fclr_si(sbi, FAILED_REFRESH_DIR); | |
1facf9fc | 29764 | + |
29765 | + root = sb->s_root; | |
29766 | + DiMustNoWaiters(root); | |
5527c038 | 29767 | + inode = d_inode(root); |
1facf9fc | 29768 | + IiMustNoWaiters(inode); |
1facf9fc | 29769 | + |
027c5e7a | 29770 | + udba = au_opt_udba(sb); |
5afbbe0d AM |
29771 | + bbot = au_sbbot(sb); |
29772 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
027c5e7a AM |
29773 | + br = au_sbr(sb, bindex); |
29774 | + err = au_hnotify_reset_br(udba, br, br->br_perm); | |
1facf9fc | 29775 | + if (unlikely(err)) |
027c5e7a AM |
29776 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", |
29777 | + bindex, err); | |
29778 | + /* go on even if err */ | |
1facf9fc | 29779 | + } |
027c5e7a | 29780 | + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1)); |
1facf9fc | 29781 | + |
b95c5147 | 29782 | + if (do_idop) { |
79b8bda9 AM |
29783 | + if (au_ftest_si(sbi, NO_DREVAL)) { |
29784 | + AuDebugOn(sb->s_d_op == &aufs_dop_noreval); | |
29785 | + sb->s_d_op = &aufs_dop_noreval; | |
b95c5147 AM |
29786 | + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr); |
29787 | + sbi->si_iop_array = aufs_iop_nogetattr; | |
79b8bda9 AM |
29788 | + } else { |
29789 | + AuDebugOn(sb->s_d_op == &aufs_dop); | |
29790 | + sb->s_d_op = &aufs_dop; | |
b95c5147 AM |
29791 | + AuDebugOn(sbi->si_iop_array == aufs_iop); |
29792 | + sbi->si_iop_array = aufs_iop; | |
79b8bda9 | 29793 | + } |
b95c5147 AM |
29794 | + pr_info("reset to %pf and %pf\n", |
29795 | + sb->s_d_op, sbi->si_iop_array); | |
79b8bda9 AM |
29796 | + } |
29797 | + | |
027c5e7a | 29798 | + di_write_unlock(root); |
b95c5147 AM |
29799 | + err = au_refresh_d(sb, do_idop); |
29800 | + e = au_refresh_i(sb, do_idop); | |
027c5e7a AM |
29801 | + if (unlikely(e && !err)) |
29802 | + err = e; | |
1facf9fc | 29803 | + /* aufs_write_lock() calls ..._child() */ |
29804 | + di_write_lock_child(root); | |
027c5e7a AM |
29805 | + |
29806 | + au_cpup_attr_all(inode, /*force*/1); | |
29807 | + | |
29808 | + if (unlikely(err)) | |
29809 | + AuIOErr("refresh failed, ignored, %d\n", err); | |
1facf9fc | 29810 | +} |
29811 | + | |
29812 | +/* stop extra interpretation of errno in mount(8), and strange error messages */ | |
29813 | +static int cvt_err(int err) | |
29814 | +{ | |
29815 | + AuTraceErr(err); | |
29816 | + | |
29817 | + switch (err) { | |
29818 | + case -ENOENT: | |
29819 | + case -ENOTDIR: | |
29820 | + case -EEXIST: | |
29821 | + case -EIO: | |
29822 | + err = -EINVAL; | |
29823 | + } | |
29824 | + return err; | |
29825 | +} | |
29826 | + | |
29827 | +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data) | |
29828 | +{ | |
4a4d8108 AM |
29829 | + int err, do_dx; |
29830 | + unsigned int mntflags; | |
be52b249 AM |
29831 | + struct au_opts opts = { |
29832 | + .opt = NULL | |
29833 | + }; | |
1facf9fc | 29834 | + struct dentry *root; |
29835 | + struct inode *inode; | |
29836 | + struct au_sbinfo *sbinfo; | |
29837 | + | |
29838 | + err = 0; | |
29839 | + root = sb->s_root; | |
29840 | + if (!data || !*data) { | |
e49829fe JR |
29841 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
29842 | + if (!err) { | |
29843 | + di_write_lock_child(root); | |
29844 | + err = au_opts_verify(sb, *flags, /*pending*/0); | |
29845 | + aufs_write_unlock(root); | |
29846 | + } | |
1facf9fc | 29847 | + goto out; |
29848 | + } | |
29849 | + | |
29850 | + err = -ENOMEM; | |
1facf9fc | 29851 | + opts.opt = (void *)__get_free_page(GFP_NOFS); |
29852 | + if (unlikely(!opts.opt)) | |
29853 | + goto out; | |
29854 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
29855 | + opts.flags = AuOpts_REMOUNT; | |
29856 | + opts.sb_flags = *flags; | |
29857 | + | |
29858 | + /* parse it before aufs lock */ | |
29859 | + err = au_opts_parse(sb, data, &opts); | |
29860 | + if (unlikely(err)) | |
29861 | + goto out_opts; | |
29862 | + | |
29863 | + sbinfo = au_sbi(sb); | |
5527c038 | 29864 | + inode = d_inode(root); |
febd17d6 | 29865 | + inode_lock(inode); |
e49829fe JR |
29866 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
29867 | + if (unlikely(err)) | |
29868 | + goto out_mtx; | |
29869 | + di_write_lock_child(root); | |
1facf9fc | 29870 | + |
29871 | + /* au_opts_remount() may return an error */ | |
29872 | + err = au_opts_remount(sb, &opts); | |
29873 | + au_opts_free(&opts); | |
29874 | + | |
027c5e7a | 29875 | + if (au_ftest_opts(opts.flags, REFRESH)) |
b95c5147 | 29876 | + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP)); |
1facf9fc | 29877 | + |
4a4d8108 AM |
29878 | + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) { |
29879 | + mntflags = au_mntflags(sb); | |
29880 | + do_dx = !!au_opt_test(mntflags, DIO); | |
29881 | + au_dy_arefresh(do_dx); | |
29882 | + } | |
29883 | + | |
076b876e | 29884 | + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */ |
1facf9fc | 29885 | + aufs_write_unlock(root); |
953406b4 | 29886 | + |
e49829fe | 29887 | +out_mtx: |
febd17d6 | 29888 | + inode_unlock(inode); |
4f0767ce | 29889 | +out_opts: |
1c60b727 | 29890 | + free_page((unsigned long)opts.opt); |
4f0767ce | 29891 | +out: |
1facf9fc | 29892 | + err = cvt_err(err); |
29893 | + AuTraceErr(err); | |
29894 | + return err; | |
29895 | +} | |
29896 | + | |
4a4d8108 | 29897 | +static const struct super_operations aufs_sop = { |
1facf9fc | 29898 | + .alloc_inode = aufs_alloc_inode, |
29899 | + .destroy_inode = aufs_destroy_inode, | |
b752ccd1 | 29900 | + /* always deleting, no clearing */ |
1facf9fc | 29901 | + .drop_inode = generic_delete_inode, |
29902 | + .show_options = aufs_show_options, | |
29903 | + .statfs = aufs_statfs, | |
29904 | + .put_super = aufs_put_super, | |
537831f9 | 29905 | + .sync_fs = aufs_sync_fs, |
1facf9fc | 29906 | + .remount_fs = aufs_remount_fs |
29907 | +}; | |
29908 | + | |
29909 | +/* ---------------------------------------------------------------------- */ | |
29910 | + | |
29911 | +static int alloc_root(struct super_block *sb) | |
29912 | +{ | |
29913 | + int err; | |
29914 | + struct inode *inode; | |
29915 | + struct dentry *root; | |
29916 | + | |
29917 | + err = -ENOMEM; | |
29918 | + inode = au_iget_locked(sb, AUFS_ROOT_INO); | |
29919 | + err = PTR_ERR(inode); | |
29920 | + if (IS_ERR(inode)) | |
29921 | + goto out; | |
29922 | + | |
b95c5147 | 29923 | + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */ |
1facf9fc | 29924 | + inode->i_fop = &aufs_dir_fop; |
29925 | + inode->i_mode = S_IFDIR; | |
9dbd164d | 29926 | + set_nlink(inode, 2); |
1facf9fc | 29927 | + unlock_new_inode(inode); |
29928 | + | |
92d182d2 | 29929 | + root = d_make_root(inode); |
1facf9fc | 29930 | + if (unlikely(!root)) |
92d182d2 | 29931 | + goto out; |
1facf9fc | 29932 | + err = PTR_ERR(root); |
29933 | + if (IS_ERR(root)) | |
92d182d2 | 29934 | + goto out; |
1facf9fc | 29935 | + |
4a4d8108 | 29936 | + err = au_di_init(root); |
1facf9fc | 29937 | + if (!err) { |
29938 | + sb->s_root = root; | |
29939 | + return 0; /* success */ | |
29940 | + } | |
29941 | + dput(root); | |
1facf9fc | 29942 | + |
4f0767ce | 29943 | +out: |
1facf9fc | 29944 | + return err; |
1facf9fc | 29945 | +} |
29946 | + | |
29947 | +static int aufs_fill_super(struct super_block *sb, void *raw_data, | |
29948 | + int silent __maybe_unused) | |
29949 | +{ | |
29950 | + int err; | |
be52b249 AM |
29951 | + struct au_opts opts = { |
29952 | + .opt = NULL | |
29953 | + }; | |
79b8bda9 | 29954 | + struct au_sbinfo *sbinfo; |
1facf9fc | 29955 | + struct dentry *root; |
29956 | + struct inode *inode; | |
29957 | + char *arg = raw_data; | |
29958 | + | |
29959 | + if (unlikely(!arg || !*arg)) { | |
29960 | + err = -EINVAL; | |
4a4d8108 | 29961 | + pr_err("no arg\n"); |
1facf9fc | 29962 | + goto out; |
29963 | + } | |
29964 | + | |
29965 | + err = -ENOMEM; | |
1facf9fc | 29966 | + opts.opt = (void *)__get_free_page(GFP_NOFS); |
29967 | + if (unlikely(!opts.opt)) | |
29968 | + goto out; | |
29969 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
29970 | + opts.sb_flags = sb->s_flags; | |
29971 | + | |
29972 | + err = au_si_alloc(sb); | |
29973 | + if (unlikely(err)) | |
29974 | + goto out_opts; | |
79b8bda9 | 29975 | + sbinfo = au_sbi(sb); |
1facf9fc | 29976 | + |
29977 | + /* all timestamps always follow the ones on the branch */ | |
2121bcd9 | 29978 | + sb->s_flags |= SB_NOATIME | SB_NODIRATIME; |
1facf9fc | 29979 | + sb->s_op = &aufs_sop; |
027c5e7a | 29980 | + sb->s_d_op = &aufs_dop; |
1facf9fc | 29981 | + sb->s_magic = AUFS_SUPER_MAGIC; |
29982 | + sb->s_maxbytes = 0; | |
c1595e42 | 29983 | + sb->s_stack_depth = 1; |
1facf9fc | 29984 | + au_export_init(sb); |
f2c43d5f | 29985 | + au_xattr_init(sb); |
1facf9fc | 29986 | + |
29987 | + err = alloc_root(sb); | |
29988 | + if (unlikely(err)) { | |
29989 | + si_write_unlock(sb); | |
29990 | + goto out_info; | |
29991 | + } | |
29992 | + root = sb->s_root; | |
5527c038 | 29993 | + inode = d_inode(root); |
1facf9fc | 29994 | + |
29995 | + /* | |
29996 | + * actually we can parse options regardless aufs lock here. | |
29997 | + * but at remount time, parsing must be done before aufs lock. | |
29998 | + * so we follow the same rule. | |
29999 | + */ | |
30000 | + ii_write_lock_parent(inode); | |
30001 | + aufs_write_unlock(root); | |
30002 | + err = au_opts_parse(sb, arg, &opts); | |
30003 | + if (unlikely(err)) | |
30004 | + goto out_root; | |
30005 | + | |
30006 | + /* lock vfs_inode first, then aufs. */ | |
febd17d6 | 30007 | + inode_lock(inode); |
1facf9fc | 30008 | + aufs_write_lock(root); |
30009 | + err = au_opts_mount(sb, &opts); | |
30010 | + au_opts_free(&opts); | |
79b8bda9 AM |
30011 | + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) { |
30012 | + sb->s_d_op = &aufs_dop_noreval; | |
30013 | + pr_info("%pf\n", sb->s_d_op); | |
30014 | + au_refresh_dop(root, /*force_reval*/0); | |
b95c5147 AM |
30015 | + sbinfo->si_iop_array = aufs_iop_nogetattr; |
30016 | + au_refresh_iop(inode, /*force_getattr*/0); | |
79b8bda9 | 30017 | + } |
1facf9fc | 30018 | + aufs_write_unlock(root); |
febd17d6 | 30019 | + inode_unlock(inode); |
4a4d8108 AM |
30020 | + if (!err) |
30021 | + goto out_opts; /* success */ | |
1facf9fc | 30022 | + |
4f0767ce | 30023 | +out_root: |
1facf9fc | 30024 | + dput(root); |
30025 | + sb->s_root = NULL; | |
4f0767ce | 30026 | +out_info: |
79b8bda9 AM |
30027 | + dbgaufs_si_fin(sbinfo); |
30028 | + kobject_put(&sbinfo->si_kobj); | |
1facf9fc | 30029 | + sb->s_fs_info = NULL; |
4f0767ce | 30030 | +out_opts: |
1c60b727 | 30031 | + free_page((unsigned long)opts.opt); |
4f0767ce | 30032 | +out: |
1facf9fc | 30033 | + AuTraceErr(err); |
30034 | + err = cvt_err(err); | |
30035 | + AuTraceErr(err); | |
30036 | + return err; | |
30037 | +} | |
30038 | + | |
30039 | +/* ---------------------------------------------------------------------- */ | |
30040 | + | |
027c5e7a AM |
30041 | +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags, |
30042 | + const char *dev_name __maybe_unused, | |
30043 | + void *raw_data) | |
1facf9fc | 30044 | +{ |
027c5e7a | 30045 | + struct dentry *root; |
1facf9fc | 30046 | + struct super_block *sb; |
30047 | + | |
30048 | + /* all timestamps always follow the ones on the branch */ | |
30049 | + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */ | |
027c5e7a AM |
30050 | + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super); |
30051 | + if (IS_ERR(root)) | |
30052 | + goto out; | |
30053 | + | |
30054 | + sb = root->d_sb; | |
30055 | + si_write_lock(sb, !AuLock_FLUSH); | |
30056 | + sysaufs_brs_add(sb, 0); | |
30057 | + si_write_unlock(sb); | |
30058 | + au_sbilist_add(sb); | |
30059 | + | |
30060 | +out: | |
30061 | + return root; | |
1facf9fc | 30062 | +} |
30063 | + | |
e49829fe JR |
30064 | +static void aufs_kill_sb(struct super_block *sb) |
30065 | +{ | |
30066 | + struct au_sbinfo *sbinfo; | |
30067 | + | |
30068 | + sbinfo = au_sbi(sb); | |
30069 | + if (sbinfo) { | |
30070 | + au_sbilist_del(sb); | |
30071 | + aufs_write_lock(sb->s_root); | |
076b876e | 30072 | + au_fhsm_fin(sb); |
e49829fe JR |
30073 | + if (sbinfo->si_wbr_create_ops->fin) |
30074 | + sbinfo->si_wbr_create_ops->fin(sb); | |
30075 | + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) { | |
30076 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE); | |
b95c5147 | 30077 | + au_remount_refresh(sb, /*do_idop*/0); |
e49829fe JR |
30078 | + } |
30079 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
30080 | + au_plink_put(sb, /*verbose*/1); | |
30081 | + au_xino_clr(sb); | |
8b6a4947 | 30082 | + au_dr_opt_flush(sb); |
1e00d052 | 30083 | + sbinfo->si_sb = NULL; |
e49829fe | 30084 | + aufs_write_unlock(sb->s_root); |
e49829fe JR |
30085 | + au_nwt_flush(&sbinfo->si_nowait); |
30086 | + } | |
98d9a5b1 | 30087 | + kill_anon_super(sb); |
e49829fe JR |
30088 | +} |
30089 | + | |
1facf9fc | 30090 | +struct file_system_type aufs_fs_type = { |
30091 | + .name = AUFS_FSTYPE, | |
c06a8ce3 AM |
30092 | + /* a race between rename and others */ |
30093 | + .fs_flags = FS_RENAME_DOES_D_MOVE, | |
027c5e7a | 30094 | + .mount = aufs_mount, |
e49829fe | 30095 | + .kill_sb = aufs_kill_sb, |
1facf9fc | 30096 | + /* no need to __module_get() and module_put(). */ |
30097 | + .owner = THIS_MODULE, | |
30098 | +}; | |
7f207e10 AM |
30099 | diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h |
30100 | --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 30101 | +++ linux/fs/aufs/super.h 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 30102 | @@ -0,0 +1,626 @@ |
1facf9fc | 30103 | +/* |
a2654f78 | 30104 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 30105 | + * |
30106 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30107 | + * it under the terms of the GNU General Public License as published by | |
30108 | + * the Free Software Foundation; either version 2 of the License, or | |
30109 | + * (at your option) any later version. | |
dece6358 AM |
30110 | + * |
30111 | + * This program is distributed in the hope that it will be useful, | |
30112 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30113 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30114 | + * GNU General Public License for more details. | |
30115 | + * | |
30116 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30117 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30118 | + */ |
30119 | + | |
30120 | +/* | |
30121 | + * super_block operations | |
30122 | + */ | |
30123 | + | |
30124 | +#ifndef __AUFS_SUPER_H__ | |
30125 | +#define __AUFS_SUPER_H__ | |
30126 | + | |
30127 | +#ifdef __KERNEL__ | |
30128 | + | |
30129 | +#include <linux/fs.h> | |
5527c038 | 30130 | +#include <linux/kobject.h> |
8b6a4947 | 30131 | +#include "hbl.h" |
1facf9fc | 30132 | +#include "rwsem.h" |
1facf9fc | 30133 | +#include "wkq.h" |
30134 | + | |
1facf9fc | 30135 | +/* policies to select one among multiple writable branches */ |
30136 | +struct au_wbr_copyup_operations { | |
30137 | + int (*copyup)(struct dentry *dentry); | |
30138 | +}; | |
30139 | + | |
392086de AM |
30140 | +#define AuWbr_DIR 1 /* target is a dir */ |
30141 | +#define AuWbr_PARENT (1 << 1) /* always require a parent */ | |
30142 | + | |
30143 | +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name) | |
30144 | +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; } | |
30145 | +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; } | |
30146 | + | |
1facf9fc | 30147 | +struct au_wbr_create_operations { |
392086de | 30148 | + int (*create)(struct dentry *dentry, unsigned int flags); |
1facf9fc | 30149 | + int (*init)(struct super_block *sb); |
30150 | + int (*fin)(struct super_block *sb); | |
30151 | +}; | |
30152 | + | |
30153 | +struct au_wbr_mfs { | |
30154 | + struct mutex mfs_lock; /* protect this structure */ | |
30155 | + unsigned long mfs_jiffy; | |
30156 | + unsigned long mfs_expire; | |
30157 | + aufs_bindex_t mfs_bindex; | |
30158 | + | |
30159 | + unsigned long long mfsrr_bytes; | |
30160 | + unsigned long long mfsrr_watermark; | |
30161 | +}; | |
30162 | + | |
86dc4139 AM |
30163 | +#define AuPlink_NHASH 100 |
30164 | +static inline int au_plink_hash(ino_t ino) | |
30165 | +{ | |
30166 | + return ino % AuPlink_NHASH; | |
30167 | +} | |
30168 | + | |
076b876e AM |
30169 | +/* File-based Hierarchical Storage Management */ |
30170 | +struct au_fhsm { | |
30171 | +#ifdef CONFIG_AUFS_FHSM | |
30172 | + /* allow only one process who can receive the notification */ | |
30173 | + spinlock_t fhsm_spin; | |
30174 | + pid_t fhsm_pid; | |
30175 | + wait_queue_head_t fhsm_wqh; | |
30176 | + atomic_t fhsm_readable; | |
30177 | + | |
c1595e42 | 30178 | + /* these are protected by si_rwsem */ |
076b876e | 30179 | + unsigned long fhsm_expire; |
c1595e42 | 30180 | + aufs_bindex_t fhsm_bottom; |
076b876e AM |
30181 | +#endif |
30182 | +}; | |
30183 | + | |
1facf9fc | 30184 | +struct au_branch; |
30185 | +struct au_sbinfo { | |
30186 | + /* nowait tasks in the system-wide workqueue */ | |
30187 | + struct au_nowait_tasks si_nowait; | |
30188 | + | |
b752ccd1 AM |
30189 | + /* |
30190 | + * tried sb->s_umount, but failed due to the dependecy between i_mutex. | |
30191 | + * rwsem for au_sbinfo is necessary. | |
30192 | + */ | |
dece6358 | 30193 | + struct au_rwsem si_rwsem; |
1facf9fc | 30194 | + |
7f207e10 | 30195 | + /* |
523b37e3 AM |
30196 | + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from |
30197 | + * remount. | |
7f207e10 | 30198 | + */ |
5afbbe0d | 30199 | + struct percpu_counter si_ninodes, si_nfiles; |
7f207e10 | 30200 | + |
1facf9fc | 30201 | + /* branch management */ |
30202 | + unsigned int si_generation; | |
30203 | + | |
2000de60 | 30204 | + /* see AuSi_ flags */ |
1facf9fc | 30205 | + unsigned char au_si_status; |
30206 | + | |
5afbbe0d | 30207 | + aufs_bindex_t si_bbot; |
7f207e10 AM |
30208 | + |
30209 | + /* dirty trick to keep br_id plus */ | |
30210 | + unsigned int si_last_br_id : | |
30211 | + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1; | |
1facf9fc | 30212 | + struct au_branch **si_branch; |
30213 | + | |
30214 | + /* policy to select a writable branch */ | |
30215 | + unsigned char si_wbr_copyup; | |
30216 | + unsigned char si_wbr_create; | |
30217 | + struct au_wbr_copyup_operations *si_wbr_copyup_ops; | |
30218 | + struct au_wbr_create_operations *si_wbr_create_ops; | |
30219 | + | |
30220 | + /* round robin */ | |
30221 | + atomic_t si_wbr_rr_next; | |
30222 | + | |
30223 | + /* most free space */ | |
30224 | + struct au_wbr_mfs si_wbr_mfs; | |
30225 | + | |
076b876e AM |
30226 | + /* File-based Hierarchical Storage Management */ |
30227 | + struct au_fhsm si_fhsm; | |
30228 | + | |
1facf9fc | 30229 | + /* mount flags */ |
30230 | + /* include/asm-ia64/siginfo.h defines a macro named si_flags */ | |
30231 | + unsigned int si_mntflags; | |
30232 | + | |
30233 | + /* external inode number (bitmap and translation table) */ | |
5527c038 JR |
30234 | + vfs_readf_t si_xread; |
30235 | + vfs_writef_t si_xwrite; | |
1facf9fc | 30236 | + struct file *si_xib; |
30237 | + struct mutex si_xib_mtx; /* protect xib members */ | |
30238 | + unsigned long *si_xib_buf; | |
30239 | + unsigned long si_xib_last_pindex; | |
30240 | + int si_xib_next_bit; | |
30241 | + aufs_bindex_t si_xino_brid; | |
392086de AM |
30242 | + unsigned long si_xino_jiffy; |
30243 | + unsigned long si_xino_expire; | |
1facf9fc | 30244 | + /* reserved for future use */ |
30245 | + /* unsigned long long si_xib_limit; */ /* Max xib file size */ | |
30246 | + | |
30247 | +#ifdef CONFIG_AUFS_EXPORT | |
30248 | + /* i_generation */ | |
30249 | + struct file *si_xigen; | |
30250 | + atomic_t si_xigen_next; | |
30251 | +#endif | |
30252 | + | |
b912730e | 30253 | + /* dirty trick to suppoer atomic_open */ |
8b6a4947 | 30254 | + struct hlist_bl_head si_aopen; |
b912730e | 30255 | + |
1facf9fc | 30256 | + /* vdir parameters */ |
e49829fe | 30257 | + unsigned long si_rdcache; /* max cache time in jiffies */ |
1facf9fc | 30258 | + unsigned int si_rdblk; /* deblk size */ |
30259 | + unsigned int si_rdhash; /* hash size */ | |
30260 | + | |
30261 | + /* | |
30262 | + * If the number of whiteouts are larger than si_dirwh, leave all of | |
30263 | + * them after au_whtmp_ren to reduce the cost of rmdir(2). | |
30264 | + * future fsck.aufs or kernel thread will remove them later. | |
30265 | + * Otherwise, remove all whiteouts and the dir in rmdir(2). | |
30266 | + */ | |
30267 | + unsigned int si_dirwh; | |
30268 | + | |
1facf9fc | 30269 | + /* pseudo_link list */ |
8b6a4947 | 30270 | + struct hlist_bl_head si_plink[AuPlink_NHASH]; |
1facf9fc | 30271 | + wait_queue_head_t si_plink_wq; |
4a4d8108 | 30272 | + spinlock_t si_plink_maint_lock; |
e49829fe | 30273 | + pid_t si_plink_maint_pid; |
1facf9fc | 30274 | + |
523b37e3 | 30275 | + /* file list */ |
8b6a4947 | 30276 | + struct hlist_bl_head si_files; |
523b37e3 | 30277 | + |
b95c5147 AM |
30278 | + /* with/without getattr, brother of sb->s_d_op */ |
30279 | + struct inode_operations *si_iop_array; | |
30280 | + | |
1facf9fc | 30281 | + /* |
30282 | + * sysfs and lifetime management. | |
30283 | + * this is not a small structure and it may be a waste of memory in case | |
30284 | + * of sysfs is disabled, particulary when many aufs-es are mounted. | |
30285 | + * but using sysfs is majority. | |
30286 | + */ | |
30287 | + struct kobject si_kobj; | |
30288 | +#ifdef CONFIG_DEBUG_FS | |
86dc4139 AM |
30289 | + struct dentry *si_dbgaufs; |
30290 | + struct dentry *si_dbgaufs_plink; | |
30291 | + struct dentry *si_dbgaufs_xib; | |
1facf9fc | 30292 | +#ifdef CONFIG_AUFS_EXPORT |
30293 | + struct dentry *si_dbgaufs_xigen; | |
30294 | +#endif | |
30295 | +#endif | |
30296 | + | |
e49829fe | 30297 | +#ifdef CONFIG_AUFS_SBILIST |
8b6a4947 | 30298 | + struct hlist_bl_node si_list; |
e49829fe JR |
30299 | +#endif |
30300 | + | |
1facf9fc | 30301 | + /* dirty, necessary for unmounting, sysfs and sysrq */ |
30302 | + struct super_block *si_sb; | |
30303 | +}; | |
30304 | + | |
dece6358 AM |
30305 | +/* sbinfo status flags */ |
30306 | +/* | |
30307 | + * set true when refresh_dirs() failed at remount time. | |
30308 | + * then try refreshing dirs at access time again. | |
30309 | + * if it is false, refreshing dirs at access time is unnecesary | |
30310 | + */ | |
027c5e7a | 30311 | +#define AuSi_FAILED_REFRESH_DIR 1 |
076b876e | 30312 | +#define AuSi_FHSM (1 << 1) /* fhsm is active now */ |
79b8bda9 | 30313 | +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */ |
076b876e AM |
30314 | + |
30315 | +#ifndef CONFIG_AUFS_FHSM | |
30316 | +#undef AuSi_FHSM | |
30317 | +#define AuSi_FHSM 0 | |
30318 | +#endif | |
30319 | + | |
dece6358 AM |
30320 | +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi, |
30321 | + unsigned int flag) | |
30322 | +{ | |
30323 | + AuRwMustAnyLock(&sbi->si_rwsem); | |
30324 | + return sbi->au_si_status & flag; | |
30325 | +} | |
30326 | +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name) | |
30327 | +#define au_fset_si(sbinfo, name) do { \ | |
30328 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
30329 | + (sbinfo)->au_si_status |= AuSi_##name; \ | |
30330 | +} while (0) | |
30331 | +#define au_fclr_si(sbinfo, name) do { \ | |
30332 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
30333 | + (sbinfo)->au_si_status &= ~AuSi_##name; \ | |
30334 | +} while (0) | |
30335 | + | |
1facf9fc | 30336 | +/* ---------------------------------------------------------------------- */ |
30337 | + | |
30338 | +/* policy to select one among writable branches */ | |
4a4d8108 AM |
30339 | +#define AuWbrCopyup(sbinfo, ...) \ |
30340 | + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__)) | |
30341 | +#define AuWbrCreate(sbinfo, ...) \ | |
30342 | + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__)) | |
1facf9fc | 30343 | + |
30344 | +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */ | |
30345 | +#define AuLock_DW 1 /* write-lock dentry */ | |
30346 | +#define AuLock_IR (1 << 1) /* read-lock inode */ | |
30347 | +#define AuLock_IW (1 << 2) /* write-lock inode */ | |
30348 | +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */ | |
b95c5147 | 30349 | +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */ |
f2c43d5f | 30350 | + /* except RENAME_EXCHANGE */ |
e49829fe JR |
30351 | +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */ |
30352 | +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */ | |
027c5e7a | 30353 | +#define AuLock_GEN (1 << 7) /* test digen/iigen */ |
1facf9fc | 30354 | +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name) |
7f207e10 AM |
30355 | +#define au_fset_lock(flags, name) \ |
30356 | + do { (flags) |= AuLock_##name; } while (0) | |
30357 | +#define au_fclr_lock(flags, name) \ | |
30358 | + do { (flags) &= ~AuLock_##name; } while (0) | |
1facf9fc | 30359 | + |
30360 | +/* ---------------------------------------------------------------------- */ | |
30361 | + | |
30362 | +/* super.c */ | |
30363 | +extern struct file_system_type aufs_fs_type; | |
30364 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino); | |
79b8bda9 AM |
30365 | +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array, |
30366 | + unsigned long long max, void *arg); | |
79b8bda9 AM |
30367 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, |
30368 | + struct super_block *sb, void *arg); | |
7f207e10 AM |
30369 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max); |
30370 | +void au_iarray_free(struct inode **a, unsigned long long max); | |
1facf9fc | 30371 | + |
30372 | +/* sbinfo.c */ | |
30373 | +void au_si_free(struct kobject *kobj); | |
30374 | +int au_si_alloc(struct super_block *sb); | |
e2f27e51 | 30375 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink); |
1facf9fc | 30376 | + |
30377 | +unsigned int au_sigen_inc(struct super_block *sb); | |
30378 | +aufs_bindex_t au_new_br_id(struct super_block *sb); | |
30379 | + | |
e49829fe JR |
30380 | +int si_read_lock(struct super_block *sb, int flags); |
30381 | +int si_write_lock(struct super_block *sb, int flags); | |
30382 | +int aufs_read_lock(struct dentry *dentry, int flags); | |
1facf9fc | 30383 | +void aufs_read_unlock(struct dentry *dentry, int flags); |
30384 | +void aufs_write_lock(struct dentry *dentry); | |
30385 | +void aufs_write_unlock(struct dentry *dentry); | |
e49829fe | 30386 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags); |
1facf9fc | 30387 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2); |
30388 | + | |
30389 | +/* wbr_policy.c */ | |
30390 | +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[]; | |
30391 | +extern struct au_wbr_create_operations au_wbr_create_ops[]; | |
30392 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
c2b27bf2 | 30393 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex); |
5afbbe0d | 30394 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop); |
c2b27bf2 AM |
30395 | + |
30396 | +/* mvdown.c */ | |
30397 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg); | |
1facf9fc | 30398 | + |
076b876e AM |
30399 | +#ifdef CONFIG_AUFS_FHSM |
30400 | +/* fhsm.c */ | |
30401 | + | |
30402 | +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm) | |
30403 | +{ | |
30404 | + pid_t pid; | |
30405 | + | |
30406 | + spin_lock(&fhsm->fhsm_spin); | |
30407 | + pid = fhsm->fhsm_pid; | |
30408 | + spin_unlock(&fhsm->fhsm_spin); | |
30409 | + | |
30410 | + return pid; | |
30411 | +} | |
30412 | + | |
30413 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force); | |
30414 | +void au_fhsm_wrote_all(struct super_block *sb, int force); | |
30415 | +int au_fhsm_fd(struct super_block *sb, int oflags); | |
30416 | +int au_fhsm_br_alloc(struct au_branch *br); | |
c1595e42 | 30417 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex); |
076b876e AM |
30418 | +void au_fhsm_fin(struct super_block *sb); |
30419 | +void au_fhsm_init(struct au_sbinfo *sbinfo); | |
30420 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec); | |
30421 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo); | |
30422 | +#else | |
30423 | +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex, | |
30424 | + int force) | |
30425 | +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force) | |
30426 | +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags) | |
c1595e42 JR |
30427 | +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm) |
30428 | +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br) | |
30429 | +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex) | |
076b876e AM |
30430 | +AuStubVoid(au_fhsm_fin, struct super_block *sb) |
30431 | +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo) | |
30432 | +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec) | |
30433 | +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo) | |
30434 | +#endif | |
30435 | + | |
1facf9fc | 30436 | +/* ---------------------------------------------------------------------- */ |
30437 | + | |
30438 | +static inline struct au_sbinfo *au_sbi(struct super_block *sb) | |
30439 | +{ | |
30440 | + return sb->s_fs_info; | |
30441 | +} | |
30442 | + | |
30443 | +/* ---------------------------------------------------------------------- */ | |
30444 | + | |
30445 | +#ifdef CONFIG_AUFS_EXPORT | |
a2a7ad62 | 30446 | +int au_test_nfsd(void); |
1facf9fc | 30447 | +void au_export_init(struct super_block *sb); |
b752ccd1 | 30448 | +void au_xigen_inc(struct inode *inode); |
1facf9fc | 30449 | +int au_xigen_new(struct inode *inode); |
30450 | +int au_xigen_set(struct super_block *sb, struct file *base); | |
30451 | +void au_xigen_clr(struct super_block *sb); | |
30452 | + | |
30453 | +static inline int au_busy_or_stale(void) | |
30454 | +{ | |
b752ccd1 | 30455 | + if (!au_test_nfsd()) |
1facf9fc | 30456 | + return -EBUSY; |
30457 | + return -ESTALE; | |
30458 | +} | |
30459 | +#else | |
b752ccd1 | 30460 | +AuStubInt0(au_test_nfsd, void) |
a2a7ad62 | 30461 | +AuStubVoid(au_export_init, struct super_block *sb) |
b752ccd1 | 30462 | +AuStubVoid(au_xigen_inc, struct inode *inode) |
4a4d8108 AM |
30463 | +AuStubInt0(au_xigen_new, struct inode *inode) |
30464 | +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base) | |
30465 | +AuStubVoid(au_xigen_clr, struct super_block *sb) | |
c1595e42 | 30466 | +AuStub(int, au_busy_or_stale, return -EBUSY, void) |
1facf9fc | 30467 | +#endif /* CONFIG_AUFS_EXPORT */ |
30468 | + | |
30469 | +/* ---------------------------------------------------------------------- */ | |
30470 | + | |
e49829fe JR |
30471 | +#ifdef CONFIG_AUFS_SBILIST |
30472 | +/* module.c */ | |
8b6a4947 | 30473 | +extern struct hlist_bl_head au_sbilist; |
e49829fe JR |
30474 | + |
30475 | +static inline void au_sbilist_init(void) | |
30476 | +{ | |
8b6a4947 | 30477 | + INIT_HLIST_BL_HEAD(&au_sbilist); |
e49829fe JR |
30478 | +} |
30479 | + | |
30480 | +static inline void au_sbilist_add(struct super_block *sb) | |
30481 | +{ | |
8b6a4947 | 30482 | + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist); |
e49829fe JR |
30483 | +} |
30484 | + | |
30485 | +static inline void au_sbilist_del(struct super_block *sb) | |
30486 | +{ | |
8b6a4947 | 30487 | + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist); |
e49829fe | 30488 | +} |
53392da6 AM |
30489 | + |
30490 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
30491 | +static inline void au_sbilist_lock(void) | |
30492 | +{ | |
8b6a4947 | 30493 | + hlist_bl_lock(&au_sbilist); |
53392da6 AM |
30494 | +} |
30495 | + | |
30496 | +static inline void au_sbilist_unlock(void) | |
30497 | +{ | |
8b6a4947 | 30498 | + hlist_bl_unlock(&au_sbilist); |
53392da6 AM |
30499 | +} |
30500 | +#define AuGFP_SBILIST GFP_ATOMIC | |
30501 | +#else | |
30502 | +AuStubVoid(au_sbilist_lock, void) | |
30503 | +AuStubVoid(au_sbilist_unlock, void) | |
30504 | +#define AuGFP_SBILIST GFP_NOFS | |
30505 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
e49829fe JR |
30506 | +#else |
30507 | +AuStubVoid(au_sbilist_init, void) | |
c1595e42 JR |
30508 | +AuStubVoid(au_sbilist_add, struct super_block *sb) |
30509 | +AuStubVoid(au_sbilist_del, struct super_block *sb) | |
53392da6 AM |
30510 | +AuStubVoid(au_sbilist_lock, void) |
30511 | +AuStubVoid(au_sbilist_unlock, void) | |
30512 | +#define AuGFP_SBILIST GFP_NOFS | |
e49829fe JR |
30513 | +#endif |
30514 | + | |
30515 | +/* ---------------------------------------------------------------------- */ | |
30516 | + | |
1facf9fc | 30517 | +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo) |
30518 | +{ | |
dece6358 | 30519 | + /* |
c1595e42 | 30520 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
30521 | + * so the tiny check for si_rwsem is unnecessary. |
30522 | + */ | |
30523 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
1facf9fc | 30524 | +#ifdef CONFIG_DEBUG_FS |
30525 | + sbinfo->si_dbgaufs = NULL; | |
86dc4139 | 30526 | + sbinfo->si_dbgaufs_plink = NULL; |
1facf9fc | 30527 | + sbinfo->si_dbgaufs_xib = NULL; |
30528 | +#ifdef CONFIG_AUFS_EXPORT | |
30529 | + sbinfo->si_dbgaufs_xigen = NULL; | |
30530 | +#endif | |
30531 | +#endif | |
30532 | +} | |
30533 | + | |
30534 | +/* ---------------------------------------------------------------------- */ | |
30535 | + | |
a2654f78 AM |
30536 | +/* current->atomic_flags */ |
30537 | +/* this value should never corrupt the ones defined in linux/sched.h */ | |
30538 | +#define PFA_AUFS 7 | |
30539 | + | |
30540 | +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */ | |
30541 | +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */ | |
30542 | +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */ | |
b752ccd1 AM |
30543 | + |
30544 | +static inline int si_pid_test(struct super_block *sb) | |
30545 | +{ | |
a2654f78 | 30546 | + return !!task_test_aufs(current); |
b752ccd1 AM |
30547 | +} |
30548 | + | |
30549 | +static inline void si_pid_clr(struct super_block *sb) | |
30550 | +{ | |
a2654f78 AM |
30551 | + AuDebugOn(!task_test_aufs(current)); |
30552 | + task_clear_aufs(current); | |
b752ccd1 AM |
30553 | +} |
30554 | + | |
a2654f78 AM |
30555 | +static inline void si_pid_set(struct super_block *sb) |
30556 | +{ | |
30557 | + AuDebugOn(task_test_aufs(current)); | |
30558 | + task_set_aufs(current); | |
30559 | +} | |
febd17d6 | 30560 | + |
b752ccd1 AM |
30561 | +/* ---------------------------------------------------------------------- */ |
30562 | + | |
1facf9fc | 30563 | +/* lock superblock. mainly for entry point functions */ |
8b6a4947 AM |
30564 | +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem) |
30565 | +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem) | |
30566 | +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem) | |
30567 | +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem) | |
30568 | +/* | |
30569 | +#define __si_read_trylock_nested(sb) \ | |
30570 | + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem) | |
30571 | +#define __si_write_trylock_nested(sb) \ | |
30572 | + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem) | |
30573 | +*/ | |
30574 | + | |
30575 | +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem) | |
30576 | +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem) | |
30577 | +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem) | |
1facf9fc | 30578 | + |
dece6358 AM |
30579 | +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem) |
30580 | +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem) | |
30581 | +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem) | |
30582 | + | |
b752ccd1 AM |
30583 | +static inline void si_noflush_read_lock(struct super_block *sb) |
30584 | +{ | |
30585 | + __si_read_lock(sb); | |
30586 | + si_pid_set(sb); | |
30587 | +} | |
30588 | + | |
30589 | +static inline int si_noflush_read_trylock(struct super_block *sb) | |
30590 | +{ | |
076b876e AM |
30591 | + int locked; |
30592 | + | |
30593 | + locked = __si_read_trylock(sb); | |
b752ccd1 AM |
30594 | + if (locked) |
30595 | + si_pid_set(sb); | |
30596 | + return locked; | |
30597 | +} | |
30598 | + | |
30599 | +static inline void si_noflush_write_lock(struct super_block *sb) | |
30600 | +{ | |
30601 | + __si_write_lock(sb); | |
30602 | + si_pid_set(sb); | |
30603 | +} | |
30604 | + | |
30605 | +static inline int si_noflush_write_trylock(struct super_block *sb) | |
30606 | +{ | |
076b876e AM |
30607 | + int locked; |
30608 | + | |
30609 | + locked = __si_write_trylock(sb); | |
b752ccd1 AM |
30610 | + if (locked) |
30611 | + si_pid_set(sb); | |
30612 | + return locked; | |
30613 | +} | |
30614 | + | |
7e9cd9fe | 30615 | +#if 0 /* reserved */ |
1facf9fc | 30616 | +static inline int si_read_trylock(struct super_block *sb, int flags) |
30617 | +{ | |
30618 | + if (au_ftest_lock(flags, FLUSH)) | |
30619 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
30620 | + return si_noflush_read_trylock(sb); | |
30621 | +} | |
e49829fe | 30622 | +#endif |
1facf9fc | 30623 | + |
b752ccd1 AM |
30624 | +static inline void si_read_unlock(struct super_block *sb) |
30625 | +{ | |
30626 | + si_pid_clr(sb); | |
30627 | + __si_read_unlock(sb); | |
30628 | +} | |
30629 | + | |
7e9cd9fe | 30630 | +#if 0 /* reserved */ |
1facf9fc | 30631 | +static inline int si_write_trylock(struct super_block *sb, int flags) |
30632 | +{ | |
30633 | + if (au_ftest_lock(flags, FLUSH)) | |
30634 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
30635 | + return si_noflush_write_trylock(sb); | |
30636 | +} | |
b752ccd1 AM |
30637 | +#endif |
30638 | + | |
30639 | +static inline void si_write_unlock(struct super_block *sb) | |
30640 | +{ | |
30641 | + si_pid_clr(sb); | |
30642 | + __si_write_unlock(sb); | |
30643 | +} | |
30644 | + | |
7e9cd9fe | 30645 | +#if 0 /* reserved */ |
b752ccd1 AM |
30646 | +static inline void si_downgrade_lock(struct super_block *sb) |
30647 | +{ | |
30648 | + __si_downgrade_lock(sb); | |
30649 | +} | |
30650 | +#endif | |
1facf9fc | 30651 | + |
30652 | +/* ---------------------------------------------------------------------- */ | |
30653 | + | |
5afbbe0d | 30654 | +static inline aufs_bindex_t au_sbbot(struct super_block *sb) |
1facf9fc | 30655 | +{ |
dece6358 | 30656 | + SiMustAnyLock(sb); |
5afbbe0d | 30657 | + return au_sbi(sb)->si_bbot; |
1facf9fc | 30658 | +} |
30659 | + | |
30660 | +static inline unsigned int au_mntflags(struct super_block *sb) | |
30661 | +{ | |
dece6358 | 30662 | + SiMustAnyLock(sb); |
1facf9fc | 30663 | + return au_sbi(sb)->si_mntflags; |
30664 | +} | |
30665 | + | |
30666 | +static inline unsigned int au_sigen(struct super_block *sb) | |
30667 | +{ | |
dece6358 | 30668 | + SiMustAnyLock(sb); |
1facf9fc | 30669 | + return au_sbi(sb)->si_generation; |
30670 | +} | |
30671 | + | |
5afbbe0d AM |
30672 | +static inline unsigned long long au_ninodes(struct super_block *sb) |
30673 | +{ | |
30674 | + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes); | |
30675 | + | |
30676 | + BUG_ON(n < 0); | |
30677 | + return n; | |
30678 | +} | |
30679 | + | |
7f207e10 AM |
30680 | +static inline void au_ninodes_inc(struct super_block *sb) |
30681 | +{ | |
5afbbe0d | 30682 | + percpu_counter_inc(&au_sbi(sb)->si_ninodes); |
7f207e10 AM |
30683 | +} |
30684 | + | |
30685 | +static inline void au_ninodes_dec(struct super_block *sb) | |
30686 | +{ | |
5afbbe0d AM |
30687 | + percpu_counter_dec(&au_sbi(sb)->si_ninodes); |
30688 | +} | |
30689 | + | |
30690 | +static inline unsigned long long au_nfiles(struct super_block *sb) | |
30691 | +{ | |
30692 | + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles); | |
30693 | + | |
30694 | + BUG_ON(n < 0); | |
30695 | + return n; | |
7f207e10 AM |
30696 | +} |
30697 | + | |
30698 | +static inline void au_nfiles_inc(struct super_block *sb) | |
30699 | +{ | |
5afbbe0d | 30700 | + percpu_counter_inc(&au_sbi(sb)->si_nfiles); |
7f207e10 AM |
30701 | +} |
30702 | + | |
30703 | +static inline void au_nfiles_dec(struct super_block *sb) | |
30704 | +{ | |
5afbbe0d | 30705 | + percpu_counter_dec(&au_sbi(sb)->si_nfiles); |
7f207e10 AM |
30706 | +} |
30707 | + | |
1facf9fc | 30708 | +static inline struct au_branch *au_sbr(struct super_block *sb, |
30709 | + aufs_bindex_t bindex) | |
30710 | +{ | |
dece6358 | 30711 | + SiMustAnyLock(sb); |
1facf9fc | 30712 | + return au_sbi(sb)->si_branch[0 + bindex]; |
30713 | +} | |
30714 | + | |
30715 | +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid) | |
30716 | +{ | |
dece6358 | 30717 | + SiMustWriteLock(sb); |
1facf9fc | 30718 | + au_sbi(sb)->si_xino_brid = brid; |
30719 | +} | |
30720 | + | |
30721 | +static inline aufs_bindex_t au_xino_brid(struct super_block *sb) | |
30722 | +{ | |
dece6358 | 30723 | + SiMustAnyLock(sb); |
1facf9fc | 30724 | + return au_sbi(sb)->si_xino_brid; |
30725 | +} | |
30726 | + | |
30727 | +#endif /* __KERNEL__ */ | |
30728 | +#endif /* __AUFS_SUPER_H__ */ | |
7f207e10 AM |
30729 | diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c |
30730 | --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 30731 | +++ linux/fs/aufs/sysaufs.c 2018-01-29 07:56:20.059991935 +0100 |
523b37e3 | 30732 | @@ -0,0 +1,104 @@ |
1facf9fc | 30733 | +/* |
a2654f78 | 30734 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 30735 | + * |
30736 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30737 | + * it under the terms of the GNU General Public License as published by | |
30738 | + * the Free Software Foundation; either version 2 of the License, or | |
30739 | + * (at your option) any later version. | |
dece6358 AM |
30740 | + * |
30741 | + * This program is distributed in the hope that it will be useful, | |
30742 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30743 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30744 | + * GNU General Public License for more details. | |
30745 | + * | |
30746 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30747 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30748 | + */ |
30749 | + | |
30750 | +/* | |
30751 | + * sysfs interface and lifetime management | |
30752 | + * they are necessary regardless sysfs is disabled. | |
30753 | + */ | |
30754 | + | |
1facf9fc | 30755 | +#include <linux/random.h> |
1facf9fc | 30756 | +#include "aufs.h" |
30757 | + | |
30758 | +unsigned long sysaufs_si_mask; | |
e49829fe | 30759 | +struct kset *sysaufs_kset; |
1facf9fc | 30760 | + |
30761 | +#define AuSiAttr(_name) { \ | |
30762 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ | |
30763 | + .show = sysaufs_si_##_name, \ | |
30764 | +} | |
30765 | + | |
30766 | +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path); | |
30767 | +struct attribute *sysaufs_si_attrs[] = { | |
30768 | + &sysaufs_si_attr_xi_path.attr, | |
30769 | + NULL, | |
30770 | +}; | |
30771 | + | |
4a4d8108 | 30772 | +static const struct sysfs_ops au_sbi_ops = { |
1facf9fc | 30773 | + .show = sysaufs_si_show |
30774 | +}; | |
30775 | + | |
30776 | +static struct kobj_type au_sbi_ktype = { | |
30777 | + .release = au_si_free, | |
30778 | + .sysfs_ops = &au_sbi_ops, | |
30779 | + .default_attrs = sysaufs_si_attrs | |
30780 | +}; | |
30781 | + | |
30782 | +/* ---------------------------------------------------------------------- */ | |
30783 | + | |
30784 | +int sysaufs_si_init(struct au_sbinfo *sbinfo) | |
30785 | +{ | |
30786 | + int err; | |
30787 | + | |
e49829fe | 30788 | + sbinfo->si_kobj.kset = sysaufs_kset; |
1facf9fc | 30789 | + /* cf. sysaufs_name() */ |
30790 | + err = kobject_init_and_add | |
e49829fe | 30791 | + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL, |
1facf9fc | 30792 | + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo)); |
30793 | + | |
30794 | + dbgaufs_si_null(sbinfo); | |
30795 | + if (!err) { | |
30796 | + err = dbgaufs_si_init(sbinfo); | |
30797 | + if (unlikely(err)) | |
30798 | + kobject_put(&sbinfo->si_kobj); | |
30799 | + } | |
30800 | + return err; | |
30801 | +} | |
30802 | + | |
30803 | +void sysaufs_fin(void) | |
30804 | +{ | |
30805 | + dbgaufs_fin(); | |
e49829fe JR |
30806 | + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
30807 | + kset_unregister(sysaufs_kset); | |
1facf9fc | 30808 | +} |
30809 | + | |
30810 | +int __init sysaufs_init(void) | |
30811 | +{ | |
30812 | + int err; | |
30813 | + | |
30814 | + do { | |
30815 | + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask)); | |
30816 | + } while (!sysaufs_si_mask); | |
30817 | + | |
4a4d8108 | 30818 | + err = -EINVAL; |
e49829fe JR |
30819 | + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj); |
30820 | + if (unlikely(!sysaufs_kset)) | |
4a4d8108 | 30821 | + goto out; |
e49829fe JR |
30822 | + err = PTR_ERR(sysaufs_kset); |
30823 | + if (IS_ERR(sysaufs_kset)) | |
1facf9fc | 30824 | + goto out; |
e49829fe | 30825 | + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
1facf9fc | 30826 | + if (unlikely(err)) { |
e49829fe | 30827 | + kset_unregister(sysaufs_kset); |
1facf9fc | 30828 | + goto out; |
30829 | + } | |
30830 | + | |
30831 | + err = dbgaufs_init(); | |
30832 | + if (unlikely(err)) | |
30833 | + sysaufs_fin(); | |
4f0767ce | 30834 | +out: |
1facf9fc | 30835 | + return err; |
30836 | +} | |
7f207e10 AM |
30837 | diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h |
30838 | --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 30839 | +++ linux/fs/aufs/sysaufs.h 2018-01-29 07:56:20.059991935 +0100 |
c1595e42 | 30840 | @@ -0,0 +1,101 @@ |
1facf9fc | 30841 | +/* |
a2654f78 | 30842 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 30843 | + * |
30844 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30845 | + * it under the terms of the GNU General Public License as published by | |
30846 | + * the Free Software Foundation; either version 2 of the License, or | |
30847 | + * (at your option) any later version. | |
dece6358 AM |
30848 | + * |
30849 | + * This program is distributed in the hope that it will be useful, | |
30850 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30851 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30852 | + * GNU General Public License for more details. | |
30853 | + * | |
30854 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30855 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30856 | + */ |
30857 | + | |
30858 | +/* | |
30859 | + * sysfs interface and mount lifetime management | |
30860 | + */ | |
30861 | + | |
30862 | +#ifndef __SYSAUFS_H__ | |
30863 | +#define __SYSAUFS_H__ | |
30864 | + | |
30865 | +#ifdef __KERNEL__ | |
30866 | + | |
1facf9fc | 30867 | +#include <linux/sysfs.h> |
1facf9fc | 30868 | +#include "module.h" |
30869 | + | |
dece6358 AM |
30870 | +struct super_block; |
30871 | +struct au_sbinfo; | |
30872 | + | |
1facf9fc | 30873 | +struct sysaufs_si_attr { |
30874 | + struct attribute attr; | |
30875 | + int (*show)(struct seq_file *seq, struct super_block *sb); | |
30876 | +}; | |
30877 | + | |
30878 | +/* ---------------------------------------------------------------------- */ | |
30879 | + | |
30880 | +/* sysaufs.c */ | |
30881 | +extern unsigned long sysaufs_si_mask; | |
e49829fe | 30882 | +extern struct kset *sysaufs_kset; |
1facf9fc | 30883 | +extern struct attribute *sysaufs_si_attrs[]; |
30884 | +int sysaufs_si_init(struct au_sbinfo *sbinfo); | |
30885 | +int __init sysaufs_init(void); | |
30886 | +void sysaufs_fin(void); | |
30887 | + | |
30888 | +/* ---------------------------------------------------------------------- */ | |
30889 | + | |
30890 | +/* some people doesn't like to show a pointer in kernel */ | |
30891 | +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo) | |
30892 | +{ | |
30893 | + return sysaufs_si_mask ^ (unsigned long)sbinfo; | |
30894 | +} | |
30895 | + | |
30896 | +#define SysaufsSiNamePrefix "si_" | |
30897 | +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16) | |
30898 | +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name) | |
30899 | +{ | |
30900 | + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx", | |
30901 | + sysaufs_si_id(sbinfo)); | |
30902 | +} | |
30903 | + | |
30904 | +struct au_branch; | |
30905 | +#ifdef CONFIG_SYSFS | |
30906 | +/* sysfs.c */ | |
30907 | +extern struct attribute_group *sysaufs_attr_group; | |
30908 | + | |
30909 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb); | |
30910 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
30911 | + char *buf); | |
076b876e AM |
30912 | +long au_brinfo_ioctl(struct file *file, unsigned long arg); |
30913 | +#ifdef CONFIG_COMPAT | |
30914 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg); | |
30915 | +#endif | |
1facf9fc | 30916 | + |
30917 | +void sysaufs_br_init(struct au_branch *br); | |
30918 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
30919 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
30920 | + | |
30921 | +#define sysaufs_brs_init() do {} while (0) | |
30922 | + | |
30923 | +#else | |
30924 | +#define sysaufs_attr_group NULL | |
30925 | + | |
4a4d8108 | 30926 | +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb) |
c1595e42 JR |
30927 | +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj, |
30928 | + struct attribute *attr, char *buf) | |
4a4d8108 AM |
30929 | +AuStubVoid(sysaufs_br_init, struct au_branch *br) |
30930 | +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
30931 | +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) | |
1facf9fc | 30932 | + |
30933 | +static inline void sysaufs_brs_init(void) | |
30934 | +{ | |
30935 | + sysaufs_brs = 0; | |
30936 | +} | |
30937 | + | |
30938 | +#endif /* CONFIG_SYSFS */ | |
30939 | + | |
30940 | +#endif /* __KERNEL__ */ | |
30941 | +#endif /* __SYSAUFS_H__ */ | |
7f207e10 AM |
30942 | diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c |
30943 | --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 30944 | +++ linux/fs/aufs/sysfs.c 2018-01-29 07:56:20.059991935 +0100 |
79b8bda9 | 30945 | @@ -0,0 +1,376 @@ |
1facf9fc | 30946 | +/* |
a2654f78 | 30947 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 30948 | + * |
30949 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30950 | + * it under the terms of the GNU General Public License as published by | |
30951 | + * the Free Software Foundation; either version 2 of the License, or | |
30952 | + * (at your option) any later version. | |
dece6358 AM |
30953 | + * |
30954 | + * This program is distributed in the hope that it will be useful, | |
30955 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30956 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30957 | + * GNU General Public License for more details. | |
30958 | + * | |
30959 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30960 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30961 | + */ |
30962 | + | |
30963 | +/* | |
30964 | + * sysfs interface | |
30965 | + */ | |
30966 | + | |
076b876e | 30967 | +#include <linux/compat.h> |
1facf9fc | 30968 | +#include <linux/seq_file.h> |
1facf9fc | 30969 | +#include "aufs.h" |
30970 | + | |
4a4d8108 AM |
30971 | +#ifdef CONFIG_AUFS_FS_MODULE |
30972 | +/* this entry violates the "one line per file" policy of sysfs */ | |
30973 | +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr, | |
30974 | + char *buf) | |
30975 | +{ | |
30976 | + ssize_t err; | |
30977 | + static char *conf = | |
30978 | +/* this file is generated at compiling */ | |
30979 | +#include "conf.str" | |
30980 | + ; | |
30981 | + | |
30982 | + err = snprintf(buf, PAGE_SIZE, conf); | |
30983 | + if (unlikely(err >= PAGE_SIZE)) | |
30984 | + err = -EFBIG; | |
30985 | + return err; | |
30986 | +} | |
30987 | + | |
30988 | +static struct kobj_attribute au_config_attr = __ATTR_RO(config); | |
30989 | +#endif | |
30990 | + | |
1facf9fc | 30991 | +static struct attribute *au_attr[] = { |
4a4d8108 AM |
30992 | +#ifdef CONFIG_AUFS_FS_MODULE |
30993 | + &au_config_attr.attr, | |
30994 | +#endif | |
1facf9fc | 30995 | + NULL, /* need to NULL terminate the list of attributes */ |
30996 | +}; | |
30997 | + | |
30998 | +static struct attribute_group sysaufs_attr_group_body = { | |
30999 | + .attrs = au_attr | |
31000 | +}; | |
31001 | + | |
31002 | +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body; | |
31003 | + | |
31004 | +/* ---------------------------------------------------------------------- */ | |
31005 | + | |
31006 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb) | |
31007 | +{ | |
31008 | + int err; | |
31009 | + | |
dece6358 AM |
31010 | + SiMustAnyLock(sb); |
31011 | + | |
1facf9fc | 31012 | + err = 0; |
31013 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
31014 | + err = au_xino_path(seq, au_sbi(sb)->si_xib); | |
31015 | + seq_putc(seq, '\n'); | |
31016 | + } | |
31017 | + return err; | |
31018 | +} | |
31019 | + | |
31020 | +/* | |
31021 | + * the lifetime of branch is independent from the entry under sysfs. | |
31022 | + * sysfs handles the lifetime of the entry, and never call ->show() after it is | |
31023 | + * unlinked. | |
31024 | + */ | |
31025 | +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb, | |
392086de | 31026 | + aufs_bindex_t bindex, int idx) |
1facf9fc | 31027 | +{ |
1e00d052 | 31028 | + int err; |
1facf9fc | 31029 | + struct path path; |
31030 | + struct dentry *root; | |
31031 | + struct au_branch *br; | |
076b876e | 31032 | + au_br_perm_str_t perm; |
1facf9fc | 31033 | + |
31034 | + AuDbg("b%d\n", bindex); | |
31035 | + | |
1e00d052 | 31036 | + err = 0; |
1facf9fc | 31037 | + root = sb->s_root; |
31038 | + di_read_lock_parent(root, !AuLock_IR); | |
31039 | + br = au_sbr(sb, bindex); | |
392086de AM |
31040 | + |
31041 | + switch (idx) { | |
31042 | + case AuBrSysfs_BR: | |
31043 | + path.mnt = au_br_mnt(br); | |
31044 | + path.dentry = au_h_dptr(root, bindex); | |
79b8bda9 AM |
31045 | + err = au_seq_path(seq, &path); |
31046 | + if (!err) { | |
31047 | + au_optstr_br_perm(&perm, br->br_perm); | |
31048 | + seq_printf(seq, "=%s\n", perm.a); | |
31049 | + } | |
392086de AM |
31050 | + break; |
31051 | + case AuBrSysfs_BRID: | |
79b8bda9 | 31052 | + seq_printf(seq, "%d\n", br->br_id); |
392086de AM |
31053 | + break; |
31054 | + } | |
076b876e | 31055 | + di_read_unlock(root, !AuLock_IR); |
79b8bda9 | 31056 | + if (unlikely(err || seq_has_overflowed(seq))) |
076b876e | 31057 | + err = -E2BIG; |
392086de | 31058 | + |
1e00d052 | 31059 | + return err; |
1facf9fc | 31060 | +} |
31061 | + | |
31062 | +/* ---------------------------------------------------------------------- */ | |
31063 | + | |
31064 | +static struct seq_file *au_seq(char *p, ssize_t len) | |
31065 | +{ | |
31066 | + struct seq_file *seq; | |
31067 | + | |
31068 | + seq = kzalloc(sizeof(*seq), GFP_NOFS); | |
31069 | + if (seq) { | |
31070 | + /* mutex_init(&seq.lock); */ | |
31071 | + seq->buf = p; | |
31072 | + seq->size = len; | |
31073 | + return seq; /* success */ | |
31074 | + } | |
31075 | + | |
31076 | + seq = ERR_PTR(-ENOMEM); | |
31077 | + return seq; | |
31078 | +} | |
31079 | + | |
392086de AM |
31080 | +#define SysaufsBr_PREFIX "br" |
31081 | +#define SysaufsBrid_PREFIX "brid" | |
1facf9fc | 31082 | + |
31083 | +/* todo: file size may exceed PAGE_SIZE */ | |
31084 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
1308ab2a | 31085 | + char *buf) |
1facf9fc | 31086 | +{ |
31087 | + ssize_t err; | |
392086de | 31088 | + int idx; |
1facf9fc | 31089 | + long l; |
5afbbe0d | 31090 | + aufs_bindex_t bbot; |
1facf9fc | 31091 | + struct au_sbinfo *sbinfo; |
31092 | + struct super_block *sb; | |
31093 | + struct seq_file *seq; | |
31094 | + char *name; | |
31095 | + struct attribute **cattr; | |
31096 | + | |
31097 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
31098 | + sb = sbinfo->si_sb; | |
1308ab2a | 31099 | + |
31100 | + /* | |
31101 | + * prevent a race condition between sysfs and aufs. | |
31102 | + * for instance, sysfs_file_read() calls sysfs_get_active_two() which | |
31103 | + * prohibits maintaining the sysfs entries. | |
31104 | + * hew we acquire read lock after sysfs_get_active_two(). | |
31105 | + * on the other hand, the remount process may maintain the sysfs/aufs | |
31106 | + * entries after acquiring write lock. | |
31107 | + * it can cause a deadlock. | |
31108 | + * simply we gave up processing read here. | |
31109 | + */ | |
31110 | + err = -EBUSY; | |
31111 | + if (unlikely(!si_noflush_read_trylock(sb))) | |
31112 | + goto out; | |
1facf9fc | 31113 | + |
31114 | + seq = au_seq(buf, PAGE_SIZE); | |
31115 | + err = PTR_ERR(seq); | |
31116 | + if (IS_ERR(seq)) | |
1308ab2a | 31117 | + goto out_unlock; |
1facf9fc | 31118 | + |
31119 | + name = (void *)attr->name; | |
31120 | + cattr = sysaufs_si_attrs; | |
31121 | + while (*cattr) { | |
31122 | + if (!strcmp(name, (*cattr)->name)) { | |
31123 | + err = container_of(*cattr, struct sysaufs_si_attr, attr) | |
31124 | + ->show(seq, sb); | |
31125 | + goto out_seq; | |
31126 | + } | |
31127 | + cattr++; | |
31128 | + } | |
31129 | + | |
392086de AM |
31130 | + if (!strncmp(name, SysaufsBrid_PREFIX, |
31131 | + sizeof(SysaufsBrid_PREFIX) - 1)) { | |
31132 | + idx = AuBrSysfs_BRID; | |
31133 | + name += sizeof(SysaufsBrid_PREFIX) - 1; | |
31134 | + } else if (!strncmp(name, SysaufsBr_PREFIX, | |
31135 | + sizeof(SysaufsBr_PREFIX) - 1)) { | |
31136 | + idx = AuBrSysfs_BR; | |
1facf9fc | 31137 | + name += sizeof(SysaufsBr_PREFIX) - 1; |
392086de AM |
31138 | + } else |
31139 | + BUG(); | |
31140 | + | |
31141 | + err = kstrtol(name, 10, &l); | |
31142 | + if (!err) { | |
5afbbe0d AM |
31143 | + bbot = au_sbbot(sb); |
31144 | + if (l <= bbot) | |
392086de AM |
31145 | + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx); |
31146 | + else | |
31147 | + err = -ENOENT; | |
1facf9fc | 31148 | + } |
1facf9fc | 31149 | + |
4f0767ce | 31150 | +out_seq: |
1facf9fc | 31151 | + if (!err) { |
31152 | + err = seq->count; | |
31153 | + /* sysfs limit */ | |
31154 | + if (unlikely(err == PAGE_SIZE)) | |
31155 | + err = -EFBIG; | |
31156 | + } | |
1c60b727 | 31157 | + kfree(seq); |
4f0767ce | 31158 | +out_unlock: |
1facf9fc | 31159 | + si_read_unlock(sb); |
4f0767ce | 31160 | +out: |
1facf9fc | 31161 | + return err; |
31162 | +} | |
31163 | + | |
31164 | +/* ---------------------------------------------------------------------- */ | |
31165 | + | |
076b876e AM |
31166 | +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg) |
31167 | +{ | |
31168 | + int err; | |
31169 | + int16_t brid; | |
5afbbe0d | 31170 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
31171 | + size_t sz; |
31172 | + char *buf; | |
31173 | + struct seq_file *seq; | |
31174 | + struct au_branch *br; | |
31175 | + | |
31176 | + si_read_lock(sb, AuLock_FLUSH); | |
5afbbe0d AM |
31177 | + bbot = au_sbbot(sb); |
31178 | + err = bbot + 1; | |
076b876e AM |
31179 | + if (!arg) |
31180 | + goto out; | |
31181 | + | |
31182 | + err = -ENOMEM; | |
31183 | + buf = (void *)__get_free_page(GFP_NOFS); | |
31184 | + if (unlikely(!buf)) | |
31185 | + goto out; | |
31186 | + | |
31187 | + seq = au_seq(buf, PAGE_SIZE); | |
31188 | + err = PTR_ERR(seq); | |
31189 | + if (IS_ERR(seq)) | |
31190 | + goto out_buf; | |
31191 | + | |
31192 | + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path); | |
5afbbe0d | 31193 | + for (bindex = 0; bindex <= bbot; bindex++, arg++) { |
076b876e AM |
31194 | + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg)); |
31195 | + if (unlikely(err)) | |
31196 | + break; | |
31197 | + | |
31198 | + br = au_sbr(sb, bindex); | |
31199 | + brid = br->br_id; | |
31200 | + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id)); | |
31201 | + err = __put_user(brid, &arg->id); | |
31202 | + if (unlikely(err)) | |
31203 | + break; | |
31204 | + | |
31205 | + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm)); | |
31206 | + err = __put_user(br->br_perm, &arg->perm); | |
31207 | + if (unlikely(err)) | |
31208 | + break; | |
31209 | + | |
79b8bda9 AM |
31210 | + err = au_seq_path(seq, &br->br_path); |
31211 | + if (unlikely(err)) | |
31212 | + break; | |
31213 | + seq_putc(seq, '\0'); | |
31214 | + if (!seq_has_overflowed(seq)) { | |
076b876e AM |
31215 | + err = copy_to_user(arg->path, seq->buf, seq->count); |
31216 | + seq->count = 0; | |
31217 | + if (unlikely(err)) | |
31218 | + break; | |
31219 | + } else { | |
31220 | + err = -E2BIG; | |
31221 | + goto out_seq; | |
31222 | + } | |
31223 | + } | |
31224 | + if (unlikely(err)) | |
31225 | + err = -EFAULT; | |
31226 | + | |
31227 | +out_seq: | |
1c60b727 | 31228 | + kfree(seq); |
076b876e | 31229 | +out_buf: |
1c60b727 | 31230 | + free_page((unsigned long)buf); |
076b876e AM |
31231 | +out: |
31232 | + si_read_unlock(sb); | |
31233 | + return err; | |
31234 | +} | |
31235 | + | |
31236 | +long au_brinfo_ioctl(struct file *file, unsigned long arg) | |
31237 | +{ | |
2000de60 | 31238 | + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg); |
076b876e AM |
31239 | +} |
31240 | + | |
31241 | +#ifdef CONFIG_COMPAT | |
31242 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg) | |
31243 | +{ | |
2000de60 | 31244 | + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg)); |
076b876e AM |
31245 | +} |
31246 | +#endif | |
31247 | + | |
31248 | +/* ---------------------------------------------------------------------- */ | |
31249 | + | |
1facf9fc | 31250 | +void sysaufs_br_init(struct au_branch *br) |
31251 | +{ | |
392086de AM |
31252 | + int i; |
31253 | + struct au_brsysfs *br_sysfs; | |
31254 | + struct attribute *attr; | |
4a4d8108 | 31255 | + |
392086de AM |
31256 | + br_sysfs = br->br_sysfs; |
31257 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
31258 | + attr = &br_sysfs->attr; | |
31259 | + sysfs_attr_init(attr); | |
31260 | + attr->name = br_sysfs->name; | |
31261 | + attr->mode = S_IRUGO; | |
31262 | + br_sysfs++; | |
31263 | + } | |
1facf9fc | 31264 | +} |
31265 | + | |
31266 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
31267 | +{ | |
31268 | + struct au_branch *br; | |
31269 | + struct kobject *kobj; | |
392086de AM |
31270 | + struct au_brsysfs *br_sysfs; |
31271 | + int i; | |
5afbbe0d | 31272 | + aufs_bindex_t bbot; |
1facf9fc | 31273 | + |
31274 | + dbgaufs_brs_del(sb, bindex); | |
31275 | + | |
31276 | + if (!sysaufs_brs) | |
31277 | + return; | |
31278 | + | |
31279 | + kobj = &au_sbi(sb)->si_kobj; | |
5afbbe0d AM |
31280 | + bbot = au_sbbot(sb); |
31281 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 31282 | + br = au_sbr(sb, bindex); |
392086de AM |
31283 | + br_sysfs = br->br_sysfs; |
31284 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
31285 | + sysfs_remove_file(kobj, &br_sysfs->attr); | |
31286 | + br_sysfs++; | |
31287 | + } | |
1facf9fc | 31288 | + } |
31289 | +} | |
31290 | + | |
31291 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
31292 | +{ | |
392086de | 31293 | + int err, i; |
5afbbe0d | 31294 | + aufs_bindex_t bbot; |
1facf9fc | 31295 | + struct kobject *kobj; |
31296 | + struct au_branch *br; | |
392086de | 31297 | + struct au_brsysfs *br_sysfs; |
1facf9fc | 31298 | + |
31299 | + dbgaufs_brs_add(sb, bindex); | |
31300 | + | |
31301 | + if (!sysaufs_brs) | |
31302 | + return; | |
31303 | + | |
31304 | + kobj = &au_sbi(sb)->si_kobj; | |
5afbbe0d AM |
31305 | + bbot = au_sbbot(sb); |
31306 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 31307 | + br = au_sbr(sb, bindex); |
392086de AM |
31308 | + br_sysfs = br->br_sysfs; |
31309 | + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name), | |
31310 | + SysaufsBr_PREFIX "%d", bindex); | |
31311 | + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name), | |
31312 | + SysaufsBrid_PREFIX "%d", bindex); | |
31313 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
31314 | + err = sysfs_create_file(kobj, &br_sysfs->attr); | |
31315 | + if (unlikely(err)) | |
31316 | + pr_warn("failed %s under sysfs(%d)\n", | |
31317 | + br_sysfs->name, err); | |
31318 | + br_sysfs++; | |
31319 | + } | |
1facf9fc | 31320 | + } |
31321 | +} | |
7f207e10 AM |
31322 | diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c |
31323 | --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 31324 | +++ linux/fs/aufs/sysrq.c 2018-01-29 07:56:20.059991935 +0100 |
8b6a4947 | 31325 | @@ -0,0 +1,159 @@ |
1facf9fc | 31326 | +/* |
a2654f78 | 31327 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 31328 | + * |
31329 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31330 | + * it under the terms of the GNU General Public License as published by | |
31331 | + * the Free Software Foundation; either version 2 of the License, or | |
31332 | + * (at your option) any later version. | |
dece6358 AM |
31333 | + * |
31334 | + * This program is distributed in the hope that it will be useful, | |
31335 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31336 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31337 | + * GNU General Public License for more details. | |
31338 | + * | |
31339 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31340 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31341 | + */ |
31342 | + | |
31343 | +/* | |
31344 | + * magic sysrq hanlder | |
31345 | + */ | |
31346 | + | |
1facf9fc | 31347 | +/* #include <linux/sysrq.h> */ |
027c5e7a | 31348 | +#include <linux/writeback.h> |
1facf9fc | 31349 | +#include "aufs.h" |
31350 | + | |
31351 | +/* ---------------------------------------------------------------------- */ | |
31352 | + | |
31353 | +static void sysrq_sb(struct super_block *sb) | |
31354 | +{ | |
31355 | + char *plevel; | |
31356 | + struct au_sbinfo *sbinfo; | |
31357 | + struct file *file; | |
8b6a4947 AM |
31358 | + struct hlist_bl_head *files; |
31359 | + struct hlist_bl_node *pos; | |
523b37e3 | 31360 | + struct au_finfo *finfo; |
1facf9fc | 31361 | + |
31362 | + plevel = au_plevel; | |
31363 | + au_plevel = KERN_WARNING; | |
1facf9fc | 31364 | + |
4a4d8108 | 31365 | + /* since we define pr_fmt, call printk directly */ |
c06a8ce3 AM |
31366 | +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str) |
31367 | + | |
31368 | + sbinfo = au_sbi(sb); | |
4a4d8108 | 31369 | + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo)); |
c06a8ce3 | 31370 | + pr("superblock\n"); |
1facf9fc | 31371 | + au_dpri_sb(sb); |
027c5e7a AM |
31372 | + |
31373 | +#if 0 | |
c06a8ce3 | 31374 | + pr("root dentry\n"); |
1facf9fc | 31375 | + au_dpri_dentry(sb->s_root); |
c06a8ce3 | 31376 | + pr("root inode\n"); |
5527c038 | 31377 | + au_dpri_inode(d_inode(sb->s_root)); |
027c5e7a AM |
31378 | +#endif |
31379 | + | |
1facf9fc | 31380 | +#if 0 |
027c5e7a AM |
31381 | + do { |
31382 | + int err, i, j, ndentry; | |
31383 | + struct au_dcsub_pages dpages; | |
31384 | + struct au_dpage *dpage; | |
31385 | + | |
31386 | + err = au_dpages_init(&dpages, GFP_ATOMIC); | |
31387 | + if (unlikely(err)) | |
31388 | + break; | |
31389 | + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL); | |
31390 | + if (!err) | |
31391 | + for (i = 0; i < dpages.ndpage; i++) { | |
31392 | + dpage = dpages.dpages + i; | |
31393 | + ndentry = dpage->ndentry; | |
31394 | + for (j = 0; j < ndentry; j++) | |
31395 | + au_dpri_dentry(dpage->dentries[j]); | |
31396 | + } | |
31397 | + au_dpages_free(&dpages); | |
31398 | + } while (0); | |
31399 | +#endif | |
31400 | + | |
31401 | +#if 1 | |
31402 | + { | |
31403 | + struct inode *i; | |
076b876e | 31404 | + |
c06a8ce3 | 31405 | + pr("isolated inode\n"); |
79b8bda9 | 31406 | + spin_lock(&sb->s_inode_list_lock); |
2cbb1c4b JR |
31407 | + list_for_each_entry(i, &sb->s_inodes, i_sb_list) { |
31408 | + spin_lock(&i->i_lock); | |
b4510431 | 31409 | + if (1 || hlist_empty(&i->i_dentry)) |
027c5e7a | 31410 | + au_dpri_inode(i); |
2cbb1c4b JR |
31411 | + spin_unlock(&i->i_lock); |
31412 | + } | |
79b8bda9 | 31413 | + spin_unlock(&sb->s_inode_list_lock); |
027c5e7a | 31414 | + } |
1facf9fc | 31415 | +#endif |
c06a8ce3 | 31416 | + pr("files\n"); |
523b37e3 | 31417 | + files = &au_sbi(sb)->si_files; |
8b6a4947 AM |
31418 | + hlist_bl_lock(files); |
31419 | + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) { | |
4a4d8108 | 31420 | + umode_t mode; |
076b876e | 31421 | + |
523b37e3 | 31422 | + file = finfo->fi_file; |
c06a8ce3 | 31423 | + mode = file_inode(file)->i_mode; |
38d290e6 | 31424 | + if (!special_file(mode)) |
1facf9fc | 31425 | + au_dpri_file(file); |
523b37e3 | 31426 | + } |
8b6a4947 | 31427 | + hlist_bl_unlock(files); |
c06a8ce3 | 31428 | + pr("done\n"); |
1facf9fc | 31429 | + |
c06a8ce3 | 31430 | +#undef pr |
1facf9fc | 31431 | + au_plevel = plevel; |
1facf9fc | 31432 | +} |
31433 | + | |
31434 | +/* ---------------------------------------------------------------------- */ | |
31435 | + | |
31436 | +/* module parameter */ | |
31437 | +static char *aufs_sysrq_key = "a"; | |
31438 | +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO); | |
31439 | +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME); | |
31440 | + | |
0c5527e5 | 31441 | +static void au_sysrq(int key __maybe_unused) |
1facf9fc | 31442 | +{ |
1facf9fc | 31443 | + struct au_sbinfo *sbinfo; |
8b6a4947 | 31444 | + struct hlist_bl_node *pos; |
1facf9fc | 31445 | + |
027c5e7a | 31446 | + lockdep_off(); |
53392da6 | 31447 | + au_sbilist_lock(); |
8b6a4947 | 31448 | + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list) |
1facf9fc | 31449 | + sysrq_sb(sbinfo->si_sb); |
53392da6 | 31450 | + au_sbilist_unlock(); |
027c5e7a | 31451 | + lockdep_on(); |
1facf9fc | 31452 | +} |
31453 | + | |
31454 | +static struct sysrq_key_op au_sysrq_op = { | |
31455 | + .handler = au_sysrq, | |
31456 | + .help_msg = "Aufs", | |
31457 | + .action_msg = "Aufs", | |
31458 | + .enable_mask = SYSRQ_ENABLE_DUMP | |
31459 | +}; | |
31460 | + | |
31461 | +/* ---------------------------------------------------------------------- */ | |
31462 | + | |
31463 | +int __init au_sysrq_init(void) | |
31464 | +{ | |
31465 | + int err; | |
31466 | + char key; | |
31467 | + | |
31468 | + err = -1; | |
31469 | + key = *aufs_sysrq_key; | |
31470 | + if ('a' <= key && key <= 'z') | |
31471 | + err = register_sysrq_key(key, &au_sysrq_op); | |
31472 | + if (unlikely(err)) | |
4a4d8108 | 31473 | + pr_err("err %d, sysrq=%c\n", err, key); |
1facf9fc | 31474 | + return err; |
31475 | +} | |
31476 | + | |
31477 | +void au_sysrq_fin(void) | |
31478 | +{ | |
31479 | + int err; | |
076b876e | 31480 | + |
1facf9fc | 31481 | + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op); |
31482 | + if (unlikely(err)) | |
4a4d8108 | 31483 | + pr_err("err %d (ignored)\n", err); |
1facf9fc | 31484 | +} |
7f207e10 AM |
31485 | diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c |
31486 | --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 31487 | +++ linux/fs/aufs/vdir.c 2018-01-29 07:56:20.063325368 +0100 |
1c60b727 | 31488 | @@ -0,0 +1,892 @@ |
1facf9fc | 31489 | +/* |
a2654f78 | 31490 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 31491 | + * |
31492 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31493 | + * it under the terms of the GNU General Public License as published by | |
31494 | + * the Free Software Foundation; either version 2 of the License, or | |
31495 | + * (at your option) any later version. | |
dece6358 AM |
31496 | + * |
31497 | + * This program is distributed in the hope that it will be useful, | |
31498 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31499 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31500 | + * GNU General Public License for more details. | |
31501 | + * | |
31502 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31503 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31504 | + */ |
31505 | + | |
31506 | +/* | |
31507 | + * virtual or vertical directory | |
31508 | + */ | |
31509 | + | |
31510 | +#include "aufs.h" | |
31511 | + | |
dece6358 | 31512 | +static unsigned int calc_size(int nlen) |
1facf9fc | 31513 | +{ |
dece6358 | 31514 | + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t)); |
1facf9fc | 31515 | +} |
31516 | + | |
31517 | +static int set_deblk_end(union au_vdir_deblk_p *p, | |
31518 | + union au_vdir_deblk_p *deblk_end) | |
31519 | +{ | |
31520 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) { | |
31521 | + p->de->de_str.len = 0; | |
31522 | + /* smp_mb(); */ | |
31523 | + return 0; | |
31524 | + } | |
31525 | + return -1; /* error */ | |
31526 | +} | |
31527 | + | |
31528 | +/* returns true or false */ | |
31529 | +static int is_deblk_end(union au_vdir_deblk_p *p, | |
31530 | + union au_vdir_deblk_p *deblk_end) | |
31531 | +{ | |
31532 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) | |
31533 | + return !p->de->de_str.len; | |
31534 | + return 1; | |
31535 | +} | |
31536 | + | |
31537 | +static unsigned char *last_deblk(struct au_vdir *vdir) | |
31538 | +{ | |
31539 | + return vdir->vd_deblk[vdir->vd_nblk - 1]; | |
31540 | +} | |
31541 | + | |
31542 | +/* ---------------------------------------------------------------------- */ | |
31543 | + | |
79b8bda9 | 31544 | +/* estimate the appropriate size for name hash table */ |
1308ab2a | 31545 | +unsigned int au_rdhash_est(loff_t sz) |
31546 | +{ | |
31547 | + unsigned int n; | |
31548 | + | |
31549 | + n = UINT_MAX; | |
31550 | + sz >>= 10; | |
31551 | + if (sz < n) | |
31552 | + n = sz; | |
31553 | + if (sz < AUFS_RDHASH_DEF) | |
31554 | + n = AUFS_RDHASH_DEF; | |
4a4d8108 | 31555 | + /* pr_info("n %u\n", n); */ |
1308ab2a | 31556 | + return n; |
31557 | +} | |
31558 | + | |
1facf9fc | 31559 | +/* |
31560 | + * the allocated memory has to be freed by | |
dece6358 | 31561 | + * au_nhash_wh_free() or au_nhash_de_free(). |
1facf9fc | 31562 | + */ |
dece6358 | 31563 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp) |
1facf9fc | 31564 | +{ |
1facf9fc | 31565 | + struct hlist_head *head; |
dece6358 | 31566 | + unsigned int u; |
076b876e | 31567 | + size_t sz; |
1facf9fc | 31568 | + |
076b876e AM |
31569 | + sz = sizeof(*nhash->nh_head) * num_hash; |
31570 | + head = kmalloc(sz, gfp); | |
dece6358 AM |
31571 | + if (head) { |
31572 | + nhash->nh_num = num_hash; | |
31573 | + nhash->nh_head = head; | |
31574 | + for (u = 0; u < num_hash; u++) | |
1facf9fc | 31575 | + INIT_HLIST_HEAD(head++); |
dece6358 | 31576 | + return 0; /* success */ |
1facf9fc | 31577 | + } |
1facf9fc | 31578 | + |
dece6358 | 31579 | + return -ENOMEM; |
1facf9fc | 31580 | +} |
31581 | + | |
dece6358 AM |
31582 | +static void nhash_count(struct hlist_head *head) |
31583 | +{ | |
31584 | +#if 0 | |
31585 | + unsigned long n; | |
31586 | + struct hlist_node *pos; | |
31587 | + | |
31588 | + n = 0; | |
31589 | + hlist_for_each(pos, head) | |
31590 | + n++; | |
4a4d8108 | 31591 | + pr_info("%lu\n", n); |
dece6358 AM |
31592 | +#endif |
31593 | +} | |
31594 | + | |
31595 | +static void au_nhash_wh_do_free(struct hlist_head *head) | |
1facf9fc | 31596 | +{ |
c06a8ce3 AM |
31597 | + struct au_vdir_wh *pos; |
31598 | + struct hlist_node *node; | |
1facf9fc | 31599 | + |
c06a8ce3 | 31600 | + hlist_for_each_entry_safe(pos, node, head, wh_hash) |
1c60b727 | 31601 | + kfree(pos); |
1facf9fc | 31602 | +} |
31603 | + | |
dece6358 | 31604 | +static void au_nhash_de_do_free(struct hlist_head *head) |
1facf9fc | 31605 | +{ |
c06a8ce3 AM |
31606 | + struct au_vdir_dehstr *pos; |
31607 | + struct hlist_node *node; | |
1facf9fc | 31608 | + |
c06a8ce3 | 31609 | + hlist_for_each_entry_safe(pos, node, head, hash) |
1c60b727 | 31610 | + au_cache_free_vdir_dehstr(pos); |
1facf9fc | 31611 | +} |
31612 | + | |
dece6358 AM |
31613 | +static void au_nhash_do_free(struct au_nhash *nhash, |
31614 | + void (*free)(struct hlist_head *head)) | |
1facf9fc | 31615 | +{ |
1308ab2a | 31616 | + unsigned int n; |
1facf9fc | 31617 | + struct hlist_head *head; |
1facf9fc | 31618 | + |
dece6358 | 31619 | + n = nhash->nh_num; |
1308ab2a | 31620 | + if (!n) |
31621 | + return; | |
31622 | + | |
dece6358 | 31623 | + head = nhash->nh_head; |
1308ab2a | 31624 | + while (n-- > 0) { |
dece6358 AM |
31625 | + nhash_count(head); |
31626 | + free(head++); | |
1facf9fc | 31627 | + } |
1c60b727 | 31628 | + kfree(nhash->nh_head); |
1facf9fc | 31629 | +} |
31630 | + | |
dece6358 | 31631 | +void au_nhash_wh_free(struct au_nhash *whlist) |
1facf9fc | 31632 | +{ |
dece6358 AM |
31633 | + au_nhash_do_free(whlist, au_nhash_wh_do_free); |
31634 | +} | |
1facf9fc | 31635 | + |
dece6358 AM |
31636 | +static void au_nhash_de_free(struct au_nhash *delist) |
31637 | +{ | |
31638 | + au_nhash_do_free(delist, au_nhash_de_do_free); | |
1facf9fc | 31639 | +} |
31640 | + | |
31641 | +/* ---------------------------------------------------------------------- */ | |
31642 | + | |
31643 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, | |
31644 | + int limit) | |
31645 | +{ | |
31646 | + int num; | |
31647 | + unsigned int u, n; | |
31648 | + struct hlist_head *head; | |
c06a8ce3 | 31649 | + struct au_vdir_wh *pos; |
1facf9fc | 31650 | + |
31651 | + num = 0; | |
31652 | + n = whlist->nh_num; | |
31653 | + head = whlist->nh_head; | |
1308ab2a | 31654 | + for (u = 0; u < n; u++, head++) |
c06a8ce3 AM |
31655 | + hlist_for_each_entry(pos, head, wh_hash) |
31656 | + if (pos->wh_bindex == btgt && ++num > limit) | |
1facf9fc | 31657 | + return 1; |
1facf9fc | 31658 | + return 0; |
31659 | +} | |
31660 | + | |
31661 | +static struct hlist_head *au_name_hash(struct au_nhash *nhash, | |
dece6358 | 31662 | + unsigned char *name, |
1facf9fc | 31663 | + unsigned int len) |
31664 | +{ | |
dece6358 AM |
31665 | + unsigned int v; |
31666 | + /* const unsigned int magic_bit = 12; */ | |
31667 | + | |
1308ab2a | 31668 | + AuDebugOn(!nhash->nh_num || !nhash->nh_head); |
31669 | + | |
dece6358 | 31670 | + v = 0; |
f0c0a007 AM |
31671 | + if (len > 8) |
31672 | + len = 8; | |
dece6358 AM |
31673 | + while (len--) |
31674 | + v += *name++; | |
31675 | + /* v = hash_long(v, magic_bit); */ | |
31676 | + v %= nhash->nh_num; | |
31677 | + return nhash->nh_head + v; | |
31678 | +} | |
31679 | + | |
31680 | +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name, | |
31681 | + int nlen) | |
31682 | +{ | |
31683 | + return str->len == nlen && !memcmp(str->name, name, nlen); | |
1facf9fc | 31684 | +} |
31685 | + | |
31686 | +/* returns found or not */ | |
dece6358 | 31687 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen) |
1facf9fc | 31688 | +{ |
31689 | + struct hlist_head *head; | |
c06a8ce3 | 31690 | + struct au_vdir_wh *pos; |
1facf9fc | 31691 | + struct au_vdir_destr *str; |
31692 | + | |
dece6358 | 31693 | + head = au_name_hash(whlist, name, nlen); |
c06a8ce3 AM |
31694 | + hlist_for_each_entry(pos, head, wh_hash) { |
31695 | + str = &pos->wh_str; | |
1facf9fc | 31696 | + AuDbg("%.*s\n", str->len, str->name); |
dece6358 AM |
31697 | + if (au_nhash_test_name(str, name, nlen)) |
31698 | + return 1; | |
31699 | + } | |
31700 | + return 0; | |
31701 | +} | |
31702 | + | |
31703 | +/* returns found(true) or not */ | |
31704 | +static int test_known(struct au_nhash *delist, char *name, int nlen) | |
31705 | +{ | |
31706 | + struct hlist_head *head; | |
c06a8ce3 | 31707 | + struct au_vdir_dehstr *pos; |
dece6358 AM |
31708 | + struct au_vdir_destr *str; |
31709 | + | |
31710 | + head = au_name_hash(delist, name, nlen); | |
c06a8ce3 AM |
31711 | + hlist_for_each_entry(pos, head, hash) { |
31712 | + str = pos->str; | |
dece6358 AM |
31713 | + AuDbg("%.*s\n", str->len, str->name); |
31714 | + if (au_nhash_test_name(str, name, nlen)) | |
1facf9fc | 31715 | + return 1; |
31716 | + } | |
31717 | + return 0; | |
31718 | +} | |
31719 | + | |
dece6358 AM |
31720 | +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, |
31721 | + unsigned char d_type) | |
31722 | +{ | |
31723 | +#ifdef CONFIG_AUFS_SHWH | |
31724 | + wh->wh_ino = ino; | |
31725 | + wh->wh_type = d_type; | |
31726 | +#endif | |
31727 | +} | |
31728 | + | |
31729 | +/* ---------------------------------------------------------------------- */ | |
31730 | + | |
31731 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
31732 | + unsigned int d_type, aufs_bindex_t bindex, | |
31733 | + unsigned char shwh) | |
1facf9fc | 31734 | +{ |
31735 | + int err; | |
31736 | + struct au_vdir_destr *str; | |
31737 | + struct au_vdir_wh *wh; | |
31738 | + | |
dece6358 | 31739 | + AuDbg("%.*s\n", nlen, name); |
1308ab2a | 31740 | + AuDebugOn(!whlist->nh_num || !whlist->nh_head); |
31741 | + | |
1facf9fc | 31742 | + err = -ENOMEM; |
dece6358 | 31743 | + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS); |
1facf9fc | 31744 | + if (unlikely(!wh)) |
31745 | + goto out; | |
31746 | + | |
31747 | + err = 0; | |
31748 | + wh->wh_bindex = bindex; | |
dece6358 AM |
31749 | + if (shwh) |
31750 | + au_shwh_init_wh(wh, ino, d_type); | |
1facf9fc | 31751 | + str = &wh->wh_str; |
dece6358 AM |
31752 | + str->len = nlen; |
31753 | + memcpy(str->name, name, nlen); | |
31754 | + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen)); | |
1facf9fc | 31755 | + /* smp_mb(); */ |
31756 | + | |
4f0767ce | 31757 | +out: |
1facf9fc | 31758 | + return err; |
31759 | +} | |
31760 | + | |
1facf9fc | 31761 | +static int append_deblk(struct au_vdir *vdir) |
31762 | +{ | |
31763 | + int err; | |
dece6358 | 31764 | + unsigned long ul; |
1facf9fc | 31765 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; |
31766 | + union au_vdir_deblk_p p, deblk_end; | |
31767 | + unsigned char **o; | |
31768 | + | |
31769 | + err = -ENOMEM; | |
e2f27e51 AM |
31770 | + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1), |
31771 | + GFP_NOFS, /*may_shrink*/0); | |
1facf9fc | 31772 | + if (unlikely(!o)) |
31773 | + goto out; | |
31774 | + | |
31775 | + vdir->vd_deblk = o; | |
31776 | + p.deblk = kmalloc(deblk_sz, GFP_NOFS); | |
31777 | + if (p.deblk) { | |
31778 | + ul = vdir->vd_nblk++; | |
31779 | + vdir->vd_deblk[ul] = p.deblk; | |
31780 | + vdir->vd_last.ul = ul; | |
31781 | + vdir->vd_last.p.deblk = p.deblk; | |
31782 | + deblk_end.deblk = p.deblk + deblk_sz; | |
31783 | + err = set_deblk_end(&p, &deblk_end); | |
31784 | + } | |
31785 | + | |
4f0767ce | 31786 | +out: |
1facf9fc | 31787 | + return err; |
31788 | +} | |
31789 | + | |
dece6358 AM |
31790 | +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino, |
31791 | + unsigned int d_type, struct au_nhash *delist) | |
31792 | +{ | |
31793 | + int err; | |
31794 | + unsigned int sz; | |
31795 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; | |
31796 | + union au_vdir_deblk_p p, *room, deblk_end; | |
31797 | + struct au_vdir_dehstr *dehstr; | |
31798 | + | |
31799 | + p.deblk = last_deblk(vdir); | |
31800 | + deblk_end.deblk = p.deblk + deblk_sz; | |
31801 | + room = &vdir->vd_last.p; | |
31802 | + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk | |
31803 | + || !is_deblk_end(room, &deblk_end)); | |
31804 | + | |
31805 | + sz = calc_size(nlen); | |
31806 | + if (unlikely(sz > deblk_end.deblk - room->deblk)) { | |
31807 | + err = append_deblk(vdir); | |
31808 | + if (unlikely(err)) | |
31809 | + goto out; | |
31810 | + | |
31811 | + p.deblk = last_deblk(vdir); | |
31812 | + deblk_end.deblk = p.deblk + deblk_sz; | |
31813 | + /* smp_mb(); */ | |
31814 | + AuDebugOn(room->deblk != p.deblk); | |
31815 | + } | |
31816 | + | |
31817 | + err = -ENOMEM; | |
4a4d8108 | 31818 | + dehstr = au_cache_alloc_vdir_dehstr(); |
dece6358 AM |
31819 | + if (unlikely(!dehstr)) |
31820 | + goto out; | |
31821 | + | |
31822 | + dehstr->str = &room->de->de_str; | |
31823 | + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen)); | |
31824 | + room->de->de_ino = ino; | |
31825 | + room->de->de_type = d_type; | |
31826 | + room->de->de_str.len = nlen; | |
31827 | + memcpy(room->de->de_str.name, name, nlen); | |
31828 | + | |
31829 | + err = 0; | |
31830 | + room->deblk += sz; | |
31831 | + if (unlikely(set_deblk_end(room, &deblk_end))) | |
31832 | + err = append_deblk(vdir); | |
31833 | + /* smp_mb(); */ | |
31834 | + | |
4f0767ce | 31835 | +out: |
dece6358 AM |
31836 | + return err; |
31837 | +} | |
31838 | + | |
31839 | +/* ---------------------------------------------------------------------- */ | |
31840 | + | |
1c60b727 | 31841 | +void au_vdir_free(struct au_vdir *vdir) |
dece6358 AM |
31842 | +{ |
31843 | + unsigned char **deblk; | |
31844 | + | |
31845 | + deblk = vdir->vd_deblk; | |
1c60b727 AM |
31846 | + while (vdir->vd_nblk--) |
31847 | + kfree(*deblk++); | |
31848 | + kfree(vdir->vd_deblk); | |
31849 | + au_cache_free_vdir(vdir); | |
dece6358 AM |
31850 | +} |
31851 | + | |
1308ab2a | 31852 | +static struct au_vdir *alloc_vdir(struct file *file) |
1facf9fc | 31853 | +{ |
31854 | + struct au_vdir *vdir; | |
1308ab2a | 31855 | + struct super_block *sb; |
1facf9fc | 31856 | + int err; |
31857 | + | |
2000de60 | 31858 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
31859 | + SiMustAnyLock(sb); |
31860 | + | |
1facf9fc | 31861 | + err = -ENOMEM; |
31862 | + vdir = au_cache_alloc_vdir(); | |
31863 | + if (unlikely(!vdir)) | |
31864 | + goto out; | |
31865 | + | |
31866 | + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS); | |
31867 | + if (unlikely(!vdir->vd_deblk)) | |
31868 | + goto out_free; | |
31869 | + | |
31870 | + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk; | |
1308ab2a | 31871 | + if (!vdir->vd_deblk_sz) { |
79b8bda9 | 31872 | + /* estimate the appropriate size for deblk */ |
1308ab2a | 31873 | + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL); |
4a4d8108 | 31874 | + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */ |
1308ab2a | 31875 | + } |
1facf9fc | 31876 | + vdir->vd_nblk = 0; |
31877 | + vdir->vd_version = 0; | |
31878 | + vdir->vd_jiffy = 0; | |
31879 | + err = append_deblk(vdir); | |
31880 | + if (!err) | |
31881 | + return vdir; /* success */ | |
31882 | + | |
1c60b727 | 31883 | + kfree(vdir->vd_deblk); |
1facf9fc | 31884 | + |
4f0767ce | 31885 | +out_free: |
1c60b727 | 31886 | + au_cache_free_vdir(vdir); |
4f0767ce | 31887 | +out: |
1facf9fc | 31888 | + vdir = ERR_PTR(err); |
31889 | + return vdir; | |
31890 | +} | |
31891 | + | |
31892 | +static int reinit_vdir(struct au_vdir *vdir) | |
31893 | +{ | |
31894 | + int err; | |
31895 | + union au_vdir_deblk_p p, deblk_end; | |
31896 | + | |
31897 | + while (vdir->vd_nblk > 1) { | |
1c60b727 | 31898 | + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]); |
1facf9fc | 31899 | + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */ |
31900 | + vdir->vd_nblk--; | |
31901 | + } | |
31902 | + p.deblk = vdir->vd_deblk[0]; | |
31903 | + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz; | |
31904 | + err = set_deblk_end(&p, &deblk_end); | |
31905 | + /* keep vd_dblk_sz */ | |
31906 | + vdir->vd_last.ul = 0; | |
31907 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
31908 | + vdir->vd_version = 0; | |
31909 | + vdir->vd_jiffy = 0; | |
31910 | + /* smp_mb(); */ | |
31911 | + return err; | |
31912 | +} | |
31913 | + | |
31914 | +/* ---------------------------------------------------------------------- */ | |
31915 | + | |
1facf9fc | 31916 | +#define AuFillVdir_CALLED 1 |
31917 | +#define AuFillVdir_WHABLE (1 << 1) | |
dece6358 | 31918 | +#define AuFillVdir_SHWH (1 << 2) |
1facf9fc | 31919 | +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name) |
7f207e10 AM |
31920 | +#define au_fset_fillvdir(flags, name) \ |
31921 | + do { (flags) |= AuFillVdir_##name; } while (0) | |
31922 | +#define au_fclr_fillvdir(flags, name) \ | |
31923 | + do { (flags) &= ~AuFillVdir_##name; } while (0) | |
1facf9fc | 31924 | + |
dece6358 AM |
31925 | +#ifndef CONFIG_AUFS_SHWH |
31926 | +#undef AuFillVdir_SHWH | |
31927 | +#define AuFillVdir_SHWH 0 | |
31928 | +#endif | |
31929 | + | |
1facf9fc | 31930 | +struct fillvdir_arg { |
392086de | 31931 | + struct dir_context ctx; |
1facf9fc | 31932 | + struct file *file; |
31933 | + struct au_vdir *vdir; | |
dece6358 AM |
31934 | + struct au_nhash delist; |
31935 | + struct au_nhash whlist; | |
1facf9fc | 31936 | + aufs_bindex_t bindex; |
31937 | + unsigned int flags; | |
31938 | + int err; | |
31939 | +}; | |
31940 | + | |
392086de | 31941 | +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen, |
1facf9fc | 31942 | + loff_t offset __maybe_unused, u64 h_ino, |
31943 | + unsigned int d_type) | |
31944 | +{ | |
392086de | 31945 | + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx); |
1facf9fc | 31946 | + char *name = (void *)__name; |
31947 | + struct super_block *sb; | |
1facf9fc | 31948 | + ino_t ino; |
dece6358 | 31949 | + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH); |
1facf9fc | 31950 | + |
1facf9fc | 31951 | + arg->err = 0; |
2000de60 | 31952 | + sb = arg->file->f_path.dentry->d_sb; |
1facf9fc | 31953 | + au_fset_fillvdir(arg->flags, CALLED); |
31954 | + /* smp_mb(); */ | |
dece6358 | 31955 | + if (nlen <= AUFS_WH_PFX_LEN |
1facf9fc | 31956 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { |
dece6358 AM |
31957 | + if (test_known(&arg->delist, name, nlen) |
31958 | + || au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
31959 | + goto out; /* already exists or whiteouted */ | |
1facf9fc | 31960 | + |
dece6358 | 31961 | + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino); |
4a4d8108 AM |
31962 | + if (!arg->err) { |
31963 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) | |
31964 | + d_type = DT_UNKNOWN; | |
dece6358 AM |
31965 | + arg->err = append_de(arg->vdir, name, nlen, ino, |
31966 | + d_type, &arg->delist); | |
4a4d8108 | 31967 | + } |
1facf9fc | 31968 | + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) { |
31969 | + name += AUFS_WH_PFX_LEN; | |
dece6358 AM |
31970 | + nlen -= AUFS_WH_PFX_LEN; |
31971 | + if (au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
31972 | + goto out; /* already whiteouted */ | |
1facf9fc | 31973 | + |
dece6358 AM |
31974 | + if (shwh) |
31975 | + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type, | |
31976 | + &ino); | |
4a4d8108 AM |
31977 | + if (!arg->err) { |
31978 | + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN) | |
31979 | + d_type = DT_UNKNOWN; | |
1facf9fc | 31980 | + arg->err = au_nhash_append_wh |
dece6358 AM |
31981 | + (&arg->whlist, name, nlen, ino, d_type, |
31982 | + arg->bindex, shwh); | |
4a4d8108 | 31983 | + } |
1facf9fc | 31984 | + } |
31985 | + | |
4f0767ce | 31986 | +out: |
1facf9fc | 31987 | + if (!arg->err) |
31988 | + arg->vdir->vd_jiffy = jiffies; | |
31989 | + /* smp_mb(); */ | |
31990 | + AuTraceErr(arg->err); | |
31991 | + return arg->err; | |
31992 | +} | |
31993 | + | |
dece6358 AM |
31994 | +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir, |
31995 | + struct au_nhash *whlist, struct au_nhash *delist) | |
31996 | +{ | |
31997 | +#ifdef CONFIG_AUFS_SHWH | |
31998 | + int err; | |
31999 | + unsigned int nh, u; | |
32000 | + struct hlist_head *head; | |
c06a8ce3 AM |
32001 | + struct au_vdir_wh *pos; |
32002 | + struct hlist_node *n; | |
dece6358 AM |
32003 | + char *p, *o; |
32004 | + struct au_vdir_destr *destr; | |
32005 | + | |
32006 | + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH)); | |
32007 | + | |
32008 | + err = -ENOMEM; | |
537831f9 | 32009 | + o = p = (void *)__get_free_page(GFP_NOFS); |
dece6358 AM |
32010 | + if (unlikely(!p)) |
32011 | + goto out; | |
32012 | + | |
32013 | + err = 0; | |
32014 | + nh = whlist->nh_num; | |
32015 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
32016 | + p += AUFS_WH_PFX_LEN; | |
32017 | + for (u = 0; u < nh; u++) { | |
32018 | + head = whlist->nh_head + u; | |
c06a8ce3 AM |
32019 | + hlist_for_each_entry_safe(pos, n, head, wh_hash) { |
32020 | + destr = &pos->wh_str; | |
dece6358 AM |
32021 | + memcpy(p, destr->name, destr->len); |
32022 | + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN, | |
c06a8ce3 | 32023 | + pos->wh_ino, pos->wh_type, delist); |
dece6358 AM |
32024 | + if (unlikely(err)) |
32025 | + break; | |
32026 | + } | |
32027 | + } | |
32028 | + | |
1c60b727 | 32029 | + free_page((unsigned long)o); |
dece6358 | 32030 | + |
4f0767ce | 32031 | +out: |
dece6358 AM |
32032 | + AuTraceErr(err); |
32033 | + return err; | |
32034 | +#else | |
32035 | + return 0; | |
32036 | +#endif | |
32037 | +} | |
32038 | + | |
1facf9fc | 32039 | +static int au_do_read_vdir(struct fillvdir_arg *arg) |
32040 | +{ | |
32041 | + int err; | |
dece6358 | 32042 | + unsigned int rdhash; |
1facf9fc | 32043 | + loff_t offset; |
5afbbe0d | 32044 | + aufs_bindex_t bbot, bindex, btop; |
dece6358 | 32045 | + unsigned char shwh; |
1facf9fc | 32046 | + struct file *hf, *file; |
32047 | + struct super_block *sb; | |
32048 | + | |
1facf9fc | 32049 | + file = arg->file; |
2000de60 | 32050 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
32051 | + SiMustAnyLock(sb); |
32052 | + | |
32053 | + rdhash = au_sbi(sb)->si_rdhash; | |
1308ab2a | 32054 | + if (!rdhash) |
32055 | + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL)); | |
dece6358 AM |
32056 | + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS); |
32057 | + if (unlikely(err)) | |
1facf9fc | 32058 | + goto out; |
dece6358 AM |
32059 | + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS); |
32060 | + if (unlikely(err)) | |
1facf9fc | 32061 | + goto out_delist; |
32062 | + | |
32063 | + err = 0; | |
32064 | + arg->flags = 0; | |
dece6358 AM |
32065 | + shwh = 0; |
32066 | + if (au_opt_test(au_mntflags(sb), SHWH)) { | |
32067 | + shwh = 1; | |
32068 | + au_fset_fillvdir(arg->flags, SHWH); | |
32069 | + } | |
5afbbe0d AM |
32070 | + btop = au_fbtop(file); |
32071 | + bbot = au_fbbot_dir(file); | |
32072 | + for (bindex = btop; !err && bindex <= bbot; bindex++) { | |
4a4d8108 | 32073 | + hf = au_hf_dir(file, bindex); |
1facf9fc | 32074 | + if (!hf) |
32075 | + continue; | |
32076 | + | |
32077 | + offset = vfsub_llseek(hf, 0, SEEK_SET); | |
32078 | + err = offset; | |
32079 | + if (unlikely(offset)) | |
32080 | + break; | |
32081 | + | |
32082 | + arg->bindex = bindex; | |
32083 | + au_fclr_fillvdir(arg->flags, WHABLE); | |
dece6358 | 32084 | + if (shwh |
5afbbe0d | 32085 | + || (bindex != bbot |
dece6358 | 32086 | + && au_br_whable(au_sbr_perm(sb, bindex)))) |
1facf9fc | 32087 | + au_fset_fillvdir(arg->flags, WHABLE); |
32088 | + do { | |
32089 | + arg->err = 0; | |
32090 | + au_fclr_fillvdir(arg->flags, CALLED); | |
32091 | + /* smp_mb(); */ | |
392086de | 32092 | + err = vfsub_iterate_dir(hf, &arg->ctx); |
1facf9fc | 32093 | + if (err >= 0) |
32094 | + err = arg->err; | |
32095 | + } while (!err && au_ftest_fillvdir(arg->flags, CALLED)); | |
392086de AM |
32096 | + |
32097 | + /* | |
32098 | + * dir_relax() may be good for concurrency, but aufs should not | |
32099 | + * use it since it will cause a lockdep problem. | |
32100 | + */ | |
1facf9fc | 32101 | + } |
dece6358 AM |
32102 | + |
32103 | + if (!err && shwh) | |
32104 | + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist); | |
32105 | + | |
32106 | + au_nhash_wh_free(&arg->whlist); | |
1facf9fc | 32107 | + |
4f0767ce | 32108 | +out_delist: |
dece6358 | 32109 | + au_nhash_de_free(&arg->delist); |
4f0767ce | 32110 | +out: |
1facf9fc | 32111 | + return err; |
32112 | +} | |
32113 | + | |
32114 | +static int read_vdir(struct file *file, int may_read) | |
32115 | +{ | |
32116 | + int err; | |
32117 | + unsigned long expire; | |
32118 | + unsigned char do_read; | |
392086de AM |
32119 | + struct fillvdir_arg arg = { |
32120 | + .ctx = { | |
2000de60 | 32121 | + .actor = fillvdir |
392086de AM |
32122 | + } |
32123 | + }; | |
1facf9fc | 32124 | + struct inode *inode; |
32125 | + struct au_vdir *vdir, *allocated; | |
32126 | + | |
32127 | + err = 0; | |
c06a8ce3 | 32128 | + inode = file_inode(file); |
1facf9fc | 32129 | + IMustLock(inode); |
5afbbe0d | 32130 | + IiMustWriteLock(inode); |
dece6358 AM |
32131 | + SiMustAnyLock(inode->i_sb); |
32132 | + | |
1facf9fc | 32133 | + allocated = NULL; |
32134 | + do_read = 0; | |
32135 | + expire = au_sbi(inode->i_sb)->si_rdcache; | |
32136 | + vdir = au_ivdir(inode); | |
32137 | + if (!vdir) { | |
32138 | + do_read = 1; | |
1308ab2a | 32139 | + vdir = alloc_vdir(file); |
1facf9fc | 32140 | + err = PTR_ERR(vdir); |
32141 | + if (IS_ERR(vdir)) | |
32142 | + goto out; | |
32143 | + err = 0; | |
32144 | + allocated = vdir; | |
32145 | + } else if (may_read | |
32146 | + && (inode->i_version != vdir->vd_version | |
32147 | + || time_after(jiffies, vdir->vd_jiffy + expire))) { | |
32148 | + do_read = 1; | |
32149 | + err = reinit_vdir(vdir); | |
32150 | + if (unlikely(err)) | |
32151 | + goto out; | |
32152 | + } | |
32153 | + | |
32154 | + if (!do_read) | |
32155 | + return 0; /* success */ | |
32156 | + | |
32157 | + arg.file = file; | |
32158 | + arg.vdir = vdir; | |
32159 | + err = au_do_read_vdir(&arg); | |
32160 | + if (!err) { | |
392086de | 32161 | + /* file->f_pos = 0; */ /* todo: ctx->pos? */ |
1facf9fc | 32162 | + vdir->vd_version = inode->i_version; |
32163 | + vdir->vd_last.ul = 0; | |
32164 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
32165 | + if (allocated) | |
32166 | + au_set_ivdir(inode, allocated); | |
32167 | + } else if (allocated) | |
1c60b727 | 32168 | + au_vdir_free(allocated); |
1facf9fc | 32169 | + |
4f0767ce | 32170 | +out: |
1facf9fc | 32171 | + return err; |
32172 | +} | |
32173 | + | |
32174 | +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src) | |
32175 | +{ | |
32176 | + int err, rerr; | |
32177 | + unsigned long ul, n; | |
32178 | + const unsigned int deblk_sz = src->vd_deblk_sz; | |
32179 | + | |
32180 | + AuDebugOn(tgt->vd_nblk != 1); | |
32181 | + | |
32182 | + err = -ENOMEM; | |
32183 | + if (tgt->vd_nblk < src->vd_nblk) { | |
32184 | + unsigned char **p; | |
32185 | + | |
e2f27e51 AM |
32186 | + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk, |
32187 | + GFP_NOFS, /*may_shrink*/0); | |
1facf9fc | 32188 | + if (unlikely(!p)) |
32189 | + goto out; | |
32190 | + tgt->vd_deblk = p; | |
32191 | + } | |
32192 | + | |
1308ab2a | 32193 | + if (tgt->vd_deblk_sz != deblk_sz) { |
32194 | + unsigned char *p; | |
32195 | + | |
32196 | + tgt->vd_deblk_sz = deblk_sz; | |
e2f27e51 AM |
32197 | + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS, |
32198 | + /*may_shrink*/1); | |
1308ab2a | 32199 | + if (unlikely(!p)) |
32200 | + goto out; | |
32201 | + tgt->vd_deblk[0] = p; | |
32202 | + } | |
1facf9fc | 32203 | + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz); |
1facf9fc | 32204 | + tgt->vd_version = src->vd_version; |
32205 | + tgt->vd_jiffy = src->vd_jiffy; | |
32206 | + | |
32207 | + n = src->vd_nblk; | |
32208 | + for (ul = 1; ul < n; ul++) { | |
dece6358 AM |
32209 | + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz, |
32210 | + GFP_NOFS); | |
32211 | + if (unlikely(!tgt->vd_deblk[ul])) | |
1facf9fc | 32212 | + goto out; |
1308ab2a | 32213 | + tgt->vd_nblk++; |
1facf9fc | 32214 | + } |
1308ab2a | 32215 | + tgt->vd_nblk = n; |
32216 | + tgt->vd_last.ul = tgt->vd_last.ul; | |
32217 | + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul]; | |
32218 | + tgt->vd_last.p.deblk += src->vd_last.p.deblk | |
32219 | + - src->vd_deblk[src->vd_last.ul]; | |
1facf9fc | 32220 | + /* smp_mb(); */ |
32221 | + return 0; /* success */ | |
32222 | + | |
4f0767ce | 32223 | +out: |
1facf9fc | 32224 | + rerr = reinit_vdir(tgt); |
32225 | + BUG_ON(rerr); | |
32226 | + return err; | |
32227 | +} | |
32228 | + | |
32229 | +int au_vdir_init(struct file *file) | |
32230 | +{ | |
32231 | + int err; | |
32232 | + struct inode *inode; | |
32233 | + struct au_vdir *vdir_cache, *allocated; | |
32234 | + | |
392086de | 32235 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 32236 | + err = read_vdir(file, !file->f_pos); |
32237 | + if (unlikely(err)) | |
32238 | + goto out; | |
32239 | + | |
32240 | + allocated = NULL; | |
32241 | + vdir_cache = au_fvdir_cache(file); | |
32242 | + if (!vdir_cache) { | |
1308ab2a | 32243 | + vdir_cache = alloc_vdir(file); |
1facf9fc | 32244 | + err = PTR_ERR(vdir_cache); |
32245 | + if (IS_ERR(vdir_cache)) | |
32246 | + goto out; | |
32247 | + allocated = vdir_cache; | |
32248 | + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) { | |
392086de | 32249 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 32250 | + err = reinit_vdir(vdir_cache); |
32251 | + if (unlikely(err)) | |
32252 | + goto out; | |
32253 | + } else | |
32254 | + return 0; /* success */ | |
32255 | + | |
c06a8ce3 | 32256 | + inode = file_inode(file); |
1facf9fc | 32257 | + err = copy_vdir(vdir_cache, au_ivdir(inode)); |
32258 | + if (!err) { | |
32259 | + file->f_version = inode->i_version; | |
32260 | + if (allocated) | |
32261 | + au_set_fvdir_cache(file, allocated); | |
32262 | + } else if (allocated) | |
1c60b727 | 32263 | + au_vdir_free(allocated); |
1facf9fc | 32264 | + |
4f0767ce | 32265 | +out: |
1facf9fc | 32266 | + return err; |
32267 | +} | |
32268 | + | |
32269 | +static loff_t calc_offset(struct au_vdir *vdir) | |
32270 | +{ | |
32271 | + loff_t offset; | |
32272 | + union au_vdir_deblk_p p; | |
32273 | + | |
32274 | + p.deblk = vdir->vd_deblk[vdir->vd_last.ul]; | |
32275 | + offset = vdir->vd_last.p.deblk - p.deblk; | |
32276 | + offset += vdir->vd_deblk_sz * vdir->vd_last.ul; | |
32277 | + return offset; | |
32278 | +} | |
32279 | + | |
32280 | +/* returns true or false */ | |
392086de | 32281 | +static int seek_vdir(struct file *file, struct dir_context *ctx) |
1facf9fc | 32282 | +{ |
32283 | + int valid; | |
32284 | + unsigned int deblk_sz; | |
32285 | + unsigned long ul, n; | |
32286 | + loff_t offset; | |
32287 | + union au_vdir_deblk_p p, deblk_end; | |
32288 | + struct au_vdir *vdir_cache; | |
32289 | + | |
32290 | + valid = 1; | |
32291 | + vdir_cache = au_fvdir_cache(file); | |
32292 | + offset = calc_offset(vdir_cache); | |
32293 | + AuDbg("offset %lld\n", offset); | |
392086de | 32294 | + if (ctx->pos == offset) |
1facf9fc | 32295 | + goto out; |
32296 | + | |
32297 | + vdir_cache->vd_last.ul = 0; | |
32298 | + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0]; | |
392086de | 32299 | + if (!ctx->pos) |
1facf9fc | 32300 | + goto out; |
32301 | + | |
32302 | + valid = 0; | |
32303 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
392086de | 32304 | + ul = div64_u64(ctx->pos, deblk_sz); |
1facf9fc | 32305 | + AuDbg("ul %lu\n", ul); |
32306 | + if (ul >= vdir_cache->vd_nblk) | |
32307 | + goto out; | |
32308 | + | |
32309 | + n = vdir_cache->vd_nblk; | |
32310 | + for (; ul < n; ul++) { | |
32311 | + p.deblk = vdir_cache->vd_deblk[ul]; | |
32312 | + deblk_end.deblk = p.deblk + deblk_sz; | |
32313 | + offset = ul; | |
32314 | + offset *= deblk_sz; | |
392086de | 32315 | + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) { |
1facf9fc | 32316 | + unsigned int l; |
32317 | + | |
32318 | + l = calc_size(p.de->de_str.len); | |
32319 | + offset += l; | |
32320 | + p.deblk += l; | |
32321 | + } | |
32322 | + if (!is_deblk_end(&p, &deblk_end)) { | |
32323 | + valid = 1; | |
32324 | + vdir_cache->vd_last.ul = ul; | |
32325 | + vdir_cache->vd_last.p = p; | |
32326 | + break; | |
32327 | + } | |
32328 | + } | |
32329 | + | |
4f0767ce | 32330 | +out: |
1facf9fc | 32331 | + /* smp_mb(); */ |
32332 | + AuTraceErr(!valid); | |
32333 | + return valid; | |
32334 | +} | |
32335 | + | |
392086de | 32336 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx) |
1facf9fc | 32337 | +{ |
1facf9fc | 32338 | + unsigned int l, deblk_sz; |
32339 | + union au_vdir_deblk_p deblk_end; | |
32340 | + struct au_vdir *vdir_cache; | |
32341 | + struct au_vdir_de *de; | |
32342 | + | |
32343 | + vdir_cache = au_fvdir_cache(file); | |
392086de | 32344 | + if (!seek_vdir(file, ctx)) |
1facf9fc | 32345 | + return 0; |
32346 | + | |
32347 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
32348 | + while (1) { | |
32349 | + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
32350 | + deblk_end.deblk += deblk_sz; | |
32351 | + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) { | |
32352 | + de = vdir_cache->vd_last.p.de; | |
32353 | + AuDbg("%.*s, off%lld, i%lu, dt%d\n", | |
392086de | 32354 | + de->de_str.len, de->de_str.name, ctx->pos, |
1facf9fc | 32355 | + (unsigned long)de->de_ino, de->de_type); |
392086de AM |
32356 | + if (unlikely(!dir_emit(ctx, de->de_str.name, |
32357 | + de->de_str.len, de->de_ino, | |
32358 | + de->de_type))) { | |
1facf9fc | 32359 | + /* todo: ignore the error caused by udba? */ |
32360 | + /* return err; */ | |
32361 | + return 0; | |
32362 | + } | |
32363 | + | |
32364 | + l = calc_size(de->de_str.len); | |
32365 | + vdir_cache->vd_last.p.deblk += l; | |
392086de | 32366 | + ctx->pos += l; |
1facf9fc | 32367 | + } |
32368 | + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) { | |
32369 | + vdir_cache->vd_last.ul++; | |
32370 | + vdir_cache->vd_last.p.deblk | |
32371 | + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
392086de | 32372 | + ctx->pos = deblk_sz * vdir_cache->vd_last.ul; |
1facf9fc | 32373 | + continue; |
32374 | + } | |
32375 | + break; | |
32376 | + } | |
32377 | + | |
32378 | + /* smp_mb(); */ | |
32379 | + return 0; | |
32380 | +} | |
7f207e10 AM |
32381 | diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c |
32382 | --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 32383 | +++ linux/fs/aufs/vfsub.c 2018-01-29 07:56:20.063325368 +0100 |
8b6a4947 | 32384 | @@ -0,0 +1,894 @@ |
1facf9fc | 32385 | +/* |
a2654f78 | 32386 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 32387 | + * |
32388 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32389 | + * it under the terms of the GNU General Public License as published by | |
32390 | + * the Free Software Foundation; either version 2 of the License, or | |
32391 | + * (at your option) any later version. | |
dece6358 AM |
32392 | + * |
32393 | + * This program is distributed in the hope that it will be useful, | |
32394 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32395 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32396 | + * GNU General Public License for more details. | |
32397 | + * | |
32398 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32399 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32400 | + */ |
32401 | + | |
32402 | +/* | |
32403 | + * sub-routines for VFS | |
32404 | + */ | |
32405 | + | |
8b6a4947 | 32406 | +#include <linux/mnt_namespace.h> |
dece6358 | 32407 | +#include <linux/namei.h> |
8cdd5066 | 32408 | +#include <linux/nsproxy.h> |
dece6358 AM |
32409 | +#include <linux/security.h> |
32410 | +#include <linux/splice.h> | |
1facf9fc | 32411 | +#include "aufs.h" |
32412 | + | |
8cdd5066 JR |
32413 | +#ifdef CONFIG_AUFS_BR_FUSE |
32414 | +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb) | |
32415 | +{ | |
8cdd5066 JR |
32416 | + if (!au_test_fuse(h_sb) || !au_userns) |
32417 | + return 0; | |
32418 | + | |
8b6a4947 | 32419 | + return is_current_mnt_ns(mnt) ? 0 : -EACCES; |
8cdd5066 JR |
32420 | +} |
32421 | +#endif | |
32422 | + | |
a2654f78 AM |
32423 | +int vfsub_sync_filesystem(struct super_block *h_sb, int wait) |
32424 | +{ | |
32425 | + int err; | |
32426 | + | |
32427 | + lockdep_off(); | |
32428 | + down_read(&h_sb->s_umount); | |
32429 | + err = __sync_filesystem(h_sb, wait); | |
32430 | + up_read(&h_sb->s_umount); | |
32431 | + lockdep_on(); | |
32432 | + | |
32433 | + return err; | |
32434 | +} | |
32435 | + | |
8cdd5066 JR |
32436 | +/* ---------------------------------------------------------------------- */ |
32437 | + | |
1facf9fc | 32438 | +int vfsub_update_h_iattr(struct path *h_path, int *did) |
32439 | +{ | |
32440 | + int err; | |
32441 | + struct kstat st; | |
32442 | + struct super_block *h_sb; | |
32443 | + | |
32444 | + /* for remote fs, leave work for its getattr or d_revalidate */ | |
32445 | + /* for bad i_attr fs, handle them in aufs_getattr() */ | |
32446 | + /* still some fs may acquire i_mutex. we need to skip them */ | |
32447 | + err = 0; | |
32448 | + if (!did) | |
32449 | + did = &err; | |
32450 | + h_sb = h_path->dentry->d_sb; | |
32451 | + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb)); | |
32452 | + if (*did) | |
521ced18 | 32453 | + err = vfsub_getattr(h_path, &st); |
1facf9fc | 32454 | + |
32455 | + return err; | |
32456 | +} | |
32457 | + | |
32458 | +/* ---------------------------------------------------------------------- */ | |
32459 | + | |
4a4d8108 | 32460 | +struct file *vfsub_dentry_open(struct path *path, int flags) |
1308ab2a | 32461 | +{ |
32462 | + struct file *file; | |
32463 | + | |
b4510431 | 32464 | + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */, |
7f207e10 | 32465 | + current_cred()); |
2cbb1c4b JR |
32466 | + if (!IS_ERR_OR_NULL(file) |
32467 | + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | |
5527c038 | 32468 | + i_readcount_inc(d_inode(path->dentry)); |
4a4d8108 | 32469 | + |
1308ab2a | 32470 | + return file; |
32471 | +} | |
32472 | + | |
1facf9fc | 32473 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode) |
32474 | +{ | |
32475 | + struct file *file; | |
32476 | + | |
2cbb1c4b | 32477 | + lockdep_off(); |
7f207e10 | 32478 | + file = filp_open(path, |
2cbb1c4b | 32479 | + oflags /* | __FMODE_NONOTIFY */, |
7f207e10 | 32480 | + mode); |
2cbb1c4b | 32481 | + lockdep_on(); |
1facf9fc | 32482 | + if (IS_ERR(file)) |
32483 | + goto out; | |
32484 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
32485 | + | |
4f0767ce | 32486 | +out: |
1facf9fc | 32487 | + return file; |
32488 | +} | |
32489 | + | |
b912730e AM |
32490 | +/* |
32491 | + * Ideally this function should call VFS:do_last() in order to keep all its | |
32492 | + * checkings. But it is very hard for aufs to regenerate several VFS internal | |
32493 | + * structure such as nameidata. This is a second (or third) best approach. | |
32494 | + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open(). | |
32495 | + */ | |
32496 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
32497 | + struct vfsub_aopen_args *args, struct au_branch *br) | |
32498 | +{ | |
32499 | + int err; | |
32500 | + struct file *file = args->file; | |
32501 | + /* copied from linux/fs/namei.c:atomic_open() */ | |
32502 | + struct dentry *const DENTRY_NOT_SET = (void *)-1UL; | |
32503 | + | |
32504 | + IMustLock(dir); | |
32505 | + AuDebugOn(!dir->i_op->atomic_open); | |
32506 | + | |
32507 | + err = au_br_test_oflag(args->open_flag, br); | |
32508 | + if (unlikely(err)) | |
32509 | + goto out; | |
32510 | + | |
32511 | + args->file->f_path.dentry = DENTRY_NOT_SET; | |
32512 | + args->file->f_path.mnt = au_br_mnt(br); | |
32513 | + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag, | |
32514 | + args->create_mode, args->opened); | |
32515 | + if (err >= 0) { | |
32516 | + /* some filesystems don't set FILE_CREATED while succeeded? */ | |
32517 | + if (*args->opened & FILE_CREATED) | |
32518 | + fsnotify_create(dir, dentry); | |
32519 | + } else | |
32520 | + goto out; | |
32521 | + | |
32522 | + | |
32523 | + if (!err) { | |
32524 | + /* todo: call VFS:may_open() here */ | |
32525 | + err = open_check_o_direct(file); | |
32526 | + /* todo: ima_file_check() too? */ | |
32527 | + if (!err && (args->open_flag & __FMODE_EXEC)) | |
32528 | + err = deny_write_access(file); | |
32529 | + if (unlikely(err)) | |
32530 | + /* note that the file is created and still opened */ | |
32531 | + goto out; | |
32532 | + } | |
32533 | + | |
5afbbe0d | 32534 | + au_br_get(br); |
b912730e AM |
32535 | + fsnotify_open(file); |
32536 | + | |
32537 | +out: | |
32538 | + return err; | |
32539 | +} | |
32540 | + | |
1facf9fc | 32541 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path) |
32542 | +{ | |
32543 | + int err; | |
32544 | + | |
1facf9fc | 32545 | + err = kern_path(name, flags, path); |
5527c038 | 32546 | + if (!err && d_is_positive(path->dentry)) |
1facf9fc | 32547 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ |
32548 | + return err; | |
32549 | +} | |
32550 | + | |
febd17d6 JR |
32551 | +struct dentry *vfsub_lookup_one_len_unlocked(const char *name, |
32552 | + struct dentry *parent, int len) | |
32553 | +{ | |
32554 | + struct path path = { | |
32555 | + .mnt = NULL | |
32556 | + }; | |
32557 | + | |
32558 | + path.dentry = lookup_one_len_unlocked(name, parent, len); | |
32559 | + if (IS_ERR(path.dentry)) | |
32560 | + goto out; | |
32561 | + if (d_is_positive(path.dentry)) | |
32562 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ | |
32563 | + | |
32564 | +out: | |
32565 | + AuTraceErrPtr(path.dentry); | |
32566 | + return path.dentry; | |
32567 | +} | |
32568 | + | |
1facf9fc | 32569 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
32570 | + int len) | |
32571 | +{ | |
32572 | + struct path path = { | |
32573 | + .mnt = NULL | |
32574 | + }; | |
32575 | + | |
1308ab2a | 32576 | + /* VFS checks it too, but by WARN_ON_ONCE() */ |
5527c038 | 32577 | + IMustLock(d_inode(parent)); |
1facf9fc | 32578 | + |
32579 | + path.dentry = lookup_one_len(name, parent, len); | |
32580 | + if (IS_ERR(path.dentry)) | |
32581 | + goto out; | |
5527c038 | 32582 | + if (d_is_positive(path.dentry)) |
1facf9fc | 32583 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ |
32584 | + | |
4f0767ce | 32585 | +out: |
4a4d8108 | 32586 | + AuTraceErrPtr(path.dentry); |
1facf9fc | 32587 | + return path.dentry; |
32588 | +} | |
32589 | + | |
b4510431 | 32590 | +void vfsub_call_lkup_one(void *args) |
2cbb1c4b | 32591 | +{ |
b4510431 AM |
32592 | + struct vfsub_lkup_one_args *a = args; |
32593 | + *a->errp = vfsub_lkup_one(a->name, a->parent); | |
2cbb1c4b JR |
32594 | +} |
32595 | + | |
1facf9fc | 32596 | +/* ---------------------------------------------------------------------- */ |
32597 | + | |
32598 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
32599 | + struct dentry *d2, struct au_hinode *hdir2) | |
32600 | +{ | |
32601 | + struct dentry *d; | |
32602 | + | |
2cbb1c4b | 32603 | + lockdep_off(); |
1facf9fc | 32604 | + d = lock_rename(d1, d2); |
2cbb1c4b | 32605 | + lockdep_on(); |
4a4d8108 | 32606 | + au_hn_suspend(hdir1); |
1facf9fc | 32607 | + if (hdir1 != hdir2) |
4a4d8108 | 32608 | + au_hn_suspend(hdir2); |
1facf9fc | 32609 | + |
32610 | + return d; | |
32611 | +} | |
32612 | + | |
32613 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
32614 | + struct dentry *d2, struct au_hinode *hdir2) | |
32615 | +{ | |
4a4d8108 | 32616 | + au_hn_resume(hdir1); |
1facf9fc | 32617 | + if (hdir1 != hdir2) |
4a4d8108 | 32618 | + au_hn_resume(hdir2); |
2cbb1c4b | 32619 | + lockdep_off(); |
1facf9fc | 32620 | + unlock_rename(d1, d2); |
2cbb1c4b | 32621 | + lockdep_on(); |
1facf9fc | 32622 | +} |
32623 | + | |
32624 | +/* ---------------------------------------------------------------------- */ | |
32625 | + | |
b4510431 | 32626 | +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl) |
1facf9fc | 32627 | +{ |
32628 | + int err; | |
32629 | + struct dentry *d; | |
32630 | + | |
32631 | + IMustLock(dir); | |
32632 | + | |
32633 | + d = path->dentry; | |
32634 | + path->dentry = d->d_parent; | |
b752ccd1 | 32635 | + err = security_path_mknod(path, d, mode, 0); |
1facf9fc | 32636 | + path->dentry = d; |
32637 | + if (unlikely(err)) | |
32638 | + goto out; | |
32639 | + | |
c1595e42 | 32640 | + lockdep_off(); |
b4510431 | 32641 | + err = vfs_create(dir, path->dentry, mode, want_excl); |
c1595e42 | 32642 | + lockdep_on(); |
1facf9fc | 32643 | + if (!err) { |
32644 | + struct path tmp = *path; | |
32645 | + int did; | |
32646 | + | |
32647 | + vfsub_update_h_iattr(&tmp, &did); | |
32648 | + if (did) { | |
32649 | + tmp.dentry = path->dentry->d_parent; | |
32650 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32651 | + } | |
32652 | + /*ignore*/ | |
32653 | + } | |
32654 | + | |
4f0767ce | 32655 | +out: |
1facf9fc | 32656 | + return err; |
32657 | +} | |
32658 | + | |
32659 | +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname) | |
32660 | +{ | |
32661 | + int err; | |
32662 | + struct dentry *d; | |
32663 | + | |
32664 | + IMustLock(dir); | |
32665 | + | |
32666 | + d = path->dentry; | |
32667 | + path->dentry = d->d_parent; | |
b752ccd1 | 32668 | + err = security_path_symlink(path, d, symname); |
1facf9fc | 32669 | + path->dentry = d; |
32670 | + if (unlikely(err)) | |
32671 | + goto out; | |
32672 | + | |
c1595e42 | 32673 | + lockdep_off(); |
1facf9fc | 32674 | + err = vfs_symlink(dir, path->dentry, symname); |
c1595e42 | 32675 | + lockdep_on(); |
1facf9fc | 32676 | + if (!err) { |
32677 | + struct path tmp = *path; | |
32678 | + int did; | |
32679 | + | |
32680 | + vfsub_update_h_iattr(&tmp, &did); | |
32681 | + if (did) { | |
32682 | + tmp.dentry = path->dentry->d_parent; | |
32683 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32684 | + } | |
32685 | + /*ignore*/ | |
32686 | + } | |
32687 | + | |
4f0767ce | 32688 | +out: |
1facf9fc | 32689 | + return err; |
32690 | +} | |
32691 | + | |
32692 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev) | |
32693 | +{ | |
32694 | + int err; | |
32695 | + struct dentry *d; | |
32696 | + | |
32697 | + IMustLock(dir); | |
32698 | + | |
32699 | + d = path->dentry; | |
32700 | + path->dentry = d->d_parent; | |
027c5e7a | 32701 | + err = security_path_mknod(path, d, mode, new_encode_dev(dev)); |
1facf9fc | 32702 | + path->dentry = d; |
32703 | + if (unlikely(err)) | |
32704 | + goto out; | |
32705 | + | |
c1595e42 | 32706 | + lockdep_off(); |
1facf9fc | 32707 | + err = vfs_mknod(dir, path->dentry, mode, dev); |
c1595e42 | 32708 | + lockdep_on(); |
1facf9fc | 32709 | + if (!err) { |
32710 | + struct path tmp = *path; | |
32711 | + int did; | |
32712 | + | |
32713 | + vfsub_update_h_iattr(&tmp, &did); | |
32714 | + if (did) { | |
32715 | + tmp.dentry = path->dentry->d_parent; | |
32716 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32717 | + } | |
32718 | + /*ignore*/ | |
32719 | + } | |
32720 | + | |
4f0767ce | 32721 | +out: |
1facf9fc | 32722 | + return err; |
32723 | +} | |
32724 | + | |
32725 | +static int au_test_nlink(struct inode *inode) | |
32726 | +{ | |
32727 | + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */ | |
32728 | + | |
32729 | + if (!au_test_fs_no_limit_nlink(inode->i_sb) | |
32730 | + || inode->i_nlink < link_max) | |
32731 | + return 0; | |
32732 | + return -EMLINK; | |
32733 | +} | |
32734 | + | |
523b37e3 AM |
32735 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path, |
32736 | + struct inode **delegated_inode) | |
1facf9fc | 32737 | +{ |
32738 | + int err; | |
32739 | + struct dentry *d; | |
32740 | + | |
32741 | + IMustLock(dir); | |
32742 | + | |
5527c038 | 32743 | + err = au_test_nlink(d_inode(src_dentry)); |
1facf9fc | 32744 | + if (unlikely(err)) |
32745 | + return err; | |
32746 | + | |
b4510431 | 32747 | + /* we don't call may_linkat() */ |
1facf9fc | 32748 | + d = path->dentry; |
32749 | + path->dentry = d->d_parent; | |
b752ccd1 | 32750 | + err = security_path_link(src_dentry, path, d); |
1facf9fc | 32751 | + path->dentry = d; |
32752 | + if (unlikely(err)) | |
32753 | + goto out; | |
32754 | + | |
2cbb1c4b | 32755 | + lockdep_off(); |
523b37e3 | 32756 | + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode); |
2cbb1c4b | 32757 | + lockdep_on(); |
1facf9fc | 32758 | + if (!err) { |
32759 | + struct path tmp = *path; | |
32760 | + int did; | |
32761 | + | |
32762 | + /* fuse has different memory inode for the same inumber */ | |
32763 | + vfsub_update_h_iattr(&tmp, &did); | |
32764 | + if (did) { | |
32765 | + tmp.dentry = path->dentry->d_parent; | |
32766 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32767 | + tmp.dentry = src_dentry; | |
32768 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32769 | + } | |
32770 | + /*ignore*/ | |
32771 | + } | |
32772 | + | |
4f0767ce | 32773 | +out: |
1facf9fc | 32774 | + return err; |
32775 | +} | |
32776 | + | |
32777 | +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry, | |
523b37e3 | 32778 | + struct inode *dir, struct path *path, |
f2c43d5f | 32779 | + struct inode **delegated_inode, unsigned int flags) |
1facf9fc | 32780 | +{ |
32781 | + int err; | |
32782 | + struct path tmp = { | |
32783 | + .mnt = path->mnt | |
32784 | + }; | |
32785 | + struct dentry *d; | |
32786 | + | |
32787 | + IMustLock(dir); | |
32788 | + IMustLock(src_dir); | |
32789 | + | |
32790 | + d = path->dentry; | |
32791 | + path->dentry = d->d_parent; | |
32792 | + tmp.dentry = src_dentry->d_parent; | |
38d290e6 | 32793 | + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0); |
1facf9fc | 32794 | + path->dentry = d; |
32795 | + if (unlikely(err)) | |
32796 | + goto out; | |
32797 | + | |
2cbb1c4b | 32798 | + lockdep_off(); |
523b37e3 | 32799 | + err = vfs_rename(src_dir, src_dentry, dir, path->dentry, |
f2c43d5f | 32800 | + delegated_inode, flags); |
2cbb1c4b | 32801 | + lockdep_on(); |
1facf9fc | 32802 | + if (!err) { |
32803 | + int did; | |
32804 | + | |
32805 | + tmp.dentry = d->d_parent; | |
32806 | + vfsub_update_h_iattr(&tmp, &did); | |
32807 | + if (did) { | |
32808 | + tmp.dentry = src_dentry; | |
32809 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32810 | + tmp.dentry = src_dentry->d_parent; | |
32811 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32812 | + } | |
32813 | + /*ignore*/ | |
32814 | + } | |
32815 | + | |
4f0767ce | 32816 | +out: |
1facf9fc | 32817 | + return err; |
32818 | +} | |
32819 | + | |
32820 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode) | |
32821 | +{ | |
32822 | + int err; | |
32823 | + struct dentry *d; | |
32824 | + | |
32825 | + IMustLock(dir); | |
32826 | + | |
32827 | + d = path->dentry; | |
32828 | + path->dentry = d->d_parent; | |
b752ccd1 | 32829 | + err = security_path_mkdir(path, d, mode); |
1facf9fc | 32830 | + path->dentry = d; |
32831 | + if (unlikely(err)) | |
32832 | + goto out; | |
32833 | + | |
c1595e42 | 32834 | + lockdep_off(); |
1facf9fc | 32835 | + err = vfs_mkdir(dir, path->dentry, mode); |
c1595e42 | 32836 | + lockdep_on(); |
1facf9fc | 32837 | + if (!err) { |
32838 | + struct path tmp = *path; | |
32839 | + int did; | |
32840 | + | |
32841 | + vfsub_update_h_iattr(&tmp, &did); | |
32842 | + if (did) { | |
32843 | + tmp.dentry = path->dentry->d_parent; | |
32844 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32845 | + } | |
32846 | + /*ignore*/ | |
32847 | + } | |
32848 | + | |
4f0767ce | 32849 | +out: |
1facf9fc | 32850 | + return err; |
32851 | +} | |
32852 | + | |
32853 | +int vfsub_rmdir(struct inode *dir, struct path *path) | |
32854 | +{ | |
32855 | + int err; | |
32856 | + struct dentry *d; | |
32857 | + | |
32858 | + IMustLock(dir); | |
32859 | + | |
32860 | + d = path->dentry; | |
32861 | + path->dentry = d->d_parent; | |
b752ccd1 | 32862 | + err = security_path_rmdir(path, d); |
1facf9fc | 32863 | + path->dentry = d; |
32864 | + if (unlikely(err)) | |
32865 | + goto out; | |
32866 | + | |
2cbb1c4b | 32867 | + lockdep_off(); |
1facf9fc | 32868 | + err = vfs_rmdir(dir, path->dentry); |
2cbb1c4b | 32869 | + lockdep_on(); |
1facf9fc | 32870 | + if (!err) { |
32871 | + struct path tmp = { | |
32872 | + .dentry = path->dentry->d_parent, | |
32873 | + .mnt = path->mnt | |
32874 | + }; | |
32875 | + | |
32876 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
32877 | + } | |
32878 | + | |
4f0767ce | 32879 | +out: |
1facf9fc | 32880 | + return err; |
32881 | +} | |
32882 | + | |
32883 | +/* ---------------------------------------------------------------------- */ | |
32884 | + | |
9dbd164d | 32885 | +/* todo: support mmap_sem? */ |
1facf9fc | 32886 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, |
32887 | + loff_t *ppos) | |
32888 | +{ | |
32889 | + ssize_t err; | |
32890 | + | |
2cbb1c4b | 32891 | + lockdep_off(); |
1facf9fc | 32892 | + err = vfs_read(file, ubuf, count, ppos); |
2cbb1c4b | 32893 | + lockdep_on(); |
1facf9fc | 32894 | + if (err >= 0) |
32895 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
32896 | + return err; | |
32897 | +} | |
32898 | + | |
32899 | +/* todo: kernel_read()? */ | |
32900 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
32901 | + loff_t *ppos) | |
32902 | +{ | |
32903 | + ssize_t err; | |
32904 | + mm_segment_t oldfs; | |
b752ccd1 AM |
32905 | + union { |
32906 | + void *k; | |
32907 | + char __user *u; | |
32908 | + } buf; | |
1facf9fc | 32909 | + |
b752ccd1 | 32910 | + buf.k = kbuf; |
1facf9fc | 32911 | + oldfs = get_fs(); |
32912 | + set_fs(KERNEL_DS); | |
b752ccd1 | 32913 | + err = vfsub_read_u(file, buf.u, count, ppos); |
1facf9fc | 32914 | + set_fs(oldfs); |
32915 | + return err; | |
32916 | +} | |
32917 | + | |
32918 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
32919 | + loff_t *ppos) | |
32920 | +{ | |
32921 | + ssize_t err; | |
32922 | + | |
2cbb1c4b | 32923 | + lockdep_off(); |
1facf9fc | 32924 | + err = vfs_write(file, ubuf, count, ppos); |
2cbb1c4b | 32925 | + lockdep_on(); |
1facf9fc | 32926 | + if (err >= 0) |
32927 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
32928 | + return err; | |
32929 | +} | |
32930 | + | |
32931 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos) | |
32932 | +{ | |
32933 | + ssize_t err; | |
32934 | + mm_segment_t oldfs; | |
b752ccd1 AM |
32935 | + union { |
32936 | + void *k; | |
32937 | + const char __user *u; | |
32938 | + } buf; | |
1facf9fc | 32939 | + |
b752ccd1 | 32940 | + buf.k = kbuf; |
1facf9fc | 32941 | + oldfs = get_fs(); |
32942 | + set_fs(KERNEL_DS); | |
b752ccd1 | 32943 | + err = vfsub_write_u(file, buf.u, count, ppos); |
1facf9fc | 32944 | + set_fs(oldfs); |
32945 | + return err; | |
32946 | +} | |
32947 | + | |
4a4d8108 AM |
32948 | +int vfsub_flush(struct file *file, fl_owner_t id) |
32949 | +{ | |
32950 | + int err; | |
32951 | + | |
32952 | + err = 0; | |
523b37e3 | 32953 | + if (file->f_op->flush) { |
2000de60 | 32954 | + if (!au_test_nfs(file->f_path.dentry->d_sb)) |
2cbb1c4b JR |
32955 | + err = file->f_op->flush(file, id); |
32956 | + else { | |
32957 | + lockdep_off(); | |
32958 | + err = file->f_op->flush(file, id); | |
32959 | + lockdep_on(); | |
32960 | + } | |
4a4d8108 AM |
32961 | + if (!err) |
32962 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); | |
32963 | + /*ignore*/ | |
32964 | + } | |
32965 | + return err; | |
32966 | +} | |
32967 | + | |
392086de | 32968 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx) |
1facf9fc | 32969 | +{ |
32970 | + int err; | |
32971 | + | |
523b37e3 | 32972 | + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 32973 | + |
2cbb1c4b | 32974 | + lockdep_off(); |
392086de | 32975 | + err = iterate_dir(file, ctx); |
2cbb1c4b | 32976 | + lockdep_on(); |
1facf9fc | 32977 | + if (err >= 0) |
32978 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
1c60b727 | 32979 | + |
1facf9fc | 32980 | + return err; |
32981 | +} | |
32982 | + | |
32983 | +long vfsub_splice_to(struct file *in, loff_t *ppos, | |
32984 | + struct pipe_inode_info *pipe, size_t len, | |
32985 | + unsigned int flags) | |
32986 | +{ | |
32987 | + long err; | |
32988 | + | |
2cbb1c4b | 32989 | + lockdep_off(); |
0fc653ad | 32990 | + err = do_splice_to(in, ppos, pipe, len, flags); |
2cbb1c4b | 32991 | + lockdep_on(); |
4a4d8108 | 32992 | + file_accessed(in); |
1facf9fc | 32993 | + if (err >= 0) |
32994 | + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/ | |
32995 | + return err; | |
32996 | +} | |
32997 | + | |
32998 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
32999 | + loff_t *ppos, size_t len, unsigned int flags) | |
33000 | +{ | |
33001 | + long err; | |
33002 | + | |
2cbb1c4b | 33003 | + lockdep_off(); |
0fc653ad | 33004 | + err = do_splice_from(pipe, out, ppos, len, flags); |
2cbb1c4b | 33005 | + lockdep_on(); |
1facf9fc | 33006 | + if (err >= 0) |
33007 | + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/ | |
33008 | + return err; | |
33009 | +} | |
33010 | + | |
53392da6 AM |
33011 | +int vfsub_fsync(struct file *file, struct path *path, int datasync) |
33012 | +{ | |
33013 | + int err; | |
33014 | + | |
33015 | + /* file can be NULL */ | |
33016 | + lockdep_off(); | |
33017 | + err = vfs_fsync(file, datasync); | |
33018 | + lockdep_on(); | |
33019 | + if (!err) { | |
33020 | + if (!path) { | |
33021 | + AuDebugOn(!file); | |
33022 | + path = &file->f_path; | |
33023 | + } | |
33024 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
33025 | + } | |
33026 | + return err; | |
33027 | +} | |
33028 | + | |
1facf9fc | 33029 | +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */ |
33030 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, | |
33031 | + struct file *h_file) | |
33032 | +{ | |
33033 | + int err; | |
33034 | + struct inode *h_inode; | |
c06a8ce3 | 33035 | + struct super_block *h_sb; |
1facf9fc | 33036 | + |
1facf9fc | 33037 | + if (!h_file) { |
c06a8ce3 AM |
33038 | + err = vfsub_truncate(h_path, length); |
33039 | + goto out; | |
1facf9fc | 33040 | + } |
33041 | + | |
5527c038 | 33042 | + h_inode = d_inode(h_path->dentry); |
c06a8ce3 AM |
33043 | + h_sb = h_inode->i_sb; |
33044 | + lockdep_off(); | |
33045 | + sb_start_write(h_sb); | |
33046 | + lockdep_on(); | |
1facf9fc | 33047 | + err = locks_verify_truncate(h_inode, h_file, length); |
33048 | + if (!err) | |
953406b4 | 33049 | + err = security_path_truncate(h_path); |
2cbb1c4b JR |
33050 | + if (!err) { |
33051 | + lockdep_off(); | |
1facf9fc | 33052 | + err = do_truncate(h_path->dentry, length, attr, h_file); |
2cbb1c4b JR |
33053 | + lockdep_on(); |
33054 | + } | |
c06a8ce3 AM |
33055 | + lockdep_off(); |
33056 | + sb_end_write(h_sb); | |
33057 | + lockdep_on(); | |
1facf9fc | 33058 | + |
4f0767ce | 33059 | +out: |
1facf9fc | 33060 | + return err; |
33061 | +} | |
33062 | + | |
33063 | +/* ---------------------------------------------------------------------- */ | |
33064 | + | |
33065 | +struct au_vfsub_mkdir_args { | |
33066 | + int *errp; | |
33067 | + struct inode *dir; | |
33068 | + struct path *path; | |
33069 | + int mode; | |
33070 | +}; | |
33071 | + | |
33072 | +static void au_call_vfsub_mkdir(void *args) | |
33073 | +{ | |
33074 | + struct au_vfsub_mkdir_args *a = args; | |
33075 | + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode); | |
33076 | +} | |
33077 | + | |
33078 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode) | |
33079 | +{ | |
33080 | + int err, do_sio, wkq_err; | |
33081 | + | |
33082 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
33083 | + if (!do_sio) { |
33084 | + lockdep_off(); | |
1facf9fc | 33085 | + err = vfsub_mkdir(dir, path, mode); |
c1595e42 JR |
33086 | + lockdep_on(); |
33087 | + } else { | |
1facf9fc | 33088 | + struct au_vfsub_mkdir_args args = { |
33089 | + .errp = &err, | |
33090 | + .dir = dir, | |
33091 | + .path = path, | |
33092 | + .mode = mode | |
33093 | + }; | |
33094 | + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args); | |
33095 | + if (unlikely(wkq_err)) | |
33096 | + err = wkq_err; | |
33097 | + } | |
33098 | + | |
33099 | + return err; | |
33100 | +} | |
33101 | + | |
33102 | +struct au_vfsub_rmdir_args { | |
33103 | + int *errp; | |
33104 | + struct inode *dir; | |
33105 | + struct path *path; | |
33106 | +}; | |
33107 | + | |
33108 | +static void au_call_vfsub_rmdir(void *args) | |
33109 | +{ | |
33110 | + struct au_vfsub_rmdir_args *a = args; | |
33111 | + *a->errp = vfsub_rmdir(a->dir, a->path); | |
33112 | +} | |
33113 | + | |
33114 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path) | |
33115 | +{ | |
33116 | + int err, do_sio, wkq_err; | |
33117 | + | |
33118 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
33119 | + if (!do_sio) { |
33120 | + lockdep_off(); | |
1facf9fc | 33121 | + err = vfsub_rmdir(dir, path); |
c1595e42 JR |
33122 | + lockdep_on(); |
33123 | + } else { | |
1facf9fc | 33124 | + struct au_vfsub_rmdir_args args = { |
33125 | + .errp = &err, | |
33126 | + .dir = dir, | |
33127 | + .path = path | |
33128 | + }; | |
33129 | + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args); | |
33130 | + if (unlikely(wkq_err)) | |
33131 | + err = wkq_err; | |
33132 | + } | |
33133 | + | |
33134 | + return err; | |
33135 | +} | |
33136 | + | |
33137 | +/* ---------------------------------------------------------------------- */ | |
33138 | + | |
33139 | +struct notify_change_args { | |
33140 | + int *errp; | |
33141 | + struct path *path; | |
33142 | + struct iattr *ia; | |
523b37e3 | 33143 | + struct inode **delegated_inode; |
1facf9fc | 33144 | +}; |
33145 | + | |
33146 | +static void call_notify_change(void *args) | |
33147 | +{ | |
33148 | + struct notify_change_args *a = args; | |
33149 | + struct inode *h_inode; | |
33150 | + | |
5527c038 | 33151 | + h_inode = d_inode(a->path->dentry); |
1facf9fc | 33152 | + IMustLock(h_inode); |
33153 | + | |
33154 | + *a->errp = -EPERM; | |
33155 | + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) { | |
c1595e42 | 33156 | + lockdep_off(); |
523b37e3 AM |
33157 | + *a->errp = notify_change(a->path->dentry, a->ia, |
33158 | + a->delegated_inode); | |
c1595e42 | 33159 | + lockdep_on(); |
1facf9fc | 33160 | + if (!*a->errp) |
33161 | + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/ | |
33162 | + } | |
33163 | + AuTraceErr(*a->errp); | |
33164 | +} | |
33165 | + | |
523b37e3 AM |
33166 | +int vfsub_notify_change(struct path *path, struct iattr *ia, |
33167 | + struct inode **delegated_inode) | |
1facf9fc | 33168 | +{ |
33169 | + int err; | |
33170 | + struct notify_change_args args = { | |
523b37e3 AM |
33171 | + .errp = &err, |
33172 | + .path = path, | |
33173 | + .ia = ia, | |
33174 | + .delegated_inode = delegated_inode | |
1facf9fc | 33175 | + }; |
33176 | + | |
33177 | + call_notify_change(&args); | |
33178 | + | |
33179 | + return err; | |
33180 | +} | |
33181 | + | |
523b37e3 AM |
33182 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
33183 | + struct inode **delegated_inode) | |
1facf9fc | 33184 | +{ |
33185 | + int err, wkq_err; | |
33186 | + struct notify_change_args args = { | |
523b37e3 AM |
33187 | + .errp = &err, |
33188 | + .path = path, | |
33189 | + .ia = ia, | |
33190 | + .delegated_inode = delegated_inode | |
1facf9fc | 33191 | + }; |
33192 | + | |
33193 | + wkq_err = au_wkq_wait(call_notify_change, &args); | |
33194 | + if (unlikely(wkq_err)) | |
33195 | + err = wkq_err; | |
33196 | + | |
33197 | + return err; | |
33198 | +} | |
33199 | + | |
33200 | +/* ---------------------------------------------------------------------- */ | |
33201 | + | |
33202 | +struct unlink_args { | |
33203 | + int *errp; | |
33204 | + struct inode *dir; | |
33205 | + struct path *path; | |
523b37e3 | 33206 | + struct inode **delegated_inode; |
1facf9fc | 33207 | +}; |
33208 | + | |
33209 | +static void call_unlink(void *args) | |
33210 | +{ | |
33211 | + struct unlink_args *a = args; | |
33212 | + struct dentry *d = a->path->dentry; | |
33213 | + struct inode *h_inode; | |
33214 | + const int stop_sillyrename = (au_test_nfs(d->d_sb) | |
c1595e42 | 33215 | + && au_dcount(d) == 1); |
1facf9fc | 33216 | + |
33217 | + IMustLock(a->dir); | |
33218 | + | |
33219 | + a->path->dentry = d->d_parent; | |
33220 | + *a->errp = security_path_unlink(a->path, d); | |
33221 | + a->path->dentry = d; | |
33222 | + if (unlikely(*a->errp)) | |
33223 | + return; | |
33224 | + | |
33225 | + if (!stop_sillyrename) | |
33226 | + dget(d); | |
5527c038 JR |
33227 | + h_inode = NULL; |
33228 | + if (d_is_positive(d)) { | |
33229 | + h_inode = d_inode(d); | |
027c5e7a | 33230 | + ihold(h_inode); |
5527c038 | 33231 | + } |
1facf9fc | 33232 | + |
2cbb1c4b | 33233 | + lockdep_off(); |
523b37e3 | 33234 | + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode); |
2cbb1c4b | 33235 | + lockdep_on(); |
1facf9fc | 33236 | + if (!*a->errp) { |
33237 | + struct path tmp = { | |
33238 | + .dentry = d->d_parent, | |
33239 | + .mnt = a->path->mnt | |
33240 | + }; | |
33241 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
33242 | + } | |
33243 | + | |
33244 | + if (!stop_sillyrename) | |
33245 | + dput(d); | |
33246 | + if (h_inode) | |
33247 | + iput(h_inode); | |
33248 | + | |
33249 | + AuTraceErr(*a->errp); | |
33250 | +} | |
33251 | + | |
33252 | +/* | |
33253 | + * @dir: must be locked. | |
33254 | + * @dentry: target dentry. | |
33255 | + */ | |
523b37e3 AM |
33256 | +int vfsub_unlink(struct inode *dir, struct path *path, |
33257 | + struct inode **delegated_inode, int force) | |
1facf9fc | 33258 | +{ |
33259 | + int err; | |
33260 | + struct unlink_args args = { | |
523b37e3 AM |
33261 | + .errp = &err, |
33262 | + .dir = dir, | |
33263 | + .path = path, | |
33264 | + .delegated_inode = delegated_inode | |
1facf9fc | 33265 | + }; |
33266 | + | |
33267 | + if (!force) | |
33268 | + call_unlink(&args); | |
33269 | + else { | |
33270 | + int wkq_err; | |
33271 | + | |
33272 | + wkq_err = au_wkq_wait(call_unlink, &args); | |
33273 | + if (unlikely(wkq_err)) | |
33274 | + err = wkq_err; | |
33275 | + } | |
33276 | + | |
33277 | + return err; | |
33278 | +} | |
7f207e10 AM |
33279 | diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h |
33280 | --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 33281 | +++ linux/fs/aufs/vfsub.h 2018-01-29 07:56:20.063325368 +0100 |
3c1bdaff | 33282 | @@ -0,0 +1,360 @@ |
1facf9fc | 33283 | +/* |
a2654f78 | 33284 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 33285 | + * |
33286 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33287 | + * it under the terms of the GNU General Public License as published by | |
33288 | + * the Free Software Foundation; either version 2 of the License, or | |
33289 | + * (at your option) any later version. | |
dece6358 AM |
33290 | + * |
33291 | + * This program is distributed in the hope that it will be useful, | |
33292 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33293 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33294 | + * GNU General Public License for more details. | |
33295 | + * | |
33296 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33297 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33298 | + */ |
33299 | + | |
33300 | +/* | |
33301 | + * sub-routines for VFS | |
33302 | + */ | |
33303 | + | |
33304 | +#ifndef __AUFS_VFSUB_H__ | |
33305 | +#define __AUFS_VFSUB_H__ | |
33306 | + | |
33307 | +#ifdef __KERNEL__ | |
33308 | + | |
33309 | +#include <linux/fs.h> | |
b4510431 | 33310 | +#include <linux/mount.h> |
8cdd5066 | 33311 | +#include <linux/posix_acl.h> |
c1595e42 | 33312 | +#include <linux/xattr.h> |
7f207e10 | 33313 | +#include "debug.h" |
1facf9fc | 33314 | + |
7f207e10 | 33315 | +/* copied from linux/fs/internal.h */ |
2cbb1c4b | 33316 | +/* todo: BAD approach!! */ |
c06a8ce3 | 33317 | +extern void __mnt_drop_write(struct vfsmount *); |
b912730e | 33318 | +extern int open_check_o_direct(struct file *f); |
7f207e10 AM |
33319 | + |
33320 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 33321 | + |
33322 | +/* lock subclass for lower inode */ | |
33323 | +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */ | |
33324 | +/* reduce? gave up. */ | |
33325 | +enum { | |
c1595e42 | 33326 | + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */ |
1facf9fc | 33327 | + AuLsc_I_PARENT, /* lower inode, parent first */ |
33328 | + AuLsc_I_PARENT2, /* copyup dirs */ | |
dece6358 | 33329 | + AuLsc_I_PARENT3, /* copyup wh */ |
1facf9fc | 33330 | + AuLsc_I_CHILD, |
33331 | + AuLsc_I_CHILD2, | |
33332 | + AuLsc_I_End | |
33333 | +}; | |
33334 | + | |
33335 | +/* to debug easier, do not make them inlined functions */ | |
33336 | +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx)) | |
febd17d6 | 33337 | +#define IMustLock(i) AuDebugOn(!inode_is_locked(i)) |
1facf9fc | 33338 | + |
3c1bdaff AM |
33339 | +/* why VFS doesn't define it? */ |
33340 | +static inline | |
33341 | +void vfsub_inode_lock_shared_nested(struct inode *inode, unsigned int sc) | |
33342 | +{ | |
33343 | + down_read_nested(&inode->i_rwsem, sc); | |
33344 | +} | |
33345 | + | |
1facf9fc | 33346 | +/* ---------------------------------------------------------------------- */ |
33347 | + | |
7f207e10 AM |
33348 | +static inline void vfsub_drop_nlink(struct inode *inode) |
33349 | +{ | |
33350 | + AuDebugOn(!inode->i_nlink); | |
33351 | + drop_nlink(inode); | |
33352 | +} | |
33353 | + | |
027c5e7a AM |
33354 | +static inline void vfsub_dead_dir(struct inode *inode) |
33355 | +{ | |
33356 | + AuDebugOn(!S_ISDIR(inode->i_mode)); | |
33357 | + inode->i_flags |= S_DEAD; | |
33358 | + clear_nlink(inode); | |
33359 | +} | |
33360 | + | |
392086de AM |
33361 | +static inline int vfsub_native_ro(struct inode *inode) |
33362 | +{ | |
8b6a4947 | 33363 | + return sb_rdonly(inode->i_sb) |
392086de AM |
33364 | + || IS_RDONLY(inode) |
33365 | + /* || IS_APPEND(inode) */ | |
33366 | + || IS_IMMUTABLE(inode); | |
33367 | +} | |
33368 | + | |
8cdd5066 JR |
33369 | +#ifdef CONFIG_AUFS_BR_FUSE |
33370 | +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb); | |
33371 | +#else | |
33372 | +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb); | |
33373 | +#endif | |
33374 | + | |
a2654f78 AM |
33375 | +int vfsub_sync_filesystem(struct super_block *h_sb, int wait); |
33376 | + | |
7f207e10 AM |
33377 | +/* ---------------------------------------------------------------------- */ |
33378 | + | |
33379 | +int vfsub_update_h_iattr(struct path *h_path, int *did); | |
33380 | +struct file *vfsub_dentry_open(struct path *path, int flags); | |
33381 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode); | |
b912730e AM |
33382 | +struct vfsub_aopen_args { |
33383 | + struct file *file; | |
33384 | + unsigned int open_flag; | |
33385 | + umode_t create_mode; | |
33386 | + int *opened; | |
33387 | +}; | |
33388 | +struct au_branch; | |
33389 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
33390 | + struct vfsub_aopen_args *args, struct au_branch *br); | |
1facf9fc | 33391 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path); |
b4510431 | 33392 | + |
febd17d6 JR |
33393 | +struct dentry *vfsub_lookup_one_len_unlocked(const char *name, |
33394 | + struct dentry *parent, int len); | |
1facf9fc | 33395 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
33396 | + int len); | |
b4510431 AM |
33397 | + |
33398 | +struct vfsub_lkup_one_args { | |
33399 | + struct dentry **errp; | |
33400 | + struct qstr *name; | |
33401 | + struct dentry *parent; | |
33402 | +}; | |
33403 | + | |
33404 | +static inline struct dentry *vfsub_lkup_one(struct qstr *name, | |
33405 | + struct dentry *parent) | |
33406 | +{ | |
33407 | + return vfsub_lookup_one_len(name->name, parent, name->len); | |
33408 | +} | |
33409 | + | |
33410 | +void vfsub_call_lkup_one(void *args); | |
33411 | + | |
33412 | +/* ---------------------------------------------------------------------- */ | |
33413 | + | |
33414 | +static inline int vfsub_mnt_want_write(struct vfsmount *mnt) | |
33415 | +{ | |
33416 | + int err; | |
076b876e | 33417 | + |
b4510431 AM |
33418 | + lockdep_off(); |
33419 | + err = mnt_want_write(mnt); | |
33420 | + lockdep_on(); | |
33421 | + return err; | |
33422 | +} | |
33423 | + | |
33424 | +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt) | |
33425 | +{ | |
33426 | + lockdep_off(); | |
33427 | + mnt_drop_write(mnt); | |
33428 | + lockdep_on(); | |
33429 | +} | |
1facf9fc | 33430 | + |
7e9cd9fe | 33431 | +#if 0 /* reserved */ |
c06a8ce3 AM |
33432 | +static inline void vfsub_mnt_drop_write_file(struct file *file) |
33433 | +{ | |
33434 | + lockdep_off(); | |
33435 | + mnt_drop_write_file(file); | |
33436 | + lockdep_on(); | |
33437 | +} | |
7e9cd9fe | 33438 | +#endif |
c06a8ce3 | 33439 | + |
1facf9fc | 33440 | +/* ---------------------------------------------------------------------- */ |
33441 | + | |
33442 | +struct au_hinode; | |
33443 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
33444 | + struct dentry *d2, struct au_hinode *hdir2); | |
33445 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
33446 | + struct dentry *d2, struct au_hinode *hdir2); | |
33447 | + | |
537831f9 AM |
33448 | +int vfsub_create(struct inode *dir, struct path *path, int mode, |
33449 | + bool want_excl); | |
1facf9fc | 33450 | +int vfsub_symlink(struct inode *dir, struct path *path, |
33451 | + const char *symname); | |
33452 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev); | |
33453 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, | |
523b37e3 | 33454 | + struct path *path, struct inode **delegated_inode); |
1facf9fc | 33455 | +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry, |
523b37e3 | 33456 | + struct inode *hdir, struct path *path, |
f2c43d5f | 33457 | + struct inode **delegated_inode, unsigned int flags); |
1facf9fc | 33458 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode); |
33459 | +int vfsub_rmdir(struct inode *dir, struct path *path); | |
33460 | + | |
33461 | +/* ---------------------------------------------------------------------- */ | |
33462 | + | |
33463 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, | |
33464 | + loff_t *ppos); | |
33465 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
33466 | + loff_t *ppos); | |
33467 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
33468 | + loff_t *ppos); | |
33469 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, | |
33470 | + loff_t *ppos); | |
4a4d8108 | 33471 | +int vfsub_flush(struct file *file, fl_owner_t id); |
392086de AM |
33472 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx); |
33473 | + | |
c06a8ce3 AM |
33474 | +static inline loff_t vfsub_f_size_read(struct file *file) |
33475 | +{ | |
33476 | + return i_size_read(file_inode(file)); | |
33477 | +} | |
33478 | + | |
4a4d8108 AM |
33479 | +static inline unsigned int vfsub_file_flags(struct file *file) |
33480 | +{ | |
33481 | + unsigned int flags; | |
33482 | + | |
33483 | + spin_lock(&file->f_lock); | |
33484 | + flags = file->f_flags; | |
33485 | + spin_unlock(&file->f_lock); | |
33486 | + | |
33487 | + return flags; | |
33488 | +} | |
1308ab2a | 33489 | + |
f0c0a007 AM |
33490 | +static inline int vfsub_file_execed(struct file *file) |
33491 | +{ | |
33492 | + /* todo: direct access f_flags */ | |
33493 | + return !!(vfsub_file_flags(file) & __FMODE_EXEC); | |
33494 | +} | |
33495 | + | |
7e9cd9fe | 33496 | +#if 0 /* reserved */ |
1facf9fc | 33497 | +static inline void vfsub_file_accessed(struct file *h_file) |
33498 | +{ | |
33499 | + file_accessed(h_file); | |
33500 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/ | |
33501 | +} | |
7e9cd9fe | 33502 | +#endif |
1facf9fc | 33503 | + |
79b8bda9 | 33504 | +#if 0 /* reserved */ |
1facf9fc | 33505 | +static inline void vfsub_touch_atime(struct vfsmount *h_mnt, |
33506 | + struct dentry *h_dentry) | |
33507 | +{ | |
33508 | + struct path h_path = { | |
33509 | + .dentry = h_dentry, | |
33510 | + .mnt = h_mnt | |
33511 | + }; | |
92d182d2 | 33512 | + touch_atime(&h_path); |
1facf9fc | 33513 | + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/ |
33514 | +} | |
79b8bda9 | 33515 | +#endif |
1facf9fc | 33516 | + |
0c3ec466 AM |
33517 | +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts, |
33518 | + int flags) | |
33519 | +{ | |
5afbbe0d | 33520 | + return update_time(h_inode, ts, flags); |
0c3ec466 AM |
33521 | + /* no vfsub_update_h_iattr() since we don't have struct path */ |
33522 | +} | |
33523 | + | |
8cdd5066 JR |
33524 | +#ifdef CONFIG_FS_POSIX_ACL |
33525 | +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode) | |
33526 | +{ | |
33527 | + int err; | |
33528 | + | |
33529 | + err = posix_acl_chmod(h_inode, h_mode); | |
33530 | + if (err == -EOPNOTSUPP) | |
33531 | + err = 0; | |
33532 | + return err; | |
33533 | +} | |
33534 | +#else | |
33535 | +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode); | |
33536 | +#endif | |
33537 | + | |
4a4d8108 AM |
33538 | +long vfsub_splice_to(struct file *in, loff_t *ppos, |
33539 | + struct pipe_inode_info *pipe, size_t len, | |
33540 | + unsigned int flags); | |
33541 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
33542 | + loff_t *ppos, size_t len, unsigned int flags); | |
c06a8ce3 AM |
33543 | + |
33544 | +static inline long vfsub_truncate(struct path *path, loff_t length) | |
33545 | +{ | |
33546 | + long err; | |
076b876e | 33547 | + |
c06a8ce3 AM |
33548 | + lockdep_off(); |
33549 | + err = vfs_truncate(path, length); | |
33550 | + lockdep_on(); | |
33551 | + return err; | |
33552 | +} | |
33553 | + | |
4a4d8108 AM |
33554 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, |
33555 | + struct file *h_file); | |
53392da6 | 33556 | +int vfsub_fsync(struct file *file, struct path *path, int datasync); |
4a4d8108 | 33557 | + |
521ced18 JR |
33558 | +/* |
33559 | + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such | |
33560 | + * ioctl. | |
33561 | + */ | |
33562 | +static inline int vfsub_clone_file_range(struct file *src, struct file *dst, | |
33563 | + u64 len) | |
33564 | +{ | |
33565 | + int err; | |
33566 | + | |
33567 | + lockdep_off(); | |
33568 | + err = vfs_clone_file_range(src, 0, dst, 0, len); | |
33569 | + lockdep_on(); | |
33570 | + | |
33571 | + return err; | |
33572 | +} | |
33573 | + | |
33574 | +/* copy_file_range(2) is a systemcall */ | |
33575 | +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos, | |
33576 | + struct file *dst, loff_t dst_pos, | |
33577 | + size_t len, unsigned int flags) | |
33578 | +{ | |
33579 | + ssize_t ssz; | |
33580 | + | |
33581 | + lockdep_off(); | |
33582 | + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags); | |
33583 | + lockdep_on(); | |
33584 | + | |
33585 | + return ssz; | |
33586 | +} | |
33587 | + | |
1facf9fc | 33588 | +/* ---------------------------------------------------------------------- */ |
33589 | + | |
33590 | +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin) | |
33591 | +{ | |
33592 | + loff_t err; | |
33593 | + | |
2cbb1c4b | 33594 | + lockdep_off(); |
1facf9fc | 33595 | + err = vfs_llseek(file, offset, origin); |
2cbb1c4b | 33596 | + lockdep_on(); |
1facf9fc | 33597 | + return err; |
33598 | +} | |
33599 | + | |
33600 | +/* ---------------------------------------------------------------------- */ | |
33601 | + | |
4a4d8108 AM |
33602 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode); |
33603 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path); | |
523b37e3 AM |
33604 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
33605 | + struct inode **delegated_inode); | |
33606 | +int vfsub_notify_change(struct path *path, struct iattr *ia, | |
33607 | + struct inode **delegated_inode); | |
33608 | +int vfsub_unlink(struct inode *dir, struct path *path, | |
33609 | + struct inode **delegated_inode, int force); | |
4a4d8108 | 33610 | + |
521ced18 JR |
33611 | +static inline int vfsub_getattr(const struct path *path, struct kstat *st) |
33612 | +{ | |
33613 | + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); | |
33614 | +} | |
33615 | + | |
c1595e42 JR |
33616 | +/* ---------------------------------------------------------------------- */ |
33617 | + | |
33618 | +static inline int vfsub_setxattr(struct dentry *dentry, const char *name, | |
33619 | + const void *value, size_t size, int flags) | |
33620 | +{ | |
33621 | + int err; | |
33622 | + | |
33623 | + lockdep_off(); | |
33624 | + err = vfs_setxattr(dentry, name, value, size, flags); | |
33625 | + lockdep_on(); | |
33626 | + | |
33627 | + return err; | |
33628 | +} | |
33629 | + | |
33630 | +static inline int vfsub_removexattr(struct dentry *dentry, const char *name) | |
33631 | +{ | |
33632 | + int err; | |
33633 | + | |
33634 | + lockdep_off(); | |
33635 | + err = vfs_removexattr(dentry, name); | |
33636 | + lockdep_on(); | |
33637 | + | |
33638 | + return err; | |
33639 | +} | |
33640 | + | |
1facf9fc | 33641 | +#endif /* __KERNEL__ */ |
33642 | +#endif /* __AUFS_VFSUB_H__ */ | |
7f207e10 AM |
33643 | diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c |
33644 | --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 33645 | +++ linux/fs/aufs/wbr_policy.c 2018-01-29 07:56:20.063325368 +0100 |
f2c43d5f | 33646 | @@ -0,0 +1,830 @@ |
1facf9fc | 33647 | +/* |
a2654f78 | 33648 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 33649 | + * |
33650 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33651 | + * it under the terms of the GNU General Public License as published by | |
33652 | + * the Free Software Foundation; either version 2 of the License, or | |
33653 | + * (at your option) any later version. | |
dece6358 AM |
33654 | + * |
33655 | + * This program is distributed in the hope that it will be useful, | |
33656 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33657 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33658 | + * GNU General Public License for more details. | |
33659 | + * | |
33660 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33661 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33662 | + */ |
33663 | + | |
33664 | +/* | |
33665 | + * policies for selecting one among multiple writable branches | |
33666 | + */ | |
33667 | + | |
33668 | +#include <linux/statfs.h> | |
33669 | +#include "aufs.h" | |
33670 | + | |
33671 | +/* subset of cpup_attr() */ | |
33672 | +static noinline_for_stack | |
33673 | +int au_cpdown_attr(struct path *h_path, struct dentry *h_src) | |
33674 | +{ | |
33675 | + int err, sbits; | |
33676 | + struct iattr ia; | |
33677 | + struct inode *h_isrc; | |
33678 | + | |
5527c038 | 33679 | + h_isrc = d_inode(h_src); |
1facf9fc | 33680 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID; |
33681 | + ia.ia_mode = h_isrc->i_mode; | |
33682 | + ia.ia_uid = h_isrc->i_uid; | |
33683 | + ia.ia_gid = h_isrc->i_gid; | |
33684 | + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID)); | |
5527c038 | 33685 | + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags); |
523b37e3 AM |
33686 | + /* no delegation since it is just created */ |
33687 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 33688 | + |
33689 | + /* is this nfs only? */ | |
33690 | + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) { | |
33691 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
33692 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 33693 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); |
1facf9fc | 33694 | + } |
33695 | + | |
33696 | + return err; | |
33697 | +} | |
33698 | + | |
33699 | +#define AuCpdown_PARENT_OPQ 1 | |
33700 | +#define AuCpdown_WHED (1 << 1) | |
33701 | +#define AuCpdown_MADE_DIR (1 << 2) | |
33702 | +#define AuCpdown_DIROPQ (1 << 3) | |
33703 | +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name) | |
7f207e10 AM |
33704 | +#define au_fset_cpdown(flags, name) \ |
33705 | + do { (flags) |= AuCpdown_##name; } while (0) | |
33706 | +#define au_fclr_cpdown(flags, name) \ | |
33707 | + do { (flags) &= ~AuCpdown_##name; } while (0) | |
1facf9fc | 33708 | + |
1facf9fc | 33709 | +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst, |
c2b27bf2 | 33710 | + unsigned int *flags) |
1facf9fc | 33711 | +{ |
33712 | + int err; | |
33713 | + struct dentry *opq_dentry; | |
33714 | + | |
33715 | + opq_dentry = au_diropq_create(dentry, bdst); | |
33716 | + err = PTR_ERR(opq_dentry); | |
33717 | + if (IS_ERR(opq_dentry)) | |
33718 | + goto out; | |
33719 | + dput(opq_dentry); | |
c2b27bf2 | 33720 | + au_fset_cpdown(*flags, DIROPQ); |
1facf9fc | 33721 | + |
4f0767ce | 33722 | +out: |
1facf9fc | 33723 | + return err; |
33724 | +} | |
33725 | + | |
33726 | +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent, | |
33727 | + struct inode *dir, aufs_bindex_t bdst) | |
33728 | +{ | |
33729 | + int err; | |
33730 | + struct path h_path; | |
33731 | + struct au_branch *br; | |
33732 | + | |
33733 | + br = au_sbr(dentry->d_sb, bdst); | |
33734 | + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
33735 | + err = PTR_ERR(h_path.dentry); | |
33736 | + if (IS_ERR(h_path.dentry)) | |
33737 | + goto out; | |
33738 | + | |
33739 | + err = 0; | |
5527c038 | 33740 | + if (d_is_positive(h_path.dentry)) { |
86dc4139 | 33741 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 33742 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path, |
33743 | + dentry); | |
33744 | + } | |
33745 | + dput(h_path.dentry); | |
33746 | + | |
4f0767ce | 33747 | +out: |
1facf9fc | 33748 | + return err; |
33749 | +} | |
33750 | + | |
33751 | +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 33752 | + struct au_pin *pin, |
1facf9fc | 33753 | + struct dentry *h_parent, void *arg) |
33754 | +{ | |
33755 | + int err, rerr; | |
5afbbe0d | 33756 | + aufs_bindex_t bopq, btop; |
1facf9fc | 33757 | + struct path h_path; |
33758 | + struct dentry *parent; | |
33759 | + struct inode *h_dir, *h_inode, *inode, *dir; | |
c2b27bf2 | 33760 | + unsigned int *flags = arg; |
1facf9fc | 33761 | + |
5afbbe0d | 33762 | + btop = au_dbtop(dentry); |
1facf9fc | 33763 | + /* dentry is di-locked */ |
33764 | + parent = dget_parent(dentry); | |
5527c038 JR |
33765 | + dir = d_inode(parent); |
33766 | + h_dir = d_inode(h_parent); | |
1facf9fc | 33767 | + AuDebugOn(h_dir != au_h_iptr(dir, bdst)); |
33768 | + IMustLock(h_dir); | |
33769 | + | |
86dc4139 | 33770 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); |
1facf9fc | 33771 | + if (unlikely(err < 0)) |
33772 | + goto out; | |
33773 | + h_path.dentry = au_h_dptr(dentry, bdst); | |
33774 | + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst); | |
33775 | + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, | |
33776 | + S_IRWXU | S_IRUGO | S_IXUGO); | |
33777 | + if (unlikely(err)) | |
33778 | + goto out_put; | |
c2b27bf2 | 33779 | + au_fset_cpdown(*flags, MADE_DIR); |
1facf9fc | 33780 | + |
1facf9fc | 33781 | + bopq = au_dbdiropq(dentry); |
c2b27bf2 AM |
33782 | + au_fclr_cpdown(*flags, WHED); |
33783 | + au_fclr_cpdown(*flags, DIROPQ); | |
1facf9fc | 33784 | + if (au_dbwh(dentry) == bdst) |
c2b27bf2 AM |
33785 | + au_fset_cpdown(*flags, WHED); |
33786 | + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst) | |
33787 | + au_fset_cpdown(*flags, PARENT_OPQ); | |
5527c038 | 33788 | + h_inode = d_inode(h_path.dentry); |
febd17d6 | 33789 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
c2b27bf2 AM |
33790 | + if (au_ftest_cpdown(*flags, WHED)) { |
33791 | + err = au_cpdown_dir_opq(dentry, bdst, flags); | |
1facf9fc | 33792 | + if (unlikely(err)) { |
febd17d6 | 33793 | + inode_unlock(h_inode); |
1facf9fc | 33794 | + goto out_dir; |
33795 | + } | |
33796 | + } | |
33797 | + | |
5afbbe0d | 33798 | + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop)); |
febd17d6 | 33799 | + inode_unlock(h_inode); |
1facf9fc | 33800 | + if (unlikely(err)) |
33801 | + goto out_opq; | |
33802 | + | |
c2b27bf2 | 33803 | + if (au_ftest_cpdown(*flags, WHED)) { |
1facf9fc | 33804 | + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst); |
33805 | + if (unlikely(err)) | |
33806 | + goto out_opq; | |
33807 | + } | |
33808 | + | |
5527c038 | 33809 | + inode = d_inode(dentry); |
5afbbe0d AM |
33810 | + if (au_ibbot(inode) < bdst) |
33811 | + au_set_ibbot(inode, bdst); | |
1facf9fc | 33812 | + au_set_h_iptr(inode, bdst, au_igrab(h_inode), |
33813 | + au_hi_flags(inode, /*isdir*/1)); | |
076b876e | 33814 | + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0); |
1facf9fc | 33815 | + goto out; /* success */ |
33816 | + | |
33817 | + /* revert */ | |
4f0767ce | 33818 | +out_opq: |
c2b27bf2 | 33819 | + if (au_ftest_cpdown(*flags, DIROPQ)) { |
febd17d6 | 33820 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
1facf9fc | 33821 | + rerr = au_diropq_remove(dentry, bdst); |
febd17d6 | 33822 | + inode_unlock(h_inode); |
1facf9fc | 33823 | + if (unlikely(rerr)) { |
523b37e3 AM |
33824 | + AuIOErr("failed removing diropq for %pd b%d (%d)\n", |
33825 | + dentry, bdst, rerr); | |
1facf9fc | 33826 | + err = -EIO; |
33827 | + goto out; | |
33828 | + } | |
33829 | + } | |
4f0767ce | 33830 | +out_dir: |
c2b27bf2 | 33831 | + if (au_ftest_cpdown(*flags, MADE_DIR)) { |
1facf9fc | 33832 | + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path); |
33833 | + if (unlikely(rerr)) { | |
523b37e3 AM |
33834 | + AuIOErr("failed removing %pd b%d (%d)\n", |
33835 | + dentry, bdst, rerr); | |
1facf9fc | 33836 | + err = -EIO; |
33837 | + } | |
33838 | + } | |
4f0767ce | 33839 | +out_put: |
1facf9fc | 33840 | + au_set_h_dptr(dentry, bdst, NULL); |
5afbbe0d AM |
33841 | + if (au_dbbot(dentry) == bdst) |
33842 | + au_update_dbbot(dentry); | |
4f0767ce | 33843 | +out: |
1facf9fc | 33844 | + dput(parent); |
33845 | + return err; | |
33846 | +} | |
33847 | + | |
33848 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
33849 | +{ | |
33850 | + int err; | |
c2b27bf2 | 33851 | + unsigned int flags; |
1facf9fc | 33852 | + |
c2b27bf2 AM |
33853 | + flags = 0; |
33854 | + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags); | |
1facf9fc | 33855 | + |
33856 | + return err; | |
33857 | +} | |
33858 | + | |
33859 | +/* ---------------------------------------------------------------------- */ | |
33860 | + | |
33861 | +/* policies for create */ | |
33862 | + | |
c2b27bf2 | 33863 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex) |
4a4d8108 AM |
33864 | +{ |
33865 | + int err, i, j, ndentry; | |
33866 | + aufs_bindex_t bopq; | |
33867 | + struct au_dcsub_pages dpages; | |
33868 | + struct au_dpage *dpage; | |
33869 | + struct dentry **dentries, *parent, *d; | |
33870 | + | |
33871 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
33872 | + if (unlikely(err)) | |
33873 | + goto out; | |
33874 | + parent = dget_parent(dentry); | |
027c5e7a | 33875 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0); |
4a4d8108 AM |
33876 | + if (unlikely(err)) |
33877 | + goto out_free; | |
33878 | + | |
33879 | + err = bindex; | |
33880 | + for (i = 0; i < dpages.ndpage; i++) { | |
33881 | + dpage = dpages.dpages + i; | |
33882 | + dentries = dpage->dentries; | |
33883 | + ndentry = dpage->ndentry; | |
33884 | + for (j = 0; j < ndentry; j++) { | |
33885 | + d = dentries[j]; | |
33886 | + di_read_lock_parent2(d, !AuLock_IR); | |
33887 | + bopq = au_dbdiropq(d); | |
33888 | + di_read_unlock(d, !AuLock_IR); | |
33889 | + if (bopq >= 0 && bopq < err) | |
33890 | + err = bopq; | |
33891 | + } | |
33892 | + } | |
33893 | + | |
33894 | +out_free: | |
33895 | + dput(parent); | |
33896 | + au_dpages_free(&dpages); | |
33897 | +out: | |
33898 | + return err; | |
33899 | +} | |
33900 | + | |
1facf9fc | 33901 | +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex) |
33902 | +{ | |
33903 | + for (; bindex >= 0; bindex--) | |
33904 | + if (!au_br_rdonly(au_sbr(sb, bindex))) | |
33905 | + return bindex; | |
33906 | + return -EROFS; | |
33907 | +} | |
33908 | + | |
33909 | +/* top down parent */ | |
392086de AM |
33910 | +static int au_wbr_create_tdp(struct dentry *dentry, |
33911 | + unsigned int flags __maybe_unused) | |
1facf9fc | 33912 | +{ |
33913 | + int err; | |
5afbbe0d | 33914 | + aufs_bindex_t btop, bindex; |
1facf9fc | 33915 | + struct super_block *sb; |
33916 | + struct dentry *parent, *h_parent; | |
33917 | + | |
33918 | + sb = dentry->d_sb; | |
5afbbe0d AM |
33919 | + btop = au_dbtop(dentry); |
33920 | + err = btop; | |
33921 | + if (!au_br_rdonly(au_sbr(sb, btop))) | |
1facf9fc | 33922 | + goto out; |
33923 | + | |
33924 | + err = -EROFS; | |
33925 | + parent = dget_parent(dentry); | |
5afbbe0d | 33926 | + for (bindex = au_dbtop(parent); bindex < btop; bindex++) { |
1facf9fc | 33927 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 33928 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 33929 | + continue; |
33930 | + | |
33931 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
33932 | + err = bindex; | |
33933 | + break; | |
33934 | + } | |
33935 | + } | |
33936 | + dput(parent); | |
33937 | + | |
33938 | + /* bottom up here */ | |
4a4d8108 | 33939 | + if (unlikely(err < 0)) { |
5afbbe0d | 33940 | + err = au_wbr_bu(sb, btop - 1); |
4a4d8108 AM |
33941 | + if (err >= 0) |
33942 | + err = au_wbr_nonopq(dentry, err); | |
33943 | + } | |
1facf9fc | 33944 | + |
4f0767ce | 33945 | +out: |
1facf9fc | 33946 | + AuDbg("b%d\n", err); |
33947 | + return err; | |
33948 | +} | |
33949 | + | |
33950 | +/* ---------------------------------------------------------------------- */ | |
33951 | + | |
33952 | +/* an exception for the policy other than tdp */ | |
33953 | +static int au_wbr_create_exp(struct dentry *dentry) | |
33954 | +{ | |
33955 | + int err; | |
33956 | + aufs_bindex_t bwh, bdiropq; | |
33957 | + struct dentry *parent; | |
33958 | + | |
33959 | + err = -1; | |
33960 | + bwh = au_dbwh(dentry); | |
33961 | + parent = dget_parent(dentry); | |
33962 | + bdiropq = au_dbdiropq(parent); | |
33963 | + if (bwh >= 0) { | |
33964 | + if (bdiropq >= 0) | |
33965 | + err = min(bdiropq, bwh); | |
33966 | + else | |
33967 | + err = bwh; | |
33968 | + AuDbg("%d\n", err); | |
33969 | + } else if (bdiropq >= 0) { | |
33970 | + err = bdiropq; | |
33971 | + AuDbg("%d\n", err); | |
33972 | + } | |
33973 | + dput(parent); | |
33974 | + | |
4a4d8108 AM |
33975 | + if (err >= 0) |
33976 | + err = au_wbr_nonopq(dentry, err); | |
33977 | + | |
1facf9fc | 33978 | + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err))) |
33979 | + err = -1; | |
33980 | + | |
33981 | + AuDbg("%d\n", err); | |
33982 | + return err; | |
33983 | +} | |
33984 | + | |
33985 | +/* ---------------------------------------------------------------------- */ | |
33986 | + | |
33987 | +/* round robin */ | |
33988 | +static int au_wbr_create_init_rr(struct super_block *sb) | |
33989 | +{ | |
33990 | + int err; | |
33991 | + | |
5afbbe0d | 33992 | + err = au_wbr_bu(sb, au_sbbot(sb)); |
1facf9fc | 33993 | + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */ |
dece6358 | 33994 | + /* smp_mb(); */ |
1facf9fc | 33995 | + |
33996 | + AuDbg("b%d\n", err); | |
33997 | + return err; | |
33998 | +} | |
33999 | + | |
392086de | 34000 | +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34001 | +{ |
34002 | + int err, nbr; | |
34003 | + unsigned int u; | |
5afbbe0d | 34004 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 34005 | + struct super_block *sb; |
34006 | + atomic_t *next; | |
34007 | + | |
34008 | + err = au_wbr_create_exp(dentry); | |
34009 | + if (err >= 0) | |
34010 | + goto out; | |
34011 | + | |
34012 | + sb = dentry->d_sb; | |
34013 | + next = &au_sbi(sb)->si_wbr_rr_next; | |
5afbbe0d AM |
34014 | + bbot = au_sbbot(sb); |
34015 | + nbr = bbot + 1; | |
34016 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
392086de | 34017 | + if (!au_ftest_wbr(flags, DIR)) { |
1facf9fc | 34018 | + err = atomic_dec_return(next) + 1; |
34019 | + /* modulo for 0 is meaningless */ | |
34020 | + if (unlikely(!err)) | |
34021 | + err = atomic_dec_return(next) + 1; | |
34022 | + } else | |
34023 | + err = atomic_read(next); | |
34024 | + AuDbg("%d\n", err); | |
34025 | + u = err; | |
34026 | + err = u % nbr; | |
34027 | + AuDbg("%d\n", err); | |
34028 | + if (!au_br_rdonly(au_sbr(sb, err))) | |
34029 | + break; | |
34030 | + err = -EROFS; | |
34031 | + } | |
34032 | + | |
4a4d8108 AM |
34033 | + if (err >= 0) |
34034 | + err = au_wbr_nonopq(dentry, err); | |
34035 | + | |
4f0767ce | 34036 | +out: |
1facf9fc | 34037 | + AuDbg("%d\n", err); |
34038 | + return err; | |
34039 | +} | |
34040 | + | |
34041 | +/* ---------------------------------------------------------------------- */ | |
34042 | + | |
34043 | +/* most free space */ | |
392086de | 34044 | +static void au_mfs(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 34045 | +{ |
34046 | + struct super_block *sb; | |
34047 | + struct au_branch *br; | |
34048 | + struct au_wbr_mfs *mfs; | |
392086de | 34049 | + struct dentry *h_parent; |
5afbbe0d | 34050 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 34051 | + int err; |
34052 | + unsigned long long b, bavail; | |
7f207e10 | 34053 | + struct path h_path; |
1facf9fc | 34054 | + /* reduce the stack usage */ |
34055 | + struct kstatfs *st; | |
34056 | + | |
34057 | + st = kmalloc(sizeof(*st), GFP_NOFS); | |
34058 | + if (unlikely(!st)) { | |
34059 | + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM); | |
34060 | + return; | |
34061 | + } | |
34062 | + | |
34063 | + bavail = 0; | |
34064 | + sb = dentry->d_sb; | |
34065 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
dece6358 | 34066 | + MtxMustLock(&mfs->mfs_lock); |
1facf9fc | 34067 | + mfs->mfs_bindex = -EROFS; |
34068 | + mfs->mfsrr_bytes = 0; | |
392086de AM |
34069 | + if (!parent) { |
34070 | + bindex = 0; | |
5afbbe0d | 34071 | + bbot = au_sbbot(sb); |
392086de | 34072 | + } else { |
5afbbe0d AM |
34073 | + bindex = au_dbtop(parent); |
34074 | + bbot = au_dbtaildir(parent); | |
392086de AM |
34075 | + } |
34076 | + | |
5afbbe0d | 34077 | + for (; bindex <= bbot; bindex++) { |
392086de AM |
34078 | + if (parent) { |
34079 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 34080 | + if (!h_parent || d_is_negative(h_parent)) |
392086de AM |
34081 | + continue; |
34082 | + } | |
1facf9fc | 34083 | + br = au_sbr(sb, bindex); |
34084 | + if (au_br_rdonly(br)) | |
34085 | + continue; | |
34086 | + | |
34087 | + /* sb->s_root for NFS is unreliable */ | |
86dc4139 | 34088 | + h_path.mnt = au_br_mnt(br); |
7f207e10 AM |
34089 | + h_path.dentry = h_path.mnt->mnt_root; |
34090 | + err = vfs_statfs(&h_path, st); | |
1facf9fc | 34091 | + if (unlikely(err)) { |
34092 | + AuWarn1("failed statfs, b%d, %d\n", bindex, err); | |
34093 | + continue; | |
34094 | + } | |
34095 | + | |
34096 | + /* when the available size is equal, select the lower one */ | |
34097 | + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail) | |
34098 | + || sizeof(b) < sizeof(st->f_bsize)); | |
34099 | + b = st->f_bavail * st->f_bsize; | |
34100 | + br->br_wbr->wbr_bytes = b; | |
34101 | + if (b >= bavail) { | |
34102 | + bavail = b; | |
34103 | + mfs->mfs_bindex = bindex; | |
34104 | + mfs->mfs_jiffy = jiffies; | |
34105 | + } | |
34106 | + } | |
34107 | + | |
34108 | + mfs->mfsrr_bytes = bavail; | |
34109 | + AuDbg("b%d\n", mfs->mfs_bindex); | |
1c60b727 | 34110 | + kfree(st); |
1facf9fc | 34111 | +} |
34112 | + | |
392086de | 34113 | +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34114 | +{ |
34115 | + int err; | |
392086de | 34116 | + struct dentry *parent; |
1facf9fc | 34117 | + struct super_block *sb; |
34118 | + struct au_wbr_mfs *mfs; | |
34119 | + | |
34120 | + err = au_wbr_create_exp(dentry); | |
34121 | + if (err >= 0) | |
34122 | + goto out; | |
34123 | + | |
34124 | + sb = dentry->d_sb; | |
392086de AM |
34125 | + parent = NULL; |
34126 | + if (au_ftest_wbr(flags, PARENT)) | |
34127 | + parent = dget_parent(dentry); | |
1facf9fc | 34128 | + mfs = &au_sbi(sb)->si_wbr_mfs; |
34129 | + mutex_lock(&mfs->mfs_lock); | |
34130 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
34131 | + || mfs->mfs_bindex < 0 | |
34132 | + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))) | |
392086de | 34133 | + au_mfs(dentry, parent); |
1facf9fc | 34134 | + mutex_unlock(&mfs->mfs_lock); |
34135 | + err = mfs->mfs_bindex; | |
392086de | 34136 | + dput(parent); |
1facf9fc | 34137 | + |
4a4d8108 AM |
34138 | + if (err >= 0) |
34139 | + err = au_wbr_nonopq(dentry, err); | |
34140 | + | |
4f0767ce | 34141 | +out: |
1facf9fc | 34142 | + AuDbg("b%d\n", err); |
34143 | + return err; | |
34144 | +} | |
34145 | + | |
34146 | +static int au_wbr_create_init_mfs(struct super_block *sb) | |
34147 | +{ | |
34148 | + struct au_wbr_mfs *mfs; | |
34149 | + | |
34150 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
34151 | + mutex_init(&mfs->mfs_lock); | |
34152 | + mfs->mfs_jiffy = 0; | |
34153 | + mfs->mfs_bindex = -EROFS; | |
34154 | + | |
34155 | + return 0; | |
34156 | +} | |
34157 | + | |
34158 | +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused) | |
34159 | +{ | |
34160 | + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock); | |
34161 | + return 0; | |
34162 | +} | |
34163 | + | |
34164 | +/* ---------------------------------------------------------------------- */ | |
34165 | + | |
f2c43d5f AM |
34166 | +/* top down regardless parent, and then mfs */ |
34167 | +static int au_wbr_create_tdmfs(struct dentry *dentry, | |
34168 | + unsigned int flags __maybe_unused) | |
34169 | +{ | |
34170 | + int err; | |
34171 | + aufs_bindex_t bwh, btail, bindex, bfound, bmfs; | |
34172 | + unsigned long long watermark; | |
34173 | + struct super_block *sb; | |
34174 | + struct au_wbr_mfs *mfs; | |
34175 | + struct au_branch *br; | |
34176 | + struct dentry *parent; | |
34177 | + | |
34178 | + sb = dentry->d_sb; | |
34179 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
34180 | + mutex_lock(&mfs->mfs_lock); | |
34181 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
34182 | + || mfs->mfs_bindex < 0) | |
34183 | + au_mfs(dentry, /*parent*/NULL); | |
34184 | + watermark = mfs->mfsrr_watermark; | |
34185 | + bmfs = mfs->mfs_bindex; | |
34186 | + mutex_unlock(&mfs->mfs_lock); | |
34187 | + | |
34188 | + /* another style of au_wbr_create_exp() */ | |
34189 | + bwh = au_dbwh(dentry); | |
34190 | + parent = dget_parent(dentry); | |
34191 | + btail = au_dbtaildir(parent); | |
34192 | + if (bwh >= 0 && bwh < btail) | |
34193 | + btail = bwh; | |
34194 | + | |
34195 | + err = au_wbr_nonopq(dentry, btail); | |
34196 | + if (unlikely(err < 0)) | |
34197 | + goto out; | |
34198 | + btail = err; | |
34199 | + bfound = -1; | |
34200 | + for (bindex = 0; bindex <= btail; bindex++) { | |
34201 | + br = au_sbr(sb, bindex); | |
34202 | + if (au_br_rdonly(br)) | |
34203 | + continue; | |
34204 | + if (br->br_wbr->wbr_bytes > watermark) { | |
34205 | + bfound = bindex; | |
34206 | + break; | |
34207 | + } | |
34208 | + } | |
34209 | + err = bfound; | |
34210 | + if (err < 0) | |
34211 | + err = bmfs; | |
34212 | + | |
34213 | +out: | |
34214 | + dput(parent); | |
34215 | + AuDbg("b%d\n", err); | |
34216 | + return err; | |
34217 | +} | |
34218 | + | |
34219 | +/* ---------------------------------------------------------------------- */ | |
34220 | + | |
1facf9fc | 34221 | +/* most free space and then round robin */ |
392086de | 34222 | +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34223 | +{ |
34224 | + int err; | |
34225 | + struct au_wbr_mfs *mfs; | |
34226 | + | |
392086de | 34227 | + err = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 34228 | + if (err >= 0) { |
34229 | + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs; | |
dece6358 | 34230 | + mutex_lock(&mfs->mfs_lock); |
1facf9fc | 34231 | + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark) |
392086de | 34232 | + err = au_wbr_create_rr(dentry, flags); |
dece6358 | 34233 | + mutex_unlock(&mfs->mfs_lock); |
1facf9fc | 34234 | + } |
34235 | + | |
34236 | + AuDbg("b%d\n", err); | |
34237 | + return err; | |
34238 | +} | |
34239 | + | |
34240 | +static int au_wbr_create_init_mfsrr(struct super_block *sb) | |
34241 | +{ | |
34242 | + int err; | |
34243 | + | |
34244 | + au_wbr_create_init_mfs(sb); /* ignore */ | |
34245 | + err = au_wbr_create_init_rr(sb); | |
34246 | + | |
34247 | + return err; | |
34248 | +} | |
34249 | + | |
34250 | +/* ---------------------------------------------------------------------- */ | |
34251 | + | |
34252 | +/* top down parent and most free space */ | |
392086de | 34253 | +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34254 | +{ |
34255 | + int err, e2; | |
34256 | + unsigned long long b; | |
5afbbe0d | 34257 | + aufs_bindex_t bindex, btop, bbot; |
1facf9fc | 34258 | + struct super_block *sb; |
34259 | + struct dentry *parent, *h_parent; | |
34260 | + struct au_branch *br; | |
34261 | + | |
392086de | 34262 | + err = au_wbr_create_tdp(dentry, flags); |
1facf9fc | 34263 | + if (unlikely(err < 0)) |
34264 | + goto out; | |
34265 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
34266 | + btop = au_dbtop(parent); |
34267 | + bbot = au_dbtaildir(parent); | |
34268 | + if (btop == bbot) | |
1facf9fc | 34269 | + goto out_parent; /* success */ |
34270 | + | |
392086de | 34271 | + e2 = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 34272 | + if (e2 < 0) |
34273 | + goto out_parent; /* success */ | |
34274 | + | |
34275 | + /* when the available size is equal, select upper one */ | |
34276 | + sb = dentry->d_sb; | |
34277 | + br = au_sbr(sb, err); | |
34278 | + b = br->br_wbr->wbr_bytes; | |
34279 | + AuDbg("b%d, %llu\n", err, b); | |
34280 | + | |
5afbbe0d | 34281 | + for (bindex = btop; bindex <= bbot; bindex++) { |
1facf9fc | 34282 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 34283 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 34284 | + continue; |
34285 | + | |
34286 | + br = au_sbr(sb, bindex); | |
34287 | + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) { | |
34288 | + b = br->br_wbr->wbr_bytes; | |
34289 | + err = bindex; | |
34290 | + AuDbg("b%d, %llu\n", err, b); | |
34291 | + } | |
34292 | + } | |
34293 | + | |
4a4d8108 AM |
34294 | + if (err >= 0) |
34295 | + err = au_wbr_nonopq(dentry, err); | |
34296 | + | |
4f0767ce | 34297 | +out_parent: |
1facf9fc | 34298 | + dput(parent); |
4f0767ce | 34299 | +out: |
1facf9fc | 34300 | + AuDbg("b%d\n", err); |
34301 | + return err; | |
34302 | +} | |
34303 | + | |
34304 | +/* ---------------------------------------------------------------------- */ | |
34305 | + | |
392086de AM |
34306 | +/* |
34307 | + * - top down parent | |
34308 | + * - most free space with parent | |
34309 | + * - most free space round-robin regardless parent | |
34310 | + */ | |
34311 | +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags) | |
34312 | +{ | |
34313 | + int err; | |
34314 | + unsigned long long watermark; | |
34315 | + struct super_block *sb; | |
34316 | + struct au_branch *br; | |
34317 | + struct au_wbr_mfs *mfs; | |
34318 | + | |
34319 | + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT); | |
34320 | + if (unlikely(err < 0)) | |
34321 | + goto out; | |
34322 | + | |
34323 | + sb = dentry->d_sb; | |
34324 | + br = au_sbr(sb, err); | |
34325 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
34326 | + mutex_lock(&mfs->mfs_lock); | |
34327 | + watermark = mfs->mfsrr_watermark; | |
34328 | + mutex_unlock(&mfs->mfs_lock); | |
34329 | + if (br->br_wbr->wbr_bytes < watermark) | |
34330 | + /* regardless the parent dir */ | |
34331 | + err = au_wbr_create_mfsrr(dentry, flags); | |
34332 | + | |
34333 | +out: | |
34334 | + AuDbg("b%d\n", err); | |
34335 | + return err; | |
34336 | +} | |
34337 | + | |
34338 | +/* ---------------------------------------------------------------------- */ | |
34339 | + | |
1facf9fc | 34340 | +/* policies for copyup */ |
34341 | + | |
34342 | +/* top down parent */ | |
34343 | +static int au_wbr_copyup_tdp(struct dentry *dentry) | |
34344 | +{ | |
392086de | 34345 | + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0); |
1facf9fc | 34346 | +} |
34347 | + | |
34348 | +/* bottom up parent */ | |
34349 | +static int au_wbr_copyup_bup(struct dentry *dentry) | |
34350 | +{ | |
34351 | + int err; | |
5afbbe0d | 34352 | + aufs_bindex_t bindex, btop; |
1facf9fc | 34353 | + struct dentry *parent, *h_parent; |
34354 | + struct super_block *sb; | |
34355 | + | |
34356 | + err = -EROFS; | |
34357 | + sb = dentry->d_sb; | |
34358 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
34359 | + btop = au_dbtop(parent); |
34360 | + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) { | |
1facf9fc | 34361 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 34362 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 34363 | + continue; |
34364 | + | |
34365 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
34366 | + err = bindex; | |
34367 | + break; | |
34368 | + } | |
34369 | + } | |
34370 | + dput(parent); | |
34371 | + | |
34372 | + /* bottom up here */ | |
34373 | + if (unlikely(err < 0)) | |
5afbbe0d | 34374 | + err = au_wbr_bu(sb, btop - 1); |
1facf9fc | 34375 | + |
34376 | + AuDbg("b%d\n", err); | |
34377 | + return err; | |
34378 | +} | |
34379 | + | |
34380 | +/* bottom up */ | |
5afbbe0d | 34381 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop) |
1facf9fc | 34382 | +{ |
34383 | + int err; | |
34384 | + | |
5afbbe0d | 34385 | + err = au_wbr_bu(dentry->d_sb, btop); |
4a4d8108 | 34386 | + AuDbg("b%d\n", err); |
5afbbe0d | 34387 | + if (err > btop) |
4a4d8108 | 34388 | + err = au_wbr_nonopq(dentry, err); |
1facf9fc | 34389 | + |
34390 | + AuDbg("b%d\n", err); | |
34391 | + return err; | |
34392 | +} | |
34393 | + | |
076b876e AM |
34394 | +static int au_wbr_copyup_bu(struct dentry *dentry) |
34395 | +{ | |
34396 | + int err; | |
5afbbe0d | 34397 | + aufs_bindex_t btop; |
076b876e | 34398 | + |
5afbbe0d AM |
34399 | + btop = au_dbtop(dentry); |
34400 | + err = au_wbr_do_copyup_bu(dentry, btop); | |
076b876e AM |
34401 | + return err; |
34402 | +} | |
34403 | + | |
1facf9fc | 34404 | +/* ---------------------------------------------------------------------- */ |
34405 | + | |
34406 | +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = { | |
34407 | + [AuWbrCopyup_TDP] = { | |
34408 | + .copyup = au_wbr_copyup_tdp | |
34409 | + }, | |
34410 | + [AuWbrCopyup_BUP] = { | |
34411 | + .copyup = au_wbr_copyup_bup | |
34412 | + }, | |
34413 | + [AuWbrCopyup_BU] = { | |
34414 | + .copyup = au_wbr_copyup_bu | |
34415 | + } | |
34416 | +}; | |
34417 | + | |
34418 | +struct au_wbr_create_operations au_wbr_create_ops[] = { | |
34419 | + [AuWbrCreate_TDP] = { | |
34420 | + .create = au_wbr_create_tdp | |
34421 | + }, | |
34422 | + [AuWbrCreate_RR] = { | |
34423 | + .create = au_wbr_create_rr, | |
34424 | + .init = au_wbr_create_init_rr | |
34425 | + }, | |
34426 | + [AuWbrCreate_MFS] = { | |
34427 | + .create = au_wbr_create_mfs, | |
34428 | + .init = au_wbr_create_init_mfs, | |
34429 | + .fin = au_wbr_create_fin_mfs | |
34430 | + }, | |
34431 | + [AuWbrCreate_MFSV] = { | |
34432 | + .create = au_wbr_create_mfs, | |
34433 | + .init = au_wbr_create_init_mfs, | |
34434 | + .fin = au_wbr_create_fin_mfs | |
34435 | + }, | |
34436 | + [AuWbrCreate_MFSRR] = { | |
34437 | + .create = au_wbr_create_mfsrr, | |
34438 | + .init = au_wbr_create_init_mfsrr, | |
34439 | + .fin = au_wbr_create_fin_mfs | |
34440 | + }, | |
34441 | + [AuWbrCreate_MFSRRV] = { | |
34442 | + .create = au_wbr_create_mfsrr, | |
34443 | + .init = au_wbr_create_init_mfsrr, | |
34444 | + .fin = au_wbr_create_fin_mfs | |
34445 | + }, | |
f2c43d5f AM |
34446 | + [AuWbrCreate_TDMFS] = { |
34447 | + .create = au_wbr_create_tdmfs, | |
34448 | + .init = au_wbr_create_init_mfs, | |
34449 | + .fin = au_wbr_create_fin_mfs | |
34450 | + }, | |
34451 | + [AuWbrCreate_TDMFSV] = { | |
34452 | + .create = au_wbr_create_tdmfs, | |
34453 | + .init = au_wbr_create_init_mfs, | |
34454 | + .fin = au_wbr_create_fin_mfs | |
34455 | + }, | |
1facf9fc | 34456 | + [AuWbrCreate_PMFS] = { |
34457 | + .create = au_wbr_create_pmfs, | |
34458 | + .init = au_wbr_create_init_mfs, | |
34459 | + .fin = au_wbr_create_fin_mfs | |
34460 | + }, | |
34461 | + [AuWbrCreate_PMFSV] = { | |
34462 | + .create = au_wbr_create_pmfs, | |
34463 | + .init = au_wbr_create_init_mfs, | |
34464 | + .fin = au_wbr_create_fin_mfs | |
392086de AM |
34465 | + }, |
34466 | + [AuWbrCreate_PMFSRR] = { | |
34467 | + .create = au_wbr_create_pmfsrr, | |
34468 | + .init = au_wbr_create_init_mfsrr, | |
34469 | + .fin = au_wbr_create_fin_mfs | |
34470 | + }, | |
34471 | + [AuWbrCreate_PMFSRRV] = { | |
34472 | + .create = au_wbr_create_pmfsrr, | |
34473 | + .init = au_wbr_create_init_mfsrr, | |
34474 | + .fin = au_wbr_create_fin_mfs | |
1facf9fc | 34475 | + } |
34476 | +}; | |
7f207e10 AM |
34477 | diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c |
34478 | --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 34479 | +++ linux/fs/aufs/whout.c 2018-01-29 07:56:20.063325368 +0100 |
f2c43d5f | 34480 | @@ -0,0 +1,1061 @@ |
1facf9fc | 34481 | +/* |
a2654f78 | 34482 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 34483 | + * |
34484 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34485 | + * it under the terms of the GNU General Public License as published by | |
34486 | + * the Free Software Foundation; either version 2 of the License, or | |
34487 | + * (at your option) any later version. | |
dece6358 AM |
34488 | + * |
34489 | + * This program is distributed in the hope that it will be useful, | |
34490 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34491 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34492 | + * GNU General Public License for more details. | |
34493 | + * | |
34494 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34495 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 34496 | + */ |
34497 | + | |
34498 | +/* | |
34499 | + * whiteout for logical deletion and opaque directory | |
34500 | + */ | |
34501 | + | |
1facf9fc | 34502 | +#include "aufs.h" |
34503 | + | |
34504 | +#define WH_MASK S_IRUGO | |
34505 | + | |
34506 | +/* | |
34507 | + * If a directory contains this file, then it is opaque. We start with the | |
34508 | + * .wh. flag so that it is blocked by lookup. | |
34509 | + */ | |
0c3ec466 AM |
34510 | +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ, |
34511 | + sizeof(AUFS_WH_DIROPQ) - 1); | |
1facf9fc | 34512 | + |
34513 | +/* | |
34514 | + * generate whiteout name, which is NOT terminated by NULL. | |
34515 | + * @name: original d_name.name | |
34516 | + * @len: original d_name.len | |
34517 | + * @wh: whiteout qstr | |
34518 | + * returns zero when succeeds, otherwise error. | |
34519 | + * succeeded value as wh->name should be freed by kfree(). | |
34520 | + */ | |
34521 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name) | |
34522 | +{ | |
34523 | + char *p; | |
34524 | + | |
34525 | + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN)) | |
34526 | + return -ENAMETOOLONG; | |
34527 | + | |
34528 | + wh->len = name->len + AUFS_WH_PFX_LEN; | |
34529 | + p = kmalloc(wh->len, GFP_NOFS); | |
34530 | + wh->name = p; | |
34531 | + if (p) { | |
34532 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
34533 | + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len); | |
34534 | + /* smp_mb(); */ | |
34535 | + return 0; | |
34536 | + } | |
34537 | + return -ENOMEM; | |
34538 | +} | |
34539 | + | |
34540 | +/* ---------------------------------------------------------------------- */ | |
34541 | + | |
34542 | +/* | |
34543 | + * test if the @wh_name exists under @h_parent. | |
34544 | + * @try_sio specifies the necessary of super-io. | |
34545 | + */ | |
076b876e | 34546 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio) |
1facf9fc | 34547 | +{ |
34548 | + int err; | |
34549 | + struct dentry *wh_dentry; | |
1facf9fc | 34550 | + |
1facf9fc | 34551 | + if (!try_sio) |
b4510431 | 34552 | + wh_dentry = vfsub_lkup_one(wh_name, h_parent); |
1facf9fc | 34553 | + else |
076b876e | 34554 | + wh_dentry = au_sio_lkup_one(wh_name, h_parent); |
1facf9fc | 34555 | + err = PTR_ERR(wh_dentry); |
2000de60 JR |
34556 | + if (IS_ERR(wh_dentry)) { |
34557 | + if (err == -ENAMETOOLONG) | |
34558 | + err = 0; | |
1facf9fc | 34559 | + goto out; |
2000de60 | 34560 | + } |
1facf9fc | 34561 | + |
34562 | + err = 0; | |
5527c038 | 34563 | + if (d_is_negative(wh_dentry)) |
1facf9fc | 34564 | + goto out_wh; /* success */ |
34565 | + | |
34566 | + err = 1; | |
7e9cd9fe | 34567 | + if (d_is_reg(wh_dentry)) |
1facf9fc | 34568 | + goto out_wh; /* success */ |
34569 | + | |
34570 | + err = -EIO; | |
523b37e3 | 34571 | + AuIOErr("%pd Invalid whiteout entry type 0%o.\n", |
5527c038 | 34572 | + wh_dentry, d_inode(wh_dentry)->i_mode); |
1facf9fc | 34573 | + |
4f0767ce | 34574 | +out_wh: |
1facf9fc | 34575 | + dput(wh_dentry); |
4f0767ce | 34576 | +out: |
1facf9fc | 34577 | + return err; |
34578 | +} | |
34579 | + | |
34580 | +/* | |
34581 | + * test if the @h_dentry sets opaque or not. | |
34582 | + */ | |
076b876e | 34583 | +int au_diropq_test(struct dentry *h_dentry) |
1facf9fc | 34584 | +{ |
34585 | + int err; | |
34586 | + struct inode *h_dir; | |
34587 | + | |
5527c038 | 34588 | + h_dir = d_inode(h_dentry); |
076b876e | 34589 | + err = au_wh_test(h_dentry, &diropq_name, |
1facf9fc | 34590 | + au_test_h_perm_sio(h_dir, MAY_EXEC)); |
34591 | + return err; | |
34592 | +} | |
34593 | + | |
34594 | +/* | |
34595 | + * returns a negative dentry whose name is unique and temporary. | |
34596 | + */ | |
34597 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, | |
34598 | + struct qstr *prefix) | |
34599 | +{ | |
1facf9fc | 34600 | + struct dentry *dentry; |
34601 | + int i; | |
027c5e7a | 34602 | + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1], |
4a4d8108 | 34603 | + *name, *p; |
027c5e7a | 34604 | + /* strict atomic_t is unnecessary here */ |
1facf9fc | 34605 | + static unsigned short cnt; |
34606 | + struct qstr qs; | |
34607 | + | |
4a4d8108 AM |
34608 | + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN); |
34609 | + | |
1facf9fc | 34610 | + name = defname; |
027c5e7a AM |
34611 | + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1; |
34612 | + if (unlikely(prefix->len > DNAME_INLINE_LEN)) { | |
1facf9fc | 34613 | + dentry = ERR_PTR(-ENAMETOOLONG); |
4a4d8108 | 34614 | + if (unlikely(qs.len > NAME_MAX)) |
1facf9fc | 34615 | + goto out; |
34616 | + dentry = ERR_PTR(-ENOMEM); | |
34617 | + name = kmalloc(qs.len + 1, GFP_NOFS); | |
34618 | + if (unlikely(!name)) | |
34619 | + goto out; | |
34620 | + } | |
34621 | + | |
34622 | + /* doubly whiteout-ed */ | |
34623 | + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2); | |
34624 | + p = name + AUFS_WH_PFX_LEN * 2; | |
34625 | + memcpy(p, prefix->name, prefix->len); | |
34626 | + p += prefix->len; | |
34627 | + *p++ = '.'; | |
4a4d8108 | 34628 | + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN); |
1facf9fc | 34629 | + |
34630 | + qs.name = name; | |
34631 | + for (i = 0; i < 3; i++) { | |
b752ccd1 | 34632 | + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++); |
076b876e | 34633 | + dentry = au_sio_lkup_one(&qs, h_parent); |
5527c038 | 34634 | + if (IS_ERR(dentry) || d_is_negative(dentry)) |
1facf9fc | 34635 | + goto out_name; |
34636 | + dput(dentry); | |
34637 | + } | |
0c3ec466 | 34638 | + /* pr_warn("could not get random name\n"); */ |
1facf9fc | 34639 | + dentry = ERR_PTR(-EEXIST); |
34640 | + AuDbg("%.*s\n", AuLNPair(&qs)); | |
34641 | + BUG(); | |
34642 | + | |
4f0767ce | 34643 | +out_name: |
1facf9fc | 34644 | + if (name != defname) |
1c60b727 | 34645 | + kfree(name); |
4f0767ce | 34646 | +out: |
4a4d8108 | 34647 | + AuTraceErrPtr(dentry); |
1facf9fc | 34648 | + return dentry; |
1facf9fc | 34649 | +} |
34650 | + | |
34651 | +/* | |
34652 | + * rename the @h_dentry on @br to the whiteouted temporary name. | |
34653 | + */ | |
34654 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br) | |
34655 | +{ | |
34656 | + int err; | |
34657 | + struct path h_path = { | |
86dc4139 | 34658 | + .mnt = au_br_mnt(br) |
1facf9fc | 34659 | + }; |
523b37e3 | 34660 | + struct inode *h_dir, *delegated; |
1facf9fc | 34661 | + struct dentry *h_parent; |
34662 | + | |
34663 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ | |
5527c038 | 34664 | + h_dir = d_inode(h_parent); |
1facf9fc | 34665 | + IMustLock(h_dir); |
34666 | + | |
34667 | + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name); | |
34668 | + err = PTR_ERR(h_path.dentry); | |
34669 | + if (IS_ERR(h_path.dentry)) | |
34670 | + goto out; | |
34671 | + | |
34672 | + /* under the same dir, no need to lock_rename() */ | |
523b37e3 | 34673 | + delegated = NULL; |
f2c43d5f AM |
34674 | + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated, |
34675 | + /*flags*/0); | |
1facf9fc | 34676 | + AuTraceErr(err); |
523b37e3 AM |
34677 | + if (unlikely(err == -EWOULDBLOCK)) { |
34678 | + pr_warn("cannot retry for NFSv4 delegation" | |
34679 | + " for an internal rename\n"); | |
34680 | + iput(delegated); | |
34681 | + } | |
1facf9fc | 34682 | + dput(h_path.dentry); |
34683 | + | |
4f0767ce | 34684 | +out: |
4a4d8108 | 34685 | + AuTraceErr(err); |
1facf9fc | 34686 | + return err; |
34687 | +} | |
34688 | + | |
34689 | +/* ---------------------------------------------------------------------- */ | |
34690 | +/* | |
34691 | + * functions for removing a whiteout | |
34692 | + */ | |
34693 | + | |
34694 | +static int do_unlink_wh(struct inode *h_dir, struct path *h_path) | |
34695 | +{ | |
523b37e3 AM |
34696 | + int err, force; |
34697 | + struct inode *delegated; | |
1facf9fc | 34698 | + |
34699 | + /* | |
34700 | + * forces superio when the dir has a sticky bit. | |
34701 | + * this may be a violation of unix fs semantics. | |
34702 | + */ | |
34703 | + force = (h_dir->i_mode & S_ISVTX) | |
5527c038 | 34704 | + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid); |
523b37e3 AM |
34705 | + delegated = NULL; |
34706 | + err = vfsub_unlink(h_dir, h_path, &delegated, force); | |
34707 | + if (unlikely(err == -EWOULDBLOCK)) { | |
34708 | + pr_warn("cannot retry for NFSv4 delegation" | |
34709 | + " for an internal unlink\n"); | |
34710 | + iput(delegated); | |
34711 | + } | |
34712 | + return err; | |
1facf9fc | 34713 | +} |
34714 | + | |
34715 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
34716 | + struct dentry *dentry) | |
34717 | +{ | |
34718 | + int err; | |
34719 | + | |
34720 | + err = do_unlink_wh(h_dir, h_path); | |
34721 | + if (!err && dentry) | |
34722 | + au_set_dbwh(dentry, -1); | |
34723 | + | |
34724 | + return err; | |
34725 | +} | |
34726 | + | |
34727 | +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh, | |
34728 | + struct au_branch *br) | |
34729 | +{ | |
34730 | + int err; | |
34731 | + struct path h_path = { | |
86dc4139 | 34732 | + .mnt = au_br_mnt(br) |
1facf9fc | 34733 | + }; |
34734 | + | |
34735 | + err = 0; | |
b4510431 | 34736 | + h_path.dentry = vfsub_lkup_one(wh, h_parent); |
1facf9fc | 34737 | + if (IS_ERR(h_path.dentry)) |
34738 | + err = PTR_ERR(h_path.dentry); | |
34739 | + else { | |
5527c038 JR |
34740 | + if (d_is_reg(h_path.dentry)) |
34741 | + err = do_unlink_wh(d_inode(h_parent), &h_path); | |
1facf9fc | 34742 | + dput(h_path.dentry); |
34743 | + } | |
34744 | + | |
34745 | + return err; | |
34746 | +} | |
34747 | + | |
34748 | +/* ---------------------------------------------------------------------- */ | |
34749 | +/* | |
34750 | + * initialize/clean whiteout for a branch | |
34751 | + */ | |
34752 | + | |
34753 | +static void au_wh_clean(struct inode *h_dir, struct path *whpath, | |
34754 | + const int isdir) | |
34755 | +{ | |
34756 | + int err; | |
523b37e3 | 34757 | + struct inode *delegated; |
1facf9fc | 34758 | + |
5527c038 | 34759 | + if (d_is_negative(whpath->dentry)) |
1facf9fc | 34760 | + return; |
34761 | + | |
86dc4139 AM |
34762 | + if (isdir) |
34763 | + err = vfsub_rmdir(h_dir, whpath); | |
523b37e3 AM |
34764 | + else { |
34765 | + delegated = NULL; | |
34766 | + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0); | |
34767 | + if (unlikely(err == -EWOULDBLOCK)) { | |
34768 | + pr_warn("cannot retry for NFSv4 delegation" | |
34769 | + " for an internal unlink\n"); | |
34770 | + iput(delegated); | |
34771 | + } | |
34772 | + } | |
1facf9fc | 34773 | + if (unlikely(err)) |
523b37e3 AM |
34774 | + pr_warn("failed removing %pd (%d), ignored.\n", |
34775 | + whpath->dentry, err); | |
1facf9fc | 34776 | +} |
34777 | + | |
34778 | +static int test_linkable(struct dentry *h_root) | |
34779 | +{ | |
5527c038 | 34780 | + struct inode *h_dir = d_inode(h_root); |
1facf9fc | 34781 | + |
34782 | + if (h_dir->i_op->link) | |
34783 | + return 0; | |
34784 | + | |
523b37e3 AM |
34785 | + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n", |
34786 | + h_root, au_sbtype(h_root->d_sb)); | |
1facf9fc | 34787 | + return -ENOSYS; |
34788 | +} | |
34789 | + | |
34790 | +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */ | |
34791 | +static int au_whdir(struct inode *h_dir, struct path *path) | |
34792 | +{ | |
34793 | + int err; | |
34794 | + | |
34795 | + err = -EEXIST; | |
5527c038 | 34796 | + if (d_is_negative(path->dentry)) { |
1facf9fc | 34797 | + int mode = S_IRWXU; |
34798 | + | |
34799 | + if (au_test_nfs(path->dentry->d_sb)) | |
34800 | + mode |= S_IXUGO; | |
86dc4139 | 34801 | + err = vfsub_mkdir(h_dir, path, mode); |
2000de60 | 34802 | + } else if (d_is_dir(path->dentry)) |
1facf9fc | 34803 | + err = 0; |
34804 | + else | |
523b37e3 | 34805 | + pr_err("unknown %pd exists\n", path->dentry); |
1facf9fc | 34806 | + |
34807 | + return err; | |
34808 | +} | |
34809 | + | |
34810 | +struct au_wh_base { | |
34811 | + const struct qstr *name; | |
34812 | + struct dentry *dentry; | |
34813 | +}; | |
34814 | + | |
34815 | +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[], | |
34816 | + struct path *h_path) | |
34817 | +{ | |
34818 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
34819 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
34820 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
34821 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
34822 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
34823 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
34824 | +} | |
34825 | + | |
34826 | +/* | |
34827 | + * returns tri-state, | |
c1595e42 | 34828 | + * minus: error, caller should print the message |
1facf9fc | 34829 | + * zero: succuess |
c1595e42 | 34830 | + * plus: error, caller should NOT print the message |
1facf9fc | 34831 | + */ |
34832 | +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr, | |
34833 | + int do_plink, struct au_wh_base base[], | |
34834 | + struct path *h_path) | |
34835 | +{ | |
34836 | + int err; | |
34837 | + struct inode *h_dir; | |
34838 | + | |
5527c038 | 34839 | + h_dir = d_inode(h_root); |
1facf9fc | 34840 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
34841 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
34842 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
34843 | + if (do_plink) { | |
34844 | + err = test_linkable(h_root); | |
34845 | + if (unlikely(err)) { | |
34846 | + err = 1; | |
34847 | + goto out; | |
34848 | + } | |
34849 | + | |
34850 | + err = au_whdir(h_dir, h_path); | |
34851 | + if (unlikely(err)) | |
34852 | + goto out; | |
34853 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
34854 | + } else | |
34855 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
34856 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
34857 | + err = au_whdir(h_dir, h_path); | |
34858 | + if (unlikely(err)) | |
34859 | + goto out; | |
34860 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
34861 | + | |
4f0767ce | 34862 | +out: |
1facf9fc | 34863 | + return err; |
34864 | +} | |
34865 | + | |
34866 | +/* | |
34867 | + * for the moment, aufs supports the branch filesystem which does not support | |
34868 | + * link(2). testing on FAT which does not support i_op->setattr() fully either, | |
34869 | + * copyup failed. finally, such filesystem will not be used as the writable | |
34870 | + * branch. | |
34871 | + * | |
34872 | + * returns tri-state, see above. | |
34873 | + */ | |
34874 | +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr, | |
34875 | + int do_plink, struct au_wh_base base[], | |
34876 | + struct path *h_path) | |
34877 | +{ | |
34878 | + int err; | |
34879 | + struct inode *h_dir; | |
34880 | + | |
1308ab2a | 34881 | + WbrWhMustWriteLock(wbr); |
34882 | + | |
1facf9fc | 34883 | + err = test_linkable(h_root); |
34884 | + if (unlikely(err)) { | |
34885 | + err = 1; | |
34886 | + goto out; | |
34887 | + } | |
34888 | + | |
34889 | + /* | |
34890 | + * todo: should this create be done in /sbin/mount.aufs helper? | |
34891 | + */ | |
34892 | + err = -EEXIST; | |
5527c038 JR |
34893 | + h_dir = d_inode(h_root); |
34894 | + if (d_is_negative(base[AuBrWh_BASE].dentry)) { | |
86dc4139 AM |
34895 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
34896 | + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true); | |
7e9cd9fe | 34897 | + } else if (d_is_reg(base[AuBrWh_BASE].dentry)) |
1facf9fc | 34898 | + err = 0; |
34899 | + else | |
523b37e3 | 34900 | + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry); |
1facf9fc | 34901 | + if (unlikely(err)) |
34902 | + goto out; | |
34903 | + | |
34904 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
34905 | + if (do_plink) { | |
34906 | + err = au_whdir(h_dir, h_path); | |
34907 | + if (unlikely(err)) | |
34908 | + goto out; | |
34909 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
34910 | + } else | |
34911 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
34912 | + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry); | |
34913 | + | |
34914 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
34915 | + err = au_whdir(h_dir, h_path); | |
34916 | + if (unlikely(err)) | |
34917 | + goto out; | |
34918 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
34919 | + | |
4f0767ce | 34920 | +out: |
1facf9fc | 34921 | + return err; |
34922 | +} | |
34923 | + | |
34924 | +/* | |
34925 | + * initialize the whiteout base file/dir for @br. | |
34926 | + */ | |
86dc4139 | 34927 | +int au_wh_init(struct au_branch *br, struct super_block *sb) |
1facf9fc | 34928 | +{ |
34929 | + int err, i; | |
34930 | + const unsigned char do_plink | |
34931 | + = !!au_opt_test(au_mntflags(sb), PLINK); | |
1facf9fc | 34932 | + struct inode *h_dir; |
86dc4139 AM |
34933 | + struct path path = br->br_path; |
34934 | + struct dentry *h_root = path.dentry; | |
1facf9fc | 34935 | + struct au_wbr *wbr = br->br_wbr; |
34936 | + static const struct qstr base_name[] = { | |
0c3ec466 AM |
34937 | + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME, |
34938 | + sizeof(AUFS_BASE_NAME) - 1), | |
34939 | + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME, | |
34940 | + sizeof(AUFS_PLINKDIR_NAME) - 1), | |
34941 | + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME, | |
34942 | + sizeof(AUFS_ORPHDIR_NAME) - 1) | |
1facf9fc | 34943 | + }; |
34944 | + struct au_wh_base base[] = { | |
34945 | + [AuBrWh_BASE] = { | |
34946 | + .name = base_name + AuBrWh_BASE, | |
34947 | + .dentry = NULL | |
34948 | + }, | |
34949 | + [AuBrWh_PLINK] = { | |
34950 | + .name = base_name + AuBrWh_PLINK, | |
34951 | + .dentry = NULL | |
34952 | + }, | |
34953 | + [AuBrWh_ORPH] = { | |
34954 | + .name = base_name + AuBrWh_ORPH, | |
34955 | + .dentry = NULL | |
34956 | + } | |
34957 | + }; | |
34958 | + | |
1308ab2a | 34959 | + if (wbr) |
34960 | + WbrWhMustWriteLock(wbr); | |
1facf9fc | 34961 | + |
1facf9fc | 34962 | + for (i = 0; i < AuBrWh_Last; i++) { |
34963 | + /* doubly whiteouted */ | |
34964 | + struct dentry *d; | |
34965 | + | |
34966 | + d = au_wh_lkup(h_root, (void *)base[i].name, br); | |
34967 | + err = PTR_ERR(d); | |
34968 | + if (IS_ERR(d)) | |
34969 | + goto out; | |
34970 | + | |
34971 | + base[i].dentry = d; | |
34972 | + AuDebugOn(wbr | |
34973 | + && wbr->wbr_wh[i] | |
34974 | + && wbr->wbr_wh[i] != base[i].dentry); | |
34975 | + } | |
34976 | + | |
34977 | + if (wbr) | |
34978 | + for (i = 0; i < AuBrWh_Last; i++) { | |
34979 | + dput(wbr->wbr_wh[i]); | |
34980 | + wbr->wbr_wh[i] = NULL; | |
34981 | + } | |
34982 | + | |
34983 | + err = 0; | |
1e00d052 | 34984 | + if (!au_br_writable(br->br_perm)) { |
5527c038 | 34985 | + h_dir = d_inode(h_root); |
1facf9fc | 34986 | + au_wh_init_ro(h_dir, base, &path); |
1e00d052 | 34987 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 34988 | + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path); |
34989 | + if (err > 0) | |
34990 | + goto out; | |
34991 | + else if (err) | |
34992 | + goto out_err; | |
1e00d052 | 34993 | + } else { |
1facf9fc | 34994 | + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path); |
34995 | + if (err > 0) | |
34996 | + goto out; | |
34997 | + else if (err) | |
34998 | + goto out_err; | |
1facf9fc | 34999 | + } |
35000 | + goto out; /* success */ | |
35001 | + | |
4f0767ce | 35002 | +out_err: |
523b37e3 AM |
35003 | + pr_err("an error(%d) on the writable branch %pd(%s)\n", |
35004 | + err, h_root, au_sbtype(h_root->d_sb)); | |
4f0767ce | 35005 | +out: |
1facf9fc | 35006 | + for (i = 0; i < AuBrWh_Last; i++) |
35007 | + dput(base[i].dentry); | |
35008 | + return err; | |
35009 | +} | |
35010 | + | |
35011 | +/* ---------------------------------------------------------------------- */ | |
35012 | +/* | |
35013 | + * whiteouts are all hard-linked usually. | |
35014 | + * when its link count reaches a ceiling, we create a new whiteout base | |
35015 | + * asynchronously. | |
35016 | + */ | |
35017 | + | |
35018 | +struct reinit_br_wh { | |
35019 | + struct super_block *sb; | |
35020 | + struct au_branch *br; | |
35021 | +}; | |
35022 | + | |
35023 | +static void reinit_br_wh(void *arg) | |
35024 | +{ | |
35025 | + int err; | |
35026 | + aufs_bindex_t bindex; | |
35027 | + struct path h_path; | |
35028 | + struct reinit_br_wh *a = arg; | |
35029 | + struct au_wbr *wbr; | |
523b37e3 | 35030 | + struct inode *dir, *delegated; |
1facf9fc | 35031 | + struct dentry *h_root; |
35032 | + struct au_hinode *hdir; | |
35033 | + | |
35034 | + err = 0; | |
35035 | + wbr = a->br->br_wbr; | |
35036 | + /* big aufs lock */ | |
35037 | + si_noflush_write_lock(a->sb); | |
35038 | + if (!au_br_writable(a->br->br_perm)) | |
35039 | + goto out; | |
35040 | + bindex = au_br_index(a->sb, a->br->br_id); | |
35041 | + if (unlikely(bindex < 0)) | |
35042 | + goto out; | |
35043 | + | |
1308ab2a | 35044 | + di_read_lock_parent(a->sb->s_root, AuLock_IR); |
5527c038 | 35045 | + dir = d_inode(a->sb->s_root); |
1facf9fc | 35046 | + hdir = au_hi(dir, bindex); |
35047 | + h_root = au_h_dptr(a->sb->s_root, bindex); | |
86dc4139 | 35048 | + AuDebugOn(h_root != au_br_dentry(a->br)); |
1facf9fc | 35049 | + |
5afbbe0d | 35050 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 35051 | + wbr_wh_write_lock(wbr); |
35052 | + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode, | |
35053 | + h_root, a->br); | |
35054 | + if (!err) { | |
86dc4139 AM |
35055 | + h_path.dentry = wbr->wbr_whbase; |
35056 | + h_path.mnt = au_br_mnt(a->br); | |
523b37e3 AM |
35057 | + delegated = NULL; |
35058 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, | |
35059 | + /*force*/0); | |
35060 | + if (unlikely(err == -EWOULDBLOCK)) { | |
35061 | + pr_warn("cannot retry for NFSv4 delegation" | |
35062 | + " for an internal unlink\n"); | |
35063 | + iput(delegated); | |
35064 | + } | |
1facf9fc | 35065 | + } else { |
523b37e3 | 35066 | + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase); |
1facf9fc | 35067 | + err = 0; |
35068 | + } | |
35069 | + dput(wbr->wbr_whbase); | |
35070 | + wbr->wbr_whbase = NULL; | |
35071 | + if (!err) | |
86dc4139 | 35072 | + err = au_wh_init(a->br, a->sb); |
1facf9fc | 35073 | + wbr_wh_write_unlock(wbr); |
5afbbe0d | 35074 | + au_hn_inode_unlock(hdir); |
1308ab2a | 35075 | + di_read_unlock(a->sb->s_root, AuLock_IR); |
076b876e AM |
35076 | + if (!err) |
35077 | + au_fhsm_wrote(a->sb, bindex, /*force*/0); | |
1facf9fc | 35078 | + |
4f0767ce | 35079 | +out: |
1facf9fc | 35080 | + if (wbr) |
35081 | + atomic_dec(&wbr->wbr_wh_running); | |
5afbbe0d | 35082 | + au_br_put(a->br); |
1facf9fc | 35083 | + si_write_unlock(a->sb); |
027c5e7a | 35084 | + au_nwt_done(&au_sbi(a->sb)->si_nowait); |
1c60b727 | 35085 | + kfree(arg); |
1facf9fc | 35086 | + if (unlikely(err)) |
35087 | + AuIOErr("err %d\n", err); | |
35088 | +} | |
35089 | + | |
35090 | +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br) | |
35091 | +{ | |
35092 | + int do_dec, wkq_err; | |
35093 | + struct reinit_br_wh *arg; | |
35094 | + | |
35095 | + do_dec = 1; | |
35096 | + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1) | |
35097 | + goto out; | |
35098 | + | |
35099 | + /* ignore ENOMEM */ | |
35100 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
35101 | + if (arg) { | |
35102 | + /* | |
35103 | + * dec(wh_running), kfree(arg) and dec(br_count) | |
35104 | + * in reinit function | |
35105 | + */ | |
35106 | + arg->sb = sb; | |
35107 | + arg->br = br; | |
5afbbe0d | 35108 | + au_br_get(br); |
53392da6 | 35109 | + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0); |
1facf9fc | 35110 | + if (unlikely(wkq_err)) { |
35111 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
5afbbe0d | 35112 | + au_br_put(br); |
1c60b727 | 35113 | + kfree(arg); |
1facf9fc | 35114 | + } |
35115 | + do_dec = 0; | |
35116 | + } | |
35117 | + | |
4f0767ce | 35118 | +out: |
1facf9fc | 35119 | + if (do_dec) |
35120 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
35121 | +} | |
35122 | + | |
35123 | +/* ---------------------------------------------------------------------- */ | |
35124 | + | |
35125 | +/* | |
35126 | + * create the whiteout @wh. | |
35127 | + */ | |
35128 | +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex, | |
35129 | + struct dentry *wh) | |
35130 | +{ | |
35131 | + int err; | |
35132 | + struct path h_path = { | |
35133 | + .dentry = wh | |
35134 | + }; | |
35135 | + struct au_branch *br; | |
35136 | + struct au_wbr *wbr; | |
35137 | + struct dentry *h_parent; | |
523b37e3 | 35138 | + struct inode *h_dir, *delegated; |
1facf9fc | 35139 | + |
35140 | + h_parent = wh->d_parent; /* dir inode is locked */ | |
5527c038 | 35141 | + h_dir = d_inode(h_parent); |
1facf9fc | 35142 | + IMustLock(h_dir); |
35143 | + | |
35144 | + br = au_sbr(sb, bindex); | |
86dc4139 | 35145 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 35146 | + wbr = br->br_wbr; |
35147 | + wbr_wh_read_lock(wbr); | |
35148 | + if (wbr->wbr_whbase) { | |
523b37e3 AM |
35149 | + delegated = NULL; |
35150 | + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated); | |
35151 | + if (unlikely(err == -EWOULDBLOCK)) { | |
35152 | + pr_warn("cannot retry for NFSv4 delegation" | |
35153 | + " for an internal link\n"); | |
35154 | + iput(delegated); | |
35155 | + } | |
1facf9fc | 35156 | + if (!err || err != -EMLINK) |
35157 | + goto out; | |
35158 | + | |
35159 | + /* link count full. re-initialize br_whbase. */ | |
35160 | + kick_reinit_br_wh(sb, br); | |
35161 | + } | |
35162 | + | |
35163 | + /* return this error in this context */ | |
b4510431 | 35164 | + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true); |
076b876e AM |
35165 | + if (!err) |
35166 | + au_fhsm_wrote(sb, bindex, /*force*/0); | |
1facf9fc | 35167 | + |
4f0767ce | 35168 | +out: |
1facf9fc | 35169 | + wbr_wh_read_unlock(wbr); |
35170 | + return err; | |
35171 | +} | |
35172 | + | |
35173 | +/* ---------------------------------------------------------------------- */ | |
35174 | + | |
35175 | +/* | |
35176 | + * create or remove the diropq. | |
35177 | + */ | |
35178 | +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex, | |
35179 | + unsigned int flags) | |
35180 | +{ | |
35181 | + struct dentry *opq_dentry, *h_dentry; | |
35182 | + struct super_block *sb; | |
35183 | + struct au_branch *br; | |
35184 | + int err; | |
35185 | + | |
35186 | + sb = dentry->d_sb; | |
35187 | + br = au_sbr(sb, bindex); | |
35188 | + h_dentry = au_h_dptr(dentry, bindex); | |
b4510431 | 35189 | + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry); |
1facf9fc | 35190 | + if (IS_ERR(opq_dentry)) |
35191 | + goto out; | |
35192 | + | |
35193 | + if (au_ftest_diropq(flags, CREATE)) { | |
35194 | + err = link_or_create_wh(sb, bindex, opq_dentry); | |
35195 | + if (!err) { | |
35196 | + au_set_dbdiropq(dentry, bindex); | |
35197 | + goto out; /* success */ | |
35198 | + } | |
35199 | + } else { | |
35200 | + struct path tmp = { | |
35201 | + .dentry = opq_dentry, | |
86dc4139 | 35202 | + .mnt = au_br_mnt(br) |
1facf9fc | 35203 | + }; |
5527c038 | 35204 | + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp); |
1facf9fc | 35205 | + if (!err) |
35206 | + au_set_dbdiropq(dentry, -1); | |
35207 | + } | |
35208 | + dput(opq_dentry); | |
35209 | + opq_dentry = ERR_PTR(err); | |
35210 | + | |
4f0767ce | 35211 | +out: |
1facf9fc | 35212 | + return opq_dentry; |
35213 | +} | |
35214 | + | |
35215 | +struct do_diropq_args { | |
35216 | + struct dentry **errp; | |
35217 | + struct dentry *dentry; | |
35218 | + aufs_bindex_t bindex; | |
35219 | + unsigned int flags; | |
35220 | +}; | |
35221 | + | |
35222 | +static void call_do_diropq(void *args) | |
35223 | +{ | |
35224 | + struct do_diropq_args *a = args; | |
35225 | + *a->errp = do_diropq(a->dentry, a->bindex, a->flags); | |
35226 | +} | |
35227 | + | |
35228 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
35229 | + unsigned int flags) | |
35230 | +{ | |
35231 | + struct dentry *diropq, *h_dentry; | |
35232 | + | |
35233 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 35234 | + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE)) |
1facf9fc | 35235 | + diropq = do_diropq(dentry, bindex, flags); |
35236 | + else { | |
35237 | + int wkq_err; | |
35238 | + struct do_diropq_args args = { | |
35239 | + .errp = &diropq, | |
35240 | + .dentry = dentry, | |
35241 | + .bindex = bindex, | |
35242 | + .flags = flags | |
35243 | + }; | |
35244 | + | |
35245 | + wkq_err = au_wkq_wait(call_do_diropq, &args); | |
35246 | + if (unlikely(wkq_err)) | |
35247 | + diropq = ERR_PTR(wkq_err); | |
35248 | + } | |
35249 | + | |
35250 | + return diropq; | |
35251 | +} | |
35252 | + | |
35253 | +/* ---------------------------------------------------------------------- */ | |
35254 | + | |
35255 | +/* | |
35256 | + * lookup whiteout dentry. | |
35257 | + * @h_parent: lower parent dentry which must exist and be locked | |
35258 | + * @base_name: name of dentry which will be whiteouted | |
35259 | + * returns dentry for whiteout. | |
35260 | + */ | |
35261 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
35262 | + struct au_branch *br) | |
35263 | +{ | |
35264 | + int err; | |
35265 | + struct qstr wh_name; | |
35266 | + struct dentry *wh_dentry; | |
35267 | + | |
35268 | + err = au_wh_name_alloc(&wh_name, base_name); | |
35269 | + wh_dentry = ERR_PTR(err); | |
35270 | + if (!err) { | |
b4510431 | 35271 | + wh_dentry = vfsub_lkup_one(&wh_name, h_parent); |
1c60b727 | 35272 | + kfree(wh_name.name); |
1facf9fc | 35273 | + } |
35274 | + return wh_dentry; | |
35275 | +} | |
35276 | + | |
35277 | +/* | |
35278 | + * link/create a whiteout for @dentry on @bindex. | |
35279 | + */ | |
35280 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
35281 | + struct dentry *h_parent) | |
35282 | +{ | |
35283 | + struct dentry *wh_dentry; | |
35284 | + struct super_block *sb; | |
35285 | + int err; | |
35286 | + | |
35287 | + sb = dentry->d_sb; | |
35288 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex)); | |
5527c038 | 35289 | + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) { |
1facf9fc | 35290 | + err = link_or_create_wh(sb, bindex, wh_dentry); |
076b876e | 35291 | + if (!err) { |
1facf9fc | 35292 | + au_set_dbwh(dentry, bindex); |
076b876e AM |
35293 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
35294 | + } else { | |
1facf9fc | 35295 | + dput(wh_dentry); |
35296 | + wh_dentry = ERR_PTR(err); | |
35297 | + } | |
35298 | + } | |
35299 | + | |
35300 | + return wh_dentry; | |
35301 | +} | |
35302 | + | |
35303 | +/* ---------------------------------------------------------------------- */ | |
35304 | + | |
35305 | +/* Delete all whiteouts in this directory on branch bindex. */ | |
35306 | +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist, | |
35307 | + aufs_bindex_t bindex, struct au_branch *br) | |
35308 | +{ | |
35309 | + int err; | |
35310 | + unsigned long ul, n; | |
35311 | + struct qstr wh_name; | |
35312 | + char *p; | |
35313 | + struct hlist_head *head; | |
c06a8ce3 | 35314 | + struct au_vdir_wh *pos; |
1facf9fc | 35315 | + struct au_vdir_destr *str; |
35316 | + | |
35317 | + err = -ENOMEM; | |
537831f9 | 35318 | + p = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 35319 | + wh_name.name = p; |
35320 | + if (unlikely(!wh_name.name)) | |
35321 | + goto out; | |
35322 | + | |
35323 | + err = 0; | |
35324 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
35325 | + p += AUFS_WH_PFX_LEN; | |
35326 | + n = whlist->nh_num; | |
35327 | + head = whlist->nh_head; | |
35328 | + for (ul = 0; !err && ul < n; ul++, head++) { | |
c06a8ce3 AM |
35329 | + hlist_for_each_entry(pos, head, wh_hash) { |
35330 | + if (pos->wh_bindex != bindex) | |
1facf9fc | 35331 | + continue; |
35332 | + | |
c06a8ce3 | 35333 | + str = &pos->wh_str; |
1facf9fc | 35334 | + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) { |
35335 | + memcpy(p, str->name, str->len); | |
35336 | + wh_name.len = AUFS_WH_PFX_LEN + str->len; | |
35337 | + err = unlink_wh_name(h_dentry, &wh_name, br); | |
35338 | + if (!err) | |
35339 | + continue; | |
35340 | + break; | |
35341 | + } | |
35342 | + AuIOErr("whiteout name too long %.*s\n", | |
35343 | + str->len, str->name); | |
35344 | + err = -EIO; | |
35345 | + break; | |
35346 | + } | |
35347 | + } | |
1c60b727 | 35348 | + free_page((unsigned long)wh_name.name); |
1facf9fc | 35349 | + |
4f0767ce | 35350 | +out: |
1facf9fc | 35351 | + return err; |
35352 | +} | |
35353 | + | |
35354 | +struct del_wh_children_args { | |
35355 | + int *errp; | |
35356 | + struct dentry *h_dentry; | |
1308ab2a | 35357 | + struct au_nhash *whlist; |
1facf9fc | 35358 | + aufs_bindex_t bindex; |
35359 | + struct au_branch *br; | |
35360 | +}; | |
35361 | + | |
35362 | +static void call_del_wh_children(void *args) | |
35363 | +{ | |
35364 | + struct del_wh_children_args *a = args; | |
1308ab2a | 35365 | + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br); |
1facf9fc | 35366 | +} |
35367 | + | |
35368 | +/* ---------------------------------------------------------------------- */ | |
35369 | + | |
35370 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp) | |
35371 | +{ | |
35372 | + struct au_whtmp_rmdir *whtmp; | |
dece6358 | 35373 | + int err; |
1308ab2a | 35374 | + unsigned int rdhash; |
dece6358 AM |
35375 | + |
35376 | + SiMustAnyLock(sb); | |
1facf9fc | 35377 | + |
be52b249 | 35378 | + whtmp = kzalloc(sizeof(*whtmp), gfp); |
dece6358 AM |
35379 | + if (unlikely(!whtmp)) { |
35380 | + whtmp = ERR_PTR(-ENOMEM); | |
1facf9fc | 35381 | + goto out; |
dece6358 | 35382 | + } |
1facf9fc | 35383 | + |
1308ab2a | 35384 | + /* no estimation for dir size */ |
35385 | + rdhash = au_sbi(sb)->si_rdhash; | |
35386 | + if (!rdhash) | |
35387 | + rdhash = AUFS_RDHASH_DEF; | |
35388 | + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp); | |
35389 | + if (unlikely(err)) { | |
1c60b727 | 35390 | + kfree(whtmp); |
1308ab2a | 35391 | + whtmp = ERR_PTR(err); |
35392 | + } | |
dece6358 | 35393 | + |
4f0767ce | 35394 | +out: |
dece6358 | 35395 | + return whtmp; |
1facf9fc | 35396 | +} |
35397 | + | |
35398 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp) | |
35399 | +{ | |
027c5e7a | 35400 | + if (whtmp->br) |
5afbbe0d | 35401 | + au_br_put(whtmp->br); |
1facf9fc | 35402 | + dput(whtmp->wh_dentry); |
35403 | + iput(whtmp->dir); | |
dece6358 | 35404 | + au_nhash_wh_free(&whtmp->whlist); |
1c60b727 | 35405 | + kfree(whtmp); |
1facf9fc | 35406 | +} |
35407 | + | |
35408 | +/* | |
35409 | + * rmdir the whiteouted temporary named dir @h_dentry. | |
35410 | + * @whlist: whiteouted children. | |
35411 | + */ | |
35412 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35413 | + struct dentry *wh_dentry, struct au_nhash *whlist) | |
35414 | +{ | |
35415 | + int err; | |
2000de60 | 35416 | + unsigned int h_nlink; |
1facf9fc | 35417 | + struct path h_tmp; |
35418 | + struct inode *wh_inode, *h_dir; | |
35419 | + struct au_branch *br; | |
35420 | + | |
5527c038 | 35421 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
1facf9fc | 35422 | + IMustLock(h_dir); |
35423 | + | |
35424 | + br = au_sbr(dir->i_sb, bindex); | |
5527c038 | 35425 | + wh_inode = d_inode(wh_dentry); |
febd17d6 | 35426 | + inode_lock_nested(wh_inode, AuLsc_I_CHILD); |
1facf9fc | 35427 | + |
35428 | + /* | |
35429 | + * someone else might change some whiteouts while we were sleeping. | |
35430 | + * it means this whlist may have an obsoleted entry. | |
35431 | + */ | |
35432 | + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE)) | |
35433 | + err = del_wh_children(wh_dentry, whlist, bindex, br); | |
35434 | + else { | |
35435 | + int wkq_err; | |
35436 | + struct del_wh_children_args args = { | |
35437 | + .errp = &err, | |
35438 | + .h_dentry = wh_dentry, | |
1308ab2a | 35439 | + .whlist = whlist, |
1facf9fc | 35440 | + .bindex = bindex, |
35441 | + .br = br | |
35442 | + }; | |
35443 | + | |
35444 | + wkq_err = au_wkq_wait(call_del_wh_children, &args); | |
35445 | + if (unlikely(wkq_err)) | |
35446 | + err = wkq_err; | |
35447 | + } | |
febd17d6 | 35448 | + inode_unlock(wh_inode); |
1facf9fc | 35449 | + |
35450 | + if (!err) { | |
35451 | + h_tmp.dentry = wh_dentry; | |
86dc4139 | 35452 | + h_tmp.mnt = au_br_mnt(br); |
2000de60 | 35453 | + h_nlink = h_dir->i_nlink; |
1facf9fc | 35454 | + err = vfsub_rmdir(h_dir, &h_tmp); |
2000de60 JR |
35455 | + /* some fs doesn't change the parent nlink in some cases */ |
35456 | + h_nlink -= h_dir->i_nlink; | |
1facf9fc | 35457 | + } |
35458 | + | |
35459 | + if (!err) { | |
5afbbe0d | 35460 | + if (au_ibtop(dir) == bindex) { |
7f207e10 | 35461 | + /* todo: dir->i_mutex is necessary */ |
1facf9fc | 35462 | + au_cpup_attr_timesizes(dir); |
2000de60 JR |
35463 | + if (h_nlink) |
35464 | + vfsub_drop_nlink(dir); | |
1facf9fc | 35465 | + } |
35466 | + return 0; /* success */ | |
35467 | + } | |
35468 | + | |
523b37e3 | 35469 | + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err); |
1facf9fc | 35470 | + return err; |
35471 | +} | |
35472 | + | |
35473 | +static void call_rmdir_whtmp(void *args) | |
35474 | +{ | |
35475 | + int err; | |
e49829fe | 35476 | + aufs_bindex_t bindex; |
1facf9fc | 35477 | + struct au_whtmp_rmdir *a = args; |
35478 | + struct super_block *sb; | |
35479 | + struct dentry *h_parent; | |
35480 | + struct inode *h_dir; | |
1facf9fc | 35481 | + struct au_hinode *hdir; |
35482 | + | |
35483 | + /* rmdir by nfsd may cause deadlock with this i_mutex */ | |
febd17d6 | 35484 | + /* inode_lock(a->dir); */ |
e49829fe | 35485 | + err = -EROFS; |
1facf9fc | 35486 | + sb = a->dir->i_sb; |
e49829fe JR |
35487 | + si_read_lock(sb, !AuLock_FLUSH); |
35488 | + if (!au_br_writable(a->br->br_perm)) | |
35489 | + goto out; | |
35490 | + bindex = au_br_index(sb, a->br->br_id); | |
35491 | + if (unlikely(bindex < 0)) | |
1facf9fc | 35492 | + goto out; |
35493 | + | |
35494 | + err = -EIO; | |
1facf9fc | 35495 | + ii_write_lock_parent(a->dir); |
35496 | + h_parent = dget_parent(a->wh_dentry); | |
5527c038 | 35497 | + h_dir = d_inode(h_parent); |
e49829fe | 35498 | + hdir = au_hi(a->dir, bindex); |
86dc4139 AM |
35499 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); |
35500 | + if (unlikely(err)) | |
35501 | + goto out_mnt; | |
5afbbe0d | 35502 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
e49829fe JR |
35503 | + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, |
35504 | + a->br); | |
86dc4139 AM |
35505 | + if (!err) |
35506 | + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist); | |
5afbbe0d | 35507 | + au_hn_inode_unlock(hdir); |
86dc4139 AM |
35508 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
35509 | + | |
35510 | +out_mnt: | |
1facf9fc | 35511 | + dput(h_parent); |
35512 | + ii_write_unlock(a->dir); | |
4f0767ce | 35513 | +out: |
febd17d6 | 35514 | + /* inode_unlock(a->dir); */ |
1facf9fc | 35515 | + au_whtmp_rmdir_free(a); |
027c5e7a AM |
35516 | + si_read_unlock(sb); |
35517 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1facf9fc | 35518 | + if (unlikely(err)) |
35519 | + AuIOErr("err %d\n", err); | |
35520 | +} | |
35521 | + | |
35522 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35523 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args) | |
35524 | +{ | |
35525 | + int wkq_err; | |
e49829fe | 35526 | + struct super_block *sb; |
1facf9fc | 35527 | + |
35528 | + IMustLock(dir); | |
35529 | + | |
35530 | + /* all post-process will be done in do_rmdir_whtmp(). */ | |
e49829fe | 35531 | + sb = dir->i_sb; |
1facf9fc | 35532 | + args->dir = au_igrab(dir); |
e49829fe | 35533 | + args->br = au_sbr(sb, bindex); |
5afbbe0d | 35534 | + au_br_get(args->br); |
1facf9fc | 35535 | + args->wh_dentry = dget(wh_dentry); |
53392da6 | 35536 | + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0); |
1facf9fc | 35537 | + if (unlikely(wkq_err)) { |
523b37e3 | 35538 | + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err); |
1facf9fc | 35539 | + au_whtmp_rmdir_free(args); |
35540 | + } | |
35541 | +} | |
7f207e10 AM |
35542 | diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h |
35543 | --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 35544 | +++ linux/fs/aufs/whout.h 2018-01-29 07:56:20.063325368 +0100 |
3c1bdaff | 35545 | @@ -0,0 +1,85 @@ |
1facf9fc | 35546 | +/* |
a2654f78 | 35547 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 35548 | + * |
35549 | + * This program, aufs is free software; you can redistribute it and/or modify | |
35550 | + * it under the terms of the GNU General Public License as published by | |
35551 | + * the Free Software Foundation; either version 2 of the License, or | |
35552 | + * (at your option) any later version. | |
dece6358 AM |
35553 | + * |
35554 | + * This program is distributed in the hope that it will be useful, | |
35555 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
35556 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35557 | + * GNU General Public License for more details. | |
35558 | + * | |
35559 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 35560 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 35561 | + */ |
35562 | + | |
35563 | +/* | |
35564 | + * whiteout for logical deletion and opaque directory | |
35565 | + */ | |
35566 | + | |
35567 | +#ifndef __AUFS_WHOUT_H__ | |
35568 | +#define __AUFS_WHOUT_H__ | |
35569 | + | |
35570 | +#ifdef __KERNEL__ | |
35571 | + | |
1facf9fc | 35572 | +#include "dir.h" |
35573 | + | |
35574 | +/* whout.c */ | |
35575 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name); | |
076b876e AM |
35576 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio); |
35577 | +int au_diropq_test(struct dentry *h_dentry); | |
3c1bdaff | 35578 | +struct au_branch; |
1facf9fc | 35579 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, |
35580 | + struct qstr *prefix); | |
35581 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br); | |
35582 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
35583 | + struct dentry *dentry); | |
86dc4139 | 35584 | +int au_wh_init(struct au_branch *br, struct super_block *sb); |
1facf9fc | 35585 | + |
35586 | +/* diropq flags */ | |
35587 | +#define AuDiropq_CREATE 1 | |
35588 | +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name) | |
7f207e10 AM |
35589 | +#define au_fset_diropq(flags, name) \ |
35590 | + do { (flags) |= AuDiropq_##name; } while (0) | |
35591 | +#define au_fclr_diropq(flags, name) \ | |
35592 | + do { (flags) &= ~AuDiropq_##name; } while (0) | |
1facf9fc | 35593 | + |
35594 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
35595 | + unsigned int flags); | |
35596 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
35597 | + struct au_branch *br); | |
35598 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
35599 | + struct dentry *h_parent); | |
35600 | + | |
35601 | +/* real rmdir for the whiteout-ed dir */ | |
35602 | +struct au_whtmp_rmdir { | |
35603 | + struct inode *dir; | |
e49829fe | 35604 | + struct au_branch *br; |
1facf9fc | 35605 | + struct dentry *wh_dentry; |
dece6358 | 35606 | + struct au_nhash whlist; |
1facf9fc | 35607 | +}; |
35608 | + | |
35609 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp); | |
35610 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp); | |
35611 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35612 | + struct dentry *wh_dentry, struct au_nhash *whlist); | |
35613 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35614 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args); | |
35615 | + | |
35616 | +/* ---------------------------------------------------------------------- */ | |
35617 | + | |
35618 | +static inline struct dentry *au_diropq_create(struct dentry *dentry, | |
35619 | + aufs_bindex_t bindex) | |
35620 | +{ | |
35621 | + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE); | |
35622 | +} | |
35623 | + | |
35624 | +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex) | |
35625 | +{ | |
35626 | + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE)); | |
35627 | +} | |
35628 | + | |
35629 | +#endif /* __KERNEL__ */ | |
35630 | +#endif /* __AUFS_WHOUT_H__ */ | |
7f207e10 AM |
35631 | diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c |
35632 | --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 35633 | +++ linux/fs/aufs/wkq.c 2018-01-29 07:56:20.063325368 +0100 |
8b6a4947 | 35634 | @@ -0,0 +1,390 @@ |
1facf9fc | 35635 | +/* |
a2654f78 | 35636 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 35637 | + * |
35638 | + * This program, aufs is free software; you can redistribute it and/or modify | |
35639 | + * it under the terms of the GNU General Public License as published by | |
35640 | + * the Free Software Foundation; either version 2 of the License, or | |
35641 | + * (at your option) any later version. | |
dece6358 AM |
35642 | + * |
35643 | + * This program is distributed in the hope that it will be useful, | |
35644 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
35645 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35646 | + * GNU General Public License for more details. | |
35647 | + * | |
35648 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 35649 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 35650 | + */ |
35651 | + | |
35652 | +/* | |
35653 | + * workqueue for asynchronous/super-io operations | |
35654 | + * todo: try new dredential scheme | |
35655 | + */ | |
35656 | + | |
dece6358 | 35657 | +#include <linux/module.h> |
1facf9fc | 35658 | +#include "aufs.h" |
35659 | + | |
9dbd164d | 35660 | +/* internal workqueue named AUFS_WKQ_NAME */ |
b752ccd1 | 35661 | + |
9dbd164d | 35662 | +static struct workqueue_struct *au_wkq; |
1facf9fc | 35663 | + |
35664 | +struct au_wkinfo { | |
35665 | + struct work_struct wk; | |
7f207e10 | 35666 | + struct kobject *kobj; |
1facf9fc | 35667 | + |
35668 | + unsigned int flags; /* see wkq.h */ | |
35669 | + | |
35670 | + au_wkq_func_t func; | |
35671 | + void *args; | |
35672 | + | |
8b6a4947 AM |
35673 | +#ifdef CONFIG_LOCKDEP |
35674 | + int dont_check; | |
35675 | + struct held_lock **hlock; | |
35676 | +#endif | |
35677 | + | |
1facf9fc | 35678 | + struct completion *comp; |
35679 | +}; | |
35680 | + | |
35681 | +/* ---------------------------------------------------------------------- */ | |
8b6a4947 AM |
35682 | +/* |
35683 | + * Aufs passes some operations to the workqueue such as the internal copyup. | |
35684 | + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the | |
35685 | + * job run by workqueue depends upon the locks acquired in the other task. | |
35686 | + * Delegating a small operation to the workqueue, aufs passes its lockdep | |
35687 | + * information too. And the job in the workqueue restores the info in order to | |
35688 | + * pretend as if it acquired those locks. This is just to make LOCKDEP work | |
35689 | + * correctly and expectedly. | |
35690 | + */ | |
35691 | + | |
35692 | +#ifndef CONFIG_LOCKDEP | |
35693 | +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo); | |
35694 | +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo); | |
35695 | +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo); | |
35696 | +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo); | |
35697 | +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo); | |
35698 | +#else | |
35699 | +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo) | |
35700 | +{ | |
35701 | + wkinfo->hlock = NULL; | |
35702 | + wkinfo->dont_check = 0; | |
35703 | +} | |
35704 | + | |
35705 | +/* | |
35706 | + * 1: matched | |
35707 | + * 0: unmatched | |
35708 | + */ | |
35709 | +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name) | |
35710 | +{ | |
35711 | + static DEFINE_SPINLOCK(spin); | |
35712 | + static struct { | |
35713 | + char *name; | |
35714 | + struct lock_class_key *key; | |
35715 | + } a[] = { | |
35716 | + { .name = "&sbinfo->si_rwsem" }, | |
35717 | + { .name = "&finfo->fi_rwsem" }, | |
35718 | + { .name = "&dinfo->di_rwsem" }, | |
35719 | + { .name = "&iinfo->ii_rwsem" } | |
35720 | + }; | |
35721 | + static int set; | |
35722 | + int i; | |
35723 | + | |
35724 | + /* lockless read from 'set.' see below */ | |
35725 | + if (set == ARRAY_SIZE(a)) { | |
35726 | + for (i = 0; i < ARRAY_SIZE(a); i++) | |
35727 | + if (a[i].key == key) | |
35728 | + goto match; | |
35729 | + goto unmatch; | |
35730 | + } | |
35731 | + | |
35732 | + spin_lock(&spin); | |
35733 | + if (set) | |
35734 | + for (i = 0; i < ARRAY_SIZE(a); i++) | |
35735 | + if (a[i].key == key) { | |
35736 | + spin_unlock(&spin); | |
35737 | + goto match; | |
35738 | + } | |
35739 | + for (i = 0; i < ARRAY_SIZE(a); i++) { | |
35740 | + if (a[i].key) { | |
35741 | + if (unlikely(a[i].key == key)) { /* rare but possible */ | |
35742 | + spin_unlock(&spin); | |
35743 | + goto match; | |
35744 | + } else | |
35745 | + continue; | |
35746 | + } | |
35747 | + if (strstr(a[i].name, name)) { | |
35748 | + /* | |
35749 | + * the order of these three lines is important for the | |
35750 | + * lockless read above. | |
35751 | + */ | |
35752 | + a[i].key = key; | |
35753 | + spin_unlock(&spin); | |
35754 | + set++; | |
35755 | + /* AuDbg("%d, %s\n", set, name); */ | |
35756 | + goto match; | |
35757 | + } | |
35758 | + } | |
35759 | + spin_unlock(&spin); | |
35760 | + goto unmatch; | |
35761 | + | |
35762 | +match: | |
35763 | + return 1; | |
35764 | +unmatch: | |
35765 | + return 0; | |
35766 | +} | |
35767 | + | |
35768 | +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo) | |
35769 | +{ | |
35770 | + int err, n; | |
35771 | + struct task_struct *curr; | |
35772 | + struct held_lock **hl, *held_locks, *p; | |
35773 | + | |
35774 | + err = 0; | |
35775 | + curr = current; | |
35776 | + wkinfo->dont_check = lockdep_recursing(curr); | |
35777 | + if (wkinfo->dont_check) | |
35778 | + goto out; | |
35779 | + n = curr->lockdep_depth; | |
35780 | + if (!n) | |
35781 | + goto out; | |
35782 | + | |
35783 | + err = -ENOMEM; | |
35784 | + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS); | |
35785 | + if (unlikely(!wkinfo->hlock)) | |
35786 | + goto out; | |
35787 | + | |
35788 | + err = 0; | |
35789 | +#if 0 | |
35790 | + if (0 && au_debug_test()) /* left for debugging */ | |
35791 | + lockdep_print_held_locks(curr); | |
35792 | +#endif | |
35793 | + held_locks = curr->held_locks; | |
35794 | + hl = wkinfo->hlock; | |
35795 | + while (n--) { | |
35796 | + p = held_locks++; | |
35797 | + if (au_wkq_lockdep_test(p->instance->key, p->instance->name)) | |
35798 | + *hl++ = p; | |
35799 | + } | |
35800 | + *hl = NULL; | |
35801 | + | |
35802 | +out: | |
35803 | + return err; | |
35804 | +} | |
35805 | + | |
35806 | +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo) | |
35807 | +{ | |
35808 | + kfree(wkinfo->hlock); | |
35809 | +} | |
35810 | + | |
35811 | +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo) | |
35812 | +{ | |
35813 | + struct held_lock *p, **hl = wkinfo->hlock; | |
35814 | + int subclass; | |
35815 | + | |
35816 | + if (wkinfo->dont_check) | |
35817 | + lockdep_off(); | |
35818 | + if (!hl) | |
35819 | + return; | |
35820 | + while ((p = *hl++)) { /* assignment */ | |
35821 | + subclass = lockdep_hlock_class(p)->subclass; | |
35822 | + /* AuDbg("%s, %d\n", p->instance->name, subclass); */ | |
35823 | + if (p->read) | |
35824 | + rwsem_acquire_read(p->instance, subclass, 0, | |
35825 | + /*p->acquire_ip*/_RET_IP_); | |
35826 | + else | |
35827 | + rwsem_acquire(p->instance, subclass, 0, | |
35828 | + /*p->acquire_ip*/_RET_IP_); | |
35829 | + } | |
35830 | +} | |
35831 | + | |
35832 | +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo) | |
35833 | +{ | |
35834 | + struct held_lock *p, **hl = wkinfo->hlock; | |
35835 | + | |
35836 | + if (wkinfo->dont_check) | |
35837 | + lockdep_on(); | |
35838 | + if (!hl) | |
35839 | + return; | |
35840 | + while ((p = *hl++)) /* assignment */ | |
35841 | + rwsem_release(p->instance, 0, /*p->acquire_ip*/_RET_IP_); | |
35842 | +} | |
35843 | +#endif | |
1facf9fc | 35844 | + |
1facf9fc | 35845 | +static void wkq_func(struct work_struct *wk) |
35846 | +{ | |
35847 | + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk); | |
35848 | + | |
2dfbb274 | 35849 | + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)); |
7f207e10 AM |
35850 | + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY); |
35851 | + | |
8b6a4947 | 35852 | + au_wkq_lockdep_pre(wkinfo); |
1facf9fc | 35853 | + wkinfo->func(wkinfo->args); |
8b6a4947 | 35854 | + au_wkq_lockdep_post(wkinfo); |
1facf9fc | 35855 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) |
35856 | + complete(wkinfo->comp); | |
35857 | + else { | |
7f207e10 | 35858 | + kobject_put(wkinfo->kobj); |
9dbd164d | 35859 | + module_put(THIS_MODULE); /* todo: ?? */ |
1c60b727 | 35860 | + kfree(wkinfo); |
1facf9fc | 35861 | + } |
35862 | +} | |
35863 | + | |
35864 | +/* | |
35865 | + * Since struct completion is large, try allocating it dynamically. | |
35866 | + */ | |
c2b27bf2 | 35867 | +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */ |
1facf9fc | 35868 | +#define AuWkqCompDeclare(name) struct completion *comp = NULL |
35869 | + | |
35870 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
35871 | +{ | |
35872 | + *comp = kmalloc(sizeof(**comp), GFP_NOFS); | |
35873 | + if (*comp) { | |
35874 | + init_completion(*comp); | |
35875 | + wkinfo->comp = *comp; | |
35876 | + return 0; | |
35877 | + } | |
35878 | + return -ENOMEM; | |
35879 | +} | |
35880 | + | |
35881 | +static void au_wkq_comp_free(struct completion *comp) | |
35882 | +{ | |
1c60b727 | 35883 | + kfree(comp); |
1facf9fc | 35884 | +} |
35885 | + | |
35886 | +#else | |
35887 | + | |
35888 | +/* no braces */ | |
35889 | +#define AuWkqCompDeclare(name) \ | |
35890 | + DECLARE_COMPLETION_ONSTACK(_ ## name); \ | |
35891 | + struct completion *comp = &_ ## name | |
35892 | + | |
35893 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
35894 | +{ | |
35895 | + wkinfo->comp = *comp; | |
35896 | + return 0; | |
35897 | +} | |
35898 | + | |
35899 | +static void au_wkq_comp_free(struct completion *comp __maybe_unused) | |
35900 | +{ | |
35901 | + /* empty */ | |
35902 | +} | |
35903 | +#endif /* 4KSTACKS */ | |
35904 | + | |
53392da6 | 35905 | +static void au_wkq_run(struct au_wkinfo *wkinfo) |
1facf9fc | 35906 | +{ |
53392da6 AM |
35907 | + if (au_ftest_wkq(wkinfo->flags, NEST)) { |
35908 | + if (au_wkq_test()) { | |
38d290e6 JR |
35909 | + AuWarn1("wkq from wkq, unless silly-rename on NFS," |
35910 | + " due to a dead dir by UDBA?\n"); | |
53392da6 AM |
35911 | + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT)); |
35912 | + } | |
35913 | + } else | |
35914 | + au_dbg_verify_kthread(); | |
35915 | + | |
35916 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) { | |
a1f66529 | 35917 | + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func); |
9dbd164d | 35918 | + queue_work(au_wkq, &wkinfo->wk); |
4a4d8108 AM |
35919 | + } else { |
35920 | + INIT_WORK(&wkinfo->wk, wkq_func); | |
35921 | + schedule_work(&wkinfo->wk); | |
35922 | + } | |
1facf9fc | 35923 | +} |
35924 | + | |
7f207e10 AM |
35925 | +/* |
35926 | + * Be careful. It is easy to make deadlock happen. | |
35927 | + * processA: lock, wkq and wait | |
35928 | + * processB: wkq and wait, lock in wkq | |
35929 | + * --> deadlock | |
35930 | + */ | |
b752ccd1 | 35931 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args) |
1facf9fc | 35932 | +{ |
35933 | + int err; | |
35934 | + AuWkqCompDeclare(comp); | |
35935 | + struct au_wkinfo wkinfo = { | |
b752ccd1 | 35936 | + .flags = flags, |
1facf9fc | 35937 | + .func = func, |
35938 | + .args = args | |
35939 | + }; | |
35940 | + | |
35941 | + err = au_wkq_comp_alloc(&wkinfo, &comp); | |
8b6a4947 AM |
35942 | + if (unlikely(err)) |
35943 | + goto out; | |
35944 | + err = au_wkq_lockdep_alloc(&wkinfo); | |
35945 | + if (unlikely(err)) | |
35946 | + goto out_comp; | |
1facf9fc | 35947 | + if (!err) { |
53392da6 | 35948 | + au_wkq_run(&wkinfo); |
1facf9fc | 35949 | + /* no timeout, no interrupt */ |
35950 | + wait_for_completion(wkinfo.comp); | |
1facf9fc | 35951 | + } |
8b6a4947 | 35952 | + au_wkq_lockdep_free(&wkinfo); |
1facf9fc | 35953 | + |
8b6a4947 AM |
35954 | +out_comp: |
35955 | + au_wkq_comp_free(comp); | |
35956 | +out: | |
35957 | + destroy_work_on_stack(&wkinfo.wk); | |
1facf9fc | 35958 | + return err; |
1facf9fc | 35959 | +} |
35960 | + | |
027c5e7a AM |
35961 | +/* |
35962 | + * Note: dget/dput() in func for aufs dentries are not supported. It will be a | |
35963 | + * problem in a concurrent umounting. | |
35964 | + */ | |
53392da6 AM |
35965 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
35966 | + unsigned int flags) | |
1facf9fc | 35967 | +{ |
35968 | + int err; | |
35969 | + struct au_wkinfo *wkinfo; | |
35970 | + | |
f0c0a007 | 35971 | + atomic_inc(&au_sbi(sb)->si_nowait.nw_len); |
1facf9fc | 35972 | + |
35973 | + /* | |
35974 | + * wkq_func() must free this wkinfo. | |
35975 | + * it highly depends upon the implementation of workqueue. | |
35976 | + */ | |
35977 | + err = 0; | |
35978 | + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS); | |
35979 | + if (wkinfo) { | |
7f207e10 | 35980 | + wkinfo->kobj = &au_sbi(sb)->si_kobj; |
53392da6 | 35981 | + wkinfo->flags = flags & ~AuWkq_WAIT; |
1facf9fc | 35982 | + wkinfo->func = func; |
35983 | + wkinfo->args = args; | |
35984 | + wkinfo->comp = NULL; | |
8b6a4947 | 35985 | + au_wkq_lockdep_init(wkinfo); |
7f207e10 | 35986 | + kobject_get(wkinfo->kobj); |
9dbd164d | 35987 | + __module_get(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 35988 | + |
53392da6 | 35989 | + au_wkq_run(wkinfo); |
1facf9fc | 35990 | + } else { |
35991 | + err = -ENOMEM; | |
e49829fe | 35992 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 35993 | + } |
35994 | + | |
35995 | + return err; | |
35996 | +} | |
35997 | + | |
35998 | +/* ---------------------------------------------------------------------- */ | |
35999 | + | |
36000 | +void au_nwt_init(struct au_nowait_tasks *nwt) | |
36001 | +{ | |
f0c0a007 AM |
36002 | + atomic_set(&nwt->nw_len, 0); |
36003 | + /* smp_mb(); */ /* atomic_set */ | |
1facf9fc | 36004 | + init_waitqueue_head(&nwt->nw_wq); |
36005 | +} | |
36006 | + | |
36007 | +void au_wkq_fin(void) | |
36008 | +{ | |
9dbd164d | 36009 | + destroy_workqueue(au_wkq); |
1facf9fc | 36010 | +} |
36011 | + | |
36012 | +int __init au_wkq_init(void) | |
36013 | +{ | |
9dbd164d | 36014 | + int err; |
b752ccd1 AM |
36015 | + |
36016 | + err = 0; | |
86dc4139 | 36017 | + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE); |
9dbd164d AM |
36018 | + if (IS_ERR(au_wkq)) |
36019 | + err = PTR_ERR(au_wkq); | |
36020 | + else if (!au_wkq) | |
36021 | + err = -ENOMEM; | |
b752ccd1 AM |
36022 | + |
36023 | + return err; | |
1facf9fc | 36024 | +} |
7f207e10 AM |
36025 | diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h |
36026 | --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 36027 | +++ linux/fs/aufs/wkq.h 2018-01-29 07:56:20.063325368 +0100 |
f0c0a007 | 36028 | @@ -0,0 +1,93 @@ |
1facf9fc | 36029 | +/* |
a2654f78 | 36030 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 36031 | + * |
36032 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36033 | + * it under the terms of the GNU General Public License as published by | |
36034 | + * the Free Software Foundation; either version 2 of the License, or | |
36035 | + * (at your option) any later version. | |
dece6358 AM |
36036 | + * |
36037 | + * This program is distributed in the hope that it will be useful, | |
36038 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36039 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36040 | + * GNU General Public License for more details. | |
36041 | + * | |
36042 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 36043 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 36044 | + */ |
36045 | + | |
36046 | +/* | |
36047 | + * workqueue for asynchronous/super-io operations | |
36048 | + * todo: try new credentials management scheme | |
36049 | + */ | |
36050 | + | |
36051 | +#ifndef __AUFS_WKQ_H__ | |
36052 | +#define __AUFS_WKQ_H__ | |
36053 | + | |
36054 | +#ifdef __KERNEL__ | |
36055 | + | |
8b6a4947 | 36056 | +#include <linux/wait.h> |
5afbbe0d | 36057 | + |
dece6358 AM |
36058 | +struct super_block; |
36059 | + | |
1facf9fc | 36060 | +/* ---------------------------------------------------------------------- */ |
36061 | + | |
36062 | +/* | |
36063 | + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue | |
36064 | + */ | |
36065 | +struct au_nowait_tasks { | |
f0c0a007 | 36066 | + atomic_t nw_len; |
1facf9fc | 36067 | + wait_queue_head_t nw_wq; |
36068 | +}; | |
36069 | + | |
36070 | +/* ---------------------------------------------------------------------- */ | |
36071 | + | |
36072 | +typedef void (*au_wkq_func_t)(void *args); | |
36073 | + | |
36074 | +/* wkq flags */ | |
36075 | +#define AuWkq_WAIT 1 | |
9dbd164d | 36076 | +#define AuWkq_NEST (1 << 1) |
1facf9fc | 36077 | +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name) |
7f207e10 AM |
36078 | +#define au_fset_wkq(flags, name) \ |
36079 | + do { (flags) |= AuWkq_##name; } while (0) | |
36080 | +#define au_fclr_wkq(flags, name) \ | |
36081 | + do { (flags) &= ~AuWkq_##name; } while (0) | |
1facf9fc | 36082 | + |
9dbd164d AM |
36083 | +#ifndef CONFIG_AUFS_HNOTIFY |
36084 | +#undef AuWkq_NEST | |
36085 | +#define AuWkq_NEST 0 | |
36086 | +#endif | |
36087 | + | |
1facf9fc | 36088 | +/* wkq.c */ |
b752ccd1 | 36089 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args); |
53392da6 AM |
36090 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
36091 | + unsigned int flags); | |
1facf9fc | 36092 | +void au_nwt_init(struct au_nowait_tasks *nwt); |
36093 | +int __init au_wkq_init(void); | |
36094 | +void au_wkq_fin(void); | |
36095 | + | |
36096 | +/* ---------------------------------------------------------------------- */ | |
36097 | + | |
53392da6 AM |
36098 | +static inline int au_wkq_test(void) |
36099 | +{ | |
36100 | + return current->flags & PF_WQ_WORKER; | |
36101 | +} | |
36102 | + | |
b752ccd1 | 36103 | +static inline int au_wkq_wait(au_wkq_func_t func, void *args) |
1facf9fc | 36104 | +{ |
b752ccd1 | 36105 | + return au_wkq_do_wait(AuWkq_WAIT, func, args); |
1facf9fc | 36106 | +} |
36107 | + | |
36108 | +static inline void au_nwt_done(struct au_nowait_tasks *nwt) | |
36109 | +{ | |
f0c0a007 | 36110 | + if (atomic_dec_and_test(&nwt->nw_len)) |
1facf9fc | 36111 | + wake_up_all(&nwt->nw_wq); |
36112 | +} | |
36113 | + | |
36114 | +static inline int au_nwt_flush(struct au_nowait_tasks *nwt) | |
36115 | +{ | |
f0c0a007 | 36116 | + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len)); |
1facf9fc | 36117 | + return 0; |
36118 | +} | |
36119 | + | |
36120 | +#endif /* __KERNEL__ */ | |
36121 | +#endif /* __AUFS_WKQ_H__ */ | |
c1595e42 JR |
36122 | diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c |
36123 | --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 36124 | +++ linux/fs/aufs/xattr.c 2018-01-29 07:56:20.063325368 +0100 |
8b6a4947 | 36125 | @@ -0,0 +1,355 @@ |
c1595e42 | 36126 | +/* |
a2654f78 | 36127 | + * Copyright (C) 2014-2017 Junjiro R. Okajima |
c1595e42 JR |
36128 | + * |
36129 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36130 | + * it under the terms of the GNU General Public License as published by | |
36131 | + * the Free Software Foundation; either version 2 of the License, or | |
36132 | + * (at your option) any later version. | |
36133 | + * | |
36134 | + * This program is distributed in the hope that it will be useful, | |
36135 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36136 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36137 | + * GNU General Public License for more details. | |
36138 | + * | |
36139 | + * You should have received a copy of the GNU General Public License | |
36140 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
36141 | + */ | |
36142 | + | |
36143 | +/* | |
36144 | + * handling xattr functions | |
36145 | + */ | |
36146 | + | |
a2654f78 AM |
36147 | +#include <linux/fs.h> |
36148 | +#include <linux/posix_acl_xattr.h> | |
c1595e42 JR |
36149 | +#include <linux/xattr.h> |
36150 | +#include "aufs.h" | |
36151 | + | |
36152 | +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags) | |
36153 | +{ | |
36154 | + if (!ignore_flags) | |
36155 | + goto out; | |
36156 | + switch (err) { | |
36157 | + case -ENOMEM: | |
36158 | + case -EDQUOT: | |
36159 | + goto out; | |
36160 | + } | |
36161 | + | |
36162 | + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) { | |
36163 | + err = 0; | |
36164 | + goto out; | |
36165 | + } | |
36166 | + | |
36167 | +#define cmp(brattr, prefix) do { \ | |
36168 | + if (!strncmp(name, XATTR_##prefix##_PREFIX, \ | |
36169 | + XATTR_##prefix##_PREFIX_LEN)) { \ | |
36170 | + if (ignore_flags & AuBrAttr_ICEX_##brattr) \ | |
36171 | + err = 0; \ | |
36172 | + goto out; \ | |
36173 | + } \ | |
36174 | + } while (0) | |
36175 | + | |
36176 | + cmp(SEC, SECURITY); | |
36177 | + cmp(SYS, SYSTEM); | |
36178 | + cmp(TR, TRUSTED); | |
36179 | + cmp(USR, USER); | |
36180 | +#undef cmp | |
36181 | + | |
36182 | + if (ignore_flags & AuBrAttr_ICEX_OTH) | |
36183 | + err = 0; | |
36184 | + | |
36185 | +out: | |
36186 | + return err; | |
36187 | +} | |
36188 | + | |
36189 | +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1; | |
36190 | + | |
36191 | +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe AM |
36192 | + char *name, char **buf, unsigned int ignore_flags, |
36193 | + unsigned int verbose) | |
c1595e42 JR |
36194 | +{ |
36195 | + int err; | |
36196 | + ssize_t ssz; | |
36197 | + struct inode *h_idst; | |
36198 | + | |
36199 | + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS); | |
36200 | + err = ssz; | |
36201 | + if (unlikely(err <= 0)) { | |
c1595e42 JR |
36202 | + if (err == -ENODATA |
36203 | + || (err == -EOPNOTSUPP | |
b912730e | 36204 | + && ((ignore_flags & au_xattr_out_of_list) |
5527c038 | 36205 | + || (au_test_nfs_noacl(d_inode(h_src)) |
b912730e AM |
36206 | + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) |
36207 | + || !strcmp(name, | |
36208 | + XATTR_NAME_POSIX_ACL_DEFAULT)))) | |
36209 | + )) | |
c1595e42 | 36210 | + err = 0; |
b912730e AM |
36211 | + if (err && (verbose || au_debug_test())) |
36212 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
36213 | + goto out; |
36214 | + } | |
36215 | + | |
36216 | + /* unlock it temporary */ | |
5527c038 | 36217 | + h_idst = d_inode(h_dst); |
febd17d6 | 36218 | + inode_unlock(h_idst); |
c1595e42 | 36219 | + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0); |
febd17d6 | 36220 | + inode_lock_nested(h_idst, AuLsc_I_CHILD2); |
c1595e42 | 36221 | + if (unlikely(err)) { |
7e9cd9fe AM |
36222 | + if (verbose || au_debug_test()) |
36223 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
36224 | + err = au_xattr_ignore(err, name, ignore_flags); |
36225 | + } | |
36226 | + | |
36227 | +out: | |
36228 | + return err; | |
36229 | +} | |
36230 | + | |
7e9cd9fe AM |
36231 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
36232 | + unsigned int verbose) | |
c1595e42 JR |
36233 | +{ |
36234 | + int err, unlocked, acl_access, acl_default; | |
36235 | + ssize_t ssz; | |
36236 | + struct inode *h_isrc, *h_idst; | |
36237 | + char *value, *p, *o, *e; | |
36238 | + | |
36239 | + /* try stopping to update the source inode while we are referencing */ | |
7e9cd9fe | 36240 | + /* there should not be the parent-child relationship between them */ |
5527c038 JR |
36241 | + h_isrc = d_inode(h_src); |
36242 | + h_idst = d_inode(h_dst); | |
febd17d6 | 36243 | + inode_unlock(h_idst); |
3c1bdaff | 36244 | + vfsub_inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD); |
febd17d6 | 36245 | + inode_lock_nested(h_idst, AuLsc_I_CHILD2); |
c1595e42 JR |
36246 | + unlocked = 0; |
36247 | + | |
36248 | + /* some filesystems don't list POSIX ACL, for example tmpfs */ | |
36249 | + ssz = vfs_listxattr(h_src, NULL, 0); | |
36250 | + err = ssz; | |
36251 | + if (unlikely(err < 0)) { | |
36252 | + AuTraceErr(err); | |
36253 | + if (err == -ENODATA | |
36254 | + || err == -EOPNOTSUPP) | |
36255 | + err = 0; /* ignore */ | |
36256 | + goto out; | |
36257 | + } | |
36258 | + | |
36259 | + err = 0; | |
36260 | + p = NULL; | |
36261 | + o = NULL; | |
36262 | + if (ssz) { | |
36263 | + err = -ENOMEM; | |
36264 | + p = kmalloc(ssz, GFP_NOFS); | |
36265 | + o = p; | |
36266 | + if (unlikely(!p)) | |
36267 | + goto out; | |
36268 | + err = vfs_listxattr(h_src, p, ssz); | |
36269 | + } | |
3c1bdaff | 36270 | + inode_unlock_shared(h_isrc); |
c1595e42 JR |
36271 | + unlocked = 1; |
36272 | + AuDbg("err %d, ssz %zd\n", err, ssz); | |
36273 | + if (unlikely(err < 0)) | |
36274 | + goto out_free; | |
36275 | + | |
36276 | + err = 0; | |
36277 | + e = p + ssz; | |
36278 | + value = NULL; | |
36279 | + acl_access = 0; | |
36280 | + acl_default = 0; | |
36281 | + while (!err && p < e) { | |
36282 | + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS, | |
36283 | + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1); | |
36284 | + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT, | |
36285 | + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) | |
36286 | + - 1); | |
7e9cd9fe AM |
36287 | + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags, |
36288 | + verbose); | |
c1595e42 JR |
36289 | + p += strlen(p) + 1; |
36290 | + } | |
36291 | + AuTraceErr(err); | |
36292 | + ignore_flags |= au_xattr_out_of_list; | |
36293 | + if (!err && !acl_access) { | |
36294 | + err = au_do_cpup_xattr(h_dst, h_src, | |
36295 | + XATTR_NAME_POSIX_ACL_ACCESS, &value, | |
7e9cd9fe | 36296 | + ignore_flags, verbose); |
c1595e42 JR |
36297 | + AuTraceErr(err); |
36298 | + } | |
36299 | + if (!err && !acl_default) { | |
36300 | + err = au_do_cpup_xattr(h_dst, h_src, | |
36301 | + XATTR_NAME_POSIX_ACL_DEFAULT, &value, | |
7e9cd9fe | 36302 | + ignore_flags, verbose); |
c1595e42 JR |
36303 | + AuTraceErr(err); |
36304 | + } | |
36305 | + | |
8b6a4947 | 36306 | + kfree(value); |
c1595e42 JR |
36307 | + |
36308 | +out_free: | |
8b6a4947 | 36309 | + kfree(o); |
c1595e42 JR |
36310 | +out: |
36311 | + if (!unlocked) | |
3c1bdaff | 36312 | + inode_unlock_shared(h_isrc); |
c1595e42 JR |
36313 | + AuTraceErr(err); |
36314 | + return err; | |
36315 | +} | |
36316 | + | |
36317 | +/* ---------------------------------------------------------------------- */ | |
36318 | + | |
a2654f78 AM |
36319 | +static int au_smack_reentering(struct super_block *sb) |
36320 | +{ | |
36321 | +#if IS_ENABLED(CONFIG_SECURITY_SMACK) | |
36322 | + /* | |
36323 | + * as a part of lookup, smack_d_instantiate() is called, and it calls | |
36324 | + * i_op->getxattr(). ouch. | |
36325 | + */ | |
36326 | + return si_pid_test(sb); | |
36327 | +#else | |
36328 | + return 0; | |
36329 | +#endif | |
36330 | +} | |
36331 | + | |
c1595e42 JR |
36332 | +enum { |
36333 | + AU_XATTR_LIST, | |
36334 | + AU_XATTR_GET | |
36335 | +}; | |
36336 | + | |
36337 | +struct au_lgxattr { | |
36338 | + int type; | |
36339 | + union { | |
36340 | + struct { | |
36341 | + char *list; | |
36342 | + size_t size; | |
36343 | + } list; | |
36344 | + struct { | |
36345 | + const char *name; | |
36346 | + void *value; | |
36347 | + size_t size; | |
36348 | + } get; | |
36349 | + } u; | |
36350 | +}; | |
36351 | + | |
36352 | +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg) | |
36353 | +{ | |
36354 | + ssize_t err; | |
a2654f78 | 36355 | + int reenter; |
c1595e42 JR |
36356 | + struct path h_path; |
36357 | + struct super_block *sb; | |
36358 | + | |
36359 | + sb = dentry->d_sb; | |
a2654f78 AM |
36360 | + reenter = au_smack_reentering(sb); |
36361 | + if (!reenter) { | |
36362 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
36363 | + if (unlikely(err)) | |
36364 | + goto out; | |
36365 | + } | |
36366 | + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter); | |
c1595e42 JR |
36367 | + if (unlikely(err)) |
36368 | + goto out_si; | |
36369 | + if (unlikely(!h_path.dentry)) | |
36370 | + /* illegally overlapped or something */ | |
36371 | + goto out_di; /* pretending success */ | |
36372 | + | |
36373 | + /* always topmost entry only */ | |
36374 | + switch (arg->type) { | |
36375 | + case AU_XATTR_LIST: | |
36376 | + err = vfs_listxattr(h_path.dentry, | |
36377 | + arg->u.list.list, arg->u.list.size); | |
36378 | + break; | |
36379 | + case AU_XATTR_GET: | |
5afbbe0d | 36380 | + AuDebugOn(d_is_negative(h_path.dentry)); |
c1595e42 JR |
36381 | + err = vfs_getxattr(h_path.dentry, |
36382 | + arg->u.get.name, arg->u.get.value, | |
36383 | + arg->u.get.size); | |
36384 | + break; | |
36385 | + } | |
36386 | + | |
36387 | +out_di: | |
a2654f78 AM |
36388 | + if (!reenter) |
36389 | + di_read_unlock(dentry, AuLock_IR); | |
c1595e42 | 36390 | +out_si: |
a2654f78 AM |
36391 | + if (!reenter) |
36392 | + si_read_unlock(sb); | |
c1595e42 JR |
36393 | +out: |
36394 | + AuTraceErr(err); | |
36395 | + return err; | |
36396 | +} | |
36397 | + | |
36398 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size) | |
36399 | +{ | |
36400 | + struct au_lgxattr arg = { | |
36401 | + .type = AU_XATTR_LIST, | |
36402 | + .u.list = { | |
36403 | + .list = list, | |
36404 | + .size = size | |
36405 | + }, | |
36406 | + }; | |
36407 | + | |
36408 | + return au_lgxattr(dentry, &arg); | |
36409 | +} | |
36410 | + | |
f2c43d5f AM |
36411 | +static ssize_t au_getxattr(struct dentry *dentry, |
36412 | + struct inode *inode __maybe_unused, | |
36413 | + const char *name, void *value, size_t size) | |
c1595e42 JR |
36414 | +{ |
36415 | + struct au_lgxattr arg = { | |
36416 | + .type = AU_XATTR_GET, | |
36417 | + .u.get = { | |
36418 | + .name = name, | |
36419 | + .value = value, | |
36420 | + .size = size | |
36421 | + }, | |
36422 | + }; | |
36423 | + | |
36424 | + return au_lgxattr(dentry, &arg); | |
36425 | +} | |
36426 | + | |
f2c43d5f AM |
36427 | +static int au_setxattr(struct dentry *dentry, struct inode *inode, |
36428 | + const char *name, const void *value, size_t size, | |
36429 | + int flags) | |
c1595e42 | 36430 | +{ |
f2c43d5f | 36431 | + struct au_sxattr arg = { |
c1595e42 JR |
36432 | + .type = AU_XATTR_SET, |
36433 | + .u.set = { | |
36434 | + .name = name, | |
36435 | + .value = value, | |
36436 | + .size = size, | |
36437 | + .flags = flags | |
36438 | + }, | |
36439 | + }; | |
36440 | + | |
f2c43d5f | 36441 | + return au_sxattr(dentry, inode, &arg); |
c1595e42 JR |
36442 | +} |
36443 | + | |
36444 | +/* ---------------------------------------------------------------------- */ | |
36445 | + | |
f2c43d5f AM |
36446 | +static int au_xattr_get(const struct xattr_handler *handler, |
36447 | + struct dentry *dentry, struct inode *inode, | |
36448 | + const char *name, void *buffer, size_t size) | |
c1595e42 | 36449 | +{ |
f2c43d5f | 36450 | + return au_getxattr(dentry, inode, name, buffer, size); |
c1595e42 JR |
36451 | +} |
36452 | + | |
f2c43d5f AM |
36453 | +static int au_xattr_set(const struct xattr_handler *handler, |
36454 | + struct dentry *dentry, struct inode *inode, | |
36455 | + const char *name, const void *value, size_t size, | |
36456 | + int flags) | |
c1595e42 | 36457 | +{ |
f2c43d5f | 36458 | + return au_setxattr(dentry, inode, name, value, size, flags); |
c1595e42 JR |
36459 | +} |
36460 | + | |
36461 | +static const struct xattr_handler au_xattr_handler = { | |
f2c43d5f AM |
36462 | + .name = "", |
36463 | + .prefix = "", | |
c1595e42 JR |
36464 | + .get = au_xattr_get, |
36465 | + .set = au_xattr_set | |
c1595e42 JR |
36466 | +}; |
36467 | + | |
36468 | +static const struct xattr_handler *au_xattr_handlers[] = { | |
a2654f78 AM |
36469 | +#ifdef CONFIG_FS_POSIX_ACL |
36470 | + &posix_acl_access_xattr_handler, | |
36471 | + &posix_acl_default_xattr_handler, | |
36472 | +#endif | |
36473 | + &au_xattr_handler, /* must be last */ | |
f2c43d5f | 36474 | + NULL |
c1595e42 JR |
36475 | +}; |
36476 | + | |
36477 | +void au_xattr_init(struct super_block *sb) | |
36478 | +{ | |
f2c43d5f | 36479 | + sb->s_xattr = au_xattr_handlers; |
c1595e42 | 36480 | +} |
7f207e10 AM |
36481 | diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c |
36482 | --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 36483 | +++ linux/fs/aufs/xino.c 2018-01-29 07:56:20.063325368 +0100 |
8b6a4947 | 36484 | @@ -0,0 +1,1418 @@ |
1facf9fc | 36485 | +/* |
a2654f78 | 36486 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
1facf9fc | 36487 | + * |
36488 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36489 | + * it under the terms of the GNU General Public License as published by | |
36490 | + * the Free Software Foundation; either version 2 of the License, or | |
36491 | + * (at your option) any later version. | |
dece6358 AM |
36492 | + * |
36493 | + * This program is distributed in the hope that it will be useful, | |
36494 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36495 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36496 | + * GNU General Public License for more details. | |
36497 | + * | |
36498 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 36499 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 36500 | + */ |
36501 | + | |
36502 | +/* | |
36503 | + * external inode number translation table and bitmap | |
36504 | + */ | |
36505 | + | |
36506 | +#include <linux/seq_file.h> | |
392086de | 36507 | +#include <linux/statfs.h> |
1facf9fc | 36508 | +#include "aufs.h" |
36509 | + | |
9dbd164d | 36510 | +/* todo: unnecessary to support mmap_sem since kernel-space? */ |
5527c038 | 36511 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size, |
1facf9fc | 36512 | + loff_t *pos) |
36513 | +{ | |
36514 | + ssize_t err; | |
36515 | + mm_segment_t oldfs; | |
b752ccd1 AM |
36516 | + union { |
36517 | + void *k; | |
36518 | + char __user *u; | |
36519 | + } buf; | |
1facf9fc | 36520 | + |
b752ccd1 | 36521 | + buf.k = kbuf; |
1facf9fc | 36522 | + oldfs = get_fs(); |
36523 | + set_fs(KERNEL_DS); | |
36524 | + do { | |
36525 | + /* todo: signal_pending? */ | |
b752ccd1 | 36526 | + err = func(file, buf.u, size, pos); |
1facf9fc | 36527 | + } while (err == -EAGAIN || err == -EINTR); |
36528 | + set_fs(oldfs); | |
36529 | + | |
36530 | +#if 0 /* reserved for future use */ | |
36531 | + if (err > 0) | |
2000de60 | 36532 | + fsnotify_access(file->f_path.dentry); |
1facf9fc | 36533 | +#endif |
36534 | + | |
36535 | + return err; | |
36536 | +} | |
36537 | + | |
36538 | +/* ---------------------------------------------------------------------- */ | |
36539 | + | |
be52b249 AM |
36540 | +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf, |
36541 | + size_t size, loff_t *pos); | |
36542 | + | |
5527c038 | 36543 | +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf, |
1facf9fc | 36544 | + size_t size, loff_t *pos) |
36545 | +{ | |
36546 | + ssize_t err; | |
36547 | + mm_segment_t oldfs; | |
b752ccd1 AM |
36548 | + union { |
36549 | + void *k; | |
36550 | + const char __user *u; | |
36551 | + } buf; | |
be52b249 AM |
36552 | + int i; |
36553 | + const int prevent_endless = 10; | |
1facf9fc | 36554 | + |
be52b249 | 36555 | + i = 0; |
b752ccd1 | 36556 | + buf.k = kbuf; |
1facf9fc | 36557 | + oldfs = get_fs(); |
36558 | + set_fs(KERNEL_DS); | |
1facf9fc | 36559 | + do { |
b752ccd1 | 36560 | + err = func(file, buf.u, size, pos); |
be52b249 AM |
36561 | + if (err == -EINTR |
36562 | + && !au_wkq_test() | |
36563 | + && fatal_signal_pending(current)) { | |
36564 | + set_fs(oldfs); | |
36565 | + err = xino_fwrite_wkq(func, file, kbuf, size, pos); | |
36566 | + BUG_ON(err == -EINTR); | |
36567 | + oldfs = get_fs(); | |
36568 | + set_fs(KERNEL_DS); | |
36569 | + } | |
36570 | + } while (i++ < prevent_endless | |
36571 | + && (err == -EAGAIN || err == -EINTR)); | |
1facf9fc | 36572 | + set_fs(oldfs); |
36573 | + | |
36574 | +#if 0 /* reserved for future use */ | |
36575 | + if (err > 0) | |
2000de60 | 36576 | + fsnotify_modify(file->f_path.dentry); |
1facf9fc | 36577 | +#endif |
36578 | + | |
36579 | + return err; | |
36580 | +} | |
36581 | + | |
36582 | +struct do_xino_fwrite_args { | |
36583 | + ssize_t *errp; | |
5527c038 | 36584 | + vfs_writef_t func; |
1facf9fc | 36585 | + struct file *file; |
36586 | + void *buf; | |
36587 | + size_t size; | |
36588 | + loff_t *pos; | |
36589 | +}; | |
36590 | + | |
36591 | +static void call_do_xino_fwrite(void *args) | |
36592 | +{ | |
36593 | + struct do_xino_fwrite_args *a = args; | |
36594 | + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos); | |
36595 | +} | |
36596 | + | |
be52b249 AM |
36597 | +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf, |
36598 | + size_t size, loff_t *pos) | |
36599 | +{ | |
36600 | + ssize_t err; | |
36601 | + int wkq_err; | |
36602 | + struct do_xino_fwrite_args args = { | |
36603 | + .errp = &err, | |
36604 | + .func = func, | |
36605 | + .file = file, | |
36606 | + .buf = buf, | |
36607 | + .size = size, | |
36608 | + .pos = pos | |
36609 | + }; | |
36610 | + | |
36611 | + /* | |
36612 | + * it breaks RLIMIT_FSIZE and normal user's limit, | |
36613 | + * users should care about quota and real 'filesystem full.' | |
36614 | + */ | |
36615 | + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args); | |
36616 | + if (unlikely(wkq_err)) | |
36617 | + err = wkq_err; | |
36618 | + | |
36619 | + return err; | |
36620 | +} | |
36621 | + | |
5527c038 JR |
36622 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
36623 | + size_t size, loff_t *pos) | |
1facf9fc | 36624 | +{ |
36625 | + ssize_t err; | |
36626 | + | |
b752ccd1 AM |
36627 | + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) { |
36628 | + lockdep_off(); | |
36629 | + err = do_xino_fwrite(func, file, buf, size, pos); | |
36630 | + lockdep_on(); | |
8b6a4947 AM |
36631 | + } else { |
36632 | + lockdep_off(); | |
be52b249 | 36633 | + err = xino_fwrite_wkq(func, file, buf, size, pos); |
8b6a4947 AM |
36634 | + lockdep_on(); |
36635 | + } | |
1facf9fc | 36636 | + |
36637 | + return err; | |
36638 | +} | |
36639 | + | |
36640 | +/* ---------------------------------------------------------------------- */ | |
36641 | + | |
36642 | +/* | |
36643 | + * create a new xinofile at the same place/path as @base_file. | |
36644 | + */ | |
36645 | +struct file *au_xino_create2(struct file *base_file, struct file *copy_src) | |
36646 | +{ | |
36647 | + struct file *file; | |
4a4d8108 | 36648 | + struct dentry *base, *parent; |
523b37e3 | 36649 | + struct inode *dir, *delegated; |
1facf9fc | 36650 | + struct qstr *name; |
1308ab2a | 36651 | + struct path path; |
4a4d8108 | 36652 | + int err; |
1facf9fc | 36653 | + |
2000de60 | 36654 | + base = base_file->f_path.dentry; |
1facf9fc | 36655 | + parent = base->d_parent; /* dir inode is locked */ |
5527c038 | 36656 | + dir = d_inode(parent); |
1facf9fc | 36657 | + IMustLock(dir); |
36658 | + | |
36659 | + file = ERR_PTR(-EINVAL); | |
36660 | + name = &base->d_name; | |
4a4d8108 AM |
36661 | + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len); |
36662 | + if (IS_ERR(path.dentry)) { | |
36663 | + file = (void *)path.dentry; | |
523b37e3 AM |
36664 | + pr_err("%pd lookup err %ld\n", |
36665 | + base, PTR_ERR(path.dentry)); | |
1facf9fc | 36666 | + goto out; |
36667 | + } | |
36668 | + | |
36669 | + /* no need to mnt_want_write() since we call dentry_open() later */ | |
4a4d8108 | 36670 | + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL); |
1facf9fc | 36671 | + if (unlikely(err)) { |
36672 | + file = ERR_PTR(err); | |
523b37e3 | 36673 | + pr_err("%pd create err %d\n", base, err); |
1facf9fc | 36674 | + goto out_dput; |
36675 | + } | |
36676 | + | |
c06a8ce3 | 36677 | + path.mnt = base_file->f_path.mnt; |
4a4d8108 | 36678 | + file = vfsub_dentry_open(&path, |
7f207e10 | 36679 | + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 36680 | + /* | __FMODE_NONOTIFY */); |
1facf9fc | 36681 | + if (IS_ERR(file)) { |
523b37e3 | 36682 | + pr_err("%pd open err %ld\n", base, PTR_ERR(file)); |
1facf9fc | 36683 | + goto out_dput; |
36684 | + } | |
36685 | + | |
523b37e3 AM |
36686 | + delegated = NULL; |
36687 | + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0); | |
36688 | + if (unlikely(err == -EWOULDBLOCK)) { | |
36689 | + pr_warn("cannot retry for NFSv4 delegation" | |
36690 | + " for an internal unlink\n"); | |
36691 | + iput(delegated); | |
36692 | + } | |
1facf9fc | 36693 | + if (unlikely(err)) { |
523b37e3 | 36694 | + pr_err("%pd unlink err %d\n", base, err); |
1facf9fc | 36695 | + goto out_fput; |
36696 | + } | |
36697 | + | |
36698 | + if (copy_src) { | |
36699 | + /* no one can touch copy_src xino */ | |
c06a8ce3 | 36700 | + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src)); |
1facf9fc | 36701 | + if (unlikely(err)) { |
523b37e3 | 36702 | + pr_err("%pd copy err %d\n", base, err); |
1facf9fc | 36703 | + goto out_fput; |
36704 | + } | |
36705 | + } | |
36706 | + goto out_dput; /* success */ | |
36707 | + | |
4f0767ce | 36708 | +out_fput: |
1facf9fc | 36709 | + fput(file); |
36710 | + file = ERR_PTR(err); | |
4f0767ce | 36711 | +out_dput: |
4a4d8108 | 36712 | + dput(path.dentry); |
4f0767ce | 36713 | +out: |
1facf9fc | 36714 | + return file; |
36715 | +} | |
36716 | + | |
36717 | +struct au_xino_lock_dir { | |
36718 | + struct au_hinode *hdir; | |
36719 | + struct dentry *parent; | |
febd17d6 | 36720 | + struct inode *dir; |
1facf9fc | 36721 | +}; |
36722 | + | |
36723 | +static void au_xino_lock_dir(struct super_block *sb, struct file *xino, | |
36724 | + struct au_xino_lock_dir *ldir) | |
36725 | +{ | |
36726 | + aufs_bindex_t brid, bindex; | |
36727 | + | |
36728 | + ldir->hdir = NULL; | |
36729 | + bindex = -1; | |
36730 | + brid = au_xino_brid(sb); | |
36731 | + if (brid >= 0) | |
36732 | + bindex = au_br_index(sb, brid); | |
36733 | + if (bindex >= 0) { | |
5527c038 | 36734 | + ldir->hdir = au_hi(d_inode(sb->s_root), bindex); |
5afbbe0d | 36735 | + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT); |
1facf9fc | 36736 | + } else { |
2000de60 | 36737 | + ldir->parent = dget_parent(xino->f_path.dentry); |
febd17d6 JR |
36738 | + ldir->dir = d_inode(ldir->parent); |
36739 | + inode_lock_nested(ldir->dir, AuLsc_I_PARENT); | |
1facf9fc | 36740 | + } |
36741 | +} | |
36742 | + | |
36743 | +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir) | |
36744 | +{ | |
36745 | + if (ldir->hdir) | |
5afbbe0d | 36746 | + au_hn_inode_unlock(ldir->hdir); |
1facf9fc | 36747 | + else { |
febd17d6 | 36748 | + inode_unlock(ldir->dir); |
1facf9fc | 36749 | + dput(ldir->parent); |
36750 | + } | |
36751 | +} | |
36752 | + | |
36753 | +/* ---------------------------------------------------------------------- */ | |
36754 | + | |
36755 | +/* trucate xino files asynchronously */ | |
36756 | + | |
36757 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex) | |
36758 | +{ | |
36759 | + int err; | |
392086de AM |
36760 | + unsigned long jiffy; |
36761 | + blkcnt_t blocks; | |
5afbbe0d | 36762 | + aufs_bindex_t bi, bbot; |
392086de | 36763 | + struct kstatfs *st; |
1facf9fc | 36764 | + struct au_branch *br; |
36765 | + struct file *new_xino, *file; | |
36766 | + struct super_block *h_sb; | |
36767 | + struct au_xino_lock_dir ldir; | |
36768 | + | |
392086de | 36769 | + err = -ENOMEM; |
be52b249 | 36770 | + st = kmalloc(sizeof(*st), GFP_NOFS); |
392086de AM |
36771 | + if (unlikely(!st)) |
36772 | + goto out; | |
36773 | + | |
1facf9fc | 36774 | + err = -EINVAL; |
5afbbe0d AM |
36775 | + bbot = au_sbbot(sb); |
36776 | + if (unlikely(bindex < 0 || bbot < bindex)) | |
392086de | 36777 | + goto out_st; |
1facf9fc | 36778 | + br = au_sbr(sb, bindex); |
36779 | + file = br->br_xino.xi_file; | |
36780 | + if (!file) | |
392086de AM |
36781 | + goto out_st; |
36782 | + | |
36783 | + err = vfs_statfs(&file->f_path, st); | |
36784 | + if (unlikely(err)) | |
36785 | + AuErr1("statfs err %d, ignored\n", err); | |
36786 | + jiffy = jiffies; | |
36787 | + blocks = file_inode(file)->i_blocks; | |
36788 | + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
36789 | + bindex, (u64)blocks, st->f_bfree, st->f_blocks); | |
1facf9fc | 36790 | + |
36791 | + au_xino_lock_dir(sb, file, &ldir); | |
36792 | + /* mnt_want_write() is unnecessary here */ | |
36793 | + new_xino = au_xino_create2(file, file); | |
36794 | + au_xino_unlock_dir(&ldir); | |
36795 | + err = PTR_ERR(new_xino); | |
392086de AM |
36796 | + if (IS_ERR(new_xino)) { |
36797 | + pr_err("err %d, ignored\n", err); | |
36798 | + goto out_st; | |
36799 | + } | |
1facf9fc | 36800 | + err = 0; |
36801 | + fput(file); | |
36802 | + br->br_xino.xi_file = new_xino; | |
36803 | + | |
86dc4139 | 36804 | + h_sb = au_br_sb(br); |
5afbbe0d | 36805 | + for (bi = 0; bi <= bbot; bi++) { |
1facf9fc | 36806 | + if (unlikely(bi == bindex)) |
36807 | + continue; | |
36808 | + br = au_sbr(sb, bi); | |
86dc4139 | 36809 | + if (au_br_sb(br) != h_sb) |
1facf9fc | 36810 | + continue; |
36811 | + | |
36812 | + fput(br->br_xino.xi_file); | |
36813 | + br->br_xino.xi_file = new_xino; | |
36814 | + get_file(new_xino); | |
36815 | + } | |
36816 | + | |
392086de AM |
36817 | + err = vfs_statfs(&new_xino->f_path, st); |
36818 | + if (!err) { | |
36819 | + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n", | |
36820 | + bindex, (u64)file_inode(new_xino)->i_blocks, | |
36821 | + st->f_bfree, st->f_blocks); | |
36822 | + if (file_inode(new_xino)->i_blocks < blocks) | |
36823 | + au_sbi(sb)->si_xino_jiffy = jiffy; | |
36824 | + } else | |
36825 | + AuErr1("statfs err %d, ignored\n", err); | |
36826 | + | |
36827 | +out_st: | |
1c60b727 | 36828 | + kfree(st); |
4f0767ce | 36829 | +out: |
1facf9fc | 36830 | + return err; |
36831 | +} | |
36832 | + | |
36833 | +struct xino_do_trunc_args { | |
36834 | + struct super_block *sb; | |
36835 | + struct au_branch *br; | |
36836 | +}; | |
36837 | + | |
36838 | +static void xino_do_trunc(void *_args) | |
36839 | +{ | |
36840 | + struct xino_do_trunc_args *args = _args; | |
36841 | + struct super_block *sb; | |
36842 | + struct au_branch *br; | |
36843 | + struct inode *dir; | |
36844 | + int err; | |
36845 | + aufs_bindex_t bindex; | |
36846 | + | |
36847 | + err = 0; | |
36848 | + sb = args->sb; | |
5527c038 | 36849 | + dir = d_inode(sb->s_root); |
1facf9fc | 36850 | + br = args->br; |
36851 | + | |
36852 | + si_noflush_write_lock(sb); | |
36853 | + ii_read_lock_parent(dir); | |
36854 | + bindex = au_br_index(sb, br->br_id); | |
36855 | + err = au_xino_trunc(sb, bindex); | |
1facf9fc | 36856 | + ii_read_unlock(dir); |
36857 | + if (unlikely(err)) | |
392086de | 36858 | + pr_warn("err b%d, (%d)\n", bindex, err); |
1facf9fc | 36859 | + atomic_dec(&br->br_xino_running); |
5afbbe0d | 36860 | + au_br_put(br); |
1facf9fc | 36861 | + si_write_unlock(sb); |
027c5e7a | 36862 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1c60b727 | 36863 | + kfree(args); |
1facf9fc | 36864 | +} |
36865 | + | |
392086de AM |
36866 | +static int xino_trunc_test(struct super_block *sb, struct au_branch *br) |
36867 | +{ | |
36868 | + int err; | |
36869 | + struct kstatfs st; | |
36870 | + struct au_sbinfo *sbinfo; | |
36871 | + | |
36872 | + /* todo: si_xino_expire and the ratio should be customizable */ | |
36873 | + sbinfo = au_sbi(sb); | |
36874 | + if (time_before(jiffies, | |
36875 | + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire)) | |
36876 | + return 0; | |
36877 | + | |
36878 | + /* truncation border */ | |
36879 | + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st); | |
36880 | + if (unlikely(err)) { | |
36881 | + AuErr1("statfs err %d, ignored\n", err); | |
36882 | + return 0; | |
36883 | + } | |
36884 | + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC) | |
36885 | + return 0; | |
36886 | + | |
36887 | + return 1; | |
36888 | +} | |
36889 | + | |
1facf9fc | 36890 | +static void xino_try_trunc(struct super_block *sb, struct au_branch *br) |
36891 | +{ | |
36892 | + struct xino_do_trunc_args *args; | |
36893 | + int wkq_err; | |
36894 | + | |
392086de | 36895 | + if (!xino_trunc_test(sb, br)) |
1facf9fc | 36896 | + return; |
36897 | + | |
36898 | + if (atomic_inc_return(&br->br_xino_running) > 1) | |
36899 | + goto out; | |
36900 | + | |
36901 | + /* lock and kfree() will be called in trunc_xino() */ | |
36902 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
36903 | + if (unlikely(!args)) { | |
36904 | + AuErr1("no memory\n"); | |
f0c0a007 | 36905 | + goto out; |
1facf9fc | 36906 | + } |
36907 | + | |
5afbbe0d | 36908 | + au_br_get(br); |
1facf9fc | 36909 | + args->sb = sb; |
36910 | + args->br = br; | |
53392da6 | 36911 | + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0); |
1facf9fc | 36912 | + if (!wkq_err) |
36913 | + return; /* success */ | |
36914 | + | |
4a4d8108 | 36915 | + pr_err("wkq %d\n", wkq_err); |
5afbbe0d | 36916 | + au_br_put(br); |
1c60b727 | 36917 | + kfree(args); |
1facf9fc | 36918 | + |
4f0767ce | 36919 | +out: |
e49829fe | 36920 | + atomic_dec(&br->br_xino_running); |
1facf9fc | 36921 | +} |
36922 | + | |
36923 | +/* ---------------------------------------------------------------------- */ | |
36924 | + | |
5527c038 | 36925 | +static int au_xino_do_write(vfs_writef_t write, struct file *file, |
1facf9fc | 36926 | + ino_t h_ino, ino_t ino) |
36927 | +{ | |
36928 | + loff_t pos; | |
36929 | + ssize_t sz; | |
36930 | + | |
36931 | + pos = h_ino; | |
36932 | + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) { | |
36933 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
36934 | + return -EFBIG; | |
36935 | + } | |
36936 | + pos *= sizeof(ino); | |
36937 | + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos); | |
36938 | + if (sz == sizeof(ino)) | |
36939 | + return 0; /* success */ | |
36940 | + | |
36941 | + AuIOErr("write failed (%zd)\n", sz); | |
36942 | + return -EIO; | |
36943 | +} | |
36944 | + | |
36945 | +/* | |
36946 | + * write @ino to the xinofile for the specified branch{@sb, @bindex} | |
36947 | + * at the position of @h_ino. | |
36948 | + * even if @ino is zero, it is written to the xinofile and means no entry. | |
36949 | + * if the size of the xino file on a specific filesystem exceeds the watermark, | |
36950 | + * try truncating it. | |
36951 | + */ | |
36952 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
36953 | + ino_t ino) | |
36954 | +{ | |
36955 | + int err; | |
36956 | + unsigned int mnt_flags; | |
36957 | + struct au_branch *br; | |
36958 | + | |
36959 | + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max) | |
36960 | + || ((loff_t)-1) > 0); | |
dece6358 | 36961 | + SiMustAnyLock(sb); |
1facf9fc | 36962 | + |
36963 | + mnt_flags = au_mntflags(sb); | |
36964 | + if (!au_opt_test(mnt_flags, XINO)) | |
36965 | + return 0; | |
36966 | + | |
36967 | + br = au_sbr(sb, bindex); | |
36968 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
36969 | + h_ino, ino); | |
36970 | + if (!err) { | |
36971 | + if (au_opt_test(mnt_flags, TRUNC_XINO) | |
86dc4139 | 36972 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
1facf9fc | 36973 | + xino_try_trunc(sb, br); |
36974 | + return 0; /* success */ | |
36975 | + } | |
36976 | + | |
36977 | + AuIOErr("write failed (%d)\n", err); | |
36978 | + return -EIO; | |
36979 | +} | |
36980 | + | |
36981 | +/* ---------------------------------------------------------------------- */ | |
36982 | + | |
36983 | +/* aufs inode number bitmap */ | |
36984 | + | |
36985 | +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE; | |
36986 | +static ino_t xib_calc_ino(unsigned long pindex, int bit) | |
36987 | +{ | |
36988 | + ino_t ino; | |
36989 | + | |
36990 | + AuDebugOn(bit < 0 || page_bits <= bit); | |
36991 | + ino = AUFS_FIRST_INO + pindex * page_bits + bit; | |
36992 | + return ino; | |
36993 | +} | |
36994 | + | |
36995 | +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit) | |
36996 | +{ | |
36997 | + AuDebugOn(ino < AUFS_FIRST_INO); | |
36998 | + ino -= AUFS_FIRST_INO; | |
36999 | + *pindex = ino / page_bits; | |
37000 | + *bit = ino % page_bits; | |
37001 | +} | |
37002 | + | |
37003 | +static int xib_pindex(struct super_block *sb, unsigned long pindex) | |
37004 | +{ | |
37005 | + int err; | |
37006 | + loff_t pos; | |
37007 | + ssize_t sz; | |
37008 | + struct au_sbinfo *sbinfo; | |
37009 | + struct file *xib; | |
37010 | + unsigned long *p; | |
37011 | + | |
37012 | + sbinfo = au_sbi(sb); | |
37013 | + MtxMustLock(&sbinfo->si_xib_mtx); | |
37014 | + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE | |
37015 | + || !au_opt_test(sbinfo->si_mntflags, XINO)); | |
37016 | + | |
37017 | + if (pindex == sbinfo->si_xib_last_pindex) | |
37018 | + return 0; | |
37019 | + | |
37020 | + xib = sbinfo->si_xib; | |
37021 | + p = sbinfo->si_xib_buf; | |
37022 | + pos = sbinfo->si_xib_last_pindex; | |
37023 | + pos *= PAGE_SIZE; | |
37024 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
37025 | + if (unlikely(sz != PAGE_SIZE)) | |
37026 | + goto out; | |
37027 | + | |
37028 | + pos = pindex; | |
37029 | + pos *= PAGE_SIZE; | |
c06a8ce3 | 37030 | + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE) |
1facf9fc | 37031 | + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos); |
37032 | + else { | |
37033 | + memset(p, 0, PAGE_SIZE); | |
37034 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
37035 | + } | |
37036 | + if (sz == PAGE_SIZE) { | |
37037 | + sbinfo->si_xib_last_pindex = pindex; | |
37038 | + return 0; /* success */ | |
37039 | + } | |
37040 | + | |
4f0767ce | 37041 | +out: |
b752ccd1 AM |
37042 | + AuIOErr1("write failed (%zd)\n", sz); |
37043 | + err = sz; | |
37044 | + if (sz >= 0) | |
37045 | + err = -EIO; | |
37046 | + return err; | |
37047 | +} | |
37048 | + | |
37049 | +/* ---------------------------------------------------------------------- */ | |
37050 | + | |
37051 | +static void au_xib_clear_bit(struct inode *inode) | |
37052 | +{ | |
37053 | + int err, bit; | |
37054 | + unsigned long pindex; | |
37055 | + struct super_block *sb; | |
37056 | + struct au_sbinfo *sbinfo; | |
37057 | + | |
37058 | + AuDebugOn(inode->i_nlink); | |
37059 | + | |
37060 | + sb = inode->i_sb; | |
37061 | + xib_calc_bit(inode->i_ino, &pindex, &bit); | |
37062 | + AuDebugOn(page_bits <= bit); | |
37063 | + sbinfo = au_sbi(sb); | |
37064 | + mutex_lock(&sbinfo->si_xib_mtx); | |
37065 | + err = xib_pindex(sb, pindex); | |
37066 | + if (!err) { | |
37067 | + clear_bit(bit, sbinfo->si_xib_buf); | |
37068 | + sbinfo->si_xib_next_bit = bit; | |
37069 | + } | |
37070 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
37071 | +} | |
37072 | + | |
37073 | +/* for s_op->delete_inode() */ | |
37074 | +void au_xino_delete_inode(struct inode *inode, const int unlinked) | |
37075 | +{ | |
37076 | + int err; | |
37077 | + unsigned int mnt_flags; | |
5afbbe0d | 37078 | + aufs_bindex_t bindex, bbot, bi; |
b752ccd1 AM |
37079 | + unsigned char try_trunc; |
37080 | + struct au_iinfo *iinfo; | |
37081 | + struct super_block *sb; | |
37082 | + struct au_hinode *hi; | |
37083 | + struct inode *h_inode; | |
37084 | + struct au_branch *br; | |
5527c038 | 37085 | + vfs_writef_t xwrite; |
b752ccd1 | 37086 | + |
5afbbe0d AM |
37087 | + AuDebugOn(au_is_bad_inode(inode)); |
37088 | + | |
b752ccd1 AM |
37089 | + sb = inode->i_sb; |
37090 | + mnt_flags = au_mntflags(sb); | |
37091 | + if (!au_opt_test(mnt_flags, XINO) | |
37092 | + || inode->i_ino == AUFS_ROOT_INO) | |
37093 | + return; | |
37094 | + | |
37095 | + if (unlinked) { | |
37096 | + au_xigen_inc(inode); | |
37097 | + au_xib_clear_bit(inode); | |
37098 | + } | |
37099 | + | |
37100 | + iinfo = au_ii(inode); | |
5afbbe0d | 37101 | + bindex = iinfo->ii_btop; |
b752ccd1 AM |
37102 | + if (bindex < 0) |
37103 | + return; | |
1facf9fc | 37104 | + |
b752ccd1 AM |
37105 | + xwrite = au_sbi(sb)->si_xwrite; |
37106 | + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO); | |
5afbbe0d AM |
37107 | + hi = au_hinode(iinfo, bindex); |
37108 | + bbot = iinfo->ii_bbot; | |
37109 | + for (; bindex <= bbot; bindex++, hi++) { | |
b752ccd1 AM |
37110 | + h_inode = hi->hi_inode; |
37111 | + if (!h_inode | |
37112 | + || (!unlinked && h_inode->i_nlink)) | |
37113 | + continue; | |
1facf9fc | 37114 | + |
b752ccd1 AM |
37115 | + /* inode may not be revalidated */ |
37116 | + bi = au_br_index(sb, hi->hi_id); | |
37117 | + if (bi < 0) | |
37118 | + continue; | |
1facf9fc | 37119 | + |
b752ccd1 AM |
37120 | + br = au_sbr(sb, bi); |
37121 | + err = au_xino_do_write(xwrite, br->br_xino.xi_file, | |
37122 | + h_inode->i_ino, /*ino*/0); | |
37123 | + if (!err && try_trunc | |
86dc4139 | 37124 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
b752ccd1 | 37125 | + xino_try_trunc(sb, br); |
1facf9fc | 37126 | + } |
1facf9fc | 37127 | +} |
37128 | + | |
37129 | +/* get an unused inode number from bitmap */ | |
37130 | +ino_t au_xino_new_ino(struct super_block *sb) | |
37131 | +{ | |
37132 | + ino_t ino; | |
37133 | + unsigned long *p, pindex, ul, pend; | |
37134 | + struct au_sbinfo *sbinfo; | |
37135 | + struct file *file; | |
37136 | + int free_bit, err; | |
37137 | + | |
37138 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
37139 | + return iunique(sb, AUFS_FIRST_INO); | |
37140 | + | |
37141 | + sbinfo = au_sbi(sb); | |
37142 | + mutex_lock(&sbinfo->si_xib_mtx); | |
37143 | + p = sbinfo->si_xib_buf; | |
37144 | + free_bit = sbinfo->si_xib_next_bit; | |
37145 | + if (free_bit < page_bits && !test_bit(free_bit, p)) | |
37146 | + goto out; /* success */ | |
37147 | + free_bit = find_first_zero_bit(p, page_bits); | |
37148 | + if (free_bit < page_bits) | |
37149 | + goto out; /* success */ | |
37150 | + | |
37151 | + pindex = sbinfo->si_xib_last_pindex; | |
37152 | + for (ul = pindex - 1; ul < ULONG_MAX; ul--) { | |
37153 | + err = xib_pindex(sb, ul); | |
37154 | + if (unlikely(err)) | |
37155 | + goto out_err; | |
37156 | + free_bit = find_first_zero_bit(p, page_bits); | |
37157 | + if (free_bit < page_bits) | |
37158 | + goto out; /* success */ | |
37159 | + } | |
37160 | + | |
37161 | + file = sbinfo->si_xib; | |
c06a8ce3 | 37162 | + pend = vfsub_f_size_read(file) / PAGE_SIZE; |
1facf9fc | 37163 | + for (ul = pindex + 1; ul <= pend; ul++) { |
37164 | + err = xib_pindex(sb, ul); | |
37165 | + if (unlikely(err)) | |
37166 | + goto out_err; | |
37167 | + free_bit = find_first_zero_bit(p, page_bits); | |
37168 | + if (free_bit < page_bits) | |
37169 | + goto out; /* success */ | |
37170 | + } | |
37171 | + BUG(); | |
37172 | + | |
4f0767ce | 37173 | +out: |
1facf9fc | 37174 | + set_bit(free_bit, p); |
7f207e10 | 37175 | + sbinfo->si_xib_next_bit = free_bit + 1; |
1facf9fc | 37176 | + pindex = sbinfo->si_xib_last_pindex; |
37177 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
37178 | + ino = xib_calc_ino(pindex, free_bit); | |
37179 | + AuDbg("i%lu\n", (unsigned long)ino); | |
37180 | + return ino; | |
4f0767ce | 37181 | +out_err: |
1facf9fc | 37182 | + mutex_unlock(&sbinfo->si_xib_mtx); |
37183 | + AuDbg("i0\n"); | |
37184 | + return 0; | |
37185 | +} | |
37186 | + | |
37187 | +/* | |
37188 | + * read @ino from xinofile for the specified branch{@sb, @bindex} | |
37189 | + * at the position of @h_ino. | |
37190 | + * if @ino does not exist and @do_new is true, get new one. | |
37191 | + */ | |
37192 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
37193 | + ino_t *ino) | |
37194 | +{ | |
37195 | + int err; | |
37196 | + ssize_t sz; | |
37197 | + loff_t pos; | |
37198 | + struct file *file; | |
37199 | + struct au_sbinfo *sbinfo; | |
37200 | + | |
37201 | + *ino = 0; | |
37202 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
37203 | + return 0; /* no xino */ | |
37204 | + | |
37205 | + err = 0; | |
37206 | + sbinfo = au_sbi(sb); | |
37207 | + pos = h_ino; | |
37208 | + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) { | |
37209 | + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino); | |
37210 | + return -EFBIG; | |
37211 | + } | |
37212 | + pos *= sizeof(*ino); | |
37213 | + | |
37214 | + file = au_sbr(sb, bindex)->br_xino.xi_file; | |
c06a8ce3 | 37215 | + if (vfsub_f_size_read(file) < pos + sizeof(*ino)) |
1facf9fc | 37216 | + return 0; /* no ino */ |
37217 | + | |
37218 | + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos); | |
37219 | + if (sz == sizeof(*ino)) | |
37220 | + return 0; /* success */ | |
37221 | + | |
37222 | + err = sz; | |
37223 | + if (unlikely(sz >= 0)) { | |
37224 | + err = -EIO; | |
37225 | + AuIOErr("xino read error (%zd)\n", sz); | |
37226 | + } | |
37227 | + | |
37228 | + return err; | |
37229 | +} | |
37230 | + | |
37231 | +/* ---------------------------------------------------------------------- */ | |
37232 | + | |
37233 | +/* create and set a new xino file */ | |
37234 | + | |
37235 | +struct file *au_xino_create(struct super_block *sb, char *fname, int silent) | |
37236 | +{ | |
37237 | + struct file *file; | |
37238 | + struct dentry *h_parent, *d; | |
b912730e | 37239 | + struct inode *h_dir, *inode; |
1facf9fc | 37240 | + int err; |
37241 | + | |
37242 | + /* | |
37243 | + * at mount-time, and the xino file is the default path, | |
4a4d8108 | 37244 | + * hnotify is disabled so we have no notify events to ignore. |
1facf9fc | 37245 | + * when a user specified the xino, we cannot get au_hdir to be ignored. |
37246 | + */ | |
7f207e10 | 37247 | + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
2cbb1c4b | 37248 | + /* | __FMODE_NONOTIFY */, |
1facf9fc | 37249 | + S_IRUGO | S_IWUGO); |
37250 | + if (IS_ERR(file)) { | |
37251 | + if (!silent) | |
4a4d8108 | 37252 | + pr_err("open %s(%ld)\n", fname, PTR_ERR(file)); |
1facf9fc | 37253 | + return file; |
37254 | + } | |
37255 | + | |
37256 | + /* keep file count */ | |
b912730e AM |
37257 | + err = 0; |
37258 | + inode = file_inode(file); | |
2000de60 | 37259 | + h_parent = dget_parent(file->f_path.dentry); |
5527c038 | 37260 | + h_dir = d_inode(h_parent); |
febd17d6 | 37261 | + inode_lock_nested(h_dir, AuLsc_I_PARENT); |
1facf9fc | 37262 | + /* mnt_want_write() is unnecessary here */ |
523b37e3 | 37263 | + /* no delegation since it is just created */ |
b912730e AM |
37264 | + if (inode->i_nlink) |
37265 | + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, | |
37266 | + /*force*/0); | |
febd17d6 | 37267 | + inode_unlock(h_dir); |
1facf9fc | 37268 | + dput(h_parent); |
37269 | + if (unlikely(err)) { | |
37270 | + if (!silent) | |
4a4d8108 | 37271 | + pr_err("unlink %s(%d)\n", fname, err); |
1facf9fc | 37272 | + goto out; |
37273 | + } | |
37274 | + | |
37275 | + err = -EINVAL; | |
2000de60 | 37276 | + d = file->f_path.dentry; |
1facf9fc | 37277 | + if (unlikely(sb == d->d_sb)) { |
37278 | + if (!silent) | |
4a4d8108 | 37279 | + pr_err("%s must be outside\n", fname); |
1facf9fc | 37280 | + goto out; |
37281 | + } | |
37282 | + if (unlikely(au_test_fs_bad_xino(d->d_sb))) { | |
37283 | + if (!silent) | |
4a4d8108 AM |
37284 | + pr_err("xino doesn't support %s(%s)\n", |
37285 | + fname, au_sbtype(d->d_sb)); | |
1facf9fc | 37286 | + goto out; |
37287 | + } | |
37288 | + return file; /* success */ | |
37289 | + | |
4f0767ce | 37290 | +out: |
1facf9fc | 37291 | + fput(file); |
37292 | + file = ERR_PTR(err); | |
37293 | + return file; | |
37294 | +} | |
37295 | + | |
37296 | +/* | |
37297 | + * find another branch who is on the same filesystem of the specified | |
5afbbe0d | 37298 | + * branch{@btgt}. search until @bbot. |
1facf9fc | 37299 | + */ |
37300 | +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt, | |
5afbbe0d | 37301 | + aufs_bindex_t bbot) |
1facf9fc | 37302 | +{ |
37303 | + aufs_bindex_t bindex; | |
37304 | + struct super_block *tgt_sb = au_sbr_sb(sb, btgt); | |
37305 | + | |
37306 | + for (bindex = 0; bindex < btgt; bindex++) | |
37307 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) | |
37308 | + return bindex; | |
5afbbe0d | 37309 | + for (bindex++; bindex <= bbot; bindex++) |
1facf9fc | 37310 | + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex))) |
37311 | + return bindex; | |
37312 | + return -1; | |
37313 | +} | |
37314 | + | |
37315 | +/* ---------------------------------------------------------------------- */ | |
37316 | + | |
37317 | +/* | |
37318 | + * initialize the xinofile for the specified branch @br | |
37319 | + * at the place/path where @base_file indicates. | |
37320 | + * test whether another branch is on the same filesystem or not, | |
37321 | + * if @do_test is true. | |
37322 | + */ | |
37323 | +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino, | |
37324 | + struct file *base_file, int do_test) | |
37325 | +{ | |
37326 | + int err; | |
37327 | + ino_t ino; | |
5afbbe0d | 37328 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 37329 | + struct au_branch *shared_br, *b; |
37330 | + struct file *file; | |
37331 | + struct super_block *tgt_sb; | |
37332 | + | |
37333 | + shared_br = NULL; | |
5afbbe0d | 37334 | + bbot = au_sbbot(sb); |
1facf9fc | 37335 | + if (do_test) { |
86dc4139 | 37336 | + tgt_sb = au_br_sb(br); |
5afbbe0d | 37337 | + for (bindex = 0; bindex <= bbot; bindex++) { |
1facf9fc | 37338 | + b = au_sbr(sb, bindex); |
86dc4139 | 37339 | + if (tgt_sb == au_br_sb(b)) { |
1facf9fc | 37340 | + shared_br = b; |
37341 | + break; | |
37342 | + } | |
37343 | + } | |
37344 | + } | |
37345 | + | |
37346 | + if (!shared_br || !shared_br->br_xino.xi_file) { | |
37347 | + struct au_xino_lock_dir ldir; | |
37348 | + | |
37349 | + au_xino_lock_dir(sb, base_file, &ldir); | |
37350 | + /* mnt_want_write() is unnecessary here */ | |
37351 | + file = au_xino_create2(base_file, NULL); | |
37352 | + au_xino_unlock_dir(&ldir); | |
37353 | + err = PTR_ERR(file); | |
37354 | + if (IS_ERR(file)) | |
37355 | + goto out; | |
37356 | + br->br_xino.xi_file = file; | |
37357 | + } else { | |
37358 | + br->br_xino.xi_file = shared_br->br_xino.xi_file; | |
37359 | + get_file(br->br_xino.xi_file); | |
37360 | + } | |
37361 | + | |
37362 | + ino = AUFS_ROOT_INO; | |
37363 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file, | |
37364 | + h_ino, ino); | |
b752ccd1 AM |
37365 | + if (unlikely(err)) { |
37366 | + fput(br->br_xino.xi_file); | |
37367 | + br->br_xino.xi_file = NULL; | |
37368 | + } | |
1facf9fc | 37369 | + |
4f0767ce | 37370 | +out: |
1facf9fc | 37371 | + return err; |
37372 | +} | |
37373 | + | |
37374 | +/* ---------------------------------------------------------------------- */ | |
37375 | + | |
37376 | +/* trucate a xino bitmap file */ | |
37377 | + | |
37378 | +/* todo: slow */ | |
37379 | +static int do_xib_restore(struct super_block *sb, struct file *file, void *page) | |
37380 | +{ | |
37381 | + int err, bit; | |
37382 | + ssize_t sz; | |
37383 | + unsigned long pindex; | |
37384 | + loff_t pos, pend; | |
37385 | + struct au_sbinfo *sbinfo; | |
5527c038 | 37386 | + vfs_readf_t func; |
1facf9fc | 37387 | + ino_t *ino; |
37388 | + unsigned long *p; | |
37389 | + | |
37390 | + err = 0; | |
37391 | + sbinfo = au_sbi(sb); | |
dece6358 | 37392 | + MtxMustLock(&sbinfo->si_xib_mtx); |
1facf9fc | 37393 | + p = sbinfo->si_xib_buf; |
37394 | + func = sbinfo->si_xread; | |
c06a8ce3 | 37395 | + pend = vfsub_f_size_read(file); |
1facf9fc | 37396 | + pos = 0; |
37397 | + while (pos < pend) { | |
37398 | + sz = xino_fread(func, file, page, PAGE_SIZE, &pos); | |
37399 | + err = sz; | |
37400 | + if (unlikely(sz <= 0)) | |
37401 | + goto out; | |
37402 | + | |
37403 | + err = 0; | |
37404 | + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) { | |
37405 | + if (unlikely(*ino < AUFS_FIRST_INO)) | |
37406 | + continue; | |
37407 | + | |
37408 | + xib_calc_bit(*ino, &pindex, &bit); | |
37409 | + AuDebugOn(page_bits <= bit); | |
37410 | + err = xib_pindex(sb, pindex); | |
37411 | + if (!err) | |
37412 | + set_bit(bit, p); | |
37413 | + else | |
37414 | + goto out; | |
37415 | + } | |
37416 | + } | |
37417 | + | |
4f0767ce | 37418 | +out: |
1facf9fc | 37419 | + return err; |
37420 | +} | |
37421 | + | |
37422 | +static int xib_restore(struct super_block *sb) | |
37423 | +{ | |
37424 | + int err; | |
5afbbe0d | 37425 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 37426 | + void *page; |
37427 | + | |
37428 | + err = -ENOMEM; | |
37429 | + page = (void *)__get_free_page(GFP_NOFS); | |
37430 | + if (unlikely(!page)) | |
37431 | + goto out; | |
37432 | + | |
37433 | + err = 0; | |
5afbbe0d AM |
37434 | + bbot = au_sbbot(sb); |
37435 | + for (bindex = 0; !err && bindex <= bbot; bindex++) | |
1facf9fc | 37436 | + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) |
37437 | + err = do_xib_restore | |
37438 | + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page); | |
37439 | + else | |
37440 | + AuDbg("b%d\n", bindex); | |
1c60b727 | 37441 | + free_page((unsigned long)page); |
1facf9fc | 37442 | + |
4f0767ce | 37443 | +out: |
1facf9fc | 37444 | + return err; |
37445 | +} | |
37446 | + | |
37447 | +int au_xib_trunc(struct super_block *sb) | |
37448 | +{ | |
37449 | + int err; | |
37450 | + ssize_t sz; | |
37451 | + loff_t pos; | |
37452 | + struct au_xino_lock_dir ldir; | |
37453 | + struct au_sbinfo *sbinfo; | |
37454 | + unsigned long *p; | |
37455 | + struct file *file; | |
37456 | + | |
dece6358 AM |
37457 | + SiMustWriteLock(sb); |
37458 | + | |
1facf9fc | 37459 | + err = 0; |
37460 | + sbinfo = au_sbi(sb); | |
37461 | + if (!au_opt_test(sbinfo->si_mntflags, XINO)) | |
37462 | + goto out; | |
37463 | + | |
37464 | + file = sbinfo->si_xib; | |
c06a8ce3 | 37465 | + if (vfsub_f_size_read(file) <= PAGE_SIZE) |
1facf9fc | 37466 | + goto out; |
37467 | + | |
37468 | + au_xino_lock_dir(sb, file, &ldir); | |
37469 | + /* mnt_want_write() is unnecessary here */ | |
37470 | + file = au_xino_create2(sbinfo->si_xib, NULL); | |
37471 | + au_xino_unlock_dir(&ldir); | |
37472 | + err = PTR_ERR(file); | |
37473 | + if (IS_ERR(file)) | |
37474 | + goto out; | |
37475 | + fput(sbinfo->si_xib); | |
37476 | + sbinfo->si_xib = file; | |
37477 | + | |
37478 | + p = sbinfo->si_xib_buf; | |
37479 | + memset(p, 0, PAGE_SIZE); | |
37480 | + pos = 0; | |
37481 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos); | |
37482 | + if (unlikely(sz != PAGE_SIZE)) { | |
37483 | + err = sz; | |
37484 | + AuIOErr("err %d\n", err); | |
37485 | + if (sz >= 0) | |
37486 | + err = -EIO; | |
37487 | + goto out; | |
37488 | + } | |
37489 | + | |
37490 | + mutex_lock(&sbinfo->si_xib_mtx); | |
37491 | + /* mnt_want_write() is unnecessary here */ | |
37492 | + err = xib_restore(sb); | |
37493 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
37494 | + | |
37495 | +out: | |
37496 | + return err; | |
37497 | +} | |
37498 | + | |
37499 | +/* ---------------------------------------------------------------------- */ | |
37500 | + | |
37501 | +/* | |
37502 | + * xino mount option handlers | |
37503 | + */ | |
1facf9fc | 37504 | + |
37505 | +/* xino bitmap */ | |
37506 | +static void xino_clear_xib(struct super_block *sb) | |
37507 | +{ | |
37508 | + struct au_sbinfo *sbinfo; | |
37509 | + | |
dece6358 AM |
37510 | + SiMustWriteLock(sb); |
37511 | + | |
1facf9fc | 37512 | + sbinfo = au_sbi(sb); |
37513 | + sbinfo->si_xread = NULL; | |
37514 | + sbinfo->si_xwrite = NULL; | |
37515 | + if (sbinfo->si_xib) | |
37516 | + fput(sbinfo->si_xib); | |
37517 | + sbinfo->si_xib = NULL; | |
f0c0a007 | 37518 | + if (sbinfo->si_xib_buf) |
1c60b727 | 37519 | + free_page((unsigned long)sbinfo->si_xib_buf); |
1facf9fc | 37520 | + sbinfo->si_xib_buf = NULL; |
37521 | +} | |
37522 | + | |
37523 | +static int au_xino_set_xib(struct super_block *sb, struct file *base) | |
37524 | +{ | |
37525 | + int err; | |
37526 | + loff_t pos; | |
37527 | + struct au_sbinfo *sbinfo; | |
37528 | + struct file *file; | |
37529 | + | |
dece6358 AM |
37530 | + SiMustWriteLock(sb); |
37531 | + | |
1facf9fc | 37532 | + sbinfo = au_sbi(sb); |
37533 | + file = au_xino_create2(base, sbinfo->si_xib); | |
37534 | + err = PTR_ERR(file); | |
37535 | + if (IS_ERR(file)) | |
37536 | + goto out; | |
37537 | + if (sbinfo->si_xib) | |
37538 | + fput(sbinfo->si_xib); | |
37539 | + sbinfo->si_xib = file; | |
5527c038 JR |
37540 | + sbinfo->si_xread = vfs_readf(file); |
37541 | + sbinfo->si_xwrite = vfs_writef(file); | |
1facf9fc | 37542 | + |
37543 | + err = -ENOMEM; | |
37544 | + if (!sbinfo->si_xib_buf) | |
37545 | + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS); | |
37546 | + if (unlikely(!sbinfo->si_xib_buf)) | |
37547 | + goto out_unset; | |
37548 | + | |
37549 | + sbinfo->si_xib_last_pindex = 0; | |
37550 | + sbinfo->si_xib_next_bit = 0; | |
c06a8ce3 | 37551 | + if (vfsub_f_size_read(file) < PAGE_SIZE) { |
1facf9fc | 37552 | + pos = 0; |
37553 | + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf, | |
37554 | + PAGE_SIZE, &pos); | |
37555 | + if (unlikely(err != PAGE_SIZE)) | |
37556 | + goto out_free; | |
37557 | + } | |
37558 | + err = 0; | |
37559 | + goto out; /* success */ | |
37560 | + | |
4f0767ce | 37561 | +out_free: |
f0c0a007 | 37562 | + if (sbinfo->si_xib_buf) |
1c60b727 | 37563 | + free_page((unsigned long)sbinfo->si_xib_buf); |
b752ccd1 AM |
37564 | + sbinfo->si_xib_buf = NULL; |
37565 | + if (err >= 0) | |
37566 | + err = -EIO; | |
4f0767ce | 37567 | +out_unset: |
b752ccd1 AM |
37568 | + fput(sbinfo->si_xib); |
37569 | + sbinfo->si_xib = NULL; | |
37570 | + sbinfo->si_xread = NULL; | |
37571 | + sbinfo->si_xwrite = NULL; | |
4f0767ce | 37572 | +out: |
b752ccd1 | 37573 | + return err; |
1facf9fc | 37574 | +} |
37575 | + | |
b752ccd1 AM |
37576 | +/* xino for each branch */ |
37577 | +static void xino_clear_br(struct super_block *sb) | |
37578 | +{ | |
5afbbe0d | 37579 | + aufs_bindex_t bindex, bbot; |
b752ccd1 | 37580 | + struct au_branch *br; |
1facf9fc | 37581 | + |
5afbbe0d AM |
37582 | + bbot = au_sbbot(sb); |
37583 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
b752ccd1 AM |
37584 | + br = au_sbr(sb, bindex); |
37585 | + if (!br || !br->br_xino.xi_file) | |
37586 | + continue; | |
37587 | + | |
37588 | + fput(br->br_xino.xi_file); | |
37589 | + br->br_xino.xi_file = NULL; | |
37590 | + } | |
37591 | +} | |
37592 | + | |
37593 | +static int au_xino_set_br(struct super_block *sb, struct file *base) | |
1facf9fc | 37594 | +{ |
37595 | + int err; | |
b752ccd1 | 37596 | + ino_t ino; |
5afbbe0d | 37597 | + aufs_bindex_t bindex, bbot, bshared; |
b752ccd1 AM |
37598 | + struct { |
37599 | + struct file *old, *new; | |
37600 | + } *fpair, *p; | |
37601 | + struct au_branch *br; | |
37602 | + struct inode *inode; | |
5527c038 | 37603 | + vfs_writef_t writef; |
1facf9fc | 37604 | + |
b752ccd1 AM |
37605 | + SiMustWriteLock(sb); |
37606 | + | |
37607 | + err = -ENOMEM; | |
5afbbe0d AM |
37608 | + bbot = au_sbbot(sb); |
37609 | + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS); | |
b752ccd1 | 37610 | + if (unlikely(!fpair)) |
1facf9fc | 37611 | + goto out; |
37612 | + | |
5527c038 | 37613 | + inode = d_inode(sb->s_root); |
b752ccd1 AM |
37614 | + ino = AUFS_ROOT_INO; |
37615 | + writef = au_sbi(sb)->si_xwrite; | |
5afbbe0d | 37616 | + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) { |
b752ccd1 AM |
37617 | + bshared = is_sb_shared(sb, bindex, bindex - 1); |
37618 | + if (bshared >= 0) { | |
37619 | + /* shared xino */ | |
37620 | + *p = fpair[bshared]; | |
37621 | + get_file(p->new); | |
37622 | + } | |
37623 | + | |
37624 | + if (!p->new) { | |
37625 | + /* new xino */ | |
5afbbe0d | 37626 | + br = au_sbr(sb, bindex); |
b752ccd1 AM |
37627 | + p->old = br->br_xino.xi_file; |
37628 | + p->new = au_xino_create2(base, br->br_xino.xi_file); | |
37629 | + err = PTR_ERR(p->new); | |
37630 | + if (IS_ERR(p->new)) { | |
37631 | + p->new = NULL; | |
37632 | + goto out_pair; | |
37633 | + } | |
37634 | + } | |
37635 | + | |
37636 | + err = au_xino_do_write(writef, p->new, | |
37637 | + au_h_iptr(inode, bindex)->i_ino, ino); | |
37638 | + if (unlikely(err)) | |
37639 | + goto out_pair; | |
37640 | + } | |
37641 | + | |
5afbbe0d | 37642 | + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) { |
b752ccd1 AM |
37643 | + br = au_sbr(sb, bindex); |
37644 | + if (br->br_xino.xi_file) | |
37645 | + fput(br->br_xino.xi_file); | |
37646 | + get_file(p->new); | |
37647 | + br->br_xino.xi_file = p->new; | |
37648 | + } | |
1facf9fc | 37649 | + |
4f0767ce | 37650 | +out_pair: |
5afbbe0d | 37651 | + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) |
b752ccd1 AM |
37652 | + if (p->new) |
37653 | + fput(p->new); | |
37654 | + else | |
37655 | + break; | |
1c60b727 | 37656 | + kfree(fpair); |
4f0767ce | 37657 | +out: |
1facf9fc | 37658 | + return err; |
37659 | +} | |
b752ccd1 AM |
37660 | + |
37661 | +void au_xino_clr(struct super_block *sb) | |
37662 | +{ | |
37663 | + struct au_sbinfo *sbinfo; | |
37664 | + | |
37665 | + au_xigen_clr(sb); | |
37666 | + xino_clear_xib(sb); | |
37667 | + xino_clear_br(sb); | |
37668 | + sbinfo = au_sbi(sb); | |
37669 | + /* lvalue, do not call au_mntflags() */ | |
37670 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
37671 | +} | |
37672 | + | |
37673 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount) | |
37674 | +{ | |
37675 | + int err, skip; | |
37676 | + struct dentry *parent, *cur_parent; | |
37677 | + struct qstr *dname, *cur_name; | |
37678 | + struct file *cur_xino; | |
37679 | + struct inode *dir; | |
37680 | + struct au_sbinfo *sbinfo; | |
37681 | + | |
37682 | + SiMustWriteLock(sb); | |
37683 | + | |
37684 | + err = 0; | |
37685 | + sbinfo = au_sbi(sb); | |
2000de60 | 37686 | + parent = dget_parent(xino->file->f_path.dentry); |
b752ccd1 AM |
37687 | + if (remount) { |
37688 | + skip = 0; | |
2000de60 | 37689 | + dname = &xino->file->f_path.dentry->d_name; |
b752ccd1 AM |
37690 | + cur_xino = sbinfo->si_xib; |
37691 | + if (cur_xino) { | |
2000de60 JR |
37692 | + cur_parent = dget_parent(cur_xino->f_path.dentry); |
37693 | + cur_name = &cur_xino->f_path.dentry->d_name; | |
b752ccd1 | 37694 | + skip = (cur_parent == parent |
38d290e6 | 37695 | + && au_qstreq(dname, cur_name)); |
b752ccd1 AM |
37696 | + dput(cur_parent); |
37697 | + } | |
37698 | + if (skip) | |
37699 | + goto out; | |
37700 | + } | |
37701 | + | |
37702 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
5527c038 | 37703 | + dir = d_inode(parent); |
febd17d6 | 37704 | + inode_lock_nested(dir, AuLsc_I_PARENT); |
b752ccd1 AM |
37705 | + /* mnt_want_write() is unnecessary here */ |
37706 | + err = au_xino_set_xib(sb, xino->file); | |
37707 | + if (!err) | |
37708 | + err = au_xigen_set(sb, xino->file); | |
37709 | + if (!err) | |
37710 | + err = au_xino_set_br(sb, xino->file); | |
febd17d6 | 37711 | + inode_unlock(dir); |
b752ccd1 AM |
37712 | + if (!err) |
37713 | + goto out; /* success */ | |
37714 | + | |
37715 | + /* reset all */ | |
37716 | + AuIOErr("failed creating xino(%d).\n", err); | |
c1595e42 JR |
37717 | + au_xigen_clr(sb); |
37718 | + xino_clear_xib(sb); | |
b752ccd1 | 37719 | + |
4f0767ce | 37720 | +out: |
b752ccd1 AM |
37721 | + dput(parent); |
37722 | + return err; | |
37723 | +} | |
37724 | + | |
37725 | +/* ---------------------------------------------------------------------- */ | |
37726 | + | |
37727 | +/* | |
37728 | + * create a xinofile at the default place/path. | |
37729 | + */ | |
37730 | +struct file *au_xino_def(struct super_block *sb) | |
37731 | +{ | |
37732 | + struct file *file; | |
37733 | + char *page, *p; | |
37734 | + struct au_branch *br; | |
37735 | + struct super_block *h_sb; | |
37736 | + struct path path; | |
5afbbe0d | 37737 | + aufs_bindex_t bbot, bindex, bwr; |
b752ccd1 AM |
37738 | + |
37739 | + br = NULL; | |
5afbbe0d | 37740 | + bbot = au_sbbot(sb); |
b752ccd1 | 37741 | + bwr = -1; |
5afbbe0d | 37742 | + for (bindex = 0; bindex <= bbot; bindex++) { |
b752ccd1 AM |
37743 | + br = au_sbr(sb, bindex); |
37744 | + if (au_br_writable(br->br_perm) | |
86dc4139 | 37745 | + && !au_test_fs_bad_xino(au_br_sb(br))) { |
b752ccd1 AM |
37746 | + bwr = bindex; |
37747 | + break; | |
37748 | + } | |
37749 | + } | |
37750 | + | |
7f207e10 AM |
37751 | + if (bwr >= 0) { |
37752 | + file = ERR_PTR(-ENOMEM); | |
537831f9 | 37753 | + page = (void *)__get_free_page(GFP_NOFS); |
7f207e10 AM |
37754 | + if (unlikely(!page)) |
37755 | + goto out; | |
86dc4139 | 37756 | + path.mnt = au_br_mnt(br); |
7f207e10 AM |
37757 | + path.dentry = au_h_dptr(sb->s_root, bwr); |
37758 | + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME)); | |
37759 | + file = (void *)p; | |
37760 | + if (!IS_ERR(p)) { | |
37761 | + strcat(p, "/" AUFS_XINO_FNAME); | |
37762 | + AuDbg("%s\n", p); | |
37763 | + file = au_xino_create(sb, p, /*silent*/0); | |
37764 | + if (!IS_ERR(file)) | |
37765 | + au_xino_brid_set(sb, br->br_id); | |
37766 | + } | |
1c60b727 | 37767 | + free_page((unsigned long)page); |
7f207e10 AM |
37768 | + } else { |
37769 | + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0); | |
37770 | + if (IS_ERR(file)) | |
37771 | + goto out; | |
2000de60 | 37772 | + h_sb = file->f_path.dentry->d_sb; |
7f207e10 AM |
37773 | + if (unlikely(au_test_fs_bad_xino(h_sb))) { |
37774 | + pr_err("xino doesn't support %s(%s)\n", | |
37775 | + AUFS_XINO_DEFPATH, au_sbtype(h_sb)); | |
37776 | + fput(file); | |
37777 | + file = ERR_PTR(-EINVAL); | |
37778 | + } | |
37779 | + if (!IS_ERR(file)) | |
37780 | + au_xino_brid_set(sb, -1); | |
37781 | + } | |
0c5527e5 | 37782 | + |
7f207e10 AM |
37783 | +out: |
37784 | + return file; | |
37785 | +} | |
37786 | + | |
37787 | +/* ---------------------------------------------------------------------- */ | |
37788 | + | |
37789 | +int au_xino_path(struct seq_file *seq, struct file *file) | |
37790 | +{ | |
37791 | + int err; | |
37792 | + | |
37793 | + err = au_seq_path(seq, &file->f_path); | |
79b8bda9 | 37794 | + if (unlikely(err)) |
7f207e10 AM |
37795 | + goto out; |
37796 | + | |
7f207e10 AM |
37797 | +#define Deleted "\\040(deleted)" |
37798 | + seq->count -= sizeof(Deleted) - 1; | |
37799 | + AuDebugOn(memcmp(seq->buf + seq->count, Deleted, | |
37800 | + sizeof(Deleted) - 1)); | |
37801 | +#undef Deleted | |
37802 | + | |
37803 | +out: | |
37804 | + return err; | |
37805 | +} | |
521ced18 JR |
37806 | + |
37807 | +/* ---------------------------------------------------------------------- */ | |
37808 | + | |
37809 | +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex, | |
37810 | + ino_t h_ino, int idx) | |
37811 | +{ | |
37812 | + struct au_xino_file *xino; | |
37813 | + | |
37814 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); | |
37815 | + xino = &au_sbr(sb, bindex)->br_xino; | |
37816 | + AuDebugOn(idx < 0 || xino->xi_nondir.total <= idx); | |
37817 | + | |
37818 | + spin_lock(&xino->xi_nondir.spin); | |
37819 | + AuDebugOn(xino->xi_nondir.array[idx] != h_ino); | |
37820 | + xino->xi_nondir.array[idx] = 0; | |
37821 | + spin_unlock(&xino->xi_nondir.spin); | |
37822 | + wake_up_all(&xino->xi_nondir.wqh); | |
37823 | +} | |
37824 | + | |
37825 | +static int au_xinondir_find(struct au_xino_file *xino, ino_t h_ino) | |
37826 | +{ | |
37827 | + int found, total, i; | |
37828 | + | |
37829 | + found = -1; | |
37830 | + total = xino->xi_nondir.total; | |
37831 | + for (i = 0; i < total; i++) { | |
37832 | + if (xino->xi_nondir.array[i] != h_ino) | |
37833 | + continue; | |
37834 | + found = i; | |
37835 | + break; | |
37836 | + } | |
37837 | + | |
37838 | + return found; | |
37839 | +} | |
37840 | + | |
37841 | +static int au_xinondir_expand(struct au_xino_file *xino) | |
37842 | +{ | |
37843 | + int err, sz; | |
37844 | + ino_t *p; | |
37845 | + | |
37846 | + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX); | |
37847 | + | |
37848 | + err = -ENOMEM; | |
37849 | + sz = xino->xi_nondir.total * sizeof(ino_t); | |
37850 | + if (unlikely(sz > KMALLOC_MAX_SIZE / 2)) | |
37851 | + goto out; | |
37852 | + p = au_kzrealloc(xino->xi_nondir.array, sz, sz << 1, GFP_ATOMIC, | |
37853 | + /*may_shrink*/0); | |
37854 | + if (p) { | |
37855 | + xino->xi_nondir.array = p; | |
37856 | + xino->xi_nondir.total <<= 1; | |
37857 | + AuDbg("xi_nondir.total %d\n", xino->xi_nondir.total); | |
37858 | + err = 0; | |
37859 | + } | |
37860 | + | |
37861 | +out: | |
37862 | + return err; | |
37863 | +} | |
37864 | + | |
37865 | +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
37866 | + int *idx) | |
37867 | +{ | |
37868 | + int err, found, empty; | |
37869 | + struct au_xino_file *xino; | |
37870 | + | |
37871 | + err = 0; | |
37872 | + *idx = -1; | |
37873 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
37874 | + goto out; /* no xino */ | |
37875 | + | |
37876 | + xino = &au_sbr(sb, bindex)->br_xino; | |
37877 | + | |
37878 | +again: | |
37879 | + spin_lock(&xino->xi_nondir.spin); | |
37880 | + found = au_xinondir_find(xino, h_ino); | |
37881 | + if (found == -1) { | |
37882 | + empty = au_xinondir_find(xino, /*h_ino*/0); | |
37883 | + if (empty == -1) { | |
37884 | + empty = xino->xi_nondir.total; | |
37885 | + err = au_xinondir_expand(xino); | |
37886 | + if (unlikely(err)) | |
37887 | + goto out_unlock; | |
37888 | + } | |
37889 | + xino->xi_nondir.array[empty] = h_ino; | |
37890 | + *idx = empty; | |
37891 | + } else { | |
37892 | + spin_unlock(&xino->xi_nondir.spin); | |
37893 | + wait_event(xino->xi_nondir.wqh, | |
37894 | + xino->xi_nondir.array[found] != h_ino); | |
37895 | + goto again; | |
37896 | + } | |
37897 | + | |
37898 | +out_unlock: | |
37899 | + spin_unlock(&xino->xi_nondir.spin); | |
37900 | +out: | |
37901 | + return err; | |
37902 | +} | |
537831f9 AM |
37903 | diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h |
37904 | --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100 | |
2121bcd9 | 37905 | +++ linux/include/uapi/linux/aufs_type.h 2018-01-29 07:56:20.063325368 +0100 |
8b6a4947 | 37906 | @@ -0,0 +1,447 @@ |
7f207e10 | 37907 | +/* |
a2654f78 | 37908 | + * Copyright (C) 2005-2017 Junjiro R. Okajima |
7f207e10 AM |
37909 | + * |
37910 | + * This program, aufs is free software; you can redistribute it and/or modify | |
37911 | + * it under the terms of the GNU General Public License as published by | |
37912 | + * the Free Software Foundation; either version 2 of the License, or | |
37913 | + * (at your option) any later version. | |
37914 | + * | |
37915 | + * This program is distributed in the hope that it will be useful, | |
37916 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
37917 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
37918 | + * GNU General Public License for more details. | |
37919 | + * | |
37920 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 37921 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
37922 | + */ |
37923 | + | |
37924 | +#ifndef __AUFS_TYPE_H__ | |
37925 | +#define __AUFS_TYPE_H__ | |
37926 | + | |
f6c5ef8b AM |
37927 | +#define AUFS_NAME "aufs" |
37928 | + | |
9dbd164d | 37929 | +#ifdef __KERNEL__ |
f6c5ef8b AM |
37930 | +/* |
37931 | + * define it before including all other headers. | |
37932 | + * sched.h may use pr_* macros before defining "current", so define the | |
37933 | + * no-current version first, and re-define later. | |
37934 | + */ | |
37935 | +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__ | |
37936 | +#include <linux/sched.h> | |
37937 | +#undef pr_fmt | |
a2a7ad62 AM |
37938 | +#define pr_fmt(fmt) \ |
37939 | + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \ | |
37940 | + (int)sizeof(current->comm), current->comm, current->pid | |
9dbd164d AM |
37941 | +#else |
37942 | +#include <stdint.h> | |
37943 | +#include <sys/types.h> | |
f6c5ef8b | 37944 | +#endif /* __KERNEL__ */ |
7f207e10 | 37945 | + |
f6c5ef8b AM |
37946 | +#include <linux/limits.h> |
37947 | + | |
2121bcd9 | 37948 | +#define AUFS_VERSION "4.x-rcN-20171218" |
7f207e10 AM |
37949 | + |
37950 | +/* todo? move this to linux-2.6.19/include/magic.h */ | |
37951 | +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's') | |
37952 | + | |
37953 | +/* ---------------------------------------------------------------------- */ | |
37954 | + | |
37955 | +#ifdef CONFIG_AUFS_BRANCH_MAX_127 | |
9dbd164d | 37956 | +typedef int8_t aufs_bindex_t; |
7f207e10 AM |
37957 | +#define AUFS_BRANCH_MAX 127 |
37958 | +#else | |
9dbd164d | 37959 | +typedef int16_t aufs_bindex_t; |
7f207e10 AM |
37960 | +#ifdef CONFIG_AUFS_BRANCH_MAX_511 |
37961 | +#define AUFS_BRANCH_MAX 511 | |
37962 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023) | |
37963 | +#define AUFS_BRANCH_MAX 1023 | |
37964 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767) | |
37965 | +#define AUFS_BRANCH_MAX 32767 | |
37966 | +#endif | |
37967 | +#endif | |
37968 | + | |
37969 | +#ifdef __KERNEL__ | |
37970 | +#ifndef AUFS_BRANCH_MAX | |
37971 | +#error unknown CONFIG_AUFS_BRANCH_MAX value | |
37972 | +#endif | |
37973 | +#endif /* __KERNEL__ */ | |
37974 | + | |
37975 | +/* ---------------------------------------------------------------------- */ | |
37976 | + | |
7f207e10 AM |
37977 | +#define AUFS_FSTYPE AUFS_NAME |
37978 | + | |
37979 | +#define AUFS_ROOT_INO 2 | |
37980 | +#define AUFS_FIRST_INO 11 | |
37981 | + | |
37982 | +#define AUFS_WH_PFX ".wh." | |
37983 | +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1) | |
37984 | +#define AUFS_WH_TMP_LEN 4 | |
86dc4139 | 37985 | +/* a limit for rmdir/rename a dir and copyup */ |
7f207e10 AM |
37986 | +#define AUFS_MAX_NAMELEN (NAME_MAX \ |
37987 | + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\ | |
37988 | + - 1 /* dot */\ | |
37989 | + - AUFS_WH_TMP_LEN) /* hex */ | |
37990 | +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino" | |
37991 | +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME | |
392086de AM |
37992 | +#define AUFS_XINO_DEF_SEC 30 /* seconds */ |
37993 | +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */ | |
7f207e10 AM |
37994 | +#define AUFS_DIRWH_DEF 3 |
37995 | +#define AUFS_RDCACHE_DEF 10 /* seconds */ | |
027c5e7a | 37996 | +#define AUFS_RDCACHE_MAX 3600 /* seconds */ |
7f207e10 AM |
37997 | +#define AUFS_RDBLK_DEF 512 /* bytes */ |
37998 | +#define AUFS_RDHASH_DEF 32 | |
37999 | +#define AUFS_WKQ_NAME AUFS_NAME "d" | |
027c5e7a AM |
38000 | +#define AUFS_MFS_DEF_SEC 30 /* seconds */ |
38001 | +#define AUFS_MFS_MAX_SEC 3600 /* seconds */ | |
076b876e | 38002 | +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */ |
86dc4139 | 38003 | +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */ |
7f207e10 AM |
38004 | + |
38005 | +/* pseudo-link maintenace under /proc */ | |
38006 | +#define AUFS_PLINK_MAINT_NAME "plink_maint" | |
38007 | +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME | |
38008 | +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME | |
38009 | + | |
8b6a4947 AM |
38010 | +/* dirren, renamed dir */ |
38011 | +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr." | |
38012 | +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino" | |
38013 | +/* whiteouted doubly */ | |
38014 | +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX | |
38015 | +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME | |
38016 | + | |
7f207e10 AM |
38017 | +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */ |
38018 | +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME | |
38019 | + | |
38020 | +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME | |
38021 | +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk" | |
38022 | +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph" | |
38023 | + | |
38024 | +/* doubly whiteouted */ | |
38025 | +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME | |
38026 | +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME | |
38027 | +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME | |
38028 | + | |
1e00d052 | 38029 | +/* branch permissions and attributes */ |
7f207e10 AM |
38030 | +#define AUFS_BRPERM_RW "rw" |
38031 | +#define AUFS_BRPERM_RO "ro" | |
38032 | +#define AUFS_BRPERM_RR "rr" | |
076b876e AM |
38033 | +#define AUFS_BRATTR_COO_REG "coo_reg" |
38034 | +#define AUFS_BRATTR_COO_ALL "coo_all" | |
38035 | +#define AUFS_BRATTR_FHSM "fhsm" | |
38036 | +#define AUFS_BRATTR_UNPIN "unpin" | |
c1595e42 JR |
38037 | +#define AUFS_BRATTR_ICEX "icex" |
38038 | +#define AUFS_BRATTR_ICEX_SEC "icexsec" | |
38039 | +#define AUFS_BRATTR_ICEX_SYS "icexsys" | |
38040 | +#define AUFS_BRATTR_ICEX_TR "icextr" | |
38041 | +#define AUFS_BRATTR_ICEX_USR "icexusr" | |
38042 | +#define AUFS_BRATTR_ICEX_OTH "icexoth" | |
1e00d052 AM |
38043 | +#define AUFS_BRRATTR_WH "wh" |
38044 | +#define AUFS_BRWATTR_NLWH "nolwh" | |
076b876e AM |
38045 | +#define AUFS_BRWATTR_MOO "moo" |
38046 | + | |
38047 | +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */ | |
38048 | +#define AuBrPerm_RO (1 << 1) /* readonly */ | |
38049 | +#define AuBrPerm_RR (1 << 2) /* natively readonly */ | |
38050 | +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR) | |
38051 | + | |
38052 | +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */ | |
38053 | +#define AuBrAttr_COO_ALL (1 << 4) | |
38054 | +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL) | |
38055 | + | |
38056 | +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */ | |
38057 | +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of | |
c1595e42 JR |
38058 | + branch. meaningless since |
38059 | + linux-3.18-rc1 */ | |
38060 | + | |
38061 | +/* ignore error in copying XATTR */ | |
38062 | +#define AuBrAttr_ICEX_SEC (1 << 7) | |
38063 | +#define AuBrAttr_ICEX_SYS (1 << 8) | |
38064 | +#define AuBrAttr_ICEX_TR (1 << 9) | |
38065 | +#define AuBrAttr_ICEX_USR (1 << 10) | |
38066 | +#define AuBrAttr_ICEX_OTH (1 << 11) | |
38067 | +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \ | |
38068 | + | AuBrAttr_ICEX_SYS \ | |
38069 | + | AuBrAttr_ICEX_TR \ | |
38070 | + | AuBrAttr_ICEX_USR \ | |
38071 | + | AuBrAttr_ICEX_OTH) | |
38072 | + | |
38073 | +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */ | |
076b876e AM |
38074 | +#define AuBrRAttr_Mask AuBrRAttr_WH |
38075 | + | |
c1595e42 JR |
38076 | +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */ |
38077 | +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */ | |
076b876e AM |
38078 | +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO) |
38079 | + | |
38080 | +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO) | |
38081 | + | |
c1595e42 | 38082 | +/* #warning test userspace */ |
076b876e AM |
38083 | +#ifdef __KERNEL__ |
38084 | +#ifndef CONFIG_AUFS_FHSM | |
38085 | +#undef AuBrAttr_FHSM | |
38086 | +#define AuBrAttr_FHSM 0 | |
38087 | +#endif | |
c1595e42 JR |
38088 | +#ifndef CONFIG_AUFS_XATTR |
38089 | +#undef AuBrAttr_ICEX | |
38090 | +#define AuBrAttr_ICEX 0 | |
38091 | +#undef AuBrAttr_ICEX_SEC | |
38092 | +#define AuBrAttr_ICEX_SEC 0 | |
38093 | +#undef AuBrAttr_ICEX_SYS | |
38094 | +#define AuBrAttr_ICEX_SYS 0 | |
38095 | +#undef AuBrAttr_ICEX_TR | |
38096 | +#define AuBrAttr_ICEX_TR 0 | |
38097 | +#undef AuBrAttr_ICEX_USR | |
38098 | +#define AuBrAttr_ICEX_USR 0 | |
38099 | +#undef AuBrAttr_ICEX_OTH | |
38100 | +#define AuBrAttr_ICEX_OTH 0 | |
38101 | +#endif | |
076b876e AM |
38102 | +#endif |
38103 | + | |
38104 | +/* the longest combination */ | |
c1595e42 JR |
38105 | +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */ |
38106 | +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \ | |
38107 | + "+" AUFS_BRATTR_COO_REG \ | |
38108 | + "+" AUFS_BRATTR_FHSM \ | |
38109 | + "+" AUFS_BRATTR_UNPIN \ | |
7e9cd9fe AM |
38110 | + "+" AUFS_BRATTR_ICEX_SEC \ |
38111 | + "+" AUFS_BRATTR_ICEX_SYS \ | |
38112 | + "+" AUFS_BRATTR_ICEX_USR \ | |
38113 | + "+" AUFS_BRATTR_ICEX_OTH \ | |
076b876e AM |
38114 | + "+" AUFS_BRWATTR_NLWH) |
38115 | + | |
38116 | +typedef struct { | |
38117 | + char a[AuBrPermStrSz]; | |
38118 | +} au_br_perm_str_t; | |
38119 | + | |
38120 | +static inline int au_br_writable(int brperm) | |
38121 | +{ | |
38122 | + return brperm & AuBrPerm_RW; | |
38123 | +} | |
38124 | + | |
38125 | +static inline int au_br_whable(int brperm) | |
38126 | +{ | |
38127 | + return brperm & (AuBrPerm_RW | AuBrRAttr_WH); | |
38128 | +} | |
38129 | + | |
38130 | +static inline int au_br_wh_linkable(int brperm) | |
38131 | +{ | |
38132 | + return !(brperm & AuBrWAttr_NoLinkWH); | |
38133 | +} | |
38134 | + | |
38135 | +static inline int au_br_cmoo(int brperm) | |
38136 | +{ | |
38137 | + return brperm & AuBrAttr_CMOO_Mask; | |
38138 | +} | |
38139 | + | |
38140 | +static inline int au_br_fhsm(int brperm) | |
38141 | +{ | |
38142 | + return brperm & AuBrAttr_FHSM; | |
38143 | +} | |
7f207e10 AM |
38144 | + |
38145 | +/* ---------------------------------------------------------------------- */ | |
38146 | + | |
38147 | +/* ioctl */ | |
38148 | +enum { | |
38149 | + /* readdir in userspace */ | |
38150 | + AuCtl_RDU, | |
38151 | + AuCtl_RDU_INO, | |
38152 | + | |
076b876e AM |
38153 | + AuCtl_WBR_FD, /* pathconf wrapper */ |
38154 | + AuCtl_IBUSY, /* busy inode */ | |
38155 | + AuCtl_MVDOWN, /* move-down */ | |
38156 | + AuCtl_BR, /* info about branches */ | |
38157 | + AuCtl_FHSM_FD /* connection for fhsm */ | |
7f207e10 AM |
38158 | +}; |
38159 | + | |
38160 | +/* borrowed from linux/include/linux/kernel.h */ | |
38161 | +#ifndef ALIGN | |
38162 | +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) | |
38163 | +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) | |
38164 | +#endif | |
38165 | + | |
38166 | +/* borrowed from linux/include/linux/compiler-gcc3.h */ | |
38167 | +#ifndef __aligned | |
38168 | +#define __aligned(x) __attribute__((aligned(x))) | |
53392da6 AM |
38169 | +#endif |
38170 | + | |
38171 | +#ifdef __KERNEL__ | |
38172 | +#ifndef __packed | |
7f207e10 AM |
38173 | +#define __packed __attribute__((packed)) |
38174 | +#endif | |
53392da6 | 38175 | +#endif |
7f207e10 AM |
38176 | + |
38177 | +struct au_rdu_cookie { | |
9dbd164d AM |
38178 | + uint64_t h_pos; |
38179 | + int16_t bindex; | |
38180 | + uint8_t flags; | |
38181 | + uint8_t pad; | |
38182 | + uint32_t generation; | |
7f207e10 AM |
38183 | +} __aligned(8); |
38184 | + | |
38185 | +struct au_rdu_ent { | |
9dbd164d AM |
38186 | + uint64_t ino; |
38187 | + int16_t bindex; | |
38188 | + uint8_t type; | |
38189 | + uint8_t nlen; | |
38190 | + uint8_t wh; | |
7f207e10 AM |
38191 | + char name[0]; |
38192 | +} __aligned(8); | |
38193 | + | |
38194 | +static inline int au_rdu_len(int nlen) | |
38195 | +{ | |
38196 | + /* include the terminating NULL */ | |
38197 | + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1, | |
9dbd164d | 38198 | + sizeof(uint64_t)); |
7f207e10 AM |
38199 | +} |
38200 | + | |
38201 | +union au_rdu_ent_ul { | |
38202 | + struct au_rdu_ent __user *e; | |
9dbd164d | 38203 | + uint64_t ul; |
7f207e10 AM |
38204 | +}; |
38205 | + | |
38206 | +enum { | |
38207 | + AufsCtlRduV_SZ, | |
38208 | + AufsCtlRduV_End | |
38209 | +}; | |
38210 | + | |
38211 | +struct aufs_rdu { | |
38212 | + /* input */ | |
38213 | + union { | |
9dbd164d AM |
38214 | + uint64_t sz; /* AuCtl_RDU */ |
38215 | + uint64_t nent; /* AuCtl_RDU_INO */ | |
7f207e10 AM |
38216 | + }; |
38217 | + union au_rdu_ent_ul ent; | |
9dbd164d | 38218 | + uint16_t verify[AufsCtlRduV_End]; |
7f207e10 AM |
38219 | + |
38220 | + /* input/output */ | |
9dbd164d | 38221 | + uint32_t blk; |
7f207e10 AM |
38222 | + |
38223 | + /* output */ | |
38224 | + union au_rdu_ent_ul tail; | |
38225 | + /* number of entries which were added in a single call */ | |
9dbd164d AM |
38226 | + uint64_t rent; |
38227 | + uint8_t full; | |
38228 | + uint8_t shwh; | |
7f207e10 AM |
38229 | + |
38230 | + struct au_rdu_cookie cookie; | |
38231 | +} __aligned(8); | |
38232 | + | |
1e00d052 AM |
38233 | +/* ---------------------------------------------------------------------- */ |
38234 | + | |
8b6a4947 AM |
38235 | +/* dirren. the branch is identified by the filename who contains this */ |
38236 | +struct au_drinfo { | |
38237 | + uint64_t ino; | |
38238 | + union { | |
38239 | + uint8_t oldnamelen; | |
38240 | + uint64_t _padding; | |
38241 | + }; | |
38242 | + uint8_t oldname[0]; | |
38243 | +} __aligned(8); | |
38244 | + | |
38245 | +struct au_drinfo_fdata { | |
38246 | + uint32_t magic; | |
38247 | + struct au_drinfo drinfo; | |
38248 | +} __aligned(8); | |
38249 | + | |
38250 | +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01) | |
38251 | +/* future */ | |
38252 | +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02) | |
38253 | + | |
38254 | +/* ---------------------------------------------------------------------- */ | |
38255 | + | |
1e00d052 | 38256 | +struct aufs_wbr_fd { |
9dbd164d AM |
38257 | + uint32_t oflags; |
38258 | + int16_t brid; | |
1e00d052 AM |
38259 | +} __aligned(8); |
38260 | + | |
38261 | +/* ---------------------------------------------------------------------- */ | |
38262 | + | |
027c5e7a | 38263 | +struct aufs_ibusy { |
9dbd164d AM |
38264 | + uint64_t ino, h_ino; |
38265 | + int16_t bindex; | |
027c5e7a AM |
38266 | +} __aligned(8); |
38267 | + | |
1e00d052 AM |
38268 | +/* ---------------------------------------------------------------------- */ |
38269 | + | |
392086de AM |
38270 | +/* error code for move-down */ |
38271 | +/* the actual message strings are implemented in aufs-util.git */ | |
38272 | +enum { | |
38273 | + EAU_MVDOWN_OPAQUE = 1, | |
38274 | + EAU_MVDOWN_WHITEOUT, | |
38275 | + EAU_MVDOWN_UPPER, | |
38276 | + EAU_MVDOWN_BOTTOM, | |
38277 | + EAU_MVDOWN_NOUPPER, | |
38278 | + EAU_MVDOWN_NOLOWERBR, | |
38279 | + EAU_Last | |
38280 | +}; | |
38281 | + | |
c2b27bf2 | 38282 | +/* flags for move-down */ |
392086de AM |
38283 | +#define AUFS_MVDOWN_DMSG 1 |
38284 | +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */ | |
38285 | +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */ | |
38286 | +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */ | |
38287 | +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */ | |
38288 | +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */ | |
38289 | +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */ | |
38290 | +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */ | |
38291 | +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */ | |
076b876e AM |
38292 | +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */ |
38293 | +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */ | |
38294 | +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */ | |
38295 | +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */ | |
c2b27bf2 | 38296 | + |
076b876e | 38297 | +/* index for move-down */ |
392086de AM |
38298 | +enum { |
38299 | + AUFS_MVDOWN_UPPER, | |
38300 | + AUFS_MVDOWN_LOWER, | |
38301 | + AUFS_MVDOWN_NARRAY | |
38302 | +}; | |
38303 | + | |
076b876e AM |
38304 | +/* |
38305 | + * additional info of move-down | |
38306 | + * number of free blocks and inodes. | |
38307 | + * subset of struct kstatfs, but smaller and always 64bit. | |
38308 | + */ | |
38309 | +struct aufs_stfs { | |
38310 | + uint64_t f_blocks; | |
38311 | + uint64_t f_bavail; | |
38312 | + uint64_t f_files; | |
38313 | + uint64_t f_ffree; | |
38314 | +}; | |
38315 | + | |
38316 | +struct aufs_stbr { | |
38317 | + int16_t brid; /* optional input */ | |
38318 | + int16_t bindex; /* output */ | |
38319 | + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */ | |
38320 | +} __aligned(8); | |
38321 | + | |
c2b27bf2 | 38322 | +struct aufs_mvdown { |
076b876e AM |
38323 | + uint32_t flags; /* input/output */ |
38324 | + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */ | |
38325 | + int8_t au_errno; /* output */ | |
38326 | +} __aligned(8); | |
38327 | + | |
38328 | +/* ---------------------------------------------------------------------- */ | |
38329 | + | |
38330 | +union aufs_brinfo { | |
38331 | + /* PATH_MAX may differ between kernel-space and user-space */ | |
38332 | + char _spacer[4096]; | |
392086de | 38333 | + struct { |
076b876e AM |
38334 | + int16_t id; |
38335 | + int perm; | |
38336 | + char path[0]; | |
38337 | + }; | |
c2b27bf2 AM |
38338 | +} __aligned(8); |
38339 | + | |
38340 | +/* ---------------------------------------------------------------------- */ | |
38341 | + | |
7f207e10 AM |
38342 | +#define AuCtlType 'A' |
38343 | +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu) | |
38344 | +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu) | |
1e00d052 AM |
38345 | +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \ |
38346 | + struct aufs_wbr_fd) | |
027c5e7a | 38347 | +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy) |
392086de AM |
38348 | +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \ |
38349 | + struct aufs_mvdown) | |
076b876e AM |
38350 | +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo) |
38351 | +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int) | |
7f207e10 AM |
38352 | + |
38353 | +#endif /* __AUFS_TYPE_H__ */ | |
2121bcd9 | 38354 | SPDX-License-Identifier: GPL-2.0 |
ffa93bbd | 38355 | aufs4.x-rcN loopback patch |
5527c038 JR |
38356 | |
38357 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c | |
2121bcd9 | 38358 | index e51a59d..b4f7d3a 100644 |
5527c038 JR |
38359 | --- a/drivers/block/loop.c |
38360 | +++ b/drivers/block/loop.c | |
2121bcd9 | 38361 | @@ -600,6 +600,15 @@ static inline void loop_update_dio(struct loop_device *lo) |
8b6a4947 | 38362 | lo->use_dio); |
5527c038 JR |
38363 | } |
38364 | ||
5527c038 JR |
38365 | +static struct file *loop_real_file(struct file *file) |
38366 | +{ | |
38367 | + struct file *f = NULL; | |
38368 | + | |
38369 | + if (file->f_path.dentry->d_sb->s_op->real_loop) | |
38370 | + f = file->f_path.dentry->d_sb->s_op->real_loop(file); | |
38371 | + return f; | |
8b6a4947 AM |
38372 | +} |
38373 | + | |
c2c0f25c | 38374 | static void loop_reread_partitions(struct loop_device *lo, |
8b6a4947 AM |
38375 | struct block_device *bdev) |
38376 | { | |
2121bcd9 | 38377 | @@ -634,6 +643,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
38378 | unsigned int arg) |
38379 | { | |
38380 | struct file *file, *old_file; | |
38381 | + struct file *f, *virt_file = NULL, *old_virt_file; | |
38382 | struct inode *inode; | |
38383 | int error; | |
38384 | ||
2121bcd9 | 38385 | @@ -650,9 +660,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
38386 | file = fget(arg); |
38387 | if (!file) | |
38388 | goto out; | |
38389 | + f = loop_real_file(file); | |
38390 | + if (f) { | |
38391 | + virt_file = file; | |
38392 | + file = f; | |
38393 | + get_file(file); | |
38394 | + } | |
38395 | ||
38396 | inode = file->f_mapping->host; | |
38397 | old_file = lo->lo_backing_file; | |
38398 | + old_virt_file = lo->lo_backing_virt_file; | |
38399 | ||
38400 | error = -EINVAL; | |
38401 | ||
2121bcd9 | 38402 | @@ -667,6 +684,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
8b6a4947 AM |
38403 | blk_mq_freeze_queue(lo->lo_queue); |
38404 | mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); | |
38405 | lo->lo_backing_file = file; | |
38406 | + lo->lo_backing_virt_file = virt_file; | |
38407 | lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping); | |
38408 | mapping_set_gfp_mask(file->f_mapping, | |
38409 | lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); | |
2121bcd9 | 38410 | @@ -674,12 +692,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
8b6a4947 | 38411 | blk_mq_unfreeze_queue(lo->lo_queue); |
5527c038 JR |
38412 | |
38413 | fput(old_file); | |
38414 | + if (old_virt_file) | |
38415 | + fput(old_virt_file); | |
38416 | if (lo->lo_flags & LO_FLAGS_PARTSCAN) | |
c2c0f25c | 38417 | loop_reread_partitions(lo, bdev); |
5527c038 JR |
38418 | return 0; |
38419 | ||
38420 | out_putf: | |
38421 | fput(file); | |
38422 | + if (virt_file) | |
38423 | + fput(virt_file); | |
38424 | out: | |
38425 | return error; | |
38426 | } | |
2121bcd9 | 38427 | @@ -873,7 +895,7 @@ static int loop_prepare_queue(struct loop_device *lo) |
5527c038 JR |
38428 | static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
38429 | struct block_device *bdev, unsigned int arg) | |
38430 | { | |
38431 | - struct file *file, *f; | |
38432 | + struct file *file, *f, *virt_file = NULL; | |
38433 | struct inode *inode; | |
38434 | struct address_space *mapping; | |
8b6a4947 | 38435 | int lo_flags = 0; |
2121bcd9 | 38436 | @@ -887,6 +909,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
38437 | file = fget(arg); |
38438 | if (!file) | |
38439 | goto out; | |
38440 | + f = loop_real_file(file); | |
38441 | + if (f) { | |
38442 | + virt_file = file; | |
38443 | + file = f; | |
38444 | + get_file(file); | |
38445 | + } | |
38446 | ||
38447 | error = -EBUSY; | |
38448 | if (lo->lo_state != Lo_unbound) | |
2121bcd9 | 38449 | @@ -935,6 +963,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
38450 | lo->lo_device = bdev; |
38451 | lo->lo_flags = lo_flags; | |
38452 | lo->lo_backing_file = file; | |
38453 | + lo->lo_backing_virt_file = virt_file; | |
38454 | lo->transfer = NULL; | |
38455 | lo->ioctl = NULL; | |
38456 | lo->lo_sizelimit = 0; | |
2121bcd9 | 38457 | @@ -968,6 +997,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
38458 | |
38459 | out_putf: | |
38460 | fput(file); | |
38461 | + if (virt_file) | |
38462 | + fput(virt_file); | |
38463 | out: | |
38464 | /* This is safe: open() is still holding a reference. */ | |
38465 | module_put(THIS_MODULE); | |
2121bcd9 | 38466 | @@ -1014,6 +1045,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, |
5527c038 JR |
38467 | static int loop_clr_fd(struct loop_device *lo) |
38468 | { | |
38469 | struct file *filp = lo->lo_backing_file; | |
38470 | + struct file *virt_filp = lo->lo_backing_virt_file; | |
38471 | gfp_t gfp = lo->old_gfp_mask; | |
38472 | struct block_device *bdev = lo->lo_device; | |
38473 | ||
2121bcd9 | 38474 | @@ -1045,6 +1077,7 @@ static int loop_clr_fd(struct loop_device *lo) |
5527c038 JR |
38475 | spin_lock_irq(&lo->lo_lock); |
38476 | lo->lo_state = Lo_rundown; | |
38477 | lo->lo_backing_file = NULL; | |
38478 | + lo->lo_backing_virt_file = NULL; | |
38479 | spin_unlock_irq(&lo->lo_lock); | |
38480 | ||
38481 | loop_release_xfer(lo); | |
2121bcd9 | 38482 | @@ -1092,6 +1125,8 @@ static int loop_clr_fd(struct loop_device *lo) |
5527c038 JR |
38483 | * bd_mutex which is usually taken before lo_ctl_mutex. |
38484 | */ | |
38485 | fput(filp); | |
38486 | + if (virt_filp) | |
38487 | + fput(virt_filp); | |
38488 | return 0; | |
38489 | } | |
38490 | ||
38491 | diff --git a/drivers/block/loop.h b/drivers/block/loop.h | |
2121bcd9 | 38492 | index 0f45416..101f193 100644 |
5527c038 JR |
38493 | --- a/drivers/block/loop.h |
38494 | +++ b/drivers/block/loop.h | |
38495 | @@ -46,7 +46,7 @@ struct loop_device { | |
38496 | int (*ioctl)(struct loop_device *, int cmd, | |
38497 | unsigned long arg); | |
38498 | ||
38499 | - struct file * lo_backing_file; | |
38500 | + struct file * lo_backing_file, *lo_backing_virt_file; | |
38501 | struct block_device *lo_device; | |
5527c038 | 38502 | void *key_data; |
8b6a4947 | 38503 | |
5527c038 | 38504 | diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c |
2121bcd9 | 38505 | index 0d4ea929..af293c2 100644 |
5527c038 JR |
38506 | --- a/fs/aufs/f_op.c |
38507 | +++ b/fs/aufs/f_op.c | |
2121bcd9 | 38508 | @@ -358,7 +358,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
5527c038 JR |
38509 | if (IS_ERR(h_file)) |
38510 | goto out; | |
38511 | ||
38512 | - if (au_test_loopback_kthread()) { | |
38513 | + if (0 && au_test_loopback_kthread()) { | |
38514 | au_warn_loopback(h_file->f_path.dentry->d_sb); | |
38515 | if (file->f_mapping != h_file->f_mapping) { | |
38516 | file->f_mapping = h_file->f_mapping; | |
38517 | diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c | |
2121bcd9 | 38518 | index 3b217c2..0f5ab22 100644 |
5527c038 JR |
38519 | --- a/fs/aufs/loop.c |
38520 | +++ b/fs/aufs/loop.c | |
2121bcd9 | 38521 | @@ -133,3 +133,19 @@ void au_loopback_fin(void) |
79b8bda9 | 38522 | symbol_put(loop_backing_file); |
1c60b727 | 38523 | kfree(au_warn_loopback_array); |
5527c038 JR |
38524 | } |
38525 | + | |
38526 | +/* ---------------------------------------------------------------------- */ | |
38527 | + | |
38528 | +/* support the loopback block device insude aufs */ | |
38529 | + | |
38530 | +struct file *aufs_real_loop(struct file *file) | |
38531 | +{ | |
38532 | + struct file *f; | |
38533 | + | |
38534 | + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb)); | |
38535 | + fi_read_lock(file); | |
38536 | + f = au_hf_top(file); | |
38537 | + fi_read_unlock(file); | |
38538 | + AuDebugOn(!f); | |
38539 | + return f; | |
38540 | +} | |
38541 | diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h | |
2121bcd9 | 38542 | index 7d7bf34..ba7c188 100644 |
5527c038 JR |
38543 | --- a/fs/aufs/loop.h |
38544 | +++ b/fs/aufs/loop.h | |
2121bcd9 | 38545 | @@ -26,7 +26,11 @@ void au_warn_loopback(struct super_block *h_sb); |
5527c038 JR |
38546 | |
38547 | int au_loopback_init(void); | |
38548 | void au_loopback_fin(void); | |
38549 | + | |
38550 | +struct file *aufs_real_loop(struct file *file); | |
38551 | #else | |
38552 | +AuStub(struct file *, loop_backing_file, return NULL) | |
38553 | + | |
38554 | AuStubInt0(au_test_loopback_overlap, struct super_block *sb, | |
38555 | struct dentry *h_adding) | |
38556 | AuStubInt0(au_test_loopback_kthread, void) | |
2121bcd9 | 38557 | @@ -34,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
5527c038 JR |
38558 | |
38559 | AuStubInt0(au_loopback_init, void) | |
38560 | AuStubVoid(au_loopback_fin, void) | |
38561 | + | |
38562 | +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) | |
38563 | #endif /* BLK_DEV_LOOP */ | |
38564 | ||
38565 | #endif /* __KERNEL__ */ | |
38566 | diff --git a/fs/aufs/super.c b/fs/aufs/super.c | |
2121bcd9 | 38567 | index 357bf04..c6614df 100644 |
5527c038 JR |
38568 | --- a/fs/aufs/super.c |
38569 | +++ b/fs/aufs/super.c | |
2121bcd9 | 38570 | @@ -839,7 +839,10 @@ static const struct super_operations aufs_sop = { |
5527c038 JR |
38571 | .statfs = aufs_statfs, |
38572 | .put_super = aufs_put_super, | |
38573 | .sync_fs = aufs_sync_fs, | |
38574 | - .remount_fs = aufs_remount_fs | |
38575 | + .remount_fs = aufs_remount_fs, | |
38576 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
38577 | + .real_loop = aufs_real_loop | |
38578 | +#endif | |
38579 | }; | |
38580 | ||
38581 | /* ---------------------------------------------------------------------- */ | |
38582 | diff --git a/include/linux/fs.h b/include/linux/fs.h | |
2121bcd9 | 38583 | index 96e05b3..ba5e627 100644 |
5527c038 JR |
38584 | --- a/include/linux/fs.h |
38585 | +++ b/include/linux/fs.h | |
2121bcd9 | 38586 | @@ -1840,6 +1840,10 @@ struct super_operations { |
5527c038 JR |
38587 | struct shrink_control *); |
38588 | long (*free_cached_objects)(struct super_block *, | |
38589 | struct shrink_control *); | |
38590 | +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE) | |
38591 | + /* and aufs */ | |
38592 | + struct file *(*real_loop)(struct file *); | |
38593 | +#endif | |
38594 | }; | |
38595 | ||
38596 | /* |